Repository navigation
Send proxy credentials when downloading the binary (fixes #164) - #190
Draft
07souravkunda wants to merge 1 commit into
Draft
07souravkunda wants to merge 1 commit into
07souravkunda wants to merge 1 commit into
Conversation
proxyUser/proxyPass reached the running binary as --proxy-user/--proxy-pass but never the library's own download of that binary. Behind a proxy that requires Basic auth, the first download request (the source-URL lookup on local.browserstack.com) was refused with 407, the binary was never fetched, and start() failed with "Couldn't find binary file". Every released version behaves this way. Fixes #164. - util.buildProxyAgent is now the single place the download proxy agent is built (it was four copies). It adds Basic auth from proxyUser/proxyPass and follows the README rule that proxyPass is ignored without proxyUser. - Local.getBinaryPath forwards proxyUser/proxyPass into the download conf. - The sync path hands the credentials to the spawned download scripts through BROWSERSTACK_LOCAL_PROXY_USER/_PASS in their environment, never argv (same as the auth token). A copy already in process.env is dropped first. Tests: test/proxy_auth_download.js runs offline against a recording proxy in its own process, so the sync path cannot deadlock it. 10/10 pass; 9/10 fail on the pre-fix code. Also verified end to end with a real key: the library downloads the binary through a credential-checking proxy and the tunnel connects, async and sync, with and without TLS inspection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #164. Jira: LOC-7724
Problem
proxyUser/proxyPassreach the running BrowserStack Local binary as--proxy-user/--proxy-pass, but never the library's own download of that binary. Behind a proxy that requires Basic auth, the first download request (the source-URL lookup onlocal.browserstack.com) is refused with 407, the binary is never fetched, andstart()fails withCouldn't find binary file. Every released version behaves this way: no download path has ever built its proxy agent with credentials.Because the library parses the proxy's 407 page as JSON, the visible log is
Unable to fetch the source url to download the binary with error: SyntaxError: Unexpected token < in JSON ..., not a 407.Change
lib/util.js: newbuildProxyAgent(host, port, user, pass), now the only place the download proxy agent is built (it was four copies). It adds Basic auth fromproxyUser/proxyPassand follows the README rule thatproxyPassis ignored withoutproxyUser. A blank host or port, or the"undefined"argv placeholder, means no agent.lib/Local.js:getBinaryPathforwardsproxyUser/proxyPassinto the download conf.lib/LocalBinary.js: the asyncdownload()andgetSourceUrl()use the helper. The syncgetSourceUrlSync()/downloadSync()pass the credentials to the spawned scripts throughBROWSERSTACK_LOCAL_PROXY_USER/_PASSin the child's environment, never argv (argv is world-readable viaps), the same pattern as the existing auth token. A copy already inprocess.envis dropped first, so only this instance's settings are used.lib/download.js,lib/fetchDownloadSourceUrl.js,lib/fetchDownloadSourceUrlAsync.js: use the helper.fetchDownloadSourceUrlAsyncgainsproxyUser, proxyPassafterproxyPort;LocalBinaryis its only caller.proxyHostandproxyPortare set (existing behaviour, now documented).Testing
test/proxy_auth_download.js(new, offline). It usestest/fixtures/recording_proxy.js, a proxy that records each CONNECT'sProxy-Authorizationand refuses it with 407. The proxy runs in its own process because the sync path blocks the test process inspawnSync.test/proxy_auth_download.js(10 tests)npm test(eslint + mocha)The 4 existing failures are unrelated to this change. The three
Downloadtests callbinary.download()without a key and getInvalid auth tokenfrom the endpoint;should stop localreadsisRunning()as true right afterstop().End to end with a real key and a fresh home/tmp/cwd (no cached binary), the library downloads the binary through a forwarding proxy that rejects missing or wrong credentials, then starts the tunnel:
start()startSync()useCaCertificate)The same run against the published 1.5.16 makes one CONNECT with no
Proxy-Authorizationand fails withCouldn't find binary file(async and sync). Tested on macOS; not run on Linux or Windows.Not in this PR
proxyHostset but notproxyPort, the binary defaults to port 3128 while the download skips the proxy.SyntaxErrorrather than a clear proxy-authentication error.This supersedes #183 and #186. #183 changes only
download(), and sinceLocal.jsnever puts the credentials intoconf, astart()through an authenticating proxy still sent noProxy-Authorizationwhen tested. #186 covers the same call sites but its base predates current master.🤖 Generated with Claude Code