diff --git a/tests/emailpassword/test_passwordreset.py b/tests/emailpassword/test_passwordreset.py index 6a67dc632..118cf3972 100644 --- a/tests/emailpassword/test_passwordreset.py +++ b/tests/emailpassword/test_passwordreset.py @@ -14,6 +14,7 @@ import asyncio import json from typing import Any, Dict, Union +from urllib.parse import urlparse from fastapi import FastAPI from fastapi.requests import Request @@ -22,6 +23,7 @@ from supertokens_python import InputAppInfo, SupertokensConfig, init from supertokens_python.framework.fastapi import get_middleware from supertokens_python.recipe import emailpassword, session +from supertokens_python.recipe.emailpassword.asyncio import create_reset_password_link from supertokens_python.recipe.session import SessionContainer from supertokens_python.recipe.session.asyncio import ( create_new_session, @@ -339,3 +341,38 @@ async def send_email( assert dict_response["status"] == "OK" assert dict_response["user"]["id"] == user_info["id"] assert dict_response["user"]["email"] == user_info["email"] + + +@mark.asyncio +async def test_create_reset_password_link( + driver_config_client: TestClient, +): + init( + supertokens_config=SupertokensConfig("http://localhost:3567"), + app_info=InputAppInfo( + app_name="SuperTokens Demo", + api_domain="http://api.supertokens.io", + website_domain="http://supertokens.io", + api_base_path="/auth", + ), + framework="fastapi", + recipe_list=[ + emailpassword.init(), + session.init(get_token_transfer_method=lambda _, __, ___: "cookie"), + ], + ) + start_st() + + response_1 = sign_up_request( + driver_config_client, "random@gmail.com", "validpass123" + ) + assert response_1.status_code == 200 + dict_response = json.loads(response_1.text) + user_info = dict_response["user"] + assert dict_response["status"] == "OK" + link = await create_reset_password_link("public", user_info["id"]) + url = urlparse(link.link) # type: ignore + queries = url.query.strip("&").split("&") + assert url.path == "/auth/reset-password" + assert "tenantId=public" in queries + assert "rid=emailpassword" in queries diff --git a/tests/thirdpartyemailpassword/test_email_delivery.py b/tests/thirdpartyemailpassword/test_email_delivery.py index 0d95d31f2..49b16861d 100644 --- a/tests/thirdpartyemailpassword/test_email_delivery.py +++ b/tests/thirdpartyemailpassword/test_email_delivery.py @@ -21,6 +21,7 @@ from fastapi.requests import Request from fastapi.testclient import TestClient from pytest import fixture, mark +from urllib.parse import urlparse from supertokens_python import InputAppInfo, SupertokensConfig, init from supertokens_python.framework.fastapi import get_middleware @@ -37,6 +38,9 @@ session, thirdpartyemailpassword, ) +from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( + create_reset_password_link, +) from supertokens_python.recipe.emailverification.emaildelivery.services import ( SMTPService as EVSMTPService, ) @@ -1036,3 +1040,38 @@ async def send_email( assert email == "test@example.com" assert email_verify_url != "" + + +@mark.asyncio +async def test_create_reset_password_link( + driver_config_client: TestClient, +): + init( + supertokens_config=SupertokensConfig("http://localhost:3567"), + app_info=InputAppInfo( + app_name="SuperTokens Demo", + api_domain="http://api.supertokens.io", + website_domain="http://supertokens.io", + api_base_path="/auth", + ), + framework="fastapi", + recipe_list=[ + thirdpartyemailpassword.init(), + session.init(get_token_transfer_method=lambda _, __, ___: "cookie"), + ], + ) + start_st() + + response_1 = sign_up_request( + driver_config_client, "random@gmail.com", "validpass123" + ) + assert response_1.status_code == 200 + dict_response = json.loads(response_1.text) + user_info = dict_response["user"] + assert dict_response["status"] == "OK" + link = await create_reset_password_link("public", user_info["id"]) + url = urlparse(link.link) # type: ignore + queries = url.query.strip("&").split("&") + assert url.path == "/auth/reset-password" + assert "tenantId=public" in queries + assert "rid=thirdpartyemailpassword" in queries