def setUp(self): self.request = DownstreamRequest(RequestFactory().get('/')) self.middleware = ProxyPassReverse() # requests' response objects act like dicts of headers, so we can # take a little shortcut here. self.upstream_response = { 'URI': 'http://upstream.tld/go/', 'Location': 'http://upstream.tld/go/', 'Content-Location': 'http://upstream.tld/go/', 'Location-Foo': 'http://upstream.tld/go/' } self.view = Mock() self.view.reverse_urls = [('/yay/', 'http://upstream.tld/')] self.response = HttpResponse() # By default, the response objects headers will match the upstream # response object's headers. for key, value in iteritems(self.upstream_response): self.response[key] = value self.proxy_response = self.middleware.process_response( proxy=self.view, request=self.request, upstream_response=self.upstream_response, response=self.response)
class DownstreamRequestsTest(TestCase): def setUp(self): self.request = RequestFactory().get('/foo?bar=1') self.request.META['HTTP_my_header'] = 'foo' self.downstream_request = DownstreamRequest(self.request) def test_has_a_valid_query_string_attribute(self): self.assertEqual(self.downstream_request.query_string, 'bar=1') def test_proxy_attributes_to_their_Django_request_isntance(self): self.assertEqual(self.request.get_host(), self.downstream_request.get_host()) def test_x_forwarded_for_attribute_returns_requestor(self): self.assertEqual(self.downstream_request.x_forwarded_for, '127.0.0.1') def test_header_attribute_returns_header_set_containing_http_headers(self): self.assertEqual(self.downstream_request.headers['My-Header'], 'foo')
def setUp(self): self.request = DownstreamRequest(RequestFactory().get('/')) self.middleware = AddXFH() self.kwargs = self.middleware.process_request(Mock(), self.request, headers={})
def setUp(self): self.request = RequestFactory().get('/foo?bar=1') self.request.META['HTTP_my_header'] = 'foo' self.downstream_request = DownstreamRequest(self.request)
def setUp(self): self.request = RequestFactory().get('/foo?bar=1') self.request.META['HTTP_X_FORWARDED_FOR'] = '127.0.0.2' self.downstream_request = DownstreamRequest(self.request)