@@ -19,6 +19,39 @@ def access_protected():
19
19
return app
20
20
21
21
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
+
22
55
def test_custom_header_name (app ):
23
56
app .config ['JWT_HEADER_NAME' ] = 'Foo'
24
57
test_client = app .test_client ()
@@ -38,6 +71,18 @@ def test_custom_header_name(app):
38
71
assert response .status_code == 200
39
72
assert response .get_json () == {'foo' : 'bar' }
40
73
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
+
41
86
42
87
def test_custom_header_type (app ):
43
88
app .config ['JWT_HEADER_TYPE' ] = 'JWT'
@@ -59,6 +104,18 @@ def test_custom_header_type(app):
59
104
assert response .status_code == 200
60
105
assert response .get_json () == {'foo' : 'bar' }
61
106
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
+
62
119
# Insure new headers without a type also work
63
120
app .config ['JWT_HEADER_TYPE' ] = ''
64
121
access_headers = {'Authorization' : access_token }
0 commit comments