Skip to content

Commit b03b4fb

Browse files
test: fixes test,to actually test the values in the reset link
1 parent 42fc65b commit b03b4fb

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [unreleased]
1010

11-
## [0.17.1] - 2023-11-15
12-
- Added test for `create_reset_password_link` in both `emailpassword` and `thirdpartyemailpassword` recipes.
13-
1411
## [0.17.0] - 2023-11-14
1512
- Fixes `create_reset_password_link` in the emailpassword recipe wherein we passed the `rid` instead of the token in the link
1613

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
setup(
7272
name="supertokens_python",
73-
version="0.17.1",
73+
version="0.17.0",
7474
author="SuperTokens",
7575
license="Apache 2.0",
7676
author_email="[email protected]",

supertokens_python/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
SUPPORTED_CDI_VERSIONS = ["3.0"]
17-
VERSION = "0.17.1"
17+
VERSION = "0.17.0"
1818
TELEMETRY = "/telemetry"
1919
USER_COUNT = "/users/count"
2020
USER_DELETE = "/user/remove"

tests/emailpassword/test_passwordreset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def send_email(
180180
assert reset_url == "http://supertokens.io/auth/reset-password"
181181
assert token_info is not None and "token=" in token_info # type: ignore pylint: disable=unsupported-membership-test
182182
assert rid_info is not None and "rid=emailpassword" in rid_info # type: ignore pylint: disable=unsupported-membership-test
183-
assert tenant_info is not None and "tenantId=" in tenant_info # type: ignore pylint: disable=unsupported-membership-test
183+
assert tenant_info is not None and "tenantId=public" in tenant_info # type: ignore pylint: disable=unsupported-membership-test
184184

185185

186186
@mark.asyncio

tests/thirdpartyemailpassword/test_email_delivery.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,24 @@ async def test_create_reset_password_link(
10951095
async def test_send_reset_password_email(
10961096
driver_config_client: TestClient,
10971097
):
1098+
1099+
tenant_info, token_info, rid_info, reset_url = "", "", "", ""
1100+
1101+
class CustomEmailDeliveryService(
1102+
thirdpartyemailpassword.EmailDeliveryInterface[PasswordResetEmailTemplateVars]
1103+
):
1104+
async def send_email(
1105+
self,
1106+
template_vars: PasswordResetEmailTemplateVars,
1107+
user_context: Dict[str, Any],
1108+
):
1109+
nonlocal reset_url, token_info, rid_info, tenant_info
1110+
password_reset_url = template_vars.password_reset_link
1111+
reset_url = password_reset_url.split("?")[0]
1112+
token_info = password_reset_url.split("?")[1].split("&")[0]
1113+
rid_info = password_reset_url.split("?")[1].split("&")[1]
1114+
tenant_info = password_reset_url.split("?")[1].split("&")[2]
1115+
10981116
init(
10991117
supertokens_config=SupertokensConfig("http://localhost:3567"),
11001118
app_info=InputAppInfo(
@@ -1105,7 +1123,11 @@ async def test_send_reset_password_email(
11051123
),
11061124
framework="fastapi",
11071125
recipe_list=[
1108-
thirdpartyemailpassword.init(),
1126+
thirdpartyemailpassword.init(
1127+
email_delivery=thirdpartyemailpassword.EmailDeliveryConfig(
1128+
CustomEmailDeliveryService()
1129+
)
1130+
),
11091131
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
11101132
],
11111133
)
@@ -1121,6 +1143,47 @@ async def test_send_reset_password_email(
11211143
resp = await send_reset_password_email("public", user_info["id"])
11221144
assert isinstance(resp, SendResetPasswordEmailEmailOkResult)
11231145

1146+
assert reset_url == "http://supertokens.io/auth/reset-password"
1147+
assert token_info is not None and "token=" in token_info
1148+
assert rid_info is not None and "rid=thirdpartyemailpassword" in rid_info
1149+
assert tenant_info is not None and "tenantId=public" in tenant_info
1150+
1151+
link = await send_reset_password_email("public", "invalidUserId")
1152+
assert isinstance(link, SendResetPasswordEmailUnknownUserIdError)
1153+
1154+
with raises(GeneralError) as err:
1155+
await send_reset_password_email("invalidTenantId", user_info["id"])
1156+
assert "status code: 400" in str(err.value)
1157+
1158+
1159+
@mark.asyncio
1160+
async def test_send_reset_password_email_invalid_input(
1161+
driver_config_client: TestClient,
1162+
):
1163+
1164+
init(
1165+
supertokens_config=SupertokensConfig("http://localhost:3567"),
1166+
app_info=InputAppInfo(
1167+
app_name="SuperTokens Demo",
1168+
api_domain="http://api.supertokens.io",
1169+
website_domain="http://supertokens.io",
1170+
api_base_path="/auth",
1171+
),
1172+
framework="fastapi",
1173+
recipe_list=[
1174+
thirdpartyemailpassword.init(),
1175+
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
1176+
],
1177+
)
1178+
start_st()
1179+
1180+
response_1 = sign_up_request(
1181+
driver_config_client, "[email protected]", "validpass123"
1182+
)
1183+
assert response_1.status_code == 200
1184+
dict_response = json.loads(response_1.text)
1185+
user_info = dict_response["user"]
1186+
11241187
link = await send_reset_password_email("public", "invalidUserId")
11251188
assert isinstance(link, SendResetPasswordEmailUnknownUserIdError)
11261189

0 commit comments

Comments
 (0)