This repository was archived by the owner on May 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -101,4 +101,4 @@ def authenticate_header(self, request):
101
101
header in a `401 Unauthenticated` response, or `None` if the
102
102
authentication scheme should return `403 Permission Denied` responses.
103
103
"""
104
- return 'JWT realm="{0 }"' .format (self .www_authenticate_realm )
104
+ return '{0} realm="{1 }"' .format (api_settings . JWT_AUTH_HEADER_PREFIX , self .www_authenticate_realm )
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ def test_post_form_failing_jwt_auth(self):
114
114
"""
115
115
response = self .csrf_client .post ('/jwt/' , {'example' : 'example' })
116
116
self .assertEqual (response .status_code , status .HTTP_401_UNAUTHORIZED )
117
+ self .assertEqual (response ['WWW-Authenticate' ], 'JWT realm="api"' )
117
118
118
119
def test_post_json_failing_jwt_auth (self ):
119
120
"""
@@ -268,3 +269,18 @@ def test_different_auth_header_prefix(self):
268
269
269
270
# Restore original settings
270
271
api_settings .JWT_AUTH_HEADER_PREFIX = DEFAULTS ['JWT_AUTH_HEADER_PREFIX' ]
272
+
273
+ def test_post_form_failing_jwt_auth_different_auth_header_prefix (self ):
274
+ """
275
+ Ensure using a different setting for `JWT_AUTH_HEADER_PREFIX` and
276
+ POSTing form over JWT auth without correct credentials fails and
277
+ generated correct WWW-Authenticate header
278
+ """
279
+ api_settings .JWT_AUTH_HEADER_PREFIX = 'Bearer'
280
+
281
+ response = self .csrf_client .post ('/jwt/' , {'example' : 'example' })
282
+ self .assertEqual (response .status_code , status .HTTP_401_UNAUTHORIZED )
283
+ self .assertEqual (response ['WWW-Authenticate' ], 'Bearer realm="api"' )
284
+
285
+ # Restore original settings
286
+ api_settings .JWT_AUTH_HEADER_PREFIX = DEFAULTS ['JWT_AUTH_HEADER_PREFIX' ]
You can’t perform that action at this time.
0 commit comments