Skip to content

Commit 747c11b

Browse files
committed
basic-auth test improvements:
- refactored test_set_cors_credentials_headers_after_auth_request to test with the required (and a bad) basic auth challenge response. - do this for all present/absent username:password combos, foo:bar, foo:, : (neither) Signed-off-by: Brett Randall <javabrett@gmail.com>
1 parent 3c97d10 commit 747c11b

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

test_httpbin.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,28 @@ def test_set_cors_headers_after_request(self):
234234
)
235235

236236
def test_set_cors_credentials_headers_after_auth_request(self):
237-
response = self.app.get('/basic-auth/foo/bar')
237+
self._test_set_cors_credentials_headers_after_auth_request('/basic-auth/foo/bar', 'Basic Zm9vOmJhcg==')
238+
self._test_set_cors_credentials_headers_after_auth_request('/basic-auth/foo', 'Basic Zm9vOg==')
239+
self._test_set_cors_credentials_headers_after_auth_request('/basic-auth', 'Basic Og==')
240+
241+
def _test_set_cors_credentials_headers_after_auth_request(self, path, basic_auth):
242+
response = self.app.get(path)
238243
self.assertEqual(
239244
response.headers.get('Access-Control-Allow-Credentials'), 'true'
240245
)
241-
response = self.app.get('/basic-auth/foo')
242246
self.assertEqual(
243-
response.headers.get('Access-Control-Allow-Credentials'), 'true'
247+
response.headers.get('Www-Authenticate'), 'Basic realm="Fake Realm"'
244248
)
245-
response = self.app.get('/basic-auth')
246249
self.assertEqual(
247-
response.headers.get('Access-Control-Allow-Credentials'), 'true'
250+
response.status_code, 401
251+
)
252+
response = self.app.get(path, headers={'Authorization': 'Basic BADHASH=='})
253+
self.assertEqual(
254+
response.status_code, 401
255+
)
256+
response = self.app.get(path, headers={'Authorization': basic_auth})
257+
self.assertEqual(
258+
response.status_code, 200
248259
)
249260

250261
def test_set_cors_headers_after_request_with_request_origin(self):

0 commit comments

Comments
 (0)