summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/test.py b/test.py
index 043d059..92e2ce9 100755
--- a/test.py
+++ b/test.py
@@ -244,6 +244,33 @@ class ContentLengthMiddlewareTest(unittest.TestCase):
res.status("200 Found")
res.header("Content-length", "7")
+class BasicAuthMiddlewareTest(unittest.TestCase):
+ def setUp(self):
+ self.staticapp = applications.StaticContent(
+ "200 Found", [("Content-Type", "text/plain")], "success")
+ checkpw = middlewares.DictAuthChecker({"bar": "baz"})
+ self.app = middlewares.BasicAuthMiddleware(
+ wsgiref.validate.validator(self.staticapp), checkpw)
+ self.req = Request(self)
+
+ def test401(self):
+ res = self.req(self.app)
+ res.status(401)
+ res.header("WWW-Authenticate", lambda _: True)
+
+ def doauth(self, password="baz", status=200):
+ req = self.req.copy()
+ token = ("bar:%s" % password).encode("base64").strip()
+ req.setheader('http-authorization', 'Basic %s' % token)
+ res = req(self.app)
+ res.status(status)
+
+ def test200(self):
+ self.doauth()
+
+ def test401authfail(self):
+ self.doauth(password="spam", status=401)
+
def alltests(case):
return unittest.TestLoader().loadTestsFromTestCase(case)
@@ -253,6 +280,7 @@ fullsuite.addTest(alltests(StaticContentTest))
fullsuite.addTest(alltests(StaticFileTest))
fullsuite.addTest(alltests(AuthDigestMiddlewareTest))
fullsuite.addTest(alltests(ContentLengthMiddlewareTest))
+fullsuite.addTest(alltests(BasicAuthMiddlewareTest))
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity=2)