From 55be6d83a152fa1f165bbf03eb67e847e1082e2d Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 6 Jan 2025 23:50:18 -0300 Subject: [PATCH 01/43] fix: fix asserts and assert messages in tests --- tests/_async/test_gotrue_admin_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 5eebd8eb..c0c59831 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -150,14 +150,14 @@ async def test_modify_confirm_email_using_update_user_by_id(): } ) assert response.user - assert not response.user.email_confirmed_at + assert not response.user.confirmed_at response = await service_role_api_client().update_user_by_id( response.user.id, { "email_confirm": True, }, ) - assert response.user.email_confirmed_at + assert response.user.confirmed_at async def test_delete_user_should_be_able_delete_an_existing_user(): @@ -254,7 +254,7 @@ async def test_verify_otp_with_non_existent_phone_number(): ) assert False except AuthError as e: - assert e.message == "User not found" + assert e.message == "Token has expired or is invalid" async def test_verify_otp_with_invalid_phone_number(): From 9837eb49c95a9cecbb6ba11a05b8d965a89f2986 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 6 Jan 2025 23:50:23 -0300 Subject: [PATCH 02/43] fix: fix asserts and assert messages in tests --- tests/_sync/test_gotrue_admin_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 44d24999..9800d5f4 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -150,14 +150,14 @@ def test_modify_confirm_email_using_update_user_by_id(): } ) assert response.user - assert not response.user.email_confirmed_at + assert not response.user.confirmed_at response = service_role_api_client().update_user_by_id( response.user.id, { "email_confirm": True, }, ) - assert response.user.email_confirmed_at + assert response.user.confirmed_at def test_delete_user_should_be_able_delete_an_existing_user(): @@ -254,7 +254,7 @@ def test_verify_otp_with_non_existent_phone_number(): ) assert False except AuthError as e: - assert e.message == "User not found" + assert e.message == "Token has expired or is invalid" def test_verify_otp_with_invalid_phone_number(): From 44b3ec3f1cca44738c990c30efbcee65efc2b3b3 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 18:30:19 -0300 Subject: [PATCH 03/43] feat: add missing cases for AuthError --- tests/_sync/test_gotrue_admin_api.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 9800d5f4..1d5ffeac 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -1,4 +1,4 @@ -from supabase_auth.errors import AuthError +from supabase_auth.errors import AuthError, AuthApiError, AuthWeakPasswordError from .clients import ( auth_client_with_session, @@ -160,6 +160,31 @@ def test_modify_confirm_email_using_update_user_by_id(): assert response.user.confirmed_at +def test_invalid_credential_sign_in(): + try: + client_api_auto_confirm_off_signups_enabled_client().sign_in_with_password( + { + "email": "unknown_user@unknowndomain.com", + "password": "strong_pwd", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +def test_weak_password_error(): + credentials = mock_user_credentials() + try: + client_api_auto_confirm_off_signups_enabled_client().sign_up( + { + "email": credentials.get("email"), + "password": "123", + } + ) + except AuthWeakPasswordError as e: + assert e.to_dict() + + def test_delete_user_should_be_able_delete_an_existing_user(): credentials = mock_user_credentials() user = create_new_user_with_email(email=credentials.get("email")) From 54dbe56baf57cdc5d68424c833ed330b814bae8a Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 18:38:37 -0300 Subject: [PATCH 04/43] fix: fix style wip --- tests/_async/test_gotrue_admin_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index c0c59831..5eebd8eb 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -150,14 +150,14 @@ async def test_modify_confirm_email_using_update_user_by_id(): } ) assert response.user - assert not response.user.confirmed_at + assert not response.user.email_confirmed_at response = await service_role_api_client().update_user_by_id( response.user.id, { "email_confirm": True, }, ) - assert response.user.confirmed_at + assert response.user.email_confirmed_at async def test_delete_user_should_be_able_delete_an_existing_user(): @@ -254,7 +254,7 @@ async def test_verify_otp_with_non_existent_phone_number(): ) assert False except AuthError as e: - assert e.message == "Token has expired or is invalid" + assert e.message == "User not found" async def test_verify_otp_with_invalid_phone_number(): From cc17ee9447834475439a51d529e7b916ebac3ad9 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 18:38:44 -0300 Subject: [PATCH 05/43] fix: fix style wip --- tests/_sync/test_gotrue_admin_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 1d5ffeac..68d124f4 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -1,4 +1,4 @@ -from supabase_auth.errors import AuthError, AuthApiError, AuthWeakPasswordError +from supabase_auth.errors import AuthApiError, AuthError, AuthWeakPasswordError from .clients import ( auth_client_with_session, @@ -150,14 +150,14 @@ def test_modify_confirm_email_using_update_user_by_id(): } ) assert response.user - assert not response.user.confirmed_at + assert not response.user.email_confirmed_at response = service_role_api_client().update_user_by_id( response.user.id, { "email_confirm": True, }, ) - assert response.user.confirmed_at + assert response.user.email_confirmed_at def test_invalid_credential_sign_in(): @@ -279,7 +279,7 @@ def test_verify_otp_with_non_existent_phone_number(): ) assert False except AuthError as e: - assert e.message == "Token has expired or is invalid" + assert e.message == "User not found" def test_verify_otp_with_invalid_phone_number(): From 48a01caef05200763ed1d047bab1fccf5b69f764 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 18:45:27 -0300 Subject: [PATCH 06/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 68d124f4..5b5b4d60 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -172,17 +172,17 @@ def test_invalid_credential_sign_in(): assert e.to_dict() -def test_weak_password_error(): - credentials = mock_user_credentials() - try: - client_api_auto_confirm_off_signups_enabled_client().sign_up( - { - "email": credentials.get("email"), - "password": "123", - } - ) - except AuthWeakPasswordError as e: - assert e.to_dict() +# def test_weak_password_error(): +# credentials = mock_user_credentials() +# try: +# client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "email": credentials.get("email"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() def test_delete_user_should_be_able_delete_an_existing_user(): From 3ce9b0bc0a449aae5d160f0c3c0d027c43dcb8a8 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 18:50:26 -0300 Subject: [PATCH 07/43] fix: fix style wip --- tests/_sync/test_gotrue_admin_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 5b5b4d60..2d359671 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -1,4 +1,4 @@ -from supabase_auth.errors import AuthApiError, AuthError, AuthWeakPasswordError +from supabase_auth.errors import AuthApiError, AuthError from .clients import ( auth_client_with_session, From bbc73223cd8c80c933f7f60e12a713219c40e4bf Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 19:18:05 -0300 Subject: [PATCH 08/43] feat: add tests WIP --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98acbb8b..e429edac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,7 @@ jobs: pip install pydantic==1.10.12 make tests_only - name: Upload coverage to Coveralls + if: ${{ matrix.python-version }} == "3.12" uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 6c6f75816e9292011c8c51b08293f83b76494865 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 19:18:10 -0300 Subject: [PATCH 09/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 109 ++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 3 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 2d359671..66406bce 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -1,4 +1,10 @@ -from supabase_auth.errors import AuthApiError, AuthError +from supabase_auth.errors import ( + AuthApiError, + AuthError, + AuthInvalidCredentialsError, + AuthSessionMissingError, + AuthWeakPasswordError, +) from .clients import ( auth_client_with_session, @@ -160,7 +166,19 @@ def test_modify_confirm_email_using_update_user_by_id(): assert response.user.email_confirmed_at -def test_invalid_credential_sign_in(): +def test_invalid_credential_sign_in_with_phone(): + try: + client_api_auto_confirm_off_signups_enabled_client().sign_in_with_password( + { + "phone": "+123456789", + "password": "strong_pwd", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +def test_invalid_credential_sign_in_with_email(): try: client_api_auto_confirm_off_signups_enabled_client().sign_in_with_password( { @@ -172,7 +190,71 @@ def test_invalid_credential_sign_in(): assert e.to_dict() -# def test_weak_password_error(): +def test_sign_in_with_otp_email(): + try: + client_api_auto_confirm_off_signups_enabled_client().sign_in_with_otp( + { + "email": "unknown_user@unknowndomain.com", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +def test_sign_in_with_otp_phone(): + try: + client_api_auto_confirm_off_signups_enabled_client().sign_in_with_otp( + { + "phone": "+112345678", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +def test_resend(): + try: + client_api_auto_confirm_off_signups_enabled_client().resend( + {"phone": "+112345678", "type": "sms"} + ) + except AuthApiError as e: + assert e.to_dict() + + +def test_reauthenticate(): + try: + response = auth_client_with_session().reauthenticate() + except AuthSessionMissingError: + pass + + +def test_refresh_session(): + try: + response = auth_client_with_session().refresh_session() + except AuthSessionMissingError: + pass + + +def test_reset_password_for_email(): + credentials = mock_user_credentials() + try: + response = auth_client_with_session().reset_password_email( + email=credentials.get("email") + ) + except AuthSessionMissingError: + pass + + +def test_resend_missing_credentials(): + try: + client_api_auto_confirm_off_signups_enabled_client().resend( + {"type": "email_change"} + ) + except AuthInvalidCredentialsError as e: + assert e.to_dict() + + +# def test_weak_email_password_error(): # credentials = mock_user_credentials() # try: # client_api_auto_confirm_off_signups_enabled_client().sign_up( @@ -185,6 +267,27 @@ def test_invalid_credential_sign_in(): # assert e.to_dict() +def test_weak_phone_password_error(): + credentials = mock_user_credentials() + try: + client_api_auto_confirm_off_signups_enabled_client().sign_up( + { + "phone": credentials.get("phone"), + "password": "123", + } + ) + except AuthWeakPasswordError as e: + assert e.to_dict() + + +def test_sign_in_anonymously(): + try: + response = auth_client_with_session().sign_in_anonymously() + assert response + except AuthApiError: + pass + + def test_delete_user_should_be_able_delete_an_existing_user(): credentials = mock_user_credentials() user = create_new_user_with_email(email=credentials.get("email")) From a9945b28d8fdcbf8c3fb3fee84ca2086ef5aba6a Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 19:21:25 -0300 Subject: [PATCH 10/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 66406bce..446b3038 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -267,17 +267,17 @@ def test_resend_missing_credentials(): # assert e.to_dict() -def test_weak_phone_password_error(): - credentials = mock_user_credentials() - try: - client_api_auto_confirm_off_signups_enabled_client().sign_up( - { - "phone": credentials.get("phone"), - "password": "123", - } - ) - except AuthWeakPasswordError as e: - assert e.to_dict() +# def test_weak_phone_password_error(): +# credentials = mock_user_credentials() +# try: +# client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "phone": credentials.get("phone"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() def test_sign_in_anonymously(): From 9839c172611fc37f5e284154969bce2dca470d70 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 19:24:24 -0300 Subject: [PATCH 11/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 446b3038..70ad6564 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -3,7 +3,6 @@ AuthError, AuthInvalidCredentialsError, AuthSessionMissingError, - AuthWeakPasswordError, ) from .clients import ( From d8b04e6c20f7405e1f80601abe2d4e8c83af21f2 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 19:36:09 -0300 Subject: [PATCH 12/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 129 +++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 5eebd8eb..70d02bc9 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -1,4 +1,9 @@ -from supabase_auth.errors import AuthError +from supabase_auth.errors import ( + AuthApiError, + AuthError, + AuthInvalidCredentialsError, + AuthSessionMissingError, +) from .clients import ( auth_client_with_session, @@ -160,6 +165,128 @@ async def test_modify_confirm_email_using_update_user_by_id(): assert response.user.email_confirmed_at +async def test_invalid_credential_sign_in_with_phone(): + try: + response = await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_password( + { + "phone": "+123456789", + "password": "strong_pwd", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +async def test_invalid_credential_sign_in_with_email(): + try: + response = await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_password( + { + "email": "unknown_user@unknowndomain.com", + "password": "strong_pwd", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +async def test_sign_in_with_otp_email(): + try: + await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_otp( + { + "email": "unknown_user@unknowndomain.com", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +async def test_sign_in_with_otp_phone(): + try: + await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_otp( + { + "phone": "+112345678", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +async def test_resend(): + try: + await client_api_auto_confirm_off_signups_enabled_client().resend( + {"phone": "+112345678", "type": "sms"} + ) + except AuthApiError as e: + assert e.to_dict() + + +async def test_reauthenticate(): + try: + response = await auth_client_with_session().reauthenticate() + except AuthSessionMissingError: + pass + + +async def test_refresh_session(): + try: + response = await auth_client_with_session().refresh_session() + except AuthSessionMissingError: + pass + + +async def test_reset_password_for_email(): + credentials = mock_user_credentials() + try: + response = await auth_client_with_session().reset_password_email( + email=credentials.get("email") + ) + except AuthSessionMissingError: + pass + + +async def test_resend_missing_credentials(): + try: + await client_api_auto_confirm_off_signups_enabled_client().resend( + {"type": "email_change"} + ) + except AuthInvalidCredentialsError as e: + assert e.to_dict() + + +# async def test_weak_email_password_error(): +# credentials = mock_user_credentials() +# try: +# await client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "email": credentials.get("email"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() + + +# async def test_weak_phone_password_error(): +# credentials = mock_user_credentials() +# try: +# await client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "phone": credentials.get("phone"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() + + +async def test_sign_in_anonymously(): + try: + response = await auth_client_with_session().sign_in_anonymously() + assert response + except AuthApiError: + pass + + async def test_delete_user_should_be_able_delete_an_existing_user(): credentials = mock_user_credentials() user = await create_new_user_with_email(email=credentials.get("email")) From c227ddf11983eea612f1f7ebd5c0facf34457f91 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 19:47:17 -0300 Subject: [PATCH 13/43] fix: add missing await --- supabase_auth/_async/gotrue_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase_auth/_async/gotrue_client.py b/supabase_auth/_async/gotrue_client.py index 041ac63b..da4a6603 100644 --- a/supabase_auth/_async/gotrue_client.py +++ b/supabase_auth/_async/gotrue_client.py @@ -349,7 +349,7 @@ async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials): If you have built an organization-specific login page, you can use the organization's SSO Identity Provider UUID directly instead. """ - self._remove_session() + await self._remove_session() provider_id = credentials.get("provider_id") domain = credentials.get("domain") options = credentials.get("options", {}) From a374715f62b713a6c3cbb3d6c23ee093017ef196 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 19:56:20 -0300 Subject: [PATCH 14/43] feat: add tests WIP --- tests/test_helpers.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index afb8e128..d7242e96 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -7,7 +7,14 @@ from supabase_auth.constants import API_VERSION_HEADER_NAME from supabase_auth.errors import AuthApiError, AuthWeakPasswordError -from supabase_auth.helpers import parse_response_api_version +from supabase_auth.helpers import ( + decode_jwt_payload, + get_error_code, + parse_link_identity_response, + parse_response_api_version, +) + +from ._sync.utils import mock_access_token TEST_URL = f"http://localhost" @@ -90,3 +97,22 @@ def test_parse_response_api_version_with_invalid_dates(): response = Response(headers=headers, status_code=200) api_ver = parse_response_api_version(response) assert api_ver == None + + +def test_parse_link_identity_response(): + assert parse_link_identity_response({"url": f"{TEST_URL}/hello-world"}) + + +def test_get_error_code(): + assert get_error_code({}) == None + assert get_error_code({"error_code": "500"}) == "500" + + +def test_decode_jwt_payload(): + assert decode_jwt_payload(mock_access_token()) + + with pytest.raises( + ValueError, match=r"JWT is not valid: not a JWT structure" + ) as exc: + decode_jwt_payload("non-valid-jwt") + assert exc.value is not None From bb120880c9eb6788f70f771e32d29be92c0fbae3 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:02:37 -0300 Subject: [PATCH 15/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 70ad6564..6b71c0eb 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -1,3 +1,5 @@ +import pytest + from supabase_auth.errors import ( AuthApiError, AuthError, @@ -13,6 +15,7 @@ ) from .utils import ( create_new_user_with_email, + mock_access_token, mock_app_metadata, mock_user_credentials, mock_user_metadata, @@ -398,3 +401,26 @@ def test_verify_otp_with_invalid_phone_number(): assert False except AuthError as e: assert e.message == "Invalid phone number format (E.164 required)" + + +def test_sign_in_with_oauth(): + assert client_api_auto_confirm_off_signups_enabled_client().sign_in_with_oauth( + { + "provider": "google", + } + ) + + +def test_decode_jwt(): + assert auth_client_with_session()._decode_jwt(mock_access_token()) + + +def test_link_identity_missing_session(): + + with pytest.raises(AuthSessionMissingError) as exc: + client_api_auto_confirm_off_signups_enabled_client().link_identity( + { + "provider": "google", + } + ) + assert exc.value is not None From a2144c59c17087a3c4d81f1ad5d2dfa2937534e0 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:06:44 -0300 Subject: [PATCH 16/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 6b71c0eb..e300a1f1 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -424,3 +424,15 @@ def test_link_identity_missing_session(): } ) assert exc.value is not None + + +def test_sign_in_with_id_token(): + try: + client_api_auto_confirm_off_signups_enabled_client().sign_in_with_id_token( + { + "provider": "google", + "token": "123456", + } + ) + except AuthApiError as e: + assert e.to_dict() From cb845cadb541645619a30636c772b22a8ea74594 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:18:59 -0300 Subject: [PATCH 17/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 70d02bc9..9cbeaca2 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -1,3 +1,5 @@ +import pytest + from supabase_auth.errors import ( AuthApiError, AuthError, @@ -398,3 +400,44 @@ async def test_verify_otp_with_invalid_phone_number(): assert False except AuthError as e: assert e.message == "Invalid phone number format (E.164 required)" + + +async def test_sign_in_with_id_token(): + try: + await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_id_token( + { + "provider": "google", + "token": "123456", + } + ) + except AuthApiError as e: + assert e.to_dict() + + +async def test_sign_in_with_sso(): + assert await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_sso( + { + "domain": "google", + } + ) + + +async def test_sign_in_with_oauth(): + assert ( + await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_oauth( + { + "provider": "google", + } + ) + ) + + +async def test_link_identity_missing_session(): + + with pytest.raises(AuthSessionMissingError) as exc: + await client_api_auto_confirm_off_signups_enabled_client().link_identity( + { + "provider": "google", + } + ) + assert exc.value is not None From 8e38ce61429609399263796da1a4163d48f55bcd Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:21:48 -0300 Subject: [PATCH 18/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index e300a1f1..6a4d217e 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -29,19 +29,19 @@ def test_create_user_should_create_a_new_user(): assert response.email == credentials.get("email") -def test_create_user_with_user_metadata(): - user_metadata = mock_user_metadata() - credentials = mock_user_credentials() - response = service_role_api_client().create_user( - { - "email": credentials.get("email"), - "password": credentials.get("password"), - "user_metadata": user_metadata, - } - ) - assert response.user.email == credentials.get("email") - assert response.user.user_metadata == user_metadata - assert "profile_image" in response.user.user_metadata +# def test_create_user_with_user_metadata(): +# user_metadata = mock_user_metadata() +# credentials = mock_user_credentials() +# response = service_role_api_client().create_user( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# "user_metadata": user_metadata, +# } +# ) +# assert response.user.email == credentials.get("email") +# assert response.user.user_metadata == user_metadata +# assert "profile_image" in response.user.user_metadata def test_create_user_with_app_metadata(): From 5eff66b47bd335455da968958664cc369461ce6d Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:28:30 -0300 Subject: [PATCH 19/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 6a4d217e..17c46996 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -436,3 +436,42 @@ def test_sign_in_with_id_token(): ) except AuthApiError as e: assert e.to_dict() + + +def test_get_item_from_memory_storage(): + credentials = mock_user_credentials() + client = auth_client() + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + assert client._storage.get_item(client._storage_key) is not None + + +def test_remove_item_from_memory_storage(): + credentials = mock_user_credentials() + client = auth_client() + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + client._storage.remove_item(client._storage_key) + assert client._storage_key not in client._storage.storage From 028c6031bc4ae4e311a90cc187830d2adfa1fd1e Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:32:06 -0300 Subject: [PATCH 20/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 17c46996..b19338ac 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -440,7 +440,7 @@ def test_sign_in_with_id_token(): def test_get_item_from_memory_storage(): credentials = mock_user_credentials() - client = auth_client() + client = auth_client_with_session() client.sign_up( { "email": credentials.get("email"), @@ -459,7 +459,7 @@ def test_get_item_from_memory_storage(): def test_remove_item_from_memory_storage(): credentials = mock_user_credentials() - client = auth_client() + client = auth_client_with_session() client.sign_up( { "email": credentials.get("email"), From 9038348f0dc06fad518da36a860e16d67e38edbc Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:37:28 -0300 Subject: [PATCH 21/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 66 ++++++++++++++-------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index b19338ac..644707e6 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -438,40 +438,40 @@ def test_sign_in_with_id_token(): assert e.to_dict() -def test_get_item_from_memory_storage(): - credentials = mock_user_credentials() - client = auth_client_with_session() - client.sign_up( - { - "email": credentials.get("email"), - "password": credentials.get("password"), - } - ) +# def test_get_item_from_memory_storage(): +# credentials = mock_user_credentials() +# client = auth_client() +# client.sign_up( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# } +# ) - client.sign_in_with_password( - { - "email": credentials.get("email"), - "password": credentials.get("password"), - } - ) - assert client._storage.get_item(client._storage_key) is not None +# client.sign_in_with_password( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# } +# ) +# assert client._storage.get_item(client._storage_key) is not None -def test_remove_item_from_memory_storage(): - credentials = mock_user_credentials() - client = auth_client_with_session() - client.sign_up( - { - "email": credentials.get("email"), - "password": credentials.get("password"), - } - ) +# def test_remove_item_from_memory_storage(): +# credentials = mock_user_credentials() +# client = auth_client() +# client.sign_up( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# } +# ) - client.sign_in_with_password( - { - "email": credentials.get("email"), - "password": credentials.get("password"), - } - ) - client._storage.remove_item(client._storage_key) - assert client._storage_key not in client._storage.storage +# client.sign_in_with_password( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# } +# ) +# client._storage.remove_item(client._storage_key) +# assert client._storage_key not in client._storage.storage From 1c9179ad9e3bdbbafb95cc9a6ae24673856c8fb2 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:43:47 -0300 Subject: [PATCH 22/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 67 ++++++++++++++-------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 644707e6..c562031e 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -8,6 +8,7 @@ ) from .clients import ( + auth_client, auth_client_with_session, client_api_auto_confirm_disabled_client, client_api_auto_confirm_off_signups_enabled_client, @@ -438,40 +439,40 @@ def test_sign_in_with_id_token(): assert e.to_dict() -# def test_get_item_from_memory_storage(): -# credentials = mock_user_credentials() -# client = auth_client() -# client.sign_up( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# } -# ) +def test_get_item_from_memory_storage(): + credentials = mock_user_credentials() + client = auth_client() + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) -# client.sign_in_with_password( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# } -# ) -# assert client._storage.get_item(client._storage_key) is not None + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + assert client._storage.get_item(client._storage_key) is not None -# def test_remove_item_from_memory_storage(): -# credentials = mock_user_credentials() -# client = auth_client() -# client.sign_up( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# } -# ) +def test_remove_item_from_memory_storage(): + credentials = mock_user_credentials() + client = auth_client() + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) -# client.sign_in_with_password( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# } -# ) -# client._storage.remove_item(client._storage_key) -# assert client._storage_key not in client._storage.storage + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + client._storage.remove_item(client._storage_key) + assert client._storage_key not in client._storage.storage From cbd67e2106215558bdb7fe6fe74f357f0efc917f Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:48:32 -0300 Subject: [PATCH 23/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 9cbeaca2..1c0978a9 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -8,6 +8,7 @@ ) from .clients import ( + auth_client, auth_client_with_session, client_api_auto_confirm_disabled_client, client_api_auto_confirm_off_signups_enabled_client, @@ -441,3 +442,42 @@ async def test_link_identity_missing_session(): } ) assert exc.value is not None + + +async def test_get_item_from_memory_storage(): + credentials = mock_user_credentials() + client = auth_client() + await client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + await client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + assert await client._storage.get_item(client._storage_key) is not None + + +async def test_remove_item_from_memory_storage(): + credentials = mock_user_credentials() + client = auth_client() + await client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + await client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + await client._storage.remove_item(client._storage_key) + assert client._storage_key not in client._storage.storage From 24e6e046d085039f796c39248b9d9ac255d073b5 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:53:45 -0300 Subject: [PATCH 24/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 1c0978a9..c7453ee0 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -481,3 +481,24 @@ async def test_remove_item_from_memory_storage(): ) await client._storage.remove_item(client._storage_key) assert client._storage_key not in client._storage.storage + + +async def test_list_factors(): + credentials = mock_user_credentials() + client = auth_client() + await client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + await client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + factors = await client._list_factors() + assert factors + assert isinstance(factors.totp, list) and isinstance(factors.phone, list) From 4e87c2eaabd30ff9bffb360d56434cafcc66e3ce Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:53:52 -0300 Subject: [PATCH 25/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index c562031e..6f81706b 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -476,3 +476,24 @@ def test_remove_item_from_memory_storage(): ) client._storage.remove_item(client._storage_key) assert client._storage_key not in client._storage.storage + + +def test_list_factors(): + credentials = mock_user_credentials() + client = auth_client() + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + factors = client._list_factors() + assert factors + assert isinstance(factors.totp, list) and isinstance(factors.phone, list) From 4d17c9fdb65de3e4bf692e1061b8e2fe51763545 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 20:58:20 -0300 Subject: [PATCH 26/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index c7453ee0..c5bb0951 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -44,19 +44,19 @@ async def test_create_user_with_user_metadata(): assert "profile_image" in response.user.user_metadata -async def test_create_user_with_app_metadata(): - app_metadata = mock_app_metadata() - credentials = mock_user_credentials() - response = await service_role_api_client().create_user( - { - "email": credentials.get("email"), - "password": credentials.get("password"), - "app_metadata": app_metadata, - } - ) - assert response.user.email == credentials.get("email") - assert "provider" in response.user.app_metadata - assert "providers" in response.user.app_metadata +# async def test_create_user_with_app_metadata(): +# app_metadata = mock_app_metadata() +# credentials = mock_user_credentials() +# response = await service_role_api_client().create_user( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# "app_metadata": app_metadata, +# } +# ) +# assert response.user.email == credentials.get("email") +# assert "provider" in response.user.app_metadata +# assert "providers" in response.user.app_metadata async def test_create_user_with_user_and_app_metadata(): From b757e7ab5b4804250683e5bba86e9072ca38f459 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 21:02:18 -0300 Subject: [PATCH 27/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index c5bb0951..9f1b48c6 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -502,3 +502,24 @@ async def test_list_factors(): factors = await client._list_factors() assert factors assert isinstance(factors.totp, list) and isinstance(factors.phone, list) + + +async def test_start_auto_refresh_token(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + await client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + await client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + assert await client._start_auto_refresh_token(2.0) is None From aa24af73378d83b3ec1e5a997ed5727209af4bee Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 21:02:25 -0300 Subject: [PATCH 28/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 6f81706b..a3069882 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -497,3 +497,24 @@ def test_list_factors(): factors = client._list_factors() assert factors assert isinstance(factors.totp, list) and isinstance(factors.phone, list) + + +def test_start_auto_refresh_token(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + assert client._start_auto_refresh_token(2.0) is None From e502f9798e01e4cdaf9e16c31fab1966db25fa67 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 21:09:52 -0300 Subject: [PATCH 29/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 9f1b48c6..9e30533d 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -523,3 +523,65 @@ async def test_start_auto_refresh_token(): ) assert await client._start_auto_refresh_token(2.0) is None + + +async def test_recover_and_refresh(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + await client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + await client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + await client._recover_and_refresh() + assert client._storage_key in client._storage.storage + + +async def test_get_user_identities(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + await client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + await client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + assert (await client.get_user_identities()).identities[0].identity_data[ + "email" + ] == credentials.get("email") + + +async def test_update_user(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + await client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + await client.update_user({"password": "123e5a"}) + await client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": "123e5a", + } + ) From 44ae1293886a3aa33ca2522b707c3dc46f563e14 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 21:09:57 -0300 Subject: [PATCH 30/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index a3069882..02e29496 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -518,3 +518,65 @@ def test_start_auto_refresh_token(): ) assert client._start_auto_refresh_token(2.0) is None + + +def test_recover_and_refresh(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + client._recover_and_refresh() + assert client._storage_key in client._storage.storage + + +def test_get_user_identities(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + assert client.get_user_identities().identities[0].identity_data[ + "email" + ] == credentials.get("email") + + +def test_update_user(): + credentials = mock_user_credentials() + client = auth_client() + client._auto_refresh_token = True + client.sign_up( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + } + ) + client.update_user({"password": "123e5a"}) + client.sign_in_with_password( + { + "email": credentials.get("email"), + "password": "123e5a", + } + ) From 81a563f21bd97613fa7bad8fd1e7247d8b974fcd Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 21:13:58 -0300 Subject: [PATCH 31/43] fix: add missing await --- supabase_auth/_async/gotrue_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supabase_auth/_async/gotrue_client.py b/supabase_auth/_async/gotrue_client.py index da4a6603..fc4b0732 100644 --- a/supabase_auth/_async/gotrue_client.py +++ b/supabase_auth/_async/gotrue_client.py @@ -361,7 +361,7 @@ async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials): skip_http_redirect = options.get("skip_http_redirect", True) if domain: - return self._request( + return await self._request( "POST", "sso", body={ @@ -375,7 +375,7 @@ async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials): xform=parse_sso_response, ) if provider_id: - return self._request( + return await self._request( "POST", "sso", body={ From 9cb8a4a1ebaa65c5efdc0c0aafacbad30f2a1943 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 21:18:58 -0300 Subject: [PATCH 32/43] feat: add tests WIP --- tests/test_helpers.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index d7242e96..57dcb66a 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -9,7 +9,10 @@ from supabase_auth.errors import AuthApiError, AuthWeakPasswordError from supabase_auth.helpers import ( decode_jwt_payload, + generate_pkce_challenge, + generate_pkce_verifier, get_error_code, + is_valid_jwt, parse_link_identity_response, parse_response_api_version, ) @@ -116,3 +119,25 @@ def test_decode_jwt_payload(): ) as exc: decode_jwt_payload("non-valid-jwt") assert exc.value is not None + + +def test_generate_pkce_verifier(): + assert isinstance(generate_pkce_verifier(45), str) + with pytest.raises( + ValueError, match=r"PKCE verifier length must be between 43 and 128 characters" + ) as exc: + generate_pkce_verifier(42) + assert exc.value is not None + + +def test_generate_pkce_challenge(): + pkce = generate_pkce_verifier(45) + assert isinstance(generate_pkce_challenge(pkce), str) + + +def test_is_valid_jwt(): + jwt = mock_access_token() + assert not is_valid_jwt(1) + assert not is_valid_jwt("") + assert not is_valid_jwt("Bearer ") + assert is_valid_jwt(jwt) From a000d0070c26a70bf6725d9f66620530ff821bc9 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 21:19:03 -0300 Subject: [PATCH 33/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 9e30533d..4055bf82 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -416,11 +416,13 @@ async def test_sign_in_with_id_token(): async def test_sign_in_with_sso(): - assert await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_sso( - { - "domain": "google", - } - ) + with pytest.raises(AuthApiError, match=r"SAML 2.0 is disabled") as exc: + await client_api_auto_confirm_off_signups_enabled_client().sign_in_with_sso( + { + "domain": "google", + } + ) + assert exc.value is not None async def test_sign_in_with_oauth(): From 9ba15e117575dc251ce451509e75b890ca3c34e1 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:05:26 -0300 Subject: [PATCH 34/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 82 +++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 4055bf82..09e33640 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -44,21 +44,6 @@ async def test_create_user_with_user_metadata(): assert "profile_image" in response.user.user_metadata -# async def test_create_user_with_app_metadata(): -# app_metadata = mock_app_metadata() -# credentials = mock_user_credentials() -# response = await service_role_api_client().create_user( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# "app_metadata": app_metadata, -# } -# ) -# assert response.user.email == credentials.get("email") -# assert "provider" in response.user.app_metadata -# assert "providers" in response.user.app_metadata - - async def test_create_user_with_user_and_app_metadata(): user_metadata = mock_user_metadata() app_metadata = mock_app_metadata() @@ -256,32 +241,6 @@ async def test_resend_missing_credentials(): assert e.to_dict() -# async def test_weak_email_password_error(): -# credentials = mock_user_credentials() -# try: -# await client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "email": credentials.get("email"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() - - -# async def test_weak_phone_password_error(): -# credentials = mock_user_credentials() -# try: -# await client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "phone": credentials.get("phone"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() - - async def test_sign_in_anonymously(): try: response = await auth_client_with_session().sign_in_anonymously() @@ -587,3 +546,44 @@ async def test_update_user(): "password": "123e5a", } ) + + +# async def test_create_user_with_app_metadata(): +# app_metadata = mock_app_metadata() +# credentials = mock_user_credentials() +# response = await service_role_api_client().create_user( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# "app_metadata": app_metadata, +# } +# ) +# assert response.user.email == credentials.get("email") +# assert "provider" in response.user.app_metadata +# assert "providers" in response.user.app_metadata + + +# async def test_weak_email_password_error(): +# credentials = mock_user_credentials() +# try: +# await client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "email": credentials.get("email"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() + + +# async def test_weak_phone_password_error(): +# credentials = mock_user_credentials() +# try: +# await client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "phone": credentials.get("phone"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() From 7a397e035be23107ee24fb1439736adaaba717fd Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:05:33 -0300 Subject: [PATCH 35/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 82 ++++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 02e29496..10b1ec33 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -30,21 +30,6 @@ def test_create_user_should_create_a_new_user(): assert response.email == credentials.get("email") -# def test_create_user_with_user_metadata(): -# user_metadata = mock_user_metadata() -# credentials = mock_user_credentials() -# response = service_role_api_client().create_user( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# "user_metadata": user_metadata, -# } -# ) -# assert response.user.email == credentials.get("email") -# assert response.user.user_metadata == user_metadata -# assert "profile_image" in response.user.user_metadata - - def test_create_user_with_app_metadata(): app_metadata = mock_app_metadata() credentials = mock_user_credentials() @@ -257,32 +242,6 @@ def test_resend_missing_credentials(): assert e.to_dict() -# def test_weak_email_password_error(): -# credentials = mock_user_credentials() -# try: -# client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "email": credentials.get("email"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() - - -# def test_weak_phone_password_error(): -# credentials = mock_user_credentials() -# try: -# client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "phone": credentials.get("phone"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() - - def test_sign_in_anonymously(): try: response = auth_client_with_session().sign_in_anonymously() @@ -580,3 +539,44 @@ def test_update_user(): "password": "123e5a", } ) + + +# def test_create_user_with_user_metadata(): +# user_metadata = mock_user_metadata() +# credentials = mock_user_credentials() +# response = service_role_api_client().create_user( +# { +# "email": credentials.get("email"), +# "password": credentials.get("password"), +# "user_metadata": user_metadata, +# } +# ) +# assert response.user.email == credentials.get("email") +# assert response.user.user_metadata == user_metadata +# assert "profile_image" in response.user.user_metadata + + +# def test_weak_email_password_error(): +# credentials = mock_user_credentials() +# try: +# client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "email": credentials.get("email"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() + + +# def test_weak_phone_password_error(): +# credentials = mock_user_credentials() +# try: +# client_api_auto_confirm_off_signups_enabled_client().sign_up( +# { +# "phone": credentials.get("phone"), +# "password": "123", +# } +# ) +# except AuthWeakPasswordError as e: +# assert e.to_dict() From a33acf5b214f562760c7c64895274f55e8825e3a Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:09:01 -0300 Subject: [PATCH 36/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 10b1ec33..e96ebadd 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -569,14 +569,14 @@ def test_update_user(): # assert e.to_dict() -# def test_weak_phone_password_error(): -# credentials = mock_user_credentials() -# try: -# client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "phone": credentials.get("phone"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() +def test_weak_phone_password_error(): + credentials = mock_user_credentials() + try: + client_api_auto_confirm_off_signups_enabled_client().sign_up( + { + "phone": credentials.get("phone"), + "password": "123", + } + ) + except AuthWeakPasswordError as e: + assert e.to_dict() From 618c2e59bb75ebd6f403cd43bbcd757062c8040a Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:13:17 -0300 Subject: [PATCH 37/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index e96ebadd..110373f3 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -5,6 +5,7 @@ AuthError, AuthInvalidCredentialsError, AuthSessionMissingError, + AuthWeakPasswordError, ) from .clients import ( From 16eed143b080686595bd591e0cdb76e2a70437a0 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:18:11 -0300 Subject: [PATCH 38/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index 110373f3..d10d4eba 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -579,5 +579,5 @@ def test_weak_phone_password_error(): "password": "123", } ) - except AuthWeakPasswordError as e: + except (AuthWeakPasswordError, AuthApiError) as e: assert e.to_dict() From 5fe8c040be5930f0e36e553f01c6733fa0bbe445 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:21:54 -0300 Subject: [PATCH 39/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 09e33640..60dbc65c 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -5,6 +5,7 @@ AuthError, AuthInvalidCredentialsError, AuthSessionMissingError, + AuthWeakPasswordError, ) from .clients import ( @@ -576,14 +577,14 @@ async def test_update_user(): # assert e.to_dict() -# async def test_weak_phone_password_error(): -# credentials = mock_user_credentials() -# try: -# await client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "phone": credentials.get("phone"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() +async def test_weak_phone_password_error(): + credentials = mock_user_credentials() + try: + await client_api_auto_confirm_off_signups_enabled_client().sign_up( + { + "phone": credentials.get("phone"), + "password": "123", + } + ) + except (AuthWeakPasswordError, AuthApiError) as e: + assert e.to_dict() From 2d6464c63287f30c39dbf12131b4aeb4a0aae34d Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:27:10 -0300 Subject: [PATCH 40/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 60dbc65c..33c2c0a6 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -564,17 +564,17 @@ async def test_update_user(): # assert "providers" in response.user.app_metadata -# async def test_weak_email_password_error(): -# credentials = mock_user_credentials() -# try: -# await client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "email": credentials.get("email"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() +async def test_weak_email_password_error(): + credentials = mock_user_credentials() + try: + await client_api_auto_confirm_off_signups_enabled_client().sign_up( + { + "email": credentials.get("email"), + "password": "123", + } + ) + except (AuthWeakPasswordError, AuthApiError) as e: + assert e.to_dict() async def test_weak_phone_password_error(): From 0c30092f19d9468d24bda93f27178a3696732894 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:27:16 -0300 Subject: [PATCH 41/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index d10d4eba..b54961ba 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -557,17 +557,17 @@ def test_update_user(): # assert "profile_image" in response.user.user_metadata -# def test_weak_email_password_error(): -# credentials = mock_user_credentials() -# try: -# client_api_auto_confirm_off_signups_enabled_client().sign_up( -# { -# "email": credentials.get("email"), -# "password": "123", -# } -# ) -# except AuthWeakPasswordError as e: -# assert e.to_dict() +def test_weak_email_password_error(): + credentials = mock_user_credentials() + try: + client_api_auto_confirm_off_signups_enabled_client().sign_up( + { + "email": credentials.get("email"), + "password": "123", + } + ) + except (AuthWeakPasswordError, AuthApiError) as e: + assert e.to_dict() def test_weak_phone_password_error(): From 2cd3a59d69bbf76bc5dd87dd2aad7dcbbd041bf0 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:31:02 -0300 Subject: [PATCH 42/43] feat: add tests WIP --- tests/_sync/test_gotrue_admin_api.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/_sync/test_gotrue_admin_api.py b/tests/_sync/test_gotrue_admin_api.py index b54961ba..c885d4bf 100644 --- a/tests/_sync/test_gotrue_admin_api.py +++ b/tests/_sync/test_gotrue_admin_api.py @@ -542,19 +542,19 @@ def test_update_user(): ) -# def test_create_user_with_user_metadata(): -# user_metadata = mock_user_metadata() -# credentials = mock_user_credentials() -# response = service_role_api_client().create_user( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# "user_metadata": user_metadata, -# } -# ) -# assert response.user.email == credentials.get("email") -# assert response.user.user_metadata == user_metadata -# assert "profile_image" in response.user.user_metadata +def test_create_user_with_user_metadata(): + user_metadata = mock_user_metadata() + credentials = mock_user_credentials() + response = service_role_api_client().create_user( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + "user_metadata": user_metadata, + } + ) + assert response.user.email == credentials.get("email") + assert response.user.user_metadata == user_metadata + assert "profile_image" in response.user.user_metadata def test_weak_email_password_error(): From 124de1edb3f45a95f976288fa094419d11793c05 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 22 Jan 2025 22:33:55 -0300 Subject: [PATCH 43/43] feat: add tests WIP --- tests/_async/test_gotrue_admin_api.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/_async/test_gotrue_admin_api.py b/tests/_async/test_gotrue_admin_api.py index 33c2c0a6..701f46c8 100644 --- a/tests/_async/test_gotrue_admin_api.py +++ b/tests/_async/test_gotrue_admin_api.py @@ -549,19 +549,19 @@ async def test_update_user(): ) -# async def test_create_user_with_app_metadata(): -# app_metadata = mock_app_metadata() -# credentials = mock_user_credentials() -# response = await service_role_api_client().create_user( -# { -# "email": credentials.get("email"), -# "password": credentials.get("password"), -# "app_metadata": app_metadata, -# } -# ) -# assert response.user.email == credentials.get("email") -# assert "provider" in response.user.app_metadata -# assert "providers" in response.user.app_metadata +async def test_create_user_with_app_metadata(): + app_metadata = mock_app_metadata() + credentials = mock_user_credentials() + response = await service_role_api_client().create_user( + { + "email": credentials.get("email"), + "password": credentials.get("password"), + "app_metadata": app_metadata, + } + ) + assert response.user.email == credentials.get("email") + assert "provider" in response.user.app_metadata + assert "providers" in response.user.app_metadata async def test_weak_email_password_error():