Skip to content

Commit b4ccab5

Browse files
author
Landon Gilbert-Bland
committed
Fix handling of missing JWT in header
This was introduced in cb988e1 Fixes #282
1 parent 7ad9ab8 commit b4ccab5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

flask_jwt_extended/view_decorators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _decode_jwt_from_headers():
188188
if header_type:
189189
field_values = split(r',\s*', auth_header)
190190
jwt_header = [s for s in field_values if s.split()[0] == header_type]
191-
if len(jwt_header) < 1:
191+
if len(jwt_header) < 1 or len(jwt_header[0].split()) != 2:
192192
msg = "Bad {} header. Expected value '{} <JWT>'".format(
193193
header_name,
194194
header_type

tests/test_headers.py

+9
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ def custom_response(err_str):
151151
assert response.get_json() == {'foo': "bar"}
152152

153153

154+
def test_header_without_jwt(app):
155+
jwtM = get_jwt_manager(app)
156+
test_client = app.test_client()
157+
158+
access_headers = {'Authorization': 'Bearer '}
159+
response = test_client.get('/protected', headers=access_headers)
160+
assert response.status_code == 422
161+
assert response.get_json() == {'msg': "Bad Authorization header. Expected value 'Bearer <JWT>'"}
162+
154163
def test_custom_error_msg_key(app):
155164
app.config['JWT_ERROR_MESSAGE_KEY'] = 'message'
156165
response = app.test_client().get('/protected', headers=None)

0 commit comments

Comments
 (0)