Repository navigation
Send proxy credentials when downloading the binary (fixes #164) #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,21 @@ | ||
| module.exports.isUndefined = value => (value === undefined || value === null || value === 'undefined'); | ||
| const HttpsProxyAgent = require('https-proxy-agent'); | ||
|
|
||
| const isUndefined = value => (value === undefined || value === null || value === 'undefined'); | ||
| module.exports.isUndefined = isUndefined; | ||
|
|
||
| const isBlank = value => (isUndefined(value) || value === ''); | ||
|
|
||
| /* Builds the proxy agent for every binary-download request: the in-process async | ||
| download and the scripts the sync path spawns. Without proxyUser/proxyPass in it, | ||
| an authenticating proxy answers the CONNECT with 407 and the binary is never | ||
| downloaded, even though the running binary gets them as --proxy-user/--proxy-pass. | ||
| Same rule as the README: proxyPass is ignored unless proxyUser is set. */ | ||
| module.exports.buildProxyAgent = (proxyHost, proxyPort, proxyUser, proxyPass) => { | ||
| if(isBlank(proxyHost) || isBlank(proxyPort)) return undefined; | ||
| const agentOptions = { host: proxyHost, port: proxyPort }; | ||
| if(!isBlank(proxyUser)) { | ||
| /* https-proxy-agent sends this as `Proxy-Authorization: Basic base64(auth)`. */ | ||
| agentOptions.auth = proxyUser + ':' + (isUndefined(proxyPass) ? '' : proxyPass); | ||
| } | ||
| return new HttpsProxyAgent(agentOptions); | ||
| }; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* Test double for a corporate proxy that requires Basic auth. It runs in its own | ||
| process so the sync download path, which blocks the test process in spawnSync, | ||
| can still reach it. Every CONNECT is recorded and refused with 407, so nothing | ||
| leaves the machine. Talks to the parent over the fork IPC channel: | ||
| sends { port } once listening, answers 'dump' with { requests }, exits on 'stop'. */ | ||
| const http = require('http'); | ||
|
|
||
| const requests = []; | ||
| const server = http.createServer(function (req, res) { | ||
| res.writeHead(405); | ||
| res.end(); | ||
| }); | ||
|
|
||
| server.on('connect', function (req, socket) { | ||
| requests.push({ target: req.url, auth: req.headers['proxy-authorization'] || null }); | ||
| socket.end('HTTP/1.1 407 Proxy Authentication Required\r\n' + | ||
| 'Proxy-Authenticate: Basic realm="corp"\r\n' + | ||
| 'Content-Length: 0\r\n' + | ||
| 'Connection: close\r\n\r\n'); | ||
| }); | ||
|
|
||
| process.on('message', function (msg) { | ||
| if (msg === 'dump') process.send({ requests: requests.splice(0) }); | ||
| if (msg === 'stop') server.close(function () { process.exit(0); }); | ||
| }); | ||
|
|
||
| server.listen(0, '127.0.0.1', function () { | ||
| process.send({ port: server.address().port }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
rg -n 'proxyUser|proxyPass|undefined' lib/util.js lib/LocalBinary.js lib/Local.js lib/download.js lib/fetchDownloadSourceUrl.js lib/fetchDownloadSourceUrlAsync.jsRepository: browserstack/browserstack-local-nodejs
Length of output: 3757
Script executed:
Repository: browserstack/browserstack-local-nodejs
Length of output: 3262
Treat the literal credentials
"undefined"as valid.isBlankandisUndefinedboth treat the string'undefined'as missing. This affects credentials in two ways:'undefined'becomes an empty password. The proxy receivesuser:.'undefined'disables authentication.The library does not create these strings on its own. The string reaches
buildProxyAgentonly when a user configures'undefined'as a credential. The failure is still silent, so the proxy returns 407 or the credential is dropped.Use a credential-specific missing-value check for
proxyUserandproxyPass. Keep the'undefined'sentinel check for the host and port placeholders.Suggested fix