def do_request(resource, t=None, method="GET"): req = DummyRequest([]) req.method = method req.args = {} if t: req.args["t"] = [t] req.render(resource) return "".join(req.written), req
def do_request(resource, t=None, method="GET"): req = DummyRequest([]) req.method = method req.args = {} if t: req.args["t"] = [t] req.render(resource) return "".join(req.written), req
def make_request(uri='', method='GET', args={}): site = make_site(authenticator=Mock()) request = DummyRequest(uri.split('/')) request.method = method request.args = args resource = site.getResourceFor(request) request.render(resource) request.data = "".join(request.written) return request
def test_renderQuotesDigest(self): """ The digest value must be correctly quoted. It is a byte string in python3, so we must make sure the proper conversion is done """ resource = UnauthorizedResource([ digest.DigestCredentialFactory(b'md5', b'example\\"foo')]) request = DummyRequest([b'']) request.render(resource) auth_header = request.responseHeaders.getRawHeaders(b'www-authenticate')[0] self.assertIn(b'realm="example\\\\\\"foo"', auth_header) self.assertIn(b'hm="md5', auth_header)
def test_renderQuotesRealm(self): """ The realm value included in the I{WWW-Authenticate} header set in the response when L{UnauthorizedResounrce} is rendered has quotes and backslashes escaped. """ resource = UnauthorizedResource( [BasicCredentialFactory('example\\"foo')]) request = DummyRequest(['']) request.render(resource) self.assertEqual( request.responseHeaders.getRawHeaders('www-authenticate'), ['basic realm="example\\\\\\"foo"'])
def test_renderQuotesRealm(self): """ The realm value included in the I{WWW-Authenticate} header set in the response when L{UnauthorizedResounrce} is rendered has quotes and backslashes escaped. """ resource = UnauthorizedResource([ BasicCredentialFactory('example\\"foo')]) request = DummyRequest(['']) request.render(resource) self.assertEqual( request.responseHeaders.getRawHeaders('www-authenticate'), ['basic realm="example\\\\\\"foo"'])
def test_render(self): """ L{UnauthorizedResource} renders with a 401 response code and a I{WWW-Authenticate} header and puts a simple unauthorized message into the response body. """ resource = UnauthorizedResource([ BasicCredentialFactory('example.com')]) request = DummyRequest(['']) request.render(resource) self.assertEqual(request.responseCode, 401) self.assertEqual( request.responseHeaders.getRawHeaders('www-authenticate'), ['basic realm="example.com"']) self.assertEqual(request.written, ['Unauthorized'])
def test_render(self): """ L{UnauthorizedResource} renders with a 401 response code and a I{WWW-Authenticate} header and puts a simple unauthorized message into the response body. """ resource = UnauthorizedResource( [BasicCredentialFactory('example.com')]) request = DummyRequest(['']) request.render(resource) self.assertEqual(request.responseCode, 401) self.assertEqual( request.responseHeaders.getRawHeaders('www-authenticate'), ['basic realm="example.com"']) self.assertEqual(request.written, ['Unauthorized'])