Skip to content

Commit e6e798d

Browse files
Merge pull request #384 from supertokens/test/access-token-validation
test: Add test for access token validation
2 parents f8e4289 + ca14ee0 commit e6e798d

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
- [ ] If have added a new web framework, update the `supertokens_python/utils.py` file to include that in the `FRAMEWORKS` variable
3232
- [ ] If added a new recipe that has a User type with extra info, then be sure to change the User type in supertokens_python/types.py
3333
- [ ] Make sure that `syncio` / `asyncio` functions are consistent.
34-
34+
- [ ] If access token structure has changed
35+
- Modified test in `tests/sessions/test_access_token_version.py` to account for any new claims that are optional or omitted by the core
36+
3537
## Remaining TODOs for this PR
3638

3739
- [ ] Item1
38-
- [ ] Item2
40+
- [ ] Item2

tests/sessions/test_access_token_v3.py renamed to tests/sessions/test_access_token_version.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from supertokens_python.recipe.session.jwt import (
1414
parse_jwt_without_signature_verification,
1515
)
16+
from supertokens_python.recipe.session.access_token import (
17+
validate_access_token_structure,
18+
)
1619
from tests.utils import get_st_init_args, setup_function, start_st, teardown_function
1720

1821
_ = setup_function # type:ignore
@@ -197,3 +200,64 @@ async def test_should_validate_v3_tokens_with_check_database_enabled(app: TestCl
197200
"sessionExists": True,
198201
"sessionHandle": info["body"]["sessionHandle"],
199202
}
203+
204+
205+
async def test_validation_logic_with_keys_that_can_use_json_nulls_values_in_claims():
206+
"""We want to make sure that for access token claims that can be null, the SDK does not fail access token validation if the
207+
core does not send them as part of the payload. For this we verify that validation passes when the keys are None, empty,
208+
or of a different type.
209+
210+
For now this test checks for:
211+
- antiCsrfToken
212+
- parentRefreshTokenHash1
213+
214+
But this test should be updated to include any keys that the core considers optional in the payload (i.e either it sends
215+
JSON null or skips them entirely)
216+
"""
217+
218+
V3 = 3
219+
payload = {
220+
"sessionHandle": "",
221+
"sub": "",
222+
"refreshTokenHash1": "",
223+
"exp": float(0),
224+
"iat": float(0),
225+
}
226+
227+
validate_access_token_structure(payload, V3)
228+
229+
payload = {
230+
"sessionHandle": "",
231+
"sub": "",
232+
"refreshTokenHash1": "",
233+
"exp": float(0),
234+
"iat": float(0),
235+
"parentRefreshTokenHash1": None,
236+
"antiCsrfToken": None,
237+
}
238+
239+
validate_access_token_structure(payload, V3)
240+
241+
payload = {
242+
"sessionHandle": "",
243+
"sub": "",
244+
"refreshTokenHash1": "",
245+
"exp": float(0),
246+
"iat": float(0),
247+
"parentRefreshTokenHash1": "",
248+
"antiCsrfToken": "",
249+
}
250+
251+
validate_access_token_structure(payload, V3)
252+
253+
payload = {
254+
"sessionHandle": "",
255+
"sub": "",
256+
"refreshTokenHash1": "",
257+
"exp": float(0),
258+
"iat": float(0),
259+
"parentRefreshTokenHash1": 1,
260+
"antiCsrfToken": 1,
261+
}
262+
263+
validate_access_token_structure(payload, V3)

0 commit comments

Comments
 (0)