From e54f5f7d276e0b2e5e9b254d31068626d69c3eb1 Mon Sep 17 00:00:00 2001 From: jford Date: Fri, 27 Jul 2018 16:14:46 -0400 Subject: [PATCH 1/4] Adding a test for default agent requests --- test/request.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/request.js b/test/request.js index 217b4a4..305fcea 100644 --- a/test/request.js +++ b/test/request.js @@ -175,6 +175,19 @@ describe('request', function () { .then(done, done); }); + it('agent can be used to set default headers', function (done){ + var agent = request.agent('https://httpbin.org'); + agent.auth("user", "passwd"); + + agent + .get('/basic-auth/user/passwd') + .then(function (res){ + res.should.have.status(200); + agent.close(); + }) + .then(done, done); + }); + it('automatically closes the server down once done with it', function (done) { var server = require('http').createServer(function (req, res) { res.writeHeader(200, { 'content-type' : 'text/plain' }); @@ -240,6 +253,6 @@ describe('request', function () { res.body.cookies.biz.should.equal('baz'); }) .then(done, done); - }); + }); }); }); From dcd861caf4f9ba48604b942c3686efece2adc637 Mon Sep 17 00:00:00 2001 From: jford Date: Fri, 27 Jul 2018 17:08:08 -0400 Subject: [PATCH 2/4] Remove whitespace change from previous commit --- test/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/request.js b/test/request.js index 305fcea..daaca91 100644 --- a/test/request.js +++ b/test/request.js @@ -253,6 +253,6 @@ describe('request', function () { res.body.cookies.biz.should.equal('baz'); }) .then(done, done); - }); + }); }); }); From 61c2674742abcd2cf99ab555d285ae4ab4755aa6 Mon Sep 17 00:00:00 2001 From: jford Date: Fri, 3 Aug 2018 09:35:04 -0400 Subject: [PATCH 3/4] Add second test for arbitrary default header --- test/request.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/request.js b/test/request.js index daaca91..7510b97 100644 --- a/test/request.js +++ b/test/request.js @@ -176,6 +176,20 @@ describe('request', function () { }); it('agent can be used to set default headers', function (done){ + var agent = request.agent('https://httpbin.org'); + agent.set("Header-Name", "header_value"); + + agent + .get('/headers') + .then(function (res){ + res.should.have.status(200); + res.body.headers.should.have.property('Header-Name').that.equals("header_value"); + agent.close(); + }) + .then(done, done); + }); + + it('agent can be used to set default basic authentication', function (done){ var agent = request.agent('https://httpbin.org'); agent.auth("user", "passwd"); From c69fad796d9cfc654206ad25cf0e3c94ff04b9c0 Mon Sep 17 00:00:00 2001 From: jford Date: Fri, 3 Aug 2018 10:12:04 -0400 Subject: [PATCH 4/4] Add test for default token/bearer auth --- test/request.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/request.js b/test/request.js index 7510b97..73a73d6 100644 --- a/test/request.js +++ b/test/request.js @@ -189,6 +189,22 @@ describe('request', function () { .then(done, done); }); + it('agent can be used to set default baerer authentication', function (done){ + var agent = request.agent('https://httpbin.org'); + agent.set("Authorization", "Bearer test_bearer"); + + agent + .get('/bearer') + .then(function (res){ + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('authenticated').that.equals(true); + res.body.should.have.property('token').that.equals("test_bearer"); + agent.close(); + }) + .then(done, done); + }); + it('agent can be used to set default basic authentication', function (done){ var agent = request.agent('https://httpbin.org'); agent.auth("user", "passwd");