Skip to content

Commit

Permalink
fixes test server
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Oct 9, 2024
1 parent 1832599 commit 999c636
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/test-server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
parse_jwt_without_signature_verification,
)
from supertokens_python.types import RecipeUserId
from utils import deserialize_validator
from utils import deserialize_validator, get_max_version
from supertokens_python.recipe.session.recipe import SessionRecipe
from supertokens_python.recipe.session.session_class import Session
import supertokens_python.recipe.session.syncio as session
Expand All @@ -19,15 +19,26 @@ def create_new_session_without_request_response(): # type: ignore
return jsonify({"status": "MISSING_DATA_ERROR"})

tenant_id = data.get("tenantId", "public")
user_id = data["userId"]
from supertokens_python import convert_to_recipe_user_id

fdi_version = request.headers.get("fdi-version")
assert fdi_version is not None
if get_max_version("1.17", fdi_version) == "1.17" or (
get_max_version("2.0", fdi_version) == fdi_version
and get_max_version("3.0", fdi_version) != fdi_version
):
# fdi_version <= "1.17" or (fdi_version >= "2.0" and fdi_version < "3.0")
recipe_user_id = convert_to_recipe_user_id(data["userId"])
else:
recipe_user_id = convert_to_recipe_user_id(data["recipeUserId"])
access_token_payload = data.get("accessTokenPayload", {})
session_data_in_database = data.get("sessionDataInDatabase", {})
disable_anti_csrf = data.get("disableAntiCsrf")
user_context = data.get("userContext", {})

session_container = session.create_new_session_without_request_response(
tenant_id,
RecipeUserId(user_id),
recipe_user_id,
access_token_payload,
session_data_in_database,
disable_anti_csrf,
Expand Down
17 changes: 17 additions & 0 deletions tests/test-server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,20 @@ def toSnakeCase(camel_case: str) -> str:
else:
result += char
return result


def get_max_version(v1: str, v2: str) -> str:
v1_split = v1.split(".")
v2_split = v2.split(".")
max_loop = min(len(v1_split), len(v2_split))

for i in range(max_loop):
if int(v1_split[i]) > int(v2_split[i]):
return v1
if int(v2_split[i]) > int(v1_split[i]):
return v2

if len(v1_split) > len(v2_split):
return v1

return v2

0 comments on commit 999c636

Please sign in to comment.