|
13 | 13 | from supertokens_python.recipe.session.jwt import (
|
14 | 14 | parse_jwt_without_signature_verification,
|
15 | 15 | )
|
| 16 | +from supertokens_python.recipe.session.access_token import ( |
| 17 | + validate_access_token_structure, |
| 18 | +) |
16 | 19 | from tests.utils import get_st_init_args, setup_function, start_st, teardown_function
|
17 | 20 |
|
18 | 21 | _ = setup_function # type:ignore
|
@@ -197,3 +200,64 @@ async def test_should_validate_v3_tokens_with_check_database_enabled(app: TestCl
|
197 | 200 | "sessionExists": True,
|
198 | 201 | "sessionHandle": info["body"]["sessionHandle"],
|
199 | 202 | }
|
| 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