From 5add457898db100e064e2f5b6b390d97ec41ccc8 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 19 Mar 2024 15:37:26 +0530 Subject: [PATCH 1/2] fix: cicd test --- .../django2x/polls/urls.py | 1 + .../django2x/polls/views.py | 45 +++++++++++++++++++ .../django3x/polls/urls.py | 1 + .../django3x/polls/views.py | 44 ++++++++++++++++++ .../frontendIntegration/fastapi-server/app.py | 40 +++++++++++++++++ tests/frontendIntegration/flask-server/app.py | 40 +++++++++++++++++ 6 files changed, 171 insertions(+) diff --git a/tests/frontendIntegration/django2x/polls/urls.py b/tests/frontendIntegration/django2x/polls/urls.py index c5e764cf8..72ae6ebdc 100644 --- a/tests/frontendIntegration/django2x/polls/urls.py +++ b/tests/frontendIntegration/django2x/polls/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ # type: ignore path("index.html", views.send_file, name="index.html"), # type: ignore path("login", views.login, name="login"), # type: ignore + path("login-2.18", views.login_218, name="login_218"), # type: ignore path("beforeeach", views.before_each, name="beforeeach"), # type: ignore path("testUserConfig", views.test_config, name="testUserConfig"), # type: ignore path( diff --git a/tests/frontendIntegration/django2x/polls/views.py b/tests/frontendIntegration/django2x/polls/views.py index d64090105..c7b7ce12b 100644 --- a/tests/frontendIntegration/django2x/polls/views.py +++ b/tests/frontendIntegration/django2x/polls/views.py @@ -17,6 +17,8 @@ import sys from functools import wraps from typing import Any, Dict, Union +from base64 import b64encode +import time from django.http import HttpRequest, HttpResponse, JsonResponse from django.shortcuts import render @@ -48,6 +50,9 @@ from supertokens_python.constants import VERSION from supertokens_python.utils import is_version_gte from supertokens_python.recipe.session.syncio import get_session_information +from supertokens_python.normalised_url_path import NormalisedURLPath +from supertokens_python.querier import Querier +from supertokens_python.async_to_sync_wrapper import sync protected_prop_name = { "sub", @@ -403,6 +408,46 @@ def login(request: HttpRequest): return send_options_api_response() +def login_218(request: HttpRequest): + if request.method == "POST": + request_json = json.loads(request.body) + user_id = request_json["userId"] + payload = request_json["payload"] + + querier = Querier.get_instance() + Querier.api_version = "2.18" + + legacy_session_resp = sync( + querier.send_post_request( + NormalisedURLPath("/recipe/session"), + { + "userId": user_id, + "enableAntiCsrf": False, + "userDataInJWT": payload, + "userDataInDatabase": {}, + }, + {}, + ) + ) + Querier.api_version = None + front_token = b64encode( + json.dumps( + {"uid": user_id, "up": payload, "ate": time.time() * 1000 + 3600000} + ).encode("utf8") + ).decode("utf-8") + + return HttpResponse( + "", + headers={ + "st-access-token": legacy_session_resp["accessToken"]["token"], + "st-refresh-token": legacy_session_resp["refreshToken"]["token"], + "front-token": front_token, + }, + ) + else: + return send_options_api_response() + + def before_each(request: HttpRequest): if request.method == "POST": Test.reset() diff --git a/tests/frontendIntegration/django3x/polls/urls.py b/tests/frontendIntegration/django3x/polls/urls.py index c5e764cf8..72ae6ebdc 100644 --- a/tests/frontendIntegration/django3x/polls/urls.py +++ b/tests/frontendIntegration/django3x/polls/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ # type: ignore path("index.html", views.send_file, name="index.html"), # type: ignore path("login", views.login, name="login"), # type: ignore + path("login-2.18", views.login_218, name="login_218"), # type: ignore path("beforeeach", views.before_each, name="beforeeach"), # type: ignore path("testUserConfig", views.test_config, name="testUserConfig"), # type: ignore path( diff --git a/tests/frontendIntegration/django3x/polls/views.py b/tests/frontendIntegration/django3x/polls/views.py index 1c4c40fad..ba925aee8 100644 --- a/tests/frontendIntegration/django3x/polls/views.py +++ b/tests/frontendIntegration/django3x/polls/views.py @@ -23,6 +23,8 @@ import os import sys from functools import wraps +from base64 import b64encode +import time from django.http import HttpRequest, HttpResponse, JsonResponse from django.shortcuts import render @@ -48,6 +50,8 @@ from supertokens_python.constants import VERSION from supertokens_python.utils import is_version_gte from supertokens_python.recipe.session.asyncio import get_session_information +from supertokens_python.normalised_url_path import NormalisedURLPath +from supertokens_python.querier import Querier protected_prop_name = { "sub", @@ -407,6 +411,46 @@ async def login(request: HttpRequest): return send_options_api_response() +async def login_218(request: HttpRequest): + if request.method == "POST": + request_json = json.loads(request.body) + user_id = request_json["userId"] + payload = request_json["payload"] + + querier = Querier.get_instance() + Querier.api_version = "2.18" + + legacy_session_resp = await ( + querier.send_post_request( + NormalisedURLPath("/recipe/session"), + { + "userId": user_id, + "enableAntiCsrf": False, + "userDataInJWT": payload, + "userDataInDatabase": {}, + }, + {}, + ) + ) + Querier.api_version = None + front_token = b64encode( + json.dumps( + {"uid": user_id, "up": payload, "ate": time.time() * 1000 + 3600000} + ).encode("utf8") + ).decode("utf-8") + + return HttpResponse( + "", + headers={ + "st-access-token": legacy_session_resp["accessToken"]["token"], + "st-refresh-token": legacy_session_resp["refreshToken"]["token"], + "front-token": front_token, + }, + ) + else: + return send_options_api_response() + + async def before_each(request: HttpRequest): if request.method == "POST": Test.reset() diff --git a/tests/frontendIntegration/fastapi-server/app.py b/tests/frontendIntegration/fastapi-server/app.py index a195d0562..cf4802921 100644 --- a/tests/frontendIntegration/fastapi-server/app.py +++ b/tests/frontendIntegration/fastapi-server/app.py @@ -15,6 +15,8 @@ import os import sys from typing import Any, Dict, Union +from base64 import b64encode +import time import uvicorn # type: ignore from fastapi import Depends, FastAPI @@ -52,6 +54,8 @@ from supertokens_python.constants import VERSION from supertokens_python.utils import is_version_gte from supertokens_python.recipe.session.asyncio import get_session_information +from supertokens_python.querier import Querier +from supertokens_python.normalised_url_path import NormalisedURLPath protected_prop_name = { "sub", @@ -270,6 +274,42 @@ async def login(request: Request): return PlainTextResponse(content=_session.get_user_id()) +@app.post("/login-2.18") +async def login_218(request: Request): + request_json = await request.json() + user_id = request_json["userId"] + payload = request_json["payload"] + + querier = Querier.get_instance() + Querier.api_version = "2.18" + legacy_session_resp = await querier.send_post_request( + NormalisedURLPath("/recipe/session"), + { + "userId": user_id, + "enableAntiCsrf": False, + "userDataInJWT": payload, + "userDataInDatabase": {}, + }, + {}, + ) + Querier.api_version = None + + front_token = b64encode( + json.dumps( + {"uid": user_id, "up": payload, "ate": time.time() * 1000 + 3600000} + ).encode("utf8") + ).decode("utf-8") + + return PlainTextResponse( + content="", + headers={ + "st-access-token": legacy_session_resp["accessToken"]["token"], + "st-refresh-token": legacy_session_resp["refreshToken"]["token"], + "front-token": front_token, + }, + ) + + @app.options("/beforeeach") def before_each_options(): return send_options_api_response() diff --git a/tests/frontendIntegration/flask-server/app.py b/tests/frontendIntegration/flask-server/app.py index d1af325df..b54247656 100644 --- a/tests/frontendIntegration/flask-server/app.py +++ b/tests/frontendIntegration/flask-server/app.py @@ -16,6 +16,8 @@ import sys from functools import wraps from typing import Any, Dict, Union +from base64 import b64encode +import time from flask import Flask, g, jsonify, make_response, render_template, request from flask.wrappers import Response @@ -44,6 +46,9 @@ from supertokens_python.constants import VERSION from supertokens_python.utils import is_version_gte from supertokens_python.recipe.session.syncio import get_session_information +from supertokens_python.normalised_url_path import NormalisedURLPath +from supertokens_python.querier import Querier +from supertokens_python.async_to_sync_wrapper import sync protected_prop_name = { "sub", @@ -292,6 +297,41 @@ def login(): return _session.get_user_id() +@app.route("/login-2.18", methods=["POST"]) # type: ignore +def login_218(): + request_json = request.get_json() + user_id = request_json["userId"] + payload = request_json["payload"] + + querier = Querier.get_instance() + Querier.api_version = "2.18" + + legacy_session_resp = sync( + querier.send_post_request( + NormalisedURLPath("/recipe/session"), + { + "userId": user_id, + "enableAntiCsrf": False, + "userDataInJWT": payload, + "userDataInDatabase": {}, + }, + {}, + ) + ) + Querier.api_version = None + front_token = b64encode( + json.dumps( + {"uid": user_id, "up": payload, "ate": time.time() * 1000 + 3600000} + ).encode("utf8") + ).decode("utf-8") + + resp = Response("") + resp.headers["st-access-token"] = legacy_session_resp["accessToken"]["token"] + resp.headers["st-refresh-token"] = legacy_session_resp["refreshToken"]["token"] + resp.headers["front-token"] = front_token + return resp + + @app.route("/beforeeach", methods=["OPTIONS"]) # type: ignore def before_each_options(): return send_options_api_response() From d953d9b0913f5951aa10554c260d8055ed2e03ec Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 19 Mar 2024 16:17:31 +0530 Subject: [PATCH 2/2] fix: lint --- tests/frontendIntegration/flask-server/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/frontendIntegration/flask-server/app.py b/tests/frontendIntegration/flask-server/app.py index b54247656..d3561f105 100644 --- a/tests/frontendIntegration/flask-server/app.py +++ b/tests/frontendIntegration/flask-server/app.py @@ -299,9 +299,9 @@ def login(): @app.route("/login-2.18", methods=["POST"]) # type: ignore def login_218(): - request_json = request.get_json() - user_id = request_json["userId"] - payload = request_json["payload"] + request_json = request.get_json() # type: ignore + user_id = request_json["userId"] # type: ignore + payload = request_json["payload"] # type: ignore querier = Querier.get_instance() Querier.api_version = "2.18"