From 36342334c02b54f19b7d17a22e9c01b42032eacf Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Sat, 12 Oct 2024 14:37:41 +0530 Subject: [PATCH] fixes stuff --- .../recipe/accountlinking/interfaces.py | 3 +-- .../accountlinking/recipe_implementation.py | 4 +--- tests/test-server/accountlinking.py | 1 - tests/test-server/app.py | 2 +- tests/test-server/override_logging.py | 3 +++ tests/test-server/passwordless.py | 7 ++++--- tests/test-server/session.py | 18 ++++++++++++++++++ tests/test-server/test_functions_mapper.py | 18 +++++++++++++++++- 8 files changed, 45 insertions(+), 11 deletions(-) diff --git a/supertokens_python/recipe/accountlinking/interfaces.py b/supertokens_python/recipe/accountlinking/interfaces.py index 0322024f..2058765d 100644 --- a/supertokens_python/recipe/accountlinking/interfaces.py +++ b/supertokens_python/recipe/accountlinking/interfaces.py @@ -260,11 +260,10 @@ def __init__( class LinkAccountsInputUserNotPrimaryError: - def __init__(self, description: Optional[str] = None): + def __init__(self): self.status: Literal[ "INPUT_USER_IS_NOT_A_PRIMARY_USER" ] = "INPUT_USER_IS_NOT_A_PRIMARY_USER" - self.description = description class UnlinkAccountOkResult: diff --git a/supertokens_python/recipe/accountlinking/recipe_implementation.py b/supertokens_python/recipe/accountlinking/recipe_implementation.py index 5d4495c5..c14cbf22 100644 --- a/supertokens_python/recipe/accountlinking/recipe_implementation.py +++ b/supertokens_python/recipe/accountlinking/recipe_implementation.py @@ -290,9 +290,7 @@ async def link_accounts( description=response["description"], ) elif response["status"] == "INPUT_USER_IS_NOT_A_PRIMARY_USER": - return LinkAccountsInputUserNotPrimaryError( - description=response["description"], - ) + return LinkAccountsInputUserNotPrimaryError() else: raise Exception(f"Unknown response status: {response['status']}") diff --git a/tests/test-server/accountlinking.py b/tests/test-server/accountlinking.py index 6b3ec9a0..30b73b69 100644 --- a/tests/test-server/accountlinking.py +++ b/tests/test-server/accountlinking.py @@ -114,7 +114,6 @@ def link_accounts_api(): # type: ignore else: return jsonify( { - "description": response.description, "status": response.status, } ) diff --git a/tests/test-server/app.py b/tests/test-server/app.py index 89fbe465..da08cf5d 100644 --- a/tests/test-server/app.py +++ b/tests/test-server/app.py @@ -326,7 +326,7 @@ async def custom_unauthorised_callback( ), on_account_linked=callback_with_log( "AccountLinking.onAccountLinked", - recipe_config_json.get("on_account_linked"), + recipe_config_json.get("onAccountLinked"), ), override=accountlinking.InputOverrideConfig( functions=override_builder_with_logging( diff --git a/tests/test-server/override_logging.py b/tests/test-server/override_logging.py index 2604922f..2bb2d5a2 100644 --- a/tests/test-server/override_logging.py +++ b/tests/test-server/override_logging.py @@ -4,6 +4,7 @@ from httpx import Response from supertokens_python.framework.flask.flask_request import FlaskRequest +from supertokens_python.recipe.accountlinking import RecipeLevelUser from supertokens_python.recipe.accountlinking.interfaces import ( CreatePrimaryUserOkResult, LinkAccountsOkResult, @@ -134,4 +135,6 @@ def transform_logged_data(data: Any, visited: Union[Set[Any], None] = None) -> A return {"status": "EMAIL_ALREADY_VERIFIED_ERROR"} if isinstance(data, PasswordResetPostOkResult): return {"status": "OK", "user": data.user.to_json(), "email": data.email} + if isinstance(data, RecipeLevelUser): + return data.to_json() return data diff --git a/tests/test-server/passwordless.py b/tests/test-server/passwordless.py index 339d6802..eb88607d 100644 --- a/tests/test-server/passwordless.py +++ b/tests/test-server/passwordless.py @@ -70,6 +70,7 @@ def create_code_api(): # type: ignore ) return jsonify( { + "status": "OK", "codeId": response.code_id, "preAuthSessionId": response.pre_auth_session_id, "codeLifeTime": response.code_life_time, @@ -89,10 +90,10 @@ def consume_code_api(): # type: ignore session = convert_session_to_container(body) response = consume_code( - device_id=body["deviceId"], - pre_auth_session_id=body["preAuthSessionId"], + device_id=body.get("deviceId"), + pre_auth_session_id=body.get("preAuthSessionId"), user_input_code=body.get("userInputCode"), - link_code=body["linkCode"], + link_code=body.get("linkCode", None), tenant_id=body.get("tenantId", "public"), user_context=body.get("userContext"), session=session, diff --git a/tests/test-server/session.py b/tests/test-server/session.py index b29468db..ca1e4096 100644 --- a/tests/test-server/session.py +++ b/tests/test-server/session.py @@ -53,6 +53,24 @@ def create_new_session_without_request_response(): # type: ignore return jsonify(convert_session_to_json(session_container)) + @app.route("/test/session/getallsessionhandlesforuser", methods=["POST"]) # type: ignore + def get_all_session_handles_for_user_api(): # type: ignore + data = request.json + if data is None: + return jsonify({"status": "MISSING_DATA_ERROR"}) + + user_id = data["userId"] + fetch_sessions_for_all_linked_accounts = data.get( + "fetchSessionsForAllLinkedAccounts", True + ) + tenant_id = data.get("tenantId", "public") + user_context = data.get("userContext", {}) + + response = session.get_all_session_handles_for_user( + user_id, fetch_sessions_for_all_linked_accounts, tenant_id, user_context + ) + return jsonify(response) + @app.route("/test/session/getsessionwithoutrequestresponse", methods=["POST"]) # type: ignore def get_session_without_request_response(): # type: ignore data = request.json diff --git a/tests/test-server/test_functions_mapper.py b/tests/test-server/test_functions_mapper.py index 211275f3..cc0c80ae 100644 --- a/tests/test-server/test_functions_mapper.py +++ b/tests/test-server/test_functions_mapper.py @@ -59,6 +59,18 @@ def func(*args): # type: ignore return func # type: ignore + elif eval_str.startswith("accountlinking.init.onAccountLinked"): + + async def on_account_linked( + user: User, recipe_level_user: RecipeLevelUser, user_context: Dict[str, Any] + ) -> None: + global primary_user_in_callback + global new_account_info_in_callback + primary_user_in_callback = user + new_account_info_in_callback = recipe_level_user + + return on_account_linked + elif eval_str.startswith("emailverification.init.emailDelivery.override"): from supertokens_python.recipe.emailverification.types import ( EmailDeliveryOverrideInput as EVEmailDeliveryOverrideInput, @@ -712,7 +724,11 @@ def to_json(self) -> Dict[str, Any]: else None ), "email": self.email, - "newAccountInfoInCallback": self.new_account_info_in_callback, + "newAccountInfoInCallback": ( + self.new_account_info_in_callback.to_json() + if self.new_account_info_in_callback is not None + else None + ), "primaryUserInCallback": ( self.primary_user_in_callback.to_json() if self.primary_user_in_callback is not None