Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cicd test #479

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/frontendIntegration/django2x/polls/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 45 additions & 0 deletions tests/frontendIntegration/django2x/polls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/frontendIntegration/django3x/polls/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
44 changes: 44 additions & 0 deletions tests/frontendIntegration/django3x/polls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
40 changes: 40 additions & 0 deletions tests/frontendIntegration/fastapi-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
40 changes: 40 additions & 0 deletions tests/frontendIntegration/flask-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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() # type: ignore
user_id = request_json["userId"] # type: ignore
payload = request_json["payload"] # type: ignore

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()
Expand Down
Loading