Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

Commit

Permalink
account for empty strings in HTTPS_PROXY
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Mar 6, 2017
1 parent d3f98c7 commit 2b2385d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/check.js
Expand Up @@ -68,11 +68,12 @@ module.exports = function (options, callback) {
options = {};
}

options.proxy = options.proxy || Conf.proxy;
options.proxy = options.proxy || process.env.https_proxy || process.env.HTTPS_PROXY;
if (options.proxy) {
Conf.api.agent = new ProxyAgent(options.proxy);
delete options.proxy;
var proxy = options.proxy || Conf.proxy;
proxy = proxy || process.env.https_proxy || process.env.HTTPS_PROXY;
delete options.proxy;

if (proxy) {
Conf.api.agent = new ProxyAgent(proxy);
}

// Set defaults
Expand Down
24 changes: 22 additions & 2 deletions test/unit.js
Expand Up @@ -236,12 +236,13 @@ describe('check', function () {
proxy: 'http://127.0.0.1:8080'
};

Nock('http://127.0.0.1:8080')
Nock('https://api.nodesecurity.io')
.post('/check')
.reply(200);

Check(options, function (err, results) {

expect(err).to.not.exist();
done();
});
});
Expand All @@ -255,12 +256,31 @@ describe('check', function () {
shrinkwrap: workingOptions.shrinkwrap
};

Nock('http://127.0.0.1:8080')
Nock('https://api.nodesecurity.io')
.post('/check')
.reply(200);

Check(options, function (err, results) {

expect(err).to.not.exist();
done();
});
});

it('Does not fail if env var sets empty string for proxy', function (done) {

process.env.https_proxy = process.env.HTTPS_PROXY = '';

var options = {
package: workingOptions.package,
shrinkwrap: workingOptions.shrinkwrap
};

Check(options, function (err, results) {

expect(err).to.not.exist();
delete process.env.https_proxy;
delete process.env.HTTPS_PROXY;
done();
});
});
Expand Down

0 comments on commit 2b2385d

Please sign in to comment.