1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Start to add HTTP-PROXY tests back in

This commit is contained in:
Ben Hardill 2021-06-08 10:30:24 +01:00
parent 591b61945f
commit 17a139f27f
No known key found for this signature in database
GPG Key ID: 74DD076979ABB1E7
2 changed files with 47 additions and 16 deletions

View File

@ -113,6 +113,7 @@
"node-red-node-test-helper": "^0.2.7", "node-red-node-test-helper": "^0.2.7",
"node-sass": "^5.0.0", "node-sass": "^5.0.0",
"nodemon": "2.0.7", "nodemon": "2.0.7",
"proxy": "^1.0.2",
"should": "13.2.3", "should": "13.2.3",
"sinon": "10.0.1", "sinon": "10.0.1",
"stoppable": "^1.1.0", "stoppable": "^1.1.0",

View File

@ -25,7 +25,7 @@ var httpRequestNode = require("nr-test-utils").require("@node-red/nodes/core/net
var tlsNode = require("nr-test-utils").require("@node-red/nodes/core/network/05-tls.js"); var tlsNode = require("nr-test-utils").require("@node-red/nodes/core/network/05-tls.js");
var httpProxyNode = require("nr-test-utils").require("@node-red/nodes/core/network/06-httpproxy.js"); var httpProxyNode = require("nr-test-utils").require("@node-red/nodes/core/network/06-httpproxy.js");
var hashSum = require("hash-sum"); var hashSum = require("hash-sum");
var httpProxy = require('http-proxy'); var httpProxy = require('proxy');
var cookieParser = require('cookie-parser'); var cookieParser = require('cookie-parser');
var multer = require("multer"); var multer = require("multer");
var RED = require("nr-test-utils").require("node-red/lib/red"); var RED = require("nr-test-utils").require("node-red/lib/red");
@ -76,20 +76,48 @@ describe('HTTP Request Node', function() {
testSslServer.listen(testSslPort); testSslServer.listen(testSslPort);
testProxyPort += 1; testProxyPort += 1;
testProxyServer = stoppable(httpProxy.createProxyServer({target:'http://localhost:' + testPort})); // testProxyServer = stoppable(httpProxy.createProxyServer({target:'http://localhost:' + testPort}));
testProxyServer.on('proxyReq', function(proxyReq, req, res, options) { // testProxyServer.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.setHeader('x-testproxy-header', 'foobar'); // proxyReq.setHeader('x-testproxy-header', 'foobar');
}); // });
testProxyServer.on('proxyRes', function (proxyRes, req, res, options) { // testProxyServer.on('proxyRes', function (proxyRes, req, res, options) {
// if (req.url == getTestURL('/proxyAuthenticate')){
// var user = auth.parse(req.headers['proxy-authorization']);
// if (!(user.name == "foouser" && user.pass == "barpassword")){
// proxyRes.headers['proxy-authenticate'] = 'BASIC realm="test"';
// proxyRes.statusCode = 407;
// }
// }
// });
// testProxyServer.listen(testProxyPort);
testProxyServer = stoppable(httpProxy(http.createServer()))
//var t = httpProxy(testProxyServer)
testProxyServer.on('request', function(req,res){
console.log("********************************* ARGS")
if (!res.headersSent) {
res.setHeader("x-testproxy-header", "foobar")
}
})
testProxyServer.authenticate = function(req,callback){
console.log("********************************* AUTH")
if (req.url == getTestURL('/proxyAuthenticate')) { if (req.url == getTestURL('/proxyAuthenticate')) {
var user = auth.parse(req.headers['proxy-authorization']); var authHeader = req.headers['proxy-authorization'];
if (!(user.name == "foouser" && user.pass == "barpassword")){ if (authHeader) {
proxyRes.headers['proxy-authenticate'] = 'BASIC realm="test"'; var user = auth.parse(authHeader)
proxyRes.statusCode = 407; if (user.name == "foouser" && user.pass == "barpassword") {
console.err("Proxy Authentication pased")
callback(null, true)
} else {
callback(null, false)
}
} else {
callback(null, false)
}
} else {
callback(null, true)
} }
} }
}); testProxyServer.listen(testProxyPort)
testProxyServer.listen(testProxyPort);
done(err); done(err);
}); });
} }
@ -1387,7 +1415,7 @@ describe('HTTP Request Node', function() {
}); });
//Removing HTTP Proxy testcases as GOT + Proxy_Agent doesn't work with mock'd proxy //Removing HTTP Proxy testcases as GOT + Proxy_Agent doesn't work with mock'd proxy
/* /* */
it('should use http_proxy', function(done) { it('should use http_proxy', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"POST",ret:"obj",url:getTestURL('/postInspect')}, var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"POST",ret:"obj",url:getTestURL('/postInspect')},
{id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];
@ -1410,6 +1438,8 @@ describe('HTTP Request Node', function() {
}); });
}); });
it('should use http_proxy when environment variable is invalid', function(done) { it('should use http_proxy when environment variable is invalid', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"POST",ret:"obj",url:getTestURL('/postInspect')}, var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"POST",ret:"obj",url:getTestURL('/postInspect')},
{id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];
@ -1453,7 +1483,7 @@ describe('HTTP Request Node', function() {
n1.receive({payload:"foo"}); n1.receive({payload:"foo"});
}); });
}); });
/*
it('should use no_proxy', function(done) { it('should use no_proxy', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"POST",ret:"obj",url:getTestURL('/postInspect')}, var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"POST",ret:"obj",url:getTestURL('/postInspect')},
{id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];