def test_ssl_proxy_server(): class MyListener(ProxyListener): def forward_request(self, *args, **kwargs): invocations.append((args, kwargs)) return 200 invocations = [] # start SSL proxy listener = MyListener() port = get_free_tcp_port() server = start_proxy_server(port, update_listener=listener, use_ssl=True) wait_for_port_open(port) # start SSL proxy proxy_port = get_free_tcp_port() proxy = start_ssl_proxy(proxy_port, port, asynchronous=True) wait_for_port_open(proxy_port) # invoke SSL proxy server url = f"https://{LOCALHOST_HOSTNAME}:{proxy_port}" num_requests = 3 for i in range(num_requests): response = requests.get(url, verify=False) assert response.status_code == 200 # assert backend server has been invoked assert len(invocations) == num_requests # clean up proxy.stop() server.stop()
def test_ssl_proxy_server(self): class MyListener(ProxyListener): def forward_request(self, *args, **kwargs): invocations.append((args, kwargs)) return {"foo": "bar"} invocations = [] # start SSL proxy listener = MyListener() port = get_free_tcp_port() server = start_proxy_server(port, update_listener=listener, use_ssl=True) wait_for_port_open(port) # start SSL proxy proxy_port = get_free_tcp_port() proxy = start_ssl_proxy(proxy_port, port, asynchronous=True, fix_encoding=True) wait_for_port_open(proxy_port) # invoke SSL proxy server url = f"https://{LOCALHOST_HOSTNAME}:{proxy_port}" num_requests = 3 for i in range(num_requests): response = requests.get(url, verify=False) assert response.status_code == 200 # assert backend server has been invoked assert len(invocations) == num_requests # invoke SSL proxy server with gzip response for encoding in ["gzip", "gzip, deflate"]: headers = {HEADER_ACCEPT_ENCODING: encoding} response = requests.get(url, headers=headers, verify=False, stream=True) result = response.raw.read() assert to_str(gzip.decompress(result)) == json.dumps( {"foo": "bar"}) # clean up proxy.stop() server.stop()