def test_pathRedirect(self): root = BaseTestResource() redirect = resource.RedirectResource(path="/other") root.putChild("r", redirect) ds = [] for url1, url2 in ( ("http://host/r", "http://host/other"), ("http://host/r/foo", "http://host/other"), ): ds.append(self.assertResponse( (resource.RedirectResource(path="/other"), url1), (301, {"location": url2}, self.html(url2)) )) return defer.DeferredList(ds, fireOnOneErrback=True)
def test_noRedirect(self): # This is useless, since it's a loop, but hey ds = [] for url in ("http://host/", "http://host/foo"): ds.append(self.assertResponse( (resource.RedirectResource(), url), (301, {"location": url}, self.html(url)) )) return defer.DeferredList(ds, fireOnOneErrback=True)
def test_hostRedirect(self): ds = [] for url1, url2 in ( ("http://host/", "http://other/"), ("http://host/foo", "http://other/foo"), ): ds.append(self.assertResponse( (resource.RedirectResource(host="other"), url1), (301, {"location": url2}, self.html(url2)) )) return defer.DeferredList(ds, fireOnOneErrback=True)
def test_redirectResource(self): """ Make sure a redirect response has the correct status and Location header. """ redirectResource = resource.RedirectResource(scheme='https', host='localhost', port=443, path='/foo', querystring='bar=baz') return self.assertResponse( (redirectResource, 'http://localhost/'), (301, {'location': 'https://localhost/foo?bar=baz'}, None))
def test_redirectResourceWithoutSSLSchemeRemapping(self): """ Make sure a redirect response has the correct status and Location header, when SSL is off, and the client request uses scheme http with the SSL port. """ def chanrequest2(root, uri, length, headers, method, version, prepath, content): site = server.Site(root) site.EnableSSL = False site.SSLPort = 8443 site.BindSSLPorts = [] return TestChanRequest(site, method, prepath, uri, length, headers, version, content) self.patch(self, "chanrequest", chanrequest2) redirectResource = resource.RedirectResource(path='/foo') return self.assertResponse( (redirectResource, 'http://localhost:8443/'), (301, {'location': 'http://localhost:8443/foo'}, None))