summary refs log tree commit diff
path: root/tests/http/test_proxyagent.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/http/test_proxyagent.py')
-rw-r--r--tests/http/test_proxyagent.py58
1 files changed, 9 insertions, 49 deletions
diff --git a/tests/http/test_proxyagent.py b/tests/http/test_proxyagent.py

index 34df39429b..3ea8b5bec7 100644 --- a/tests/http/test_proxyagent.py +++ b/tests/http/test_proxyagent.py
@@ -361,81 +361,41 @@ class MatrixFederationAgentTests(TestCase): body = self.successResultOf(treq.content(resp)) self.assertEqual(body, b"result") - @patch.dict(os.environ, {"HTTPS_PROXY": "proxy.com"}) - def test_https_request_via_uppercase_proxy_with_blacklist(self): + @patch.dict(os.environ, {"http_proxy": "proxy.com:8888"}) + def test_http_request_via_proxy_with_blacklist(self): # The blacklist includes the configured proxy IP. agent = ProxyAgent( BlacklistingReactorWrapper( self.reactor, ip_whitelist=None, ip_blacklist=IPSet(["1.0.0.0/8"]) ), self.reactor, - contextFactory=get_test_https_policy(), use_proxy=True, ) self.reactor.lookups["proxy.com"] = "1.2.3.5" - d = agent.request(b"GET", b"https://test.com/abc") + d = agent.request(b"GET", b"http://test.com") # there should be a pending TCP connection clients = self.reactor.tcpClients self.assertEqual(len(clients), 1) (host, port, client_factory, _timeout, _bindAddress) = clients[0] self.assertEqual(host, "1.2.3.5") - self.assertEqual(port, 1080) + self.assertEqual(port, 8888) - # make a test HTTP server, and wire up the client - proxy_server = self._make_connection( + # make a test server, and wire up the client + http_server = self._make_connection( client_factory, _get_test_protocol_factory() ) - # fish the transports back out so that we can do the old switcheroo - s2c_transport = proxy_server.transport - client_protocol = s2c_transport.other - c2s_transport = client_protocol.transport - # the FakeTransport is async, so we need to pump the reactor self.reactor.advance(0) - # now there should be a pending CONNECT request - self.assertEqual(len(proxy_server.requests), 1) - - request = proxy_server.requests[0] - self.assertEqual(request.method, b"CONNECT") - self.assertEqual(request.path, b"test.com:443") - - # tell the proxy server not to close the connection - proxy_server.persistent = True - - # this just stops the http Request trying to do a chunked response - # request.setHeader(b"Content-Length", b"0") - request.finish() - - # now we can replace the proxy channel with a new, SSL-wrapped HTTP channel - ssl_factory = _wrap_server_factory_for_tls(_get_test_protocol_factory()) - ssl_protocol = ssl_factory.buildProtocol(None) - http_server = ssl_protocol.wrappedProtocol - - ssl_protocol.makeConnection( - FakeTransport(client_protocol, self.reactor, ssl_protocol) - ) - c2s_transport.other = ssl_protocol - - self.reactor.advance(0) - - server_name = ssl_protocol._tlsConnection.get_servername() - expected_sni = b"test.com" - self.assertEqual( - server_name, - expected_sni, - "Expected SNI %s but got %s" % (expected_sni, server_name), - ) - # now there should be a pending request self.assertEqual(len(http_server.requests), 1) request = http_server.requests[0] self.assertEqual(request.method, b"GET") - self.assertEqual(request.path, b"/abc") + self.assertEqual(request.path, b"http://test.com") self.assertEqual(request.requestHeaders.getRawHeaders(b"host"), [b"test.com"]) request.write(b"result") request.finish() @@ -446,8 +406,8 @@ class MatrixFederationAgentTests(TestCase): body = self.successResultOf(treq.content(resp)) self.assertEqual(body, b"result") - @patch.dict(os.environ, {"https_proxy": "proxy.com"}) - def test_https_request_via_proxy_with_blacklist(self): + @patch.dict(os.environ, {"HTTPS_PROXY": "proxy.com"}) + def test_https_request_via_uppercase_proxy_with_blacklist(self): # The blacklist includes the configured proxy IP. agent = ProxyAgent( BlacklistingReactorWrapper(