Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adds test for create_reset_password_link #460

Merged
merged 8 commits into from
Nov 17, 2023
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ 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.0",
version="0.17.1",
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.0"
VERSION = "0.17.1"
TELEMETRY = "/telemetry"
USER_COUNT = "/users/count"
USER_DELETE = "/user/remove"
Expand Down
50 changes: 49 additions & 1 deletion tests/emailpassword/test_passwordreset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@
import asyncio
import json
from typing import Any, Dict, Union
from urllib.parse import urlparse

from fastapi import FastAPI
from fastapi.requests import Request
from fastapi.testclient import TestClient
from pytest import fixture, mark
from pytest import fixture, mark, raises
from supertokens_python import InputAppInfo, SupertokensConfig, init
from supertokens_python.exceptions import GeneralError
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.emailpassword.interfaces import (
CreateResetPasswordLinkUnknownUserIdError,
)
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.asyncio import (
create_new_session,
Expand Down Expand Up @@ -339,3 +345,45 @@ 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, "[email protected]", "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

link = await create_reset_password_link("public", "invalidUserId")
assert isinstance(link, CreateResetPasswordLinkUnknownUserIdError)

with raises(GeneralError) as err:
await create_reset_password_link("invalidTenantId", user_info["id"])
assert "status code: 400" in str(err.value)
52 changes: 51 additions & 1 deletion tests/thirdpartyemailpassword/test_email_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
from fastapi import FastAPI
from fastapi.requests import Request
from fastapi.testclient import TestClient
from pytest import fixture, mark
from pytest import fixture, mark, raises
from urllib.parse import urlparse

from supertokens_python import InputAppInfo, SupertokensConfig, init
from supertokens_python.exceptions import GeneralError
from supertokens_python.framework.fastapi import get_middleware
from supertokens_python.ingredients.emaildelivery import EmailDeliveryInterface
from supertokens_python.ingredients.emaildelivery.types import (
Expand All @@ -37,6 +39,12 @@
session,
thirdpartyemailpassword,
)
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
create_reset_password_link,
)
from supertokens_python.recipe.thirdpartyemailpassword.interfaces import (
CreateResetPasswordLinkUnknownUserIdError,
)
from supertokens_python.recipe.emailverification.emaildelivery.services import (
SMTPService as EVSMTPService,
)
Expand Down Expand Up @@ -1036,3 +1044,45 @@ async def send_email(

assert email == "[email protected]"
assert email_verify_url != ""


rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
@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, "[email protected]", "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

link = await create_reset_password_link("public", "invalidUserId")
assert isinstance(link, CreateResetPasswordLinkUnknownUserIdError)

with raises(GeneralError) as err:
await create_reset_password_link("invalidTenantId", user_info["id"])
assert "status code: 400" in str(err.value)
Loading