test_auth: Add test for wrong auth.

This commit is contained in:
Emil Mikulic 2021-01-17 16:55:09 +11:00
parent 7e60a9b731
commit d39cc3849a

View File

@ -35,9 +35,19 @@ class TestAuth(TestHelper):
self.assertEqual(hdrs["Content-Length"], str(self.datalen))
self.assertEqual(hdrs["Content-Type"], "image/jpeg")
self.assertContains(hdrs["Server"], "darkhttpd/")
assert body == self.data, [url, resp, status, hdrs, body]
assert body == self.data, [self.url, resp, status, hdrs, body]
self.assertEqual(body, self.data)
def test_wrong_auth(self):
resp = self.get(self.url, req_hdrs={
'Authorization':
'Basic ' + base64.b64encode(b'myuser:wrongpass').decode('utf-8')})
status, hdrs, body = parse(resp)
self.assertContains(status, '401 Unauthorized')
self.assertEqual(hdrs['WWW-Authenticate'],
'Basic realm="User Visible Realm"')
self.assertContains(hdrs['Server'], 'darkhttpd/')
if __name__ == '__main__':
unittest.main()