diff options
Diffstat (limited to 'deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/test')
-rw-r--r-- | deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/test/test.js | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/test/test.js b/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/test/test.js index 23814e2c32..da2e919835 100644 --- a/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/test/test.js +++ b/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/test/test.js @@ -14,6 +14,10 @@ var events = require('events'); var inherits = require('util').inherits; var Agent = require('../'); +var PassthroughAgent = Agent(function(req, opts) { + return opts.secureEndpoint ? https.globalAgent : http.globalAgent; +}); + describe('Agent', function() { describe('subclass', function() { it('should be subclassable', function(done) { @@ -70,10 +74,10 @@ describe('Agent', function() { it('should be the Agent instance', function(done) { var called = false; var agent = new Agent(); - agent.callback = function () { + agent.callback = function() { called = true; assert.equal(this, agent); - } + }; var info = url.parse('http://127.0.0.1/foo'); info.agent = agent; var req = http.get(info); @@ -81,15 +85,15 @@ describe('Agent', function() { assert(/no Duplex stream was returned/.test(err.message)); done(); }); - }) + }); it('should be the Agent instance with callback signature', function(done) { var called = false; var agent = new Agent(); - agent.callback = function (req, opts, fn) { + agent.callback = function(req, opts, fn) { called = true; assert.equal(this, agent); fn(); - } + }; var info = url.parse('http://127.0.0.1/foo'); info.agent = agent; var req = http.get(info); @@ -97,8 +101,8 @@ describe('Agent', function() { assert(/no Duplex stream was returned/.test(err.message)); done(); }); - }) - }) + }); + }); describe('"error" event', function() { it('should be invoked on `http.ClientRequest` instance if `callback()` has not been defined', function( done @@ -201,13 +205,7 @@ describe('Agent', function() { 'Set-Cookie: 1\r\n' + 'Set-Cookie: 2\r\n\r\n' ); - if ('function' == typeof stream.ondata) { - // node <= v0.11.3 - stream.ondata(buf, 0, buf.length); - } else { - // node > v0.11.3 - stream.emit('data', buf); - } + stream.emit('data', buf); }); req.end(); @@ -399,6 +397,28 @@ describe('"http" module', function() { done(); }); }); + + describe('PassthroughAgent', function() { + it('should pass through to `http.globalAgent`', function(done) { + // add HTTP server "request" listener + var gotReq = false; + server.once('request', function(req, res) { + gotReq = true; + res.setHeader('X-Foo', 'bar'); + res.setHeader('X-Url', req.url); + res.end(); + }); + + var info = url.parse('http://127.0.0.1:' + port + '/foo'); + info.agent = PassthroughAgent; + http.get(info, function(res) { + assert.equal('bar', res.headers['x-foo']); + assert.equal('/foo', res.headers['x-url']); + assert(gotReq); + done(); + }); + }); + }); }); describe('"https" module', function() { @@ -426,7 +446,6 @@ describe('"https" module', function() { server.close(); }); - it('should not modify the passed in Options object', function(done) { var called = false; var agent = new Agent(function(req, opts, fn) { @@ -515,6 +534,29 @@ describe('"https" module', function() { rejectUnauthorized: false }); }); + + describe('PassthroughAgent', function() { + it('should pass through to `https.globalAgent`', function(done) { + // add HTTP server "request" listener + var gotReq = false; + server.once('request', function(req, res) { + gotReq = true; + res.setHeader('X-Foo', 'bar'); + res.setHeader('X-Url', req.url); + res.end(); + }); + + var info = url.parse('https://127.0.0.1:' + port + '/foo'); + info.agent = PassthroughAgent; + info.rejectUnauthorized = false; + https.get(info, function(res) { + assert.equal('bar', res.headers['x-foo']); + assert.equal('/foo', res.headers['x-url']); + assert(gotReq); + done(); + }); + }); + }); }); describe('"ws" server', function() { |