@@ -19,6 +19,39 @@ def access_protected():
1919 return app
2020
2121
22+ def test_default_headers (app ):
23+ app .config
24+ test_client = app .test_client ()
25+
26+ with app .test_request_context ():
27+ access_token = create_access_token ('username' )
28+
29+ # Ensure other authorization types don't work
30+ access_headers = {'Authorization' : 'Basic basiccreds' }
31+ response = test_client .get ('/protected' , headers = access_headers )
32+ expected_json = {'msg' : "Bad Authorization header. Expected value 'Bearer <JWT>'" }
33+ assert response .status_code == 422
34+ assert response .get_json () == expected_json
35+
36+ # Ensure default headers work
37+ access_headers = {'Authorization' : 'Bearer {}' .format (access_token )}
38+ response = test_client .get ('/protected' , headers = access_headers )
39+ assert response .status_code == 200
40+ assert response .get_json () == {'foo' : 'bar' }
41+
42+ # Ensure default headers work with multiple field values
43+ access_headers = {'Authorization' : 'Bearer {}, Basic creds' .format (access_token )}
44+ response = test_client .get ('/protected' , headers = access_headers )
45+ assert response .status_code == 200
46+ assert response .get_json () == {'foo' : 'bar' }
47+
48+ # Ensure default headers work with multiple field values in any position
49+ access_headers = {'Authorization' : 'Basic creds, Bearer {}' .format (access_token )}
50+ response = test_client .get ('/protected' , headers = access_headers )
51+ assert response .status_code == 200
52+ assert response .get_json () == {'foo' : 'bar' }
53+
54+
2255def test_custom_header_name (app ):
2356 app .config ['JWT_HEADER_NAME' ] = 'Foo'
2457 test_client = app .test_client ()
@@ -38,6 +71,18 @@ def test_custom_header_name(app):
3871 assert response .status_code == 200
3972 assert response .get_json () == {'foo' : 'bar' }
4073
74+ # Ensure new headers work with multiple field values
75+ access_headers = {'Foo' : 'Bearer {}, Basic randomcredshere' .format (access_token )}
76+ response = test_client .get ('/protected' , headers = access_headers )
77+ assert response .status_code == 200
78+ assert response .get_json () == {'foo' : 'bar' }
79+
80+ # Ensure new headers work with multiple field values in any position
81+ access_headers = {'Foo' : 'Basic randomcredshere, Bearer {}' .format (access_token )}
82+ response = test_client .get ('/protected' , headers = access_headers )
83+ assert response .status_code == 200
84+ assert response .get_json () == {'foo' : 'bar' }
85+
4186
4287def test_custom_header_type (app ):
4388 app .config ['JWT_HEADER_TYPE' ] = 'JWT'
@@ -59,6 +104,18 @@ def test_custom_header_type(app):
59104 assert response .status_code == 200
60105 assert response .get_json () == {'foo' : 'bar' }
61106
107+ # Ensure new headers work with multiple field values
108+ access_headers = {'Authorization' : 'JWT {}, Basic creds' .format (access_token )}
109+ response = test_client .get ('/protected' , headers = access_headers )
110+ assert response .status_code == 200
111+ assert response .get_json () == {'foo' : 'bar' }
112+
113+ # Ensure new headers work with multiple field values in any position
114+ access_headers = {'Authorization' : 'Basic creds, JWT {}' .format (access_token )}
115+ response = test_client .get ('/protected' , headers = access_headers )
116+ assert response .status_code == 200
117+ assert response .get_json () == {'foo' : 'bar' }
118+
62119 # Insure new headers without a type also work
63120 app .config ['JWT_HEADER_TYPE' ] = ''
64121 access_headers = {'Authorization' : access_token }
0 commit comments