Skip to content

Commit

Permalink
Added tests for socks proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker committed Jun 19, 2023
1 parent 47e4e7b commit 0b0f081
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pyrsistent==0.16.0 # TODO(py3): 0.17.0 requires python3, see https://github.com/
executing
asttokens
responses
pysocks
ipdb
75 changes: 75 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,18 @@ def test_proxy(monkeypatch, testcase):
monkeypatch.setenv("HTTPS_PROXY", testcase["env_https_proxy"])
if testcase.get("env_no_proxy") is not None:
monkeypatch.setenv("NO_PROXY", testcase["env_no_proxy"])

kwargs = {}

if testcase["arg_http_proxy"] is not None:
kwargs["http_proxy"] = testcase["arg_http_proxy"]
if testcase["arg_https_proxy"] is not None:
kwargs["https_proxy"] = testcase["arg_https_proxy"]
if testcase.get("arg_proxy_headers") is not None:
kwargs["proxy_headers"] = testcase["arg_proxy_headers"]

client = Client(testcase["dsn"], **kwargs)

if testcase["expected_proxy_scheme"] is None:
assert client.transport._pool.proxy is None
else:
Expand All @@ -269,6 +273,77 @@ def test_proxy(monkeypatch, testcase):
assert client.transport._pool.proxy_headers == testcase["arg_proxy_headers"]


@pytest.mark.parametrize(
"testcase",
[
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": "http://localhost/123",
"arg_https_proxy": None,
"expected_proxy_class": "<class 'urllib3.poolmanager.ProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": "socks4a://localhost/123",
"arg_https_proxy": None,
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": "socks4://localhost/123",
"arg_https_proxy": None,
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": "socks5h://localhost/123",
"arg_https_proxy": None,
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": "socks5://localhost/123",
"arg_https_proxy": None,
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": None,
"arg_https_proxy": "socks4a://localhost/123",
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": None,
"arg_https_proxy": "socks4://localhost/123",
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": None,
"arg_https_proxy": "socks5h://localhost/123",
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
{
"dsn": "https://[email protected]/123",
"arg_http_proxy": None,
"arg_https_proxy": "socks5://localhost/123",
"expected_proxy_class": "<class 'urllib3.contrib.socks.SOCKSProxyManager'>",
},
],
)
def test_socks_proxy(testcase):
kwargs = {}

if testcase["arg_http_proxy"] is not None:
kwargs["http_proxy"] = testcase["arg_http_proxy"]
if testcase["arg_https_proxy"] is not None:
kwargs["https_proxy"] = testcase["arg_https_proxy"]

client = Client(testcase["dsn"], **kwargs)
assert str(type(client.transport._pool)) == testcase["expected_proxy_class"]


def test_simple_transport(sentry_init):
events = []
sentry_init(transport=events.append)
Expand Down

0 comments on commit 0b0f081

Please sign in to comment.