-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fixes test,to actually test the values in the reset link
- Loading branch information
1 parent
42fc65b
commit b03b4fb
Showing
5 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ | |
|
||
setup( | ||
name="supertokens_python", | ||
version="0.17.1", | ||
version="0.17.0", | ||
author="SuperTokens", | ||
license="Apache 2.0", | ||
author_email="[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1095,6 +1095,24 @@ async def test_create_reset_password_link( | |
async def test_send_reset_password_email( | ||
driver_config_client: TestClient, | ||
): | ||
|
||
tenant_info, token_info, rid_info, reset_url = "", "", "", "" | ||
|
||
class CustomEmailDeliveryService( | ||
thirdpartyemailpassword.EmailDeliveryInterface[PasswordResetEmailTemplateVars] | ||
): | ||
async def send_email( | ||
self, | ||
template_vars: PasswordResetEmailTemplateVars, | ||
user_context: Dict[str, Any], | ||
): | ||
nonlocal reset_url, token_info, rid_info, tenant_info | ||
password_reset_url = template_vars.password_reset_link | ||
reset_url = password_reset_url.split("?")[0] | ||
token_info = password_reset_url.split("?")[1].split("&")[0] | ||
rid_info = password_reset_url.split("?")[1].split("&")[1] | ||
tenant_info = password_reset_url.split("?")[1].split("&")[2] | ||
|
||
init( | ||
supertokens_config=SupertokensConfig("http://localhost:3567"), | ||
app_info=InputAppInfo( | ||
|
@@ -1105,7 +1123,11 @@ async def test_send_reset_password_email( | |
), | ||
framework="fastapi", | ||
recipe_list=[ | ||
thirdpartyemailpassword.init(), | ||
thirdpartyemailpassword.init( | ||
email_delivery=thirdpartyemailpassword.EmailDeliveryConfig( | ||
CustomEmailDeliveryService() | ||
) | ||
), | ||
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"), | ||
], | ||
) | ||
|
@@ -1121,6 +1143,47 @@ async def test_send_reset_password_email( | |
resp = await send_reset_password_email("public", user_info["id"]) | ||
assert isinstance(resp, SendResetPasswordEmailEmailOkResult) | ||
|
||
assert reset_url == "http://supertokens.io/auth/reset-password" | ||
assert token_info is not None and "token=" in token_info | ||
assert rid_info is not None and "rid=thirdpartyemailpassword" in rid_info | ||
assert tenant_info is not None and "tenantId=public" in tenant_info | ||
|
||
link = await send_reset_password_email("public", "invalidUserId") | ||
assert isinstance(link, SendResetPasswordEmailUnknownUserIdError) | ||
|
||
with raises(GeneralError) as err: | ||
await send_reset_password_email("invalidTenantId", user_info["id"]) | ||
assert "status code: 400" in str(err.value) | ||
|
||
|
||
@mark.asyncio | ||
async def test_send_reset_password_email_invalid_input( | ||
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, "[email protected]", "validpass123" | ||
) | ||
assert response_1.status_code == 200 | ||
dict_response = json.loads(response_1.text) | ||
user_info = dict_response["user"] | ||
|
||
link = await send_reset_password_email("public", "invalidUserId") | ||
assert isinstance(link, SendResetPasswordEmailUnknownUserIdError) | ||
|
||
|