How to Set Up a Proxy for Integration Tests in CI
Some integration tests need to run from a specific country or network. This guide shows how to wire a proxy into CI safely, with secrets, scoping, timeouts and reports you can trust.
9 min readUpdated Nov 14, 2026By XPASS Editorial Team

Most integration tests run happily from the same data centre as the CI runner. Some do not. A checkout flow that shows different payment methods per country, a redirect that depends on the visitor's region, or a localized page that must render with the right currency all need the test to appear to come from somewhere else. A Proxy lets a CI job make those requests through a chosen exit, but only if it is wired in carefully. Done badly, it adds slowness, flakiness and leaked secrets to your pipeline.
This guide covers how to configure a proxy for CI integration tests in a way that is secure, scoped and reproducible. It assumes you test your own application, or a service you have permission to test, and that you respect the terms of every site your tests touch.
Decide which tests need a proxy
Start with a short list. A test belongs in the proxy group only if its result changes with the network location of the client. Typical cases:
- Geo-based redirects or content selection on your own site.
- Currency, language or tax display depending on country.
- Compliance banners that appear only in certain regions.
- Partner or CDN behaviour that differs by region.
- Verification that a region-restricted feature is correctly blocked or allowed in your own product.
Everything else should skip the proxy. This keeps the suite fast and limits how much proxy traffic you use. Tag the group in your test runner, for example @geo, so the pipeline can run it as a separate job.

Keep configuration in environment variables
Nearly every HTTP client, browser driver and command-line tool reads the same conventional variables. Using them keeps test code free of proxy details.
| Variable | Purpose |
|---|---|
HTTP_PROXY |
Proxy URL for plain HTTP requests |
HTTPS_PROXY |
Proxy URL for HTTPS requests (tunnelled with CONNECT) |
NO_PROXY |
Comma-separated hosts that must bypass the proxy |
ALL_PROXY |
Fallback used by some tools, including SOCKS URLs |
Behaviour differs between tools, so confirm what your stack honours. Some libraries only read lower-case names, some ignore the variables unless asked, and browser drivers often need an explicit option. MDN's overview of proxy servers and tunneling explains how HTTPS traffic is tunnelled, which is why HTTPS_PROXY usually points to an http:// proxy URL even for secure sites. SOCKS proxies use a different protocol, described in RFC 1928.
Always set NO_PROXY for the services that must not go through the proxy: the test database, the internal API, the artifact registry, localhost and the container network names. A missing bypass is the most common reason a suite suddenly times out after a proxy is added.
Store credentials as CI secrets
Your proxy URL usually contains a user name and password. Treat it like any other credential.
- Create secrets in your CI system, one for the host, one for the user, one for the password, or one combined URL.
- Expose them only to the jobs that need them. Do not make them available to pull-request builds from forks.
- Make sure the CI masks the values in logs. Check that your test framework does not print the full proxy URL in error messages.
- Rotate the credentials if they ever appear in a log, a screenshot or a build artifact.
- Use a separate credential for CI, so you can revoke it without affecting other work.
A job fragment might look like this, with names adapted to your platform:
geo-tests:
stage: integration
variables:
NO_PROXY: "localhost,127.0.0.1,db,api.internal"
script:
- export HTTPS_PROXY="http://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT"
- npm run test:geo
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
Avoid set -x or verbose shell tracing in that job; it prints expanded variables.
Pin the route per test
Many geo tests assume a stable view of the world: "from country X, the page shows currency Y". If the exit IP changes midway through a test, you will get false failures. Decide how the route is selected:
- One exit per job. Simple and predictable. Good when a job tests a single region.
- One exit per test file. Useful when one job loops across regions; start a new client for each region.
- One exit per test case. Most isolated, but slower and heavier on the provider.
If you use rotation, keep the rules bounded and sticky for the duration of a test. The guide to building a bounded proxy rotation strategy describes the limits worth setting. In CI you rarely want open-ended rotation; you want repeatability.
Add a small health check at the start of each geo job. Request a neutral endpoint that you control, read the observed address or region from the response, and fail early if it does not match what the test expects. This turns a confusing failure after twenty minutes into a clear failure in the first few seconds.
Set explicit timeouts
A proxy adds a hop. Connection setup and TLS negotiation take longer than from a runner that connects directly. Default timeouts tuned for a local service are often too short.
- Set separate connect and read timeouts. Connect timeouts can be small; read timeouts must allow slow pages.
- Raise the overall test timeout for the geo group only.
- Add a limited retry for connection-level errors, not for assertion failures. Retrying a failed assertion hides real bugs.
- Keep a hard cap on the total job duration so a stuck exit cannot consume your runner minutes.
The status codes defined in RFC 9110 help you decide what is retryable. A 502 or 504 from the proxy path is a candidate for a retry; a 404 or 403 from your application is a test result, not noise.
Control concurrency
CI makes it easy to run many tests in parallel, and a proxy plan has limits on concurrent connections and traffic. Cap the number of geo workers explicitly, and avoid running several pipelines against the same credentials at once. Use a lock or a single-flight rule on the main branch if needed. Parallel jobs that share a limit produce intermittent failures that are hard to reproduce locally.
Make failures easy to read
When a geo test fails, you want to know in one glance whether the application, the route or the target was at fault. Record:
- The region the test requested.
- The observed exit address or country from the health check.
- The proxy status or error class, if any.
- Timing for connect, TLS and first byte.
- A screenshot or HTML snapshot for browser tests, with secrets removed.
Store them as build artifacts with a short retention period. If you also track how much traffic the suite consumes, the article on logging proxy traffic usage in the backend offers a structure that works for CI as well. For browser-based checks across countries, see the companion guide on cross-country rendering tests with Playwright.
Limits and what to watch for
- Use only on permitted targets. CI should test your own application or sites that allow it. Do not point test suites at third-party websites in ways their terms prohibit.
- Do not weaken TLS to make tests pass. If a certificate error appears, find the cause. Disabling verification in CI tends to leak into other environments.
- Geolocation data is approximate. A health check reduces surprises, but an IP database can still be wrong for some addresses.
- External content changes. Tests that depend on a live third-party page will break for reasons unrelated to your code. Prefer stubs for those and keep the proxy group for what you own.
- Cost and quota. Keep an eye on how much traffic the suite uses and what your plan includes; check the plan page for details.
- Forks and shared runners. Never expose proxy secrets to untrusted code, and be careful with shared runners that other teams can inspect.
A minimal workflow
- Tag geo-dependent tests and put them in their own job.
- Add proxy credentials as masked secrets, available only to that job and to protected branches.
- Export
HTTPS_PROXYandNO_PROXYinside the job script. - Run a health check that confirms the expected region.
- Run the geo tests with explicit timeouts and limited concurrency.
- Save artifacts and summary metrics; fail the job if the health check or the suite fails.
- Review usage periodically and adjust the schedule, for example nightly instead of on every commit.
Handle proxy outages gracefully
Even a well-run proxy path can be unavailable for a while: a network issue, an expired credential or a plan limit. Decide ahead of time what the pipeline should do. For a geo job on the main branch, a failed health check should fail the job with a clear message such as "proxy unreachable", not with a confusing assertion error from deep in the suite. For a scheduled nightly job, you may prefer to mark the run as skipped and notify the owner, so that a short outage does not block releases.
Keep the distinction visible in your reports. A test that failed because the application is wrong needs a developer; a test that failed because the route was unavailable needs an operator. Mixing the two trains people to ignore red builds, which is the most expensive kind of flakiness.
Keep local and CI behaviour aligned
Developers will want to reproduce a failing geo test on their own machine. Make that easy. Put the same environment variable names in a documented example file with placeholder values, and let the test setup read them the same way in both places. Provide a single command, such as npm run test:geo, that works locally once the variables are set. Never commit real credentials in that example, and never share a personal credential with the CI system. When local and CI runs behave the same, you can tell quickly whether a failure is about the code or about the pipeline.
Finally, document the group in your contributing guide: which tests belong in it, which secrets it needs, who can rotate them and how to run it locally. A page of notes saves hours when the person who set the pipeline up is on leave.
Summary
Use a proxy in CI only for tests that depend on the client's network location, and keep every other test off it. Configure the route through standard environment variables, set NO_PROXY for internal services, and store credentials as masked CI secrets. Pin the exit per test, add a quick health check, set explicit timeouts and cap concurrency so failures are meaningful rather than flaky. Keep all of this within the terms of the sites you test and the law. For available options and how they are offered, see the Proxy page.
Frequently asked questions
Should all CI tests go through a proxy?
No. Route only the tests that truly depend on the exit location or network, such as geo-specific content or regional redirects. Unit tests and tests that call internal services should bypass the proxy to stay fast and stable.
Where should proxy credentials be stored in CI?
In the secret store of your CI system, injected as masked environment variables at run time. Never commit them to the repository, print them in logs or bake them into container images.
Why do proxy-based tests become flaky?
Common causes are shared timeouts that are too short, a changing exit IP between steps, rate limits on the target, and tests that depend on live third-party content. Pinning the route per test, setting explicit timeouts and limiting concurrency removes most of the noise.
Can CI tests with a proxy be used against any website?
Only against sites you own or have permission to test, and in line with their terms and local law. Integration tests are for verifying your own application, not for collecting data from third parties without permission.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Need a proxy for this?
XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.
See proxy plansKeep reading

Proxy Guides
How to Build a Bounded Proxy Rotation Strategy
Rotation is easy to start and hard to control. This guide shows how to set limits on pool size, requests per IP and retries so a lawful workload stays predictable and easy to debug.
9 min read

Proxy Guides
How to Test Website Rendering Across Countries with Playwright
Pages often change with the visitor's country. This guide shows how to use Playwright with a proxy to verify your own localized pages, with matching locale settings, stable assertions and clear limits.
10 min read

Proxy Guides
How to Log Proxy Traffic Usage in Your Backend
Know where your proxy traffic goes. Learn which fields to log, how to count bytes, how to store and summarise usage, and how to keep the logs private.
9 min read