diff --git a/lib/check.js b/lib/check.js index 18c938d..8c8935a 100644 --- a/lib/check.js +++ b/lib/check.js @@ -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 diff --git a/test/unit.js b/test/unit.js index 388101b..12f7785 100644 --- a/test/unit.js +++ b/test/unit.js @@ -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(); }); }); @@ -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(); }); });