mirror of
https://github.com/lwthiker/curl-impersonate.git
synced 2026-10-10 19:36:32 +00:00
Use configurable binaries directory in the tests
Locate curl-impersonate and libcurl-impersonate in a directory which is configurable from the command line instead of looking for them in the current directory. '--install-dir' is passed to pytest, where a 'bin' and 'lib' directories are expected with (lib)curl-impersonate. Rename the Actions file for the Docker build to allow the creation of addition Action for native builds.
This commit is contained in:
+8
-4
@@ -19,14 +19,18 @@ RUN pip install --upgrade pip && \
|
||||
RUN mkdir /tests/firefox /tests/chrome
|
||||
|
||||
# Copy the built binaries from both containers
|
||||
COPY --from=ff /build/out/* /tests/firefox/
|
||||
COPY --from=chrome /build/out/* /tests/chrome/
|
||||
COPY --from=ff /build/out/curl-impersonate-ff /tests/install/bin/
|
||||
COPY --from=ff /build/out/curl_* /tests/install/bin/
|
||||
COPY --from=ff /build/out/libcurl-impersonate* /tests/install/lib/
|
||||
COPY --from=chrome /build/out/curl-impersonate-chrome /tests/install/bin/
|
||||
COPY --from=chrome /build/out/curl_* /tests/install/bin/
|
||||
COPY --from=chrome /build/out/libcurl-impersonate* /tests/install/lib/
|
||||
|
||||
COPY . .
|
||||
|
||||
# Compile 'minicurl' which is used for testing libcurl-impersonate.
|
||||
# 'minicurl' is compiled against the "regular" libcurl.
|
||||
# libcurl-impersonate will replace it at runtime via LD_PRELOAD.
|
||||
RUN gcc -Wall -Werror -o minicurl minicurl.c `curl-config --libs`
|
||||
RUN gcc -Wall -Werror -o /tests/install/bin/minicurl minicurl.c `curl-config --libs`
|
||||
|
||||
ENTRYPOINT ["pytest"]
|
||||
ENTRYPOINT ["pytest", "--install-dir", "/tests/install"]
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
def pytest_addoption(parser):
|
||||
# Where to find curl-impersonate's binaries
|
||||
parser.addoption("--install-dir", action="store", default="/usr/local")
|
||||
parser.addoption("--capture-interface", action="store", default="eth0")
|
||||
+48
-29
@@ -126,89 +126,89 @@ class TestImpersonation:
|
||||
# List of binaries and their expected signatures
|
||||
CURL_BINARIES_AND_SIGNATURES = [
|
||||
# Test wrapper scripts
|
||||
("chrome/curl_chrome98", None, "chrome_98.0.4758.102_win10"),
|
||||
("chrome/curl_chrome99", None, "chrome_99.0.4844.51_win10"),
|
||||
("chrome/curl_chrome99_android", None, "chrome_99.0.4844.73_android12-pixel6"),
|
||||
("chrome/curl_edge98", None, "edge_98.0.1108.62_win10"),
|
||||
("chrome/curl_edge99", None, "edge_99.0.1150.30_win10"),
|
||||
("chrome/curl_safari15_3", None, "safari_15.3_macos11.6.4"),
|
||||
("firefox/curl_ff91esr", None, "firefox_91.6.0esr_win10"),
|
||||
("firefox/curl_ff95", None, "firefox_95.0.2_win10"),
|
||||
("firefox/curl_ff98", None, "firefox_98.0_win10"),
|
||||
("curl_chrome98", None, None, "chrome_98.0.4758.102_win10"),
|
||||
("curl_chrome99", None, None, "chrome_99.0.4844.51_win10"),
|
||||
("curl_chrome99_android", None, None, "chrome_99.0.4844.73_android12-pixel6"),
|
||||
("curl_edge98", None, None, "edge_98.0.1108.62_win10"),
|
||||
("curl_edge99", None, None, "edge_99.0.1150.30_win10"),
|
||||
("curl_safari15_3", None, None, "safari_15.3_macos11.6.4"),
|
||||
("curl_ff91esr", None, None, "firefox_91.6.0esr_win10"),
|
||||
("curl_ff95", None, None, "firefox_95.0.2_win10"),
|
||||
("curl_ff98", None, None, "firefox_98.0_win10"),
|
||||
|
||||
# Test libcurl-impersonate by loading it with LD_PRELOAD to an app
|
||||
# linked against the regular libcurl and setting the
|
||||
# CURL_IMPERSONATE env var.
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./chrome/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "chrome98"
|
||||
},
|
||||
"libcurl-impersonate-chrome.so",
|
||||
"chrome_98.0.4758.102_win10"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./chrome/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "chrome99"
|
||||
},
|
||||
"libcurl-impersonate-chrome.so",
|
||||
"chrome_99.0.4844.51_win10"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./chrome/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "chrome99_android"
|
||||
},
|
||||
"libcurl-impersonate-chrome.so",
|
||||
"chrome_99.0.4844.73_android12-pixel6"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./chrome/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "edge98"
|
||||
},
|
||||
"libcurl-impersonate-chrome.so",
|
||||
"edge_98.0.1108.62_win10"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./chrome/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "edge99"
|
||||
},
|
||||
"libcurl-impersonate-chrome.so",
|
||||
"edge_99.0.1150.30_win10"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./chrome/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "safari15_3"
|
||||
},
|
||||
"libcurl-impersonate-chrome.so",
|
||||
"safari_15.3_macos11.6.4"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./firefox/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "ff91esr"
|
||||
},
|
||||
"libcurl-impersonate-ff.so",
|
||||
"firefox_91.6.0esr_win10"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./firefox/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "ff95"
|
||||
},
|
||||
"libcurl-impersonate-ff.so",
|
||||
"firefox_95.0.2_win10"
|
||||
),
|
||||
(
|
||||
"./minicurl",
|
||||
"minicurl",
|
||||
{
|
||||
"LD_PRELOAD": "./firefox/libcurl-impersonate.so",
|
||||
"CURL_IMPERSONATE": "ff98"
|
||||
},
|
||||
"libcurl-impersonate-ff.so",
|
||||
"firefox_98.0_win10"
|
||||
)
|
||||
]
|
||||
@@ -341,13 +341,15 @@ class TestImpersonation:
|
||||
return pseudo_headers, headers
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"curl_binary, env_vars, expected_signature",
|
||||
"curl_binary, env_vars, ld_preload, expected_signature",
|
||||
CURL_BINARIES_AND_SIGNATURES
|
||||
)
|
||||
def test_tls_client_hello(self,
|
||||
pytestconfig,
|
||||
tcpdump,
|
||||
curl_binary,
|
||||
env_vars,
|
||||
ld_preload,
|
||||
browser_signatures,
|
||||
expected_signature):
|
||||
"""
|
||||
@@ -358,6 +360,14 @@ class TestImpersonation:
|
||||
extracts the Client Hello packet from the capture and compares its
|
||||
signature with the expected one defined in the YAML database.
|
||||
"""
|
||||
curl_binary = os.path.join(
|
||||
pytestconfig.getoption("install_dir"), "bin", curl_binary
|
||||
)
|
||||
if ld_preload:
|
||||
env_vars["LD_PRELOAD"] = os.path.join(
|
||||
pytestconfig.getoption("install_dir"), "lib", ld_preload
|
||||
)
|
||||
|
||||
ret = self._run_curl(curl_binary,
|
||||
env_vars=env_vars,
|
||||
extra_args=None,
|
||||
@@ -396,15 +406,24 @@ class TestImpersonation:
|
||||
assert equals, msg
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"curl_binary, env_vars, expected_signature",
|
||||
"curl_binary, env_vars, ld_preload, expected_signature",
|
||||
CURL_BINARIES_AND_SIGNATURES
|
||||
)
|
||||
def test_http2_headers(self,
|
||||
pytestconfig,
|
||||
nghttpd,
|
||||
curl_binary,
|
||||
env_vars,
|
||||
ld_preload,
|
||||
browser_signatures,
|
||||
expected_signature):
|
||||
curl_binary = os.path.join(
|
||||
pytestconfig.getoption("install_dir"), "bin", curl_binary
|
||||
)
|
||||
if ld_preload:
|
||||
env_vars["LD_PRELOAD"] = os.path.join(
|
||||
pytestconfig.getoption("install_dir"), "lib", ld_preload
|
||||
)
|
||||
ret = self._run_curl(curl_binary,
|
||||
env_vars=env_vars,
|
||||
extra_args=["-k"],
|
||||
|
||||
Reference in New Issue
Block a user