Skip to content

Commit 2714d3d

Browse files
authored
Pass separate --ca-cert-dir flag for parallel TLS interception tests (#984)
* Pass separate `--ca-cert-dir` flag for parallel TLS interception tests * Temp disable `test_modify_post_response_integration` * mock ca cert dir * Is threaded an issue with TLS interception? * Disable modify chunk response for python < 3.10 * Disable modify chunk response for python < 3.10
1 parent 8f51ce3 commit 2714d3d

File tree

5 files changed

+29
-37
lines changed

5 files changed

+29
-37
lines changed

proxy/common/flag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def initialize(
379379
args.ca_cert_dir = os.path.join(
380380
args.proxy_py_data_dir, 'certificates',
381381
)
382-
os.makedirs(args.ca_cert_dir, exist_ok=True)
382+
os.makedirs(args.ca_cert_dir, exist_ok=True)
383383

384384
return args
385385

tests/integration/test_integration.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
Test the simplest proxy use scenario for smoke.
1212
"""
13+
import sys
1314
import time
1415
import pytest
1516
import tempfile
@@ -89,7 +90,9 @@ def proxy_py_subprocess(request: Any) -> Generator[int, None, None]:
8990
9091
After the testing is over, tear it down.
9192
"""
92-
port_file = Path(tempfile.gettempdir()) / 'proxy.port'
93+
temp_dir = Path(tempfile.gettempdir())
94+
port_file = temp_dir / 'proxy.port'
95+
ca_cert_dir = temp_dir / ('certificates-%s' % int(time.time()))
9396
proxy_cmd = (
9497
'python', '-m', 'proxy',
9598
'--hostname', '127.0.0.1',
@@ -98,6 +101,8 @@ def proxy_py_subprocess(request: Any) -> Generator[int, None, None]:
98101
'--enable-web-server',
99102
'--num-acceptors', '3',
100103
'--num-workers', '3',
104+
'--ca-cert-dir', str(ca_cert_dir),
105+
'--log-level', 'd',
101106
) + tuple(request.param.split())
102107
proxy_proc = Popen(proxy_cmd)
103108
# Needed because port file might not be available immediately
@@ -148,21 +153,25 @@ def test_integration_with_interception_flags(proxy_py_subprocess: int) -> None:
148153
check_output([str(shell_script_test), str(proxy_py_subprocess)])
149154

150155

151-
# @pytest.mark.smoke # type: ignore[misc]
152-
# @pytest.mark.parametrize(
153-
# 'proxy_py_subprocess',
154-
# PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN,
155-
# indirect=True,
156-
# ) # type: ignore[misc]
157-
# @pytest.mark.skipif(
158-
# IS_WINDOWS,
159-
# reason='OSError: [WinError 193] %1 is not a valid Win32 application',
160-
# ) # type: ignore[misc]
161-
# def test_modify_chunk_response_integration(proxy_py_subprocess: int) -> None:
162-
# """An acceptance test for :py:class:`~proxy.plugin.ModifyChunkResponsePlugin`
163-
# interception using ``curl`` through proxy.py."""
164-
# shell_script_test = Path(__file__).parent / 'test_modify_chunk_response.sh'
165-
# check_output([str(shell_script_test), str(proxy_py_subprocess)])
156+
@pytest.mark.smoke # type: ignore[misc]
157+
@pytest.mark.parametrize(
158+
'proxy_py_subprocess',
159+
PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN,
160+
indirect=True,
161+
) # type: ignore[misc]
162+
@pytest.mark.skipif(
163+
IS_WINDOWS,
164+
reason='OSError: [WinError 193] %1 is not a valid Win32 application',
165+
) # type: ignore[misc]
166+
@pytest.mark.skipif(
167+
sys.version_info < (3, 10),
168+
reason='For version < 3.10, GHA integration run into OSError when flushing to clients',
169+
) # type: ignore[misc]
170+
def test_modify_chunk_response_integration(proxy_py_subprocess: int) -> None:
171+
"""An acceptance test for :py:class:`~proxy.plugin.ModifyChunkResponsePlugin`
172+
interception using ``curl`` through proxy.py."""
173+
shell_script_test = Path(__file__).parent / 'test_modify_chunk_response.sh'
174+
check_output([str(shell_script_test), str(proxy_py_subprocess)])
166175

167176

168177
@pytest.mark.smoke # type: ignore[misc]

tests/integration/test_modify_chunk_response.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ plugin
7676
EOM
7777

7878
echo "[Test ModifyChunkResponsePlugin]"
79-
CMD="curl -v -x $PROXY_URL --cacert ca-cert.pem https://httpbin.org/stream/5"
80-
RESPONSE=$($CMD 2> /dev/null)
79+
RESPONSE=$(curl -v -x $PROXY_URL --cacert ca-cert.pem https://httpbin.org/stream/5 2> /dev/null)
8180
verify_response "$RESPONSE" "$MODIFIED_CHUNK_RESPONSE"
8281
VERIFIED1=$?
8382

tests/integration/test_modify_post_data.sh

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@ while true; do
5151
sleep 1
5252
done
5353

54-
verify_response() {
55-
if [ "$1" == "" ];
56-
then
57-
echo "Empty response";
58-
return 1;
59-
else
60-
if [ "$1" == "$2" ];
61-
then
62-
echo "Ok";
63-
return 0;
64-
else
65-
echo "Invalid response: '$1', expected: '$2'";
66-
return 1;
67-
fi
68-
fi;
69-
}
70-
7154
verify_contains() {
7255
if [ "$1" == "" ];
7356
then

tests/test_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from proxy.proxy import main, entry_point
1818
from proxy.common.utils import bytes_
1919
from proxy.common.constants import ( # noqa: WPS450
20-
DEFAULT_PORT, DEFAULT_PLUGINS, DEFAULT_TIMEOUT, DEFAULT_KEY_FILE,
20+
DEFAULT_CA_CERT_DIR, DEFAULT_PORT, DEFAULT_PLUGINS, DEFAULT_TIMEOUT, DEFAULT_KEY_FILE,
2121
DEFAULT_LOG_FILE, DEFAULT_PAC_FILE, DEFAULT_PID_FILE, PLUGIN_DASHBOARD,
2222
DEFAULT_CERT_FILE, DEFAULT_LOG_LEVEL, DEFAULT_PORT_FILE, PLUGIN_HTTP_PROXY,
2323
PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, DEFAULT_BASIC_AUTH,
@@ -45,6 +45,7 @@ def mock_default_args(mock_args: mock.Mock) -> None:
4545
mock_args.ca_key_file = DEFAULT_CA_KEY_FILE
4646
mock_args.ca_cert_file = DEFAULT_CA_CERT_FILE
4747
mock_args.ca_signing_key_file = DEFAULT_CA_SIGNING_KEY_FILE
48+
mock_args.ca_cert_dir = DEFAULT_CA_CERT_DIR
4849
mock_args.pid_file = DEFAULT_PID_FILE
4950
mock_args.log_file = DEFAULT_LOG_FILE
5051
mock_args.log_level = DEFAULT_LOG_LEVEL

0 commit comments

Comments
 (0)