Skip to content

fix: pass proxy credentials to binary download (fixes #164) - #183

Open
Arunendra21 wants to merge 1 commit into
browserstack:masterfrom
Arunendra21:fix/proxy-auth-binary-download
Open

fix: pass proxy credentials to binary download (fixes #164)#183
Arunendra21 wants to merge 1 commit into
browserstack:masterfrom
Arunendra21:fix/proxy-auth-binary-download

Conversation

@Arunendra21

Copy link
Copy Markdown

What

browserstack-local-nodejs already accepts proxyUser / proxyPass and forwards them to the BrowserStackLocal binary as --proxy-user / --proxy-pass (see Local.js). However, when the library downloads the binary itself, LocalBinary.download() builds the HttpsProxyAgent with only host and port:

options.agent = new HttpsProxyAgent({
  host: conf.proxyHost,
  port: conf.proxyPort
});

So behind a proxy that requires authentication, the binary download fails with 407 Proxy Authentication Required even when the user has supplied valid proxy credentials. This is #164.

Fix

Include the credentials in the proxy agent options when both proxyUser and proxyPass are provided. https-proxy-agent@^5 (the version already used here) accepts an auth: "user:pass" option, which it sends as the Proxy-Authorization header:

var proxyOptions = { host: conf.proxyHost, port: conf.proxyPort };
if (conf.proxyUser && conf.proxyPass) {
  proxyOptions.auth = conf.proxyUser + ':' + conf.proxyPass;
}
options.agent = new HttpsProxyAgent(proxyOptions);

The change is scoped to the download path and only adds auth when both credentials are present, so existing unauthenticated-proxy and no-proxy behaviour is unchanged.

Tests

Added two tests to test/local.js (they stub https.get, so no network is required):

  • credentials present -> the proxy agent carries auth: "user:pass".
  • only host/port -> no auth is set (behaviour unchanged).

Fixes #164

browserstack-local-nodejs accepts proxyUser/proxyPass and forwards them
to the BrowserStackLocal binary, but LocalBinary.download() built the
HttpsProxyAgent with only host and port. Behind a proxy that requires
authentication the binary download failed with 407 even when valid
credentials were supplied.

Include the credentials via the agent's auth option when both proxyUser
and proxyPass are present, and add tests for the authenticated and
unauthenticated cases.

Fixes browserstack#164
@Arunendra21
Arunendra21 requested a review from a team as a code owner August 23, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binary Download Doesn't Use Proxy Authentication Settings

1 participant