Skip to content

Commit 12e6b14

Browse files
dawidwolski-identtdopry
authored andcommitted
Fix: Handle AttributeError in IntrospectTokenView
1 parent 362fecb commit 12e6b14

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

oauth2_provider/views/introspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_token_response(token_value=None):
3333
.objects.select_related("user", "application")
3434
.get(token_checksum=token_checksum)
3535
)
36-
except ObjectDoesNotExist:
36+
except (AttributeError, ObjectDoesNotExist):
3737
return JsonResponse({"active": False}, status=200)
3838
else:
3939
if token.is_valid():

tests/test_introspection_view.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,28 @@ def test_view_post_notexisting_token(self):
278278
"active": False,
279279
},
280280
)
281+
282+
def test_view_post_no_token(self):
283+
"""
284+
Test that when you pass an empty token as form parameter,
285+
a json with an inactive token state is provided
286+
"""
287+
auth_headers = {
288+
"HTTP_AUTHORIZATION": "Bearer " + self.resource_server_token.token,
289+
}
290+
response = self.client.post(
291+
reverse("oauth2_provider:introspect"), **auth_headers
292+
)
293+
294+
self.assertEqual(response.status_code, 200)
295+
content = response.json()
296+
self.assertIsInstance(content, dict)
297+
self.assertDictEqual(
298+
content,
299+
{
300+
"active": False,
301+
},
302+
)
281303

282304
def test_view_post_valid_client_creds_basic_auth(self):
283305
"""Test HTTP basic auth working"""

tox.ini

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ envlist =
55
docs,
66
lint,
77
sphinxlint,
8-
py{38,39,310,311,312}-dj42,
9-
py{310,311,312}-dj50,
10-
py{310,311,312}-dj51,
11-
py{310,311,312}-djmain,
8+
py{38,39,310,311,312,313}-dj42,
9+
py{310,311,312,313}-dj50,
10+
py{310,311,312,313}-dj51,
11+
py{310,311,312,313}-djmain,
1212
py39-multi-db-dj-42
1313

1414
[gh-actions]
@@ -18,6 +18,7 @@ python =
1818
3.10: py310
1919
3.11: py311
2020
3.12: py312
21+
3.13: py313
2122

2223
[gh-actions:env]
2324
DJANGO =
@@ -54,7 +55,7 @@ deps =
5455
passenv =
5556
PYTEST_ADDOPTS
5657

57-
[testenv:py{310,311,312}-djmain]
58+
[testenv:py{310,311,312,313}-djmain]
5859
ignore_errors = true
5960
ignore_outcome = true
6061

0 commit comments

Comments
 (0)