Skip to content

Commit

Permalink
test: fixes test,to actually test the values in the reset link
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMayankThakur committed Nov 17, 2023
1 parent 42fc65b commit b03b4fb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.17.1] - 2023-11-15
- Added test for `create_reset_password_link` in both `emailpassword` and `thirdpartyemailpassword` recipes.

## [0.17.0] - 2023-11-14
- Fixes `create_reset_password_link` in the emailpassword recipe wherein we passed the `rid` instead of the token in the link

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
2 changes: 1 addition & 1 deletion supertokens_python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from __future__ import annotations

SUPPORTED_CDI_VERSIONS = ["3.0"]
VERSION = "0.17.1"
VERSION = "0.17.0"
TELEMETRY = "/telemetry"
USER_COUNT = "/users/count"
USER_DELETE = "/user/remove"
Expand Down
2 changes: 1 addition & 1 deletion tests/emailpassword/test_passwordreset.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async def send_email(
assert reset_url == "http://supertokens.io/auth/reset-password"
assert token_info is not None and "token=" in token_info # type: ignore pylint: disable=unsupported-membership-test
assert rid_info is not None and "rid=emailpassword" in rid_info # type: ignore pylint: disable=unsupported-membership-test
assert tenant_info is not None and "tenantId=" in tenant_info # type: ignore pylint: disable=unsupported-membership-test
assert tenant_info is not None and "tenantId=public" in tenant_info # type: ignore pylint: disable=unsupported-membership-test


@mark.asyncio
Expand Down
65 changes: 64 additions & 1 deletion tests/thirdpartyemailpassword/test_email_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"),
],
)
Expand All @@ -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)

Expand Down

0 comments on commit b03b4fb

Please sign in to comment.