Skip to content

Commit

Permalink
fix: auth react tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Dec 17, 2024
1 parent 2685c31 commit 0226085
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
11 changes: 10 additions & 1 deletion tests/auth-react/django3x/mysite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
emailpassword,
emailverification,
multifactorauth,
oauth2provider,
passwordless,
session,
thirdparty,
Expand Down Expand Up @@ -40,6 +41,8 @@
APIOptions as EVAPIOptions,
)
from supertokens_python.recipe.jwt import JWTRecipe
from supertokens_python.recipe.oauth2provider.recipe import OAuth2ProviderRecipe
from supertokens_python.recipe.openid.recipe import OpenIdRecipe
from supertokens_python.recipe.passwordless import (
ContactEmailOnlyConfig,
ContactEmailOrPhoneConfig,
Expand Down Expand Up @@ -315,6 +318,8 @@ def custom_init():
Supertokens.reset()
TOTPRecipe.reset()
MultiFactorAuthRecipe.reset()
OpenIdRecipe.reset()
OAuth2ProviderRecipe.reset()

def override_email_verification_apis(
original_implementation_email_verification: EmailVerificationAPIInterface,
Expand Down Expand Up @@ -942,6 +947,10 @@ async def resync_session_and_fetch_mfa_info_put(
)
),
},
{
"id": "oauth2provider",
"init": oauth2provider.init(),
},
]

accountlinking_config_input: Dict[str, Any] = {
Expand Down Expand Up @@ -1002,7 +1011,7 @@ async def should_do_automatic_account_linking(
supertokens_config=SupertokensConfig("http://localhost:9000"),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="0.0.0.0:" + get_api_port(),
api_domain="localhost:" + get_api_port(),
website_domain=get_website_domain(),
),
framework="django",
Expand Down
1 change: 1 addition & 0 deletions tests/auth-react/django3x/polls/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
name="setEnabledRecipes",
),
path("test/getTOTPCode", views.test_get_totp_code, name="getTotpCode"), # type: ignore
path("test/create-oauth2-client", views.test_create_oauth2_client, name="createOAuth2Client"), # type: ignore
path("test/getDevice", views.test_get_device, name="getDevice"), # type: ignore
path("test/featureFlags", views.test_feature_flags, name="featureFlags"), # type: ignore
path("beforeeach", views.before_each, name="beforeeach"), # type: ignore
Expand Down
11 changes: 11 additions & 0 deletions tests/auth-react/django3x/polls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from supertokens_python.recipe.multifactorauth.asyncio import (
add_to_required_secondary_factors_for_user,
)
from supertokens_python.recipe.oauth2provider.syncio import create_oauth2_client
from supertokens_python.recipe.oauth2provider.interfaces import CreateOAuth2ClientInput
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.interfaces import SessionClaimValidator
from supertokens_python.recipe.thirdparty import ProviderConfig
Expand Down Expand Up @@ -457,6 +459,14 @@ def test_get_totp_code(request: HttpRequest):
return JsonResponse({"totp": code})


def test_create_oauth2_client(request: HttpRequest):
body = json.loads(request.body)
if body is None:
raise Exception("Invalid request body")
client = create_oauth2_client(CreateOAuth2ClientInput.from_json(body))
return JsonResponse(client.to_json())


def before_each(request: HttpRequest):
import mysite.store

Expand Down Expand Up @@ -486,6 +496,7 @@ def test_feature_flags(request: HttpRequest):
"mfa",
"recipeConfig",
"accountlinking-fixes",
"oauth2",
]
}
)
23 changes: 22 additions & 1 deletion tests/auth-react/fastapi-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from supertokens_python.recipe import (
emailpassword,
emailverification,
oauth2provider,
passwordless,
session,
thirdparty,
Expand Down Expand Up @@ -106,6 +107,10 @@
AssociateUserToTenantUnknownUserIdError,
TenantConfigCreateOrUpdate,
)
from supertokens_python.recipe.oauth2provider.interfaces import CreateOAuth2ClientInput
from supertokens_python.recipe.oauth2provider.recipe import OAuth2ProviderRecipe
from supertokens_python.recipe.oauth2provider.asyncio import create_oauth2_client
from supertokens_python.recipe.openid.recipe import OpenIdRecipe
from supertokens_python.recipe.passwordless import (
ContactEmailOnlyConfig,
ContactEmailOrPhoneConfig,
Expand Down Expand Up @@ -391,6 +396,8 @@ def custom_init():
Supertokens.reset()
TOTPRecipe.reset()
MultiFactorAuthRecipe.reset()
OpenIdRecipe.reset()
OAuth2ProviderRecipe.reset()

def override_email_verification_apis(
original_implementation_email_verification: EmailVerificationAPIInterface,
Expand Down Expand Up @@ -1021,6 +1028,10 @@ async def resync_session_and_fetch_mfa_info_put(
)
),
},
{
"id": "oauth2provider",
"init": oauth2provider.init(),
},
]

global accountlinking_config
Expand Down Expand Up @@ -1084,7 +1095,7 @@ async def should_do_automatic_account_linking(
supertokens_config=SupertokensConfig("http://localhost:9000"),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="0.0.0.0:" + get_api_port(),
api_domain="localhost:" + get_api_port(),
website_domain=get_website_domain(),
),
framework="fastapi",
Expand Down Expand Up @@ -1374,6 +1385,15 @@ async def test_get_totp_code(request: Request):
return JSONResponse({"totp": code})


@app.post("/test/create-oauth2-client")
async def test_create_oauth2_client(request: Request):
body = await request.json()
if body is None:
raise Exception("Invalid request body")
client = await create_oauth2_client(CreateOAuth2ClientInput.from_json(body))
return JSONResponse(client.to_json())


@app.get("/test/getDevice")
def test_get_device(request: Request):
global code_store
Expand All @@ -1397,6 +1417,7 @@ def test_feature_flags(request: Request):
"mfa",
"recipeConfig",
"accountlinking-fixes",
"oauth2",
]
return JSONResponse({"available": available})

Expand Down
23 changes: 22 additions & 1 deletion tests/auth-react/flask-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
accountlinking,
emailpassword,
emailverification,
oauth2provider,
passwordless,
session,
thirdparty,
Expand Down Expand Up @@ -77,6 +78,10 @@
delete_tenant,
disassociate_user_from_tenant,
)
from supertokens_python.recipe.oauth2provider.syncio import create_oauth2_client
from supertokens_python.recipe.oauth2provider.interfaces import CreateOAuth2ClientInput
from supertokens_python.recipe.oauth2provider.recipe import OAuth2ProviderRecipe
from supertokens_python.recipe.openid.recipe import OpenIdRecipe
from supertokens_python.recipe.passwordless.syncio import update_user
from supertokens_python.recipe.session.exceptions import (
ClaimValidationError,
Expand Down Expand Up @@ -374,6 +379,8 @@ def custom_init():
Supertokens.reset()
TOTPRecipe.reset()
MultiFactorAuthRecipe.reset()
OpenIdRecipe.reset()
OAuth2ProviderRecipe.reset()

def override_email_verification_apis(
original_implementation_email_verification: EmailVerificationAPIInterface,
Expand Down Expand Up @@ -1004,6 +1011,10 @@ async def resync_session_and_fetch_mfa_info_put(
)
),
},
{
"id": "oauth2provider",
"init": oauth2provider.init(),
},
]

global accountlinking_config
Expand Down Expand Up @@ -1066,7 +1077,7 @@ async def should_do_automatic_account_linking(
supertokens_config=SupertokensConfig("http://localhost:9000"),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="0.0.0.0:" + get_api_port(),
api_domain="localhost:" + get_api_port(),
website_domain=get_website_domain(),
),
framework="flask",
Expand Down Expand Up @@ -1401,6 +1412,15 @@ def test_get_totp_code():
return jsonify({"totp": code})


@app.post("/test/create-oauth2-client") # type: ignore
def test_create_oauth2_client():
body = request.get_json()
if body is None:
raise Exception("Invalid request body")
client = create_oauth2_client(CreateOAuth2ClientInput.from_json(body))
return jsonify(client.to_json())


@app.get("/test/getDevice") # type: ignore
def test_get_device():
global code_store
Expand All @@ -1424,6 +1444,7 @@ def test_feature_flags():
"mfa",
"recipeConfig",
"accountlinking-fixes",
"oauth2",
]
return jsonify({"available": available})

Expand Down

0 comments on commit 0226085

Please sign in to comment.