|
8 | 8 | from django.utils import timezone
|
9 | 9 | from jwcrypto import jwt
|
10 | 10 | from oauthlib.common import Request
|
| 11 | +from oauthlib.oauth2.rfc6749 import errors as rfc6749_errors |
11 | 12 |
|
12 | 13 | from oauth2_provider.exceptions import FatalClientError
|
13 |
| -from oauth2_provider.models import get_access_token_model, get_application_model, get_refresh_token_model |
| 14 | +from oauth2_provider.models import ( |
| 15 | + get_access_token_model, |
| 16 | + get_application_model, |
| 17 | + get_grant_model, |
| 18 | + get_refresh_token_model, |
| 19 | +) |
14 | 20 | from oauth2_provider.oauth2_backends import get_oauthlib_core
|
15 | 21 | from oauth2_provider.oauth2_validators import OAuth2Validator
|
16 | 22 |
|
|
30 | 36 | UserModel = get_user_model()
|
31 | 37 | Application = get_application_model()
|
32 | 38 | AccessToken = get_access_token_model()
|
| 39 | +Grant = get_grant_model() |
33 | 40 | RefreshToken = get_refresh_token_model()
|
34 | 41 |
|
35 | 42 | CLEARTEXT_SECRET = "1234567890abcdefghijklmnopqrstuvwxyz"
|
@@ -580,3 +587,14 @@ def test_validate_id_token_bad_token_no_aud(oauth2_settings, mocker, oidc_key):
|
580 | 587 | validator = OAuth2Validator()
|
581 | 588 | status = validator.validate_id_token(token.serialize(), ["openid"], mocker.sentinel.request)
|
582 | 589 | assert status is False
|
| 590 | + |
| 591 | + |
| 592 | +@pytest.mark.django_db |
| 593 | +def test_invalidate_authorization_token_returns_invalid_grant_error_when_grant_does_not_exist(): |
| 594 | + client_id = "123" |
| 595 | + code = "12345" |
| 596 | + request = Request("/") |
| 597 | + assert Grant.objects.all().count() == 0 |
| 598 | + with pytest.raises(rfc6749_errors.InvalidGrantError): |
| 599 | + validator = OAuth2Validator() |
| 600 | + validator.invalidate_authorization_code(client_id=client_id, code=code, request=request) |
0 commit comments