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

Add Testcase & Fix typo

This commit is contained in:
Ben Hardill 2021-07-28 08:52:35 +01:00
parent 555e815402
commit a76c6f86c6
No known key found for this signature in database
GPG Key ID: 74DD076979ABB1E7
2 changed files with 66 additions and 4 deletions

View File

@ -455,7 +455,7 @@ in your Node-RED user directory (${RED.settings.userDir}).
}
if (opts.https.cert) {
opts.https.certificate = opts.https.cert;
delete opt.https.cert;
delete opts.https.cert;
}
} else {
if (msg.hasOwnProperty('rejectUnauthorized')) {

View File

@ -42,6 +42,8 @@ describe('HTTP Request Node', function() {
var testProxyPort = 10444;
var testProxyServerAuth;
var testProxyAuthPort = 10554;
var testSslClientServer;
var testSslClientPort = 10664;
//save environment variables
var preEnvHttpProxyLowerCase;
@ -57,6 +59,7 @@ describe('HTTP Request Node', function() {
testServer = stoppable(http.createServer(testApp));
testServer.listen(testPort,function(err) {
testSslPort += 1;
console.log("ssl port", testSslPort);
var sslOptions = {
key: fs.readFileSync('test/resources/ssl/server.key'),
cert: fs.readFileSync('test/resources/ssl/server.crt')
@ -75,7 +78,25 @@ describe('HTTP Request Node', function() {
*/
};
testSslServer = stoppable(https.createServer(sslOptions,testApp));
testSslServer.listen(testSslPort);
testSslServer.listen(testSslPort, function(err){
if (err) {
console.log(err);
} else {
console.log("started testSslServer");
}
});
testSslClientPort += 1;
var sslClientOptions = {
key: fs.readFileSync('test/resources/ssl/server.key'),
cert: fs.readFileSync('test/resources/ssl/server.crt'),
ca: fs.readFileSync('test/resources/ssl/server.crt'),
requestCert: true
};
testSslClientServer = stoppable(https.createServer(sslClientOptions, testApp));
testSslClientServer.listen(testSslClientPort, function(err){
console.log("ssl-client", err)
});
testProxyPort += 1;
testProxyServer = stoppable(httpProxy(http.createServer()))
@ -121,6 +142,10 @@ describe('HTTP Request Node', function() {
return "https://localhost:"+testSslPort+url;
}
function getSslClientTestURL(url) {
return "https://localhost:"+testSslClientPort+url;
}
function getDifferentTestURL(url) {
return "http://127.0.0.1:"+testPort+url;
}
@ -280,6 +305,14 @@ describe('HTTP Request Node', function() {
headers:result
});
})
testApp.get('/getClientCert', function(req,res) {
if (req.client.authorized) {
res.send('hello');
} else {
res.status(401).send();
}
})
startServer(function(err) {
if (err) {
done(err);
@ -293,7 +326,9 @@ describe('HTTP Request Node', function() {
testProxyServer.stop(() => {
testProxyServerAuth.stop(() => {
testSslServer.stop(() => {
helper.stopServer(done);
testSslClientServer.stop(() => {
helper.stopServer(done);
})
});
});
});
@ -1520,7 +1555,7 @@ describe('HTTP Request Node', function() {
it('should use tls-config and verify serverCert', function(done) {
var flow = [
{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"txt",url:getSslTestURLWithoutProtocol('/text'),tls:"n3"},
{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"txt",url:getSslTestURL('/text'),tls:"n3"},
{id:"n2", type:"helper"},
{id:"n3", type:"tls-config", cert:"test/resources/ssl/server.crt", key:"test/resources/ssl/server.key", ca:"test/resources/ssl/server.crt", verifyservercert:true}];
var testNodes = [httpRequestNode, tlsNode];
@ -1545,6 +1580,33 @@ describe('HTTP Request Node', function() {
});
});
it('should use tls-config and send client cert', function(done) {
var flow = [
{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"txt",url:getSslClientTestURL('/getClientCert'),tls:"n3"},
{id:"n2", type:"helper"},
{id:"n3", type:"tls-config", cert:"test/resources/ssl/server.crt", key:"test/resources/ssl/server.key", ca:"test/resources/ssl/server.crt", verifyservercert:false}];
var testNodes = [httpRequestNode,tlsNode];
helper.load(testNodes, flow, function() {
var n3 = helper.getNode("n3");
var n2 = helper.getNode("n2");
var n1 = helper.getNode("n1");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload','hello');
msg.should.have.property('statusCode',200);
msg.should.have.property('headers');
msg.headers.should.have.property('content-length',''+('hello'.length));
msg.headers.should.have.property('content-type').which.startWith('text/html');
msg.should.have.property('responseUrl').which.startWith('https://');
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo"});
})
});
//Removing HTTP Proxy testcases as GOT + Proxy_Agent doesn't work with mock'd proxy
/* */
it('should use http_proxy', function(done) {