def testAuthentication(self): conf.use_test_db(True) self.load_fixtures() req = DummyReq('cartman', 'cartmans_pw', 'GET', '/storageauthtest/login/xmlrpc', '') basic = BasicAccessControl(req) self.assertTrue(basic.is_authentic()) req = DummyReq('cartman', 'cartmanspw', 'GET', '/storageauthtest/login/xmlrpc', '') basic = BasicAccessControl(req) self.assertFalse(basic.is_authentic()) req = DummyReq('*****@*****.**', 'nomailforme', 'GET', '/storageauthtest/login/xmlrpc', '') basic = BasicAccessControl(req) self.assertTrue(basic.is_authentic()) req = DummyReq('user%40nomail.box', 'nomailforme', 'GET', '/storageauthtest/login/xmlrpc', '') basic = BasicAccessControl(req) self.assertTrue(basic.is_authentic()) req = DummyReq('*****@*****.**', 'wrongpw', 'GET', '/storageauthtest/login/xmlrpc', '') basic = BasicAccessControl(req) self.assertFalse(basic.is_authentic()) req = DummyReq('user%40nomail.box', 'wrongpw', 'GET', '/storageauthtest/login/xmlrpc', '') basic = BasicAccessControl(req) self.assertFalse(basic.is_authentic())
def headerparserhandler(req): from mod_python.apache import HTTP_UNAUTHORIZED, HTTP_FORBIDDEN, OK control = BasicAccessControl(req) # Check authentication if not control.is_authentic(): req.err_headers_out['WWW-Authenticate'] = 'Basic realm="%s"' % control.options['realm'] return HTTP_UNAUTHORIZED # Check if blocked or expired if control.is_blocked(): return HTTP_FORBIDDEN return OK