Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/LocalBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,14 @@ function LocalBinary(){

var options = url.parse(this.httpPath);
if(conf.proxyHost && conf.proxyPort) {
options.agent = new HttpsProxyAgent({
var proxyOptions = {
host: conf.proxyHost,
port: conf.proxyPort
});
};
if(conf.proxyUser && conf.proxyPass) {
proxyOptions.auth = conf.proxyUser + ':' + conf.proxyPass;
}
options.agent = new HttpsProxyAgent(proxyOptions);
}
if (conf.useCaCertificate) {
try {
Expand Down
46 changes: 46 additions & 0 deletions test/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,52 @@ describe('LocalBinary', function () {
});
});

it('should pass proxy authentication to the binary download when proxyUser/proxyPass are set', function () {
var https = require('https');
var getDownloadPathStub = sinon.stub(binary, 'getDownloadPath', function (conf, retries, cb) {
cb(null, 'https://bstack-downloads.example/BrowserStackLocal');
});
var httpsGetStub = sinon.stub(https, 'get').returns({ on: function () { return this; } });

try {
var conf = {
proxyHost: '127.0.0.1',
proxyPort: proxyPort,
proxyUser: 'user',
proxyPass: 'pass'
};
binary.download(conf, tempDownloadPath, function () {});

expect(httpsGetStub.calledOnce).to.equal(true);
var passedOptions = httpsGetStub.firstCall.args[0];
expect(passedOptions.agent).to.be.an('object');
expect(passedOptions.agent.proxy.auth).to.equal('user:pass');
} finally {
httpsGetStub.restore();
getDownloadPathStub.restore();
}
});

it('should not set proxy authentication when only host/port are provided', function () {
var https = require('https');
var getDownloadPathStub = sinon.stub(binary, 'getDownloadPath', function (conf, retries, cb) {
cb(null, 'https://bstack-downloads.example/BrowserStackLocal');
});
var httpsGetStub = sinon.stub(https, 'get').returns({ on: function () { return this; } });

try {
var conf = { proxyHost: '127.0.0.1', proxyPort: proxyPort };
binary.download(conf, tempDownloadPath, function () {});

var passedOptions = httpsGetStub.firstCall.args[0];
expect(passedOptions.agent).to.be.an('object');
expect(passedOptions.agent.proxy.auth).to.equal(undefined);
} finally {
httpsGetStub.restore();
getDownloadPathStub.restore();
}
});

it('should download binaries in sync', function () {
this.timeout(MAX_TIMEOUT);
var conf = {};
Expand Down