From d39cc3849a4cce35db26bb55a9e60d342f1002c0 Mon Sep 17 00:00:00 2001 From: Emil Mikulic Date: Sun, 17 Jan 2021 16:55:09 +1100 Subject: [PATCH] test_auth: Add test for wrong auth. --- devel/test_auth.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/devel/test_auth.py b/devel/test_auth.py index a071b7a..c8ad94d 100755 --- a/devel/test_auth.py +++ b/devel/test_auth.py @@ -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()