From 71a06aab0249487ff650c8a47906cc8281561664 Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Mon, 8 Dec 2014 16:14:48 -0500 Subject: [PATCH] [test] add tests for the changeOrigin cases in properly setting the host header --- test/lib-http-proxy-common-test.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 7cb5e1481..87777c25f 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -216,7 +216,7 @@ describe('lib/http-proxy/common.js', function () { // // This is the proper failing test case for the common.join problem // - it('should correctly format the a toProxy URL', function () { + it('should correctly format the toProxy URL', function () { var outgoing = {}; var google = 'https://google.com' common.setupOutgoing(outgoing, { @@ -225,7 +225,33 @@ describe('lib/http-proxy/common.js', function () { }, { url: google }); expect(outgoing.path).to.eql('/' + google); - }) + }); + + describe('when using changeOrigin', function () { + it('should correctly set the port to the host when it is a non-standard port using url.parse', function () { + var outgoing = {}; + var myEndpoint = 'https://myCouch.com:6984'; + common.setupOutgoing(outgoing, { + target: url.parse(myEndpoint), + changeOrigin: true + }, { url: '/' }); + + expect(outgoing.headers.host).to.eql('mycouch.com:6984'); + }); + it('should correctly set the port to the host when it is a non-standard port when setting host and port manually (which ignores port)', function () { + var outgoing = {}; + common.setupOutgoing(outgoing, { + target: { + protocol: 'https:', + host: 'mycouch.com', + port: 6984 + }, + changeOrigin: true + }, { url: '/' }); + expect(outgoing.headers.host).to.eql('mycouch.com:6984'); + }) + }); + }); describe('#setupSocket', function () {