Skip to content

curl-impersonate: A special build of curl that can impersonate Chrome & Firefox

Use configurable binaries directory in the tests

lwthikerfacd6e55514f
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test-docker.yml
similarity index 96%
rename from .github/workflows/build-and-test.yml
rename to .github/workflows/build-and-test-docker.yml
index ac8d04b..accfc1a 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test-docker.yml
@@ -1,4 +1,4 @@
-name: Build and test
+name: Docker images
on:
push:
@@ -10,7 +10,7 @@ on:
jobs:
build-and-test:
- name: Build curl-impersonate and run the tests
+ name: Build curl-impersonate Docker images and run the tests
runs-on: ubuntu-latest
services:
# A local registry is needed to push the build images to because we use
diff --git a/README.md b/README.md
index 04aa055..bdcaacd 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# curl-impersonate · ![workflow](https://github.com/lwthiker/curl-impersonate/actions/workflows/build-and-test.yml/badge.svg)
+# curl-impersonate · ![workflow](https://github.com/lwthiker/curl-impersonate/actions/workflows/build-and-test-docker.yml/badge.svg)
A special compilation of [curl](https://github.com/curl/curl) that makes it impersonate real browsers. It can impersonate the four major browsers: Chrome, Edge, Safari & Firefox. This curl binary is able to perform a TLS handshake that is identical to that of a real browser.
diff --git a/tests/Dockerfile b/tests/Dockerfile
index d7b1801..e510d19 100644
--- a/tests/Dockerfile
+++ b/tests/Dockerfile
@@ -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"]
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..5428fa0
--- /dev/null
+++ b/tests/conftest.py
@@ -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")
diff --git a/tests/test_impersonate.py b/tests/test_impersonate.py
index 1e0925a..9446b44 100644
--- a/tests/test_impersonate.py
+++ b/tests/test_impersonate.py
@@ -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"],