Skip to content

Commit 01c2609

Browse files
committed
test: Fix failing tests
1 parent 5b36b16 commit 01c2609

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

supertokens_python/recipe/session/recipe.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
TokenTheftError,
2727
UnauthorisedError,
2828
InvalidClaimsError,
29+
TryRefreshTokenError,
2930
)
3031
from ...types import MaybeAwaitable
3132

@@ -239,10 +240,14 @@ async def handle_error(
239240
return await self.config.error_handlers.on_invalid_claim(
240241
self, request, err.payload, response
241242
)
242-
log_debug_message("errorHandler: returning TRY_REFRESH_TOKEN")
243-
return await self.config.error_handlers.on_try_refresh_token(
244-
request, str(err), response
245-
)
243+
if isinstance(err, TryRefreshTokenError):
244+
log_debug_message("errorHandler: returning TRY_REFRESH_TOKEN")
245+
return await self.config.error_handlers.on_try_refresh_token(
246+
request, str(err), response
247+
)
248+
249+
# TODO: Is raising err okay?
250+
raise err
246251

247252
def get_all_cors_headers(self) -> List[str]:
248253
cors_headers = get_cors_allowed_headers()

tests/emailpassword/test_emailverify.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
get_session,
4949
refresh_session,
5050
)
51+
from supertokens_python.recipe.session.constants import ANTI_CSRF_HEADER_KEY
5152
from supertokens_python.utils import is_version_gte
5253
from tests.utils import (
5354
TEST_ACCESS_TOKEN_MAX_AGE_CONFIG_KEY,
@@ -133,7 +134,11 @@ async def test_the_generate_token_api_with_valid_input_email_not_verified(
133134
api_base_path="/auth",
134135
),
135136
framework="fastapi",
136-
recipe_list=[session.init(anti_csrf="VIA_TOKEN"), emailpassword.init()],
137+
recipe_list=[
138+
session.init(anti_csrf="VIA_TOKEN"),
139+
emailverification.init("OPTIONAL"),
140+
emailpassword.init(),
141+
],
137142
)
138143
start_st()
139144

@@ -170,7 +175,11 @@ async def test_the_generate_token_api_with_valid_input_email_verified_and_test_e
170175
api_base_path="/auth",
171176
),
172177
framework="fastapi",
173-
recipe_list=[session.init(anti_csrf="VIA_TOKEN"), emailpassword.init()],
178+
recipe_list=[
179+
session.init(anti_csrf="VIA_TOKEN"),
180+
emailverification.init("OPTIONAL"),
181+
emailpassword.init(),
182+
],
174183
)
175184
start_st()
176185

@@ -213,7 +222,11 @@ async def test_the_generate_token_api_with_valid_input_no_session_and_check_outp
213222
api_base_path="/auth",
214223
),
215224
framework="fastapi",
216-
recipe_list=[session.init(anti_csrf="VIA_TOKEN"), emailpassword.init()],
225+
recipe_list=[
226+
session.init(anti_csrf="VIA_TOKEN"),
227+
emailverification.init("OPTIONAL"),
228+
emailpassword.init(),
229+
],
217230
)
218231
start_st()
219232

@@ -238,7 +251,11 @@ async def test_the_generate_token_api_with_an_expired_access_token_and_see_that_
238251
api_base_path="/auth",
239252
),
240253
framework="fastapi",
241-
recipe_list=[session.init(anti_csrf="VIA_TOKEN"), emailpassword.init()],
254+
recipe_list=[
255+
session.init(anti_csrf="VIA_TOKEN"),
256+
emailverification.init("OPTIONAL"),
257+
emailpassword.init(),
258+
],
242259
)
243260
start_st()
244261

@@ -723,7 +740,9 @@ async def custom_f(
723740
assert token is not None
724741

725742
response_3 = driver_config_client.post(
726-
url="/auth/user/email/verify", json={"method": "token", "token": token}
743+
url="/auth/user/email/verify",
744+
json={"method": "token", "token": token},
745+
headers={ANTI_CSRF_HEADER_KEY: response_1.headers.get("anti-csrf")},
727746
)
728747

729748
dict_response = json.loads(response_3.text)
@@ -760,7 +779,11 @@ async def test_the_email_verify_with_no_session_using_the_get_method(
760779
api_base_path="/auth",
761780
),
762781
framework="fastapi",
763-
recipe_list=[session.init(anti_csrf="VIA_TOKEN"), emailpassword.init()],
782+
recipe_list=[
783+
session.init(anti_csrf="VIA_TOKEN"),
784+
emailverification.init("OPTIONAL"),
785+
emailpassword.init(),
786+
],
764787
)
765788
start_st()
766789

@@ -850,7 +873,9 @@ async def email_verify_post(
850873
assert token is not None
851874

852875
response_3 = driver_config_client.post(
853-
url="/auth/user/email/verify", json={"method": "token", "token": token}
876+
url="/auth/user/email/verify",
877+
json={"method": "token", "token": token},
878+
headers={ANTI_CSRF_HEADER_KEY: response_1.headers.get("anti-csrf")},
854879
)
855880

856881
dict_response = json.loads(response_3.text)
@@ -946,7 +971,9 @@ async def email_verify_post(
946971
assert token is not None
947972

948973
response_3 = driver_config_client.post(
949-
url="/auth/user/email/verify", json={"method": "token", "token": token}
974+
url="/auth/user/email/verify",
975+
json={"method": "token", "token": token},
976+
headers={ANTI_CSRF_HEADER_KEY: response_1.headers.get("anti-csrf")},
950977
)
951978

952979
dict_response = json.loads(response_3.text)
@@ -974,7 +1001,11 @@ async def test_the_generate_token_api_with_valid_input_and_then_remove_token(
9741001
api_base_path="/auth",
9751002
),
9761003
framework="fastapi",
977-
recipe_list=[session.init(anti_csrf="VIA_TOKEN"), emailpassword.init()],
1004+
recipe_list=[
1005+
session.init(anti_csrf="VIA_TOKEN"),
1006+
emailverification.init("OPTIONAL"),
1007+
emailpassword.init(),
1008+
],
9781009
)
9791010
start_st()
9801011

tests/input_validation/test_input_validation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def test_init_validation_emailpassword():
8888
],
8989
)
9090
assert (
91-
"email_verification_feature must be of type InputEmailVerificationConfig or None"
91+
"Email Verification recipe mode must be one of 'REQUIRED' or 'OPTIONAL'"
9292
== str(ex.value)
9393
)
9494

@@ -473,7 +473,7 @@ async def test_init_validation_thirdpartyemailpassword():
473473
],
474474
)
475475
assert (
476-
"email_verification_feature must be of type InputEmailVerificationConfig or None"
476+
"Email Verification recipe mode must be one of 'REQUIRED' or 'OPTIONAL'"
477477
== str(ex.value)
478478
)
479479

@@ -608,7 +608,7 @@ async def test_init_validation_thirdpartypasswordless():
608608
],
609609
)
610610
assert (
611-
"email_verification_feature must be an instance of InputEmailVerificationConfig or None"
611+
"Email Verification recipe mode must be one of 'REQUIRED' or 'OPTIONAL'"
612612
== str(ex.value)
613613
)
614614

0 commit comments

Comments
 (0)