Skip to content

Commit

Permalink
fixes more code
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Oct 9, 2024
1 parent 999c636 commit e5fe1da
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ async def create_new_session_in_request(
del final_access_token_payload[prop]

for claim in claims_added_by_other_recipes:
update = await claim.build(user_id, recipe_user_id, tenant_id, user_context)
update = await claim.build(
user_id, recipe_user_id, tenant_id, final_access_token_payload, user_context
)
final_access_token_payload.update(update)

log_debug_message("createNewSession: Access token payload built")
Expand Down
19 changes: 15 additions & 4 deletions tests/test-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from supertokens_python.recipe.thirdparty.recipe import ThirdPartyRecipe
from supertokens_python.recipe.usermetadata.recipe import UserMetadataRecipe
from supertokens_python.recipe.userroles.recipe import UserRolesRecipe
from test_functions_mapper import get_func # type: ignore
from test_functions_mapper import get_func, get_override_params, reset_override_params # type: ignore
from emailpassword import add_emailpassword_routes
from multitenancy import add_multitenancy_routes
from session import add_session_routes
Expand Down Expand Up @@ -137,6 +137,8 @@ def inner(*args, **kwargs): # type: ignore


def st_reset():
override_logging.reset_override_logs()
reset_override_params()
ProcessState.get_instance().reset()
Supertokens.reset()
SessionRecipe.reset()
Expand Down Expand Up @@ -331,7 +333,15 @@ def inner(
user_context: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
if interceptor_func is not None:
return interceptor_func(url, method, headers, params, body, user_context) # type: ignore
resp = interceptor_func(url, method, headers, params, body, user_context) # type: ignore
return {
"url": resp[0],
"method": resp[1],
"headers": resp[2],
"params": resp[3],
"body": resp[4],
"user_context": resp[5],
}
return {
"url": url,
"method": method,
Expand Down Expand Up @@ -382,7 +392,7 @@ def init_handler():

@app.route("/test/overrideparams", methods=["GET"]) # type: ignore
def override_params():
return jsonify("TODO")
return jsonify(get_override_params().to_json())


@app.route("/test/featureflag", methods=["GET"]) # type: ignore
Expand All @@ -391,8 +401,9 @@ def feature_flag():


@app.route("/test/resetoverrideparams", methods=["POST"]) # type: ignore
def reset_override_params():
def reset_override_params_api():
override_logging.reset_override_logs()
reset_override_params()
return jsonify({"ok": True})


Expand Down
148 changes: 147 additions & 1 deletion tests/test-server/test_functions_mapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Callable
from typing import Callable, List
from typing import Dict, Any, Optional
from supertokens_python.recipe.accountlinking import RecipeLevelUser
from supertokens_python.types import RecipeUserId
from supertokens_python.types import APIResponse, User


class Info:
Expand All @@ -15,3 +19,145 @@ def func(*args): # type: ignore
return func # type: ignore

raise Exception("Unknown eval string")


class OverrideParams(APIResponse):
def __init__(
self,
send_email_to_user_id: Optional[str] = None,
token: Optional[str] = None,
user_post_password_reset: Optional[User] = None,
email_post_password_reset: Optional[str] = None,
send_email_callback_called: Optional[bool] = None,
send_email_to_user_email: Optional[str] = None,
send_email_inputs: Optional[List[str]] = None,
send_sms_inputs: Optional[List[str]] = None,
send_email_to_recipe_user_id: Optional[str] = None,
user_in_callback: Optional[User] = None,
email: Optional[str] = None,
new_account_info_in_callback: Optional[RecipeLevelUser] = None,
primary_user_in_callback: Optional[User] = None,
user_id_in_callback: Optional[str] = None,
recipe_user_id_in_callback: Optional[str] = None,
core_call_count: int = 0,
store: Optional[Any] = None,
):
self.send_email_to_user_id = send_email_to_user_id
self.token = token
self.user_post_password_reset = user_post_password_reset
self.email_post_password_reset = email_post_password_reset
self.send_email_callback_called = send_email_callback_called
self.send_email_to_user_email = send_email_to_user_email
self.send_email_inputs = send_email_inputs
self.send_sms_inputs = send_sms_inputs
self.send_email_to_recipe_user_id = send_email_to_recipe_user_id
self.user_in_callback = user_in_callback
self.email = email
self.new_account_info_in_callback = new_account_info_in_callback
self.primary_user_in_callback = primary_user_in_callback
self.user_id_in_callback = user_id_in_callback
self.recipe_user_id_in_callback = recipe_user_id_in_callback
self.core_call_count = core_call_count
self.store = store

def to_json(self) -> Dict[str, Any]:
return {
"sendEmailToUserId": self.send_email_to_user_id,
"token": self.token,
"userPostPasswordReset": (
self.user_post_password_reset.to_json()
if self.user_post_password_reset is not None
else None
),
"emailPostPasswordReset": self.email_post_password_reset,
"sendEmailCallbackCalled": self.send_email_callback_called,
"sendEmailToUserEmail": self.send_email_to_user_email,
"sendEmailInputs": self.send_email_inputs,
"sendSmsInputs": self.send_sms_inputs,
"sendEmailToRecipeUserId": self.send_email_to_recipe_user_id,
"userInCallback": (
self.user_in_callback.to_json()
if self.user_in_callback is not None
else None
),
"email": self.email,
"newAccountInfoInCallback": self.new_account_info_in_callback,
"primaryUserInCallback": (
self.primary_user_in_callback.to_json()
if self.primary_user_in_callback is not None
else None
),
"userIdInCallback": self.user_id_in_callback,
"recipeUserIdInCallback": self.recipe_user_id_in_callback,
"info": {
"coreCallCount": self.core_call_count,
},
"store": self.store,
}


def get_override_params() -> OverrideParams:
return OverrideParams(
send_email_to_user_id=send_email_to_user_id,
token=token,
user_post_password_reset=user_post_password_reset,
email_post_password_reset=email_post_password_reset,
send_email_callback_called=send_email_callback_called,
send_email_to_user_email=send_email_to_user_email,
send_email_inputs=send_email_inputs,
send_sms_inputs=send_sms_inputs,
send_email_to_recipe_user_id=send_email_to_recipe_user_id,
user_in_callback=user_in_callback,
email=email,
new_account_info_in_callback=new_account_info_in_callback,
primary_user_in_callback=(
primary_user_in_callback if primary_user_in_callback else None
),
user_id_in_callback=user_id_in_callback,
recipe_user_id_in_callback=(
recipe_user_id_in_callback.get_as_string()
if isinstance(recipe_user_id_in_callback, RecipeUserId)
else None
),
core_call_count=Info.core_call_count,
store=store,
)


def reset_override_params():
global send_email_to_user_id, token, user_post_password_reset, email_post_password_reset, send_email_callback_called, send_email_to_user_email, send_email_inputs, send_sms_inputs, send_email_to_recipe_user_id, user_in_callback, email, primary_user_in_callback, new_account_info_in_callback, user_id_in_callback, recipe_user_id_in_callback, store
send_email_to_user_id = None
token = None
user_post_password_reset = None
email_post_password_reset = None
send_email_callback_called = False
send_email_to_user_email = None
send_email_inputs = []
send_sms_inputs = []
send_email_to_recipe_user_id = None
user_in_callback = None
email = None
primary_user_in_callback = None
new_account_info_in_callback = None
user_id_in_callback = None
recipe_user_id_in_callback = None
store = None
Info.core_call_count = 0


send_email_to_user_id: Optional[str] = None
token: Optional[str] = None
user_post_password_reset: Optional[User] = None
email_post_password_reset: Optional[str] = None
send_email_callback_called: bool = False
send_email_to_user_email: Optional[str] = None
send_email_inputs: List[str] = []
send_sms_inputs: List[str] = []
send_email_to_recipe_user_id: Optional[str] = None
user_in_callback: Optional[User] = None
email: Optional[str] = None
primary_user_in_callback: Optional[User] = None
new_account_info_in_callback: Optional[RecipeLevelUser] = None
user_id_in_callback: Optional[str] = None
recipe_user_id_in_callback: Optional[RecipeUserId] = None
store: Optional[str] = None

0 comments on commit e5fe1da

Please sign in to comment.