diff --git a/test/test_http_proxy.py b/test/test_http_proxy.py index c6b7fbdf6..54a176d34 100644 --- a/test/test_http_proxy.py +++ b/test/test_http_proxy.py @@ -7,9 +7,8 @@ import os import random import ssl import threading -import time from http.server import BaseHTTPRequestHandler -from socketserver import BaseRequestHandler, ThreadingTCPServer +from socketserver import ThreadingTCPServer import pytest @@ -302,6 +301,7 @@ class TestHTTPProxy: with ctx.http_server(HTTPProxyHandler) as server_address: with handler(proxies={ctx.REQUEST_PROTO: f'http://{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh) + assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is False assert 'Proxy-Authorization' not in proxy_info['headers'] assert proxy_info['proxy'] == server_address @@ -310,6 +310,7 @@ class TestHTTPProxy: with ctx.http_server(HTTPProxyHandler, username='test', password='test') as server_address: with handler(proxies={ctx.REQUEST_PROTO: f'http://test:test@{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh) + assert proxy_info['proxy'] == server_address assert 'Proxy-Authorization' in proxy_info['headers'] def test_http_bad_auth(self, handler, ctx): @@ -327,14 +328,15 @@ class TestHTTPProxy: with handler(proxies={ctx.REQUEST_PROTO: f'http://{server_address}'}, source_address=source_address) as rh: proxy_info = ctx.proxy_info_request(rh) - assert proxy_info['client_address'][0] == source_address assert proxy_info['proxy'] == server_address + assert proxy_info['client_address'][0] == source_address @pytest.mark.skip_handler('Urllib', 'urllib does not support https proxies') def test_https(self, handler, ctx): with ctx.http_server(HTTPSProxyHandler) as server_address: with handler(verify=False, proxies={ctx.REQUEST_PROTO: f'https://{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh) + assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is False assert 'Proxy-Authorization' not in proxy_info['headers'] assert proxy_info['proxy'] == server_address @@ -353,6 +355,7 @@ class TestHTTPProxy: with ctx.http_server(HTTPProxyHandler) as server_address: with handler(proxies={ctx.REQUEST_PROTO: f'http://{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh, target_domain='中文.tw') + assert proxy_info['proxy'] == server_address assert proxy_info['path'].startswith('http://xn--fiq228c.tw') assert proxy_info['headers']['Host'].split(':', 1)[0] == 'xn--fiq228c.tw' assert proxy_info['proxy'] == server_address @@ -370,6 +373,7 @@ class TestHTTPConnectProxy: with ctx.http_server(HTTPConnectProxyHandler) as server_address: with handler(verify=False, proxies={ctx.REQUEST_PROTO: f'http://{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh) + assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is True assert 'Proxy-Authorization' not in proxy_info['headers'] assert proxy_info['proxy'] == server_address @@ -378,9 +382,14 @@ class TestHTTPConnectProxy: with ctx.http_server(HTTPConnectProxyHandler, username='test', password='test') as server_address: with handler(verify=False, proxies={ctx.REQUEST_PROTO: f'http://test:test@{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh) + assert proxy_info['proxy'] == server_address assert 'Proxy-Authorization' in proxy_info['headers'] assert proxy_info['proxy'] == server_address + @pytest.mark.skip_handler( + 'Requests', + 'bug in urllib3 causes unclosed socket: https://github.com/urllib3/urllib3/issues/3374' + ) def test_http_connect_bad_auth(self, handler, ctx): with ctx.http_server(HTTPConnectProxyHandler, username='test', password='test') as server_address: with handler(verify=False, proxies={ctx.REQUEST_PROTO: f'http://test:bad@{server_address}'}) as rh: @@ -395,14 +404,15 @@ class TestHTTPConnectProxy: source_address=source_address, verify=False) as rh: proxy_info = ctx.proxy_info_request(rh) - assert proxy_info['client_address'][0] == source_address assert proxy_info['proxy'] == server_address + assert proxy_info['client_address'][0] == source_address @pytest.mark.skipif(urllib3 is None, reason='requires urllib3 to test') def test_https_connect_proxy(self, handler, ctx): with ctx.http_server(HTTPSConnectProxyHandler) as server_address: with handler(verify=False, proxies={ctx.REQUEST_PROTO: f'https://{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh) + assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is True assert 'Proxy-Authorization' not in proxy_info['headers'] assert proxy_info['proxy'] == server_address @@ -422,5 +432,6 @@ class TestHTTPConnectProxy: with ctx.http_server(HTTPSConnectProxyHandler, username='test', password='test') as server_address: with handler(verify=False, proxies={ctx.REQUEST_PROTO: f'https://test:test@{server_address}'}) as rh: proxy_info = ctx.proxy_info_request(rh) + assert proxy_info['proxy'] == server_address assert 'Proxy-Authorization' in proxy_info['headers'] assert proxy_info['proxy'] == server_address