| 1 |
from datetime import timedelta |
| 2 |
|
| 3 |
from django.utils import timezone |
| 4 |
|
| 5 |
from allauth.socialaccount.internal.jwtkit import verify_and_decode |
| 6 |
from allauth.socialaccount.providers.apple.client import jwt_encode |
| 7 |
from allauth.socialaccount.providers.oauth2.client import OAuth2Error |
| 8 |
|
| 9 |
|
| 10 |
def test_verify_and_decode(enable_cache): |
| 11 |
now = timezone.now() |
| 12 |
payload = { |
| 13 |
"iss": "https://accounts.google.com", |
| 14 |
"azp": "client_id", |
| 15 |
"aud": "client_id", |
| 16 |
"sub": "108204268033311374519", |
| 17 |
"hd": "example.com", |
| 18 |
"locale": "en", |
| 19 |
"iat": now, |
| 20 |
"jti": "a4e9b64d5e31da48a2037216e4ba9a5f5f4f50a0", |
| 21 |
"exp": now + timedelta(hours=1), |
| 22 |
} |
| 23 |
id_token = jwt_encode(payload, "secret") |
| 24 |
for attempt in range(2): |
| 25 |
try: |
| 26 |
verify_and_decode( |
| 27 |
credential=id_token, |
| 28 |
keys_url="/", |
| 29 |
issuer=payload["iss"], |
| 30 |
audience=payload["aud"], |
| 31 |
lookup_kid=False, |
| 32 |
verify_signature=False, |
| 33 |
) |
| 34 |
assert attempt == 0 |
| 35 |
except OAuth2Error: |
| 36 |
assert attempt == 1 |