Skip to content

Commit 8605fe6

Browse files
authored
Bluebutton 638 more descriptive 404 reason (#685)
* Add test for new error description * Change Http404 to OAuth2 InvalidGrantError exception * Change test expected status from 404 to 401.
1 parent f846cd1 commit 8605fe6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

apps/dot_ext/oauth2_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from django.utils import timezone
44
from django.utils.timezone import timedelta
5-
from django.http import Http404
65

76
from oauth2_provider.models import AccessToken, RefreshToken
87
from oauth2_provider.oauth2_validators import OAuth2Validator
98
from django.core.exceptions import ObjectDoesNotExist
109
from apps.pkce.oauth2_validators import PKCEValidatorMixin
10+
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
1111

1212

1313
class SingleAccessTokenValidator(
@@ -99,4 +99,4 @@ def get_original_scopes(self, refresh_token, request, *args, **kwargs):
9999
try:
100100
return super().get_original_scopes(refresh_token, request, *args, **kwargs)
101101
except ObjectDoesNotExist:
102-
raise Http404
102+
raise InvalidGrantError

apps/dot_ext/tests/test_authorization.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_refresh_with_expired_token(self):
198198
'client_secret': application.client_secret,
199199
}
200200
response = self.client.post(reverse('oauth2_provider:token'), data=refresh_request_data)
201-
self.assertEqual(response.status_code, 404)
201+
self.assertEqual(response.status_code, 401)
202202

203203
def test_refresh_with_revoked_token(self):
204204
redirect_uri = 'http://localhost'
@@ -261,4 +261,5 @@ def test_refresh_with_revoked_token(self):
261261
'client_secret': application.client_secret,
262262
}
263263
response = self.client.post(reverse('oauth2_provider:token'), data=refresh_request_data)
264-
self.assertEqual(response.status_code, 404)
264+
self.assertEqual(response.status_code, 401)
265+
self.assertEqual(response.content, b'{"error": "invalid_grant"}')

0 commit comments

Comments
 (0)