Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMoelans committed Feb 5, 2025
1 parent a2508cd commit 1b857ec
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
3 changes: 3 additions & 0 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ main(int argc, char **argv)
if (has_arg(argc, argv, "http-proxy-ipv6")) {
sentry_options_set_proxy(options, "http://[::1]:8080");
}
if (has_arg(argc, argv, "proxy-empty")) {
sentry_options_set_proxy(options, "");
}

if (has_arg(argc, argv, "socks5-proxy")) {
sentry_options_set_proxy(options, "socks5://127.0.0.1:1080");
Expand Down
10 changes: 7 additions & 3 deletions tests/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,25 @@ def start_mitmdump(proxy_type, proxy_auth: str = None):


def proxy_test_finally(
expected_logsize,
expected_httpserver_logsize,
httpserver,
proxy_process,
proxy_log_assert=assert_no_proxy_request,
expected_proxy_logsize=None,
):
if expected_proxy_logsize is None:
expected_proxy_logsize = expected_httpserver_logsize

if proxy_process:
# Give mitmdump some time to get a response from the mock server
time.sleep(0.5)
proxy_process.terminate()
proxy_process.wait()
stdout, stderr = proxy_process.communicate()
if expected_logsize == 0:
if expected_proxy_logsize == 0:
# don't expect any incoming requests to make it through the proxy
proxy_log_assert(stdout)
else:
# request passed through successfully
assert "POST" in stdout and "200 OK" in stdout
assert len(httpserver.log) == expected_logsize
assert len(httpserver.log) == expected_httpserver_logsize
45 changes: 45 additions & 0 deletions tests/test_integration_crashpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,51 @@ def test_crashpad_crash_proxy_env_port_incorrect(cmake, httpserver):
cleanup_proxy_env_vars()


def test_crashpad_proxy_set_empty(cmake, httpserver):
if not shutil.which("mitmdump"):
pytest.skip("mitmdump is not installed")

proxy_process = None # store the proxy process to terminate it later
setup_proxy_env_vars(port=8080) # we start the proxy but expect it to remain unused
try:
env, proxy_process, tmp_path = _setup_crashpad_proxy_test(
cmake, httpserver, "http-proxy"
)

with httpserver.wait(timeout=10) as waiting:
child = run(
tmp_path, "sentry_example", ["log", "crash", "proxy-empty"], env=env
)
assert child.returncode # well, it's a crash after all
assert waiting.result

finally:
proxy_test_finally(1, httpserver, proxy_process, expected_proxy_logsize=0)
cleanup_proxy_env_vars()


def test_crashpad_proxy_https_not_http(cmake, httpserver):
if not shutil.which("mitmdump"):
pytest.skip("mitmdump is not installed")

proxy_process = None # store the proxy process to terminate it later
# we start the proxy but expect it to remain unused (dsn is http, so shouldn't use https proxy)
os.environ["https_proxy"] = f"http://localhost:8080"
try:
env, proxy_process, tmp_path = _setup_crashpad_proxy_test(
cmake, httpserver, "http-proxy"
)

with httpserver.wait(timeout=10) as waiting:
child = run(tmp_path, "sentry_example", ["log", "crash"], env=env)
assert child.returncode # well, it's a crash after all
assert waiting.result

finally:
proxy_test_finally(1, httpserver, proxy_process, expected_proxy_logsize=0)
del os.environ["https_proxy"]


@pytest.mark.parametrize(
"run_args",
[
Expand Down
49 changes: 49 additions & 0 deletions tests/test_integration_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,55 @@ def test_proxy_ipv6(cmake, httpserver):
proxy_test_finally(1, httpserver, proxy_process)


def test_proxy_set_empty(cmake, httpserver):
if not shutil.which("mitmdump"):
pytest.skip("mitmdump is not installed")

proxy_process = None # store the proxy process to terminate it later
setup_proxy_env_vars(port=8080) # we start the proxy but expect it to remain unused
try:
env, proxy_process, tmp_path = _setup_http_proxy_test(
cmake, httpserver, "http-proxy"
)

run(
tmp_path,
"sentry_example",
["log", "capture-event", "proxy-empty"],
check=True,
env=env,
)

finally:
proxy_test_finally(1, httpserver, proxy_process, expected_proxy_logsize=0)
cleanup_proxy_env_vars()


def test_proxy_https_not_http(cmake, httpserver):
if not shutil.which("mitmdump"):
pytest.skip("mitmdump is not installed")

proxy_process = None # store the proxy process to terminate it later
# we start the proxy but expect it to remain unused (dsn is http, so shouldn't use https proxy)
os.environ["https_proxy"] = f"http://localhost:8080"
try:
env, proxy_process, tmp_path = _setup_http_proxy_test(
cmake, httpserver, "http-proxy"
)

run(
tmp_path,
"sentry_example",
["log", "capture-event"],
check=True,
env=env,
)

finally:
proxy_test_finally(1, httpserver, proxy_process, expected_proxy_logsize=0)
del os.environ["https_proxy"]


@pytest.mark.parametrize(
"run_args",
[
Expand Down

0 comments on commit 1b857ec

Please sign in to comment.