File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change 2
2
import hashlib
3
3
4
4
from django .core .exceptions import ObjectDoesNotExist
5
- from django .http import JsonResponse
5
+ from django .http import JsonResponse , HttpResponseBadRequest
6
6
from django .utils .decorators import method_decorator
7
7
from django .views .decorators .csrf import csrf_exempt
8
8
@@ -33,8 +33,12 @@ def get_token_response(token_value=None):
33
33
.objects .select_related ("user" , "application" )
34
34
.get (token_checksum = token_checksum )
35
35
)
36
- except ( AttributeError , ObjectDoesNotExist ) :
36
+ except ObjectDoesNotExist :
37
37
return JsonResponse ({"active" : False }, status = 200 )
38
+ except AttributeError :
39
+ return HttpResponseBadRequest (
40
+ {"error" : "invalid_request" , "error_description" : "Token parameter is missing." }
41
+ )
38
42
else :
39
43
if token .is_valid ():
40
44
data = {
Original file line number Diff line number Diff line change @@ -281,23 +281,17 @@ def test_view_post_notexisting_token(self):
281
281
282
282
def test_view_post_no_token (self ):
283
283
"""
284
- Test that when you pass an empty token as form parameter,
285
- a json with an inactive token state is provided
284
+ Test that when you pass no token HTTP 400 is returned
286
285
"""
287
286
auth_headers = {
288
287
"HTTP_AUTHORIZATION" : "Bearer " + self .resource_server_token .token ,
289
288
}
290
289
response = self .client .post (reverse ("oauth2_provider:introspect" ), ** auth_headers )
291
290
292
- self .assertEqual (response .status_code , 200 )
291
+ self .assertEqual (response .status_code , 400 )
293
292
content = response .json ()
294
293
self .assertIsInstance (content , dict )
295
- self .assertDictEqual (
296
- content ,
297
- {
298
- "active" : False ,
299
- },
300
- )
294
+ self .assertEqual (content ["error" ], "invalid_request" )
301
295
302
296
def test_view_post_valid_client_creds_basic_auth (self ):
303
297
"""Test HTTP basic auth working"""
You can’t perform that action at this time.
0 commit comments