From df158bfc53e35e62609d8169f3883f6dcf12b73c Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 15:11:56 -0700 Subject: [PATCH] added auth header test --- .idea/.name | 1 + .idea/encodings.xml | 4 + .idea/inspectionProfiles/Project_Default.xml | 8 + .../inspectionProfiles/profiles_settings.xml | 7 + .idea/jsLibraryMappings.xml | 6 + .idea/jsLinters/jscs.xml | 4 + .idea/jsLinters/jshint.xml | 70 +++++ .../node_http_proxy_node_modules.xml | 14 + .idea/modules.xml | 8 + .idea/node-http-proxy.iml | 9 + .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 6 + .idea/workspace.xml | 245 ++++++++++++++++++ lib/http-proxy/common.js | 2 +- ...lib-http-proxy-passes-web-incoming-test.js | 27 ++ 15 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 .idea/.name create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/jsLinters/jscs.xml create mode 100644 .idea/jsLinters/jshint.xml create mode 100644 .idea/libraries/node_http_proxy_node_modules.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/node-http-proxy.iml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..cef877d --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +node-http-proxy \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..d821048 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..65ef114 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..61cd2da --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jsLinters/jscs.xml b/.idea/jsLinters/jscs.xml new file mode 100644 index 0000000..8fc0d29 --- /dev/null +++ b/.idea/jsLinters/jscs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLinters/jshint.xml b/.idea/jsLinters/jshint.xml new file mode 100644 index 0000000..c5f5980 --- /dev/null +++ b/.idea/jsLinters/jshint.xml @@ -0,0 +1,70 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/node_http_proxy_node_modules.xml b/.idea/libraries/node_http_proxy_node_modules.xml new file mode 100644 index 0000000..2000165 --- /dev/null +++ b/.idea/libraries/node_http_proxy_node_modules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..32e963d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/node-http-proxy.iml b/.idea/node-http-proxy.iml new file mode 100644 index 0000000..99ac459 --- /dev/null +++ b/.idea/node-http-proxy.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..dea6016 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1426197133406 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index a8722f2..59ece4d 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -46,7 +46,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) { extend(outgoing.headers, options.headers); } - if(options.auth){ + if (options.auth) { outgoing.auth = options.auth; } diff --git a/test/lib-http-proxy-passes-web-incoming-test.js b/test/lib-http-proxy-passes-web-incoming-test.js index f2c6f13..f6d532d 100644 --- a/test/lib-http-proxy-passes-web-incoming-test.js +++ b/test/lib-http-proxy-passes-web-incoming-test.js @@ -299,4 +299,31 @@ describe('#createProxyServer.web() using own http server', function () { http.request('http://127.0.0.1:8081', function() {}).end(); }); + + it('should proxy the request with the Authorization header set', function (done) { + var proxy = httpProxy.createProxyServer({ + target: 'http://127.0.0.1:8080', + auth: 'user:pass' + }); + + function requestHandler(req, res) { + proxy.web(req, res); + } + + var proxyServer = http.createServer(requestHandler); + + var source = http.createServer(function(req, res) { + source.close(); + proxyServer.close(); + var auth = new Buffer(req.headers.authorization.split(' ')[1], 'base64'); + expect(req.method).to.eql('GET'); + expect(auth.toString()).to.eql('user:pass'); + done(); + }); + + proxyServer.listen('8081'); + source.listen('8080'); + + http.request('http://127.0.0.1:8081', function() {}).end(); + }); }); \ No newline at end of file