From 0ebfd467cf34911e4c82325623b233d10473635f Mon Sep 17 00:00:00 2001 From: sowmyasudhasingh Date: Wed, 19 Jan 2022 15:24:57 +0530 Subject: [PATCH 1/5] Enable remote threadless and threaded integration test for windows --- tests/integration/test_integration.py | 74 +++++++++++++++++---------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 6acee8ee71..b89640bccf 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -37,29 +37,37 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str: )) -PROXY_PY_FLAGS_INTEGRATION = ( - ('--threadless'), +_PROXY_PY_FLAGS_INTEGRATION = [ ('--threadless --local-executor 0'), ('--threaded'), -) - -PROXY_PY_HTTPS = ( - ('--threadless ' + _https_server_flags()), +] +if not IS_WINDOWS: + _PROXY_PY_FLAGS_INTEGRATION += [ + ('--threadless'), + ] +PROXY_PY_FLAGS_INTEGRATION = tuple(_PROXY_PY_FLAGS_INTEGRATION) + +_PROXY_PY_HTTPS = [ ('--threadless --local-executor 0 ' + _https_server_flags()), ('--threaded ' + _https_server_flags()), -) - -PROXY_PY_FLAGS_TLS_INTERCEPTION = ( - ('--threadless ' + _tls_interception_flags()), +] +if not IS_WINDOWS: + _PROXY_PY_HTTPS += [ + ('--threadless ' + _https_server_flags()), + ] +PROXY_PY_HTTPS = tuple(_PROXY_PY_HTTPS) + +_PROXY_PY_FLAGS_TLS_INTERCEPTION = [ ('--threadless --local-executor 0 ' + _tls_interception_flags()), ('--threaded ' + _tls_interception_flags()), -) - -PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN = ( - ( - '--threadless --plugin proxy.plugin.ModifyChunkResponsePlugin ' + - _tls_interception_flags('-chunk') - ), +] +if not IS_WINDOWS: + _PROXY_PY_FLAGS_TLS_INTERCEPTION += [ + ('--threadless ' + _tls_interception_flags()), + ] +PROXY_PY_FLAGS_TLS_INTERCEPTION = tuple(_PROXY_PY_FLAGS_TLS_INTERCEPTION) + +_PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN = [ ( '--threadless --local-executor 0 --plugin proxy.plugin.ModifyChunkResponsePlugin ' + _tls_interception_flags('-chunk') @@ -68,21 +76,37 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str: '--threaded --plugin proxy.plugin.ModifyChunkResponsePlugin ' + _tls_interception_flags('-chunk') ), +] +if not IS_WINDOWS: + _PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN += [ + ( + '--threadless --plugin proxy.plugin.ModifyChunkResponsePlugin ' + + _tls_interception_flags('-chunk') + ), + ] +PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN = tuple( + _PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN, ) -PROXY_PY_FLAGS_MODIFY_POST_DATA_PLUGIN = ( - ( - '--threadless --plugin proxy.plugin.ModifyPostDataPlugin ' + - _tls_interception_flags('-post') - ), +_PROXY_PY_FLAGS_MODIFY_POST_DATA_PLUGIN = [ ( '--threadless --local-executor 0 --plugin proxy.plugin.ModifyPostDataPlugin ' + _tls_interception_flags('-post') ), ( - '--threaded --plugin proxy.plugin.ModifyPostDataPlugin ' + + '--threadless --plugin proxy.plugin.ModifyPostDataPlugin ' + _tls_interception_flags('-post') ), +] +if not IS_WINDOWS: + _PROXY_PY_FLAGS_MODIFY_POST_DATA_PLUGIN += [ + ( + '--threaded --plugin proxy.plugin.ModifyPostDataPlugin ' + + _tls_interception_flags('-post') + ), + ] +PROXY_PY_FLAGS_MODIFY_POST_DATA_PLUGIN = tuple( + _PROXY_PY_FLAGS_MODIFY_POST_DATA_PLUGIN, ) @@ -162,10 +186,6 @@ def proxy_py_subprocess(request: Any) -> Generator[int, None, None]: PROXY_PY_FLAGS_INTEGRATION, indirect=True, ) # type: ignore[misc] -@pytest.mark.skipif( - IS_WINDOWS, - reason='OSError: [WinError 193] %1 is not a valid Win32 application', -) # type: ignore[misc] def test_integration(proxy_py_subprocess: int) -> None: """An acceptance test using ``curl`` through proxy.py.""" this_test_module = Path(__file__) From f358ec7c0ecead803d06ac1c5e60778643669867 Mon Sep 17 00:00:00 2001 From: Sowmya Singh Date: Wed, 19 Jan 2022 15:33:59 +0530 Subject: [PATCH 2/5] Run only threaded on windows --- tests/integration/test_integration.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index b89640bccf..8aaa2de4a0 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -38,40 +38,36 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str: _PROXY_PY_FLAGS_INTEGRATION = [ - ('--threadless --local-executor 0'), ('--threaded'), ] if not IS_WINDOWS: _PROXY_PY_FLAGS_INTEGRATION += [ + ('--threadless --local-executor 0'), ('--threadless'), ] PROXY_PY_FLAGS_INTEGRATION = tuple(_PROXY_PY_FLAGS_INTEGRATION) _PROXY_PY_HTTPS = [ - ('--threadless --local-executor 0 ' + _https_server_flags()), ('--threaded ' + _https_server_flags()), ] if not IS_WINDOWS: _PROXY_PY_HTTPS += [ + ('--threadless --local-executor 0 ' + _https_server_flags()), ('--threadless ' + _https_server_flags()), ] PROXY_PY_HTTPS = tuple(_PROXY_PY_HTTPS) _PROXY_PY_FLAGS_TLS_INTERCEPTION = [ - ('--threadless --local-executor 0 ' + _tls_interception_flags()), ('--threaded ' + _tls_interception_flags()), ] if not IS_WINDOWS: _PROXY_PY_FLAGS_TLS_INTERCEPTION += [ + ('--threadless --local-executor 0 ' + _tls_interception_flags()), ('--threadless ' + _tls_interception_flags()), ] PROXY_PY_FLAGS_TLS_INTERCEPTION = tuple(_PROXY_PY_FLAGS_TLS_INTERCEPTION) _PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN = [ - ( - '--threadless --local-executor 0 --plugin proxy.plugin.ModifyChunkResponsePlugin ' + - _tls_interception_flags('-chunk') - ), ( '--threaded --plugin proxy.plugin.ModifyChunkResponsePlugin ' + _tls_interception_flags('-chunk') @@ -79,6 +75,10 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str: ] if not IS_WINDOWS: _PROXY_PY_FLAGS_MODIFY_CHUNK_RESPONSE_PLUGIN += [ + ( + '--threadless --local-executor 0 --plugin proxy.plugin.ModifyChunkResponsePlugin ' + + _tls_interception_flags('-chunk') + ), ( '--threadless --plugin proxy.plugin.ModifyChunkResponsePlugin ' + _tls_interception_flags('-chunk') @@ -90,18 +90,18 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str: _PROXY_PY_FLAGS_MODIFY_POST_DATA_PLUGIN = [ ( - '--threadless --local-executor 0 --plugin proxy.plugin.ModifyPostDataPlugin ' + - _tls_interception_flags('-post') - ), - ( - '--threadless --plugin proxy.plugin.ModifyPostDataPlugin ' + + '--threaded --plugin proxy.plugin.ModifyPostDataPlugin ' + _tls_interception_flags('-post') ), ] if not IS_WINDOWS: _PROXY_PY_FLAGS_MODIFY_POST_DATA_PLUGIN += [ ( - '--threaded --plugin proxy.plugin.ModifyPostDataPlugin ' + + '--threadless --local-executor 0 --plugin proxy.plugin.ModifyPostDataPlugin ' + + _tls_interception_flags('-post') + ), + ( + '--threadless --plugin proxy.plugin.ModifyPostDataPlugin ' + _tls_interception_flags('-post') ), ] From 9d06bbdb44d839187b1629071f3e8171aef7a642 Mon Sep 17 00:00:00 2001 From: Sowmya Singh Date: Wed, 19 Jan 2022 17:45:47 +0530 Subject: [PATCH 3/5] Use powershell for execution of integration script on Windows --- tests/integration/test_integration.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 8aaa2de4a0..831553ecd1 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -16,12 +16,17 @@ import subprocess from pathlib import Path -from typing import Any, Generator -from subprocess import Popen, check_output +from typing import Any, Generator, List +from subprocess import Popen, check_output as _check_output from proxy.common.constants import IS_WINDOWS +def check_output(args: List[Any]) -> str: + args = args if not IS_WINDOWS else ['powershell'] + args + return _check_output(args) + + def _https_server_flags() -> str: return ' '.join(( '--key-file', 'https-key.pem', @@ -110,7 +115,7 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str: ) -@pytest.fixture(scope='session', autouse=True) # type: ignore[misc] +@pytest.fixture(scope='session', autouse=not IS_WINDOWS) # type: ignore[misc] def _gen_https_certificates(request: Any) -> None: check_output([ 'make', 'https-certificates', @@ -120,7 +125,7 @@ def _gen_https_certificates(request: Any) -> None: ]) -@pytest.fixture(scope='session', autouse=True) # type: ignore[misc] +@pytest.fixture(scope='session', autouse=not IS_WINDOWS) # type: ignore[misc] def _gen_ca_certificates(request: Any) -> None: check_output([ 'make', 'ca-certificates', From 46807abdb7ce46c2527b8cc3f4acf2b461020e5e Mon Sep 17 00:00:00 2001 From: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com> Date: Wed, 19 Jan 2022 18:08:33 +0530 Subject: [PATCH 4/5] Update test_integration.py --- tests/integration/test_integration.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 831553ecd1..d5c5ee9c9a 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -191,6 +191,10 @@ def proxy_py_subprocess(request: Any) -> Generator[int, None, None]: PROXY_PY_FLAGS_INTEGRATION, indirect=True, ) # type: ignore[misc] +@pytest.mark.skipif( + IS_WINDOWS, + reason='OSError: [WinError 193] %1 is not a valid Win32 application', +) # type: ignore[misc] def test_integration(proxy_py_subprocess: int) -> None: """An acceptance test using ``curl`` through proxy.py.""" this_test_module = Path(__file__) From c1c86291cc8c5a1ee257649d1a3024eb28ad274b Mon Sep 17 00:00:00 2001 From: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com> Date: Wed, 19 Jan 2022 18:25:53 +0530 Subject: [PATCH 5/5] Update test_integration.py --- tests/integration/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index d5c5ee9c9a..e8fd9b7ce5 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -22,7 +22,7 @@ from proxy.common.constants import IS_WINDOWS -def check_output(args: List[Any]) -> str: +def check_output(args: List[Any]) -> bytes: args = args if not IS_WINDOWS else ['powershell'] + args return _check_output(args)