mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'dev' into repackage
This commit is contained in:
@@ -46,6 +46,9 @@ describe('HTTP Request Node', function() {
|
||||
var preEnvNoProxyLowerCase;
|
||||
var preEnvNoProxyUpperCase;
|
||||
|
||||
//rediect cookie variables
|
||||
var receivedCookies = {};
|
||||
|
||||
function startServer(done) {
|
||||
testPort += 1;
|
||||
testServer = stoppable(http.createServer(testApp));
|
||||
@@ -98,6 +101,10 @@ describe('HTTP Request Node', function() {
|
||||
return "https://localhost:"+testSslPort+url;
|
||||
}
|
||||
|
||||
function getDifferentTestURL(url) {
|
||||
return "http://127.0.0.1:"+testPort+url;
|
||||
}
|
||||
|
||||
function getSslTestURLWithoutProtocol(url) {
|
||||
return "localhost:"+testSslPort+url;
|
||||
}
|
||||
@@ -182,6 +189,24 @@ describe('HTTP Request Node', function() {
|
||||
testApp.options('/*', function(req,res) {
|
||||
res.status(200).end();
|
||||
});
|
||||
testApp.get('/redirectToSameDomain', function(req, res) {
|
||||
var key = req.headers.host + req.url;
|
||||
receivedCookies[key] = req.cookies;
|
||||
res.cookie('redirectToSameDomainCookie','same1');
|
||||
res.redirect(getTestURL('/redirectReturn'));
|
||||
});
|
||||
testApp.get('/redirectToDifferentDomain', function(req, res) {
|
||||
var key = req.headers.host + req.url;
|
||||
receivedCookies[key] = req.cookies;
|
||||
res.cookie('redirectToDifferentDomain','different1');
|
||||
res.redirect(getDifferentTestURL('/redirectReturn'));
|
||||
});
|
||||
testApp.get('/redirectReturn', function(req, res) {
|
||||
var key = req.headers.host + req.url;
|
||||
receivedCookies[key] = req.cookies;
|
||||
res.cookie('redirectReturn','return1');
|
||||
res.status(200).end();
|
||||
});
|
||||
startServer(function(err) {
|
||||
if (err) {
|
||||
done(err);
|
||||
@@ -1240,4 +1265,162 @@ describe('HTTP Request Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('redirect-cookie', function() {
|
||||
it('should send cookies to the same domain when redirected(no cookies)', function(done) {
|
||||
var flow = [{id:'n1',type:'http request',wires:[['n2']],method:'GET',ret:'obj',url:getTestURL('/redirectToSameDomain')},
|
||||
{id:"n2", type:"helper"}];
|
||||
receivedCookies = {};
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
var cookies1 = receivedCookies['localhost:'+testPort+'/redirectToSameDomain'];
|
||||
var cookies2 = receivedCookies['localhost:'+testPort+'/redirectReturn'];
|
||||
if (cookies1 && Object.keys(cookies1).length != 0) {
|
||||
done(new Error('Invalid cookie(path:/rediectToSame)'));
|
||||
return;
|
||||
}
|
||||
if ((cookies2 && Object.keys(cookies2).length != 1) ||
|
||||
cookies2['redirectToSameDomainCookie'] !== 'same1') {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
n1.receive({});
|
||||
});
|
||||
});
|
||||
it('should not send cookies to the different domain when redirected(no cookies)', function(done) {
|
||||
var flow = [{id:'n1',type:'http request',wires:[['n2']],method:'GET',ret:'obj',url:getTestURL('/redirectToDifferentDomain')},
|
||||
{id:"n2", type:"helper"}];
|
||||
receivedCookies = {};
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
var cookies1 = receivedCookies['localhost:'+testPort+'/redirectToSameDomain'];
|
||||
var cookies2 = receivedCookies['127.0.0.1:'+testPort+'/redirectReturn'];
|
||||
if (cookies1 && Object.keys(cookies1).length != 0) {
|
||||
done(new Error('Invalid cookie(path:/rediectToDiffer)'));
|
||||
return;
|
||||
}
|
||||
if (cookies2 && Object.keys(cookies2).length != 0) {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
n1.receive({});
|
||||
});
|
||||
});
|
||||
it('should send cookies to the same domain when redirected(msg.cookies)', function(done) {
|
||||
var flow = [{id:'n1',type:'http request',wires:[['n2']],method:'GET',ret:'obj',url:getTestURL('/redirectToSameDomain')},
|
||||
{id:"n2", type:"helper"}];
|
||||
receivedCookies = {};
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
var cookies1 = receivedCookies['localhost:'+testPort+'/redirectToSameDomain'];
|
||||
var cookies2 = receivedCookies['localhost:'+testPort+'/redirectReturn'];
|
||||
if ((cookies1 && Object.keys(cookies1).length != 1) ||
|
||||
cookies1['requestCookie'] !== 'request1') {
|
||||
done(new Error('Invalid cookie(path:/rediectToSame)'));
|
||||
return;
|
||||
}
|
||||
if ((cookies2 && Object.keys(cookies2).length != 2) ||
|
||||
cookies1['requestCookie'] !== 'request1' ||
|
||||
cookies2['redirectToSameDomainCookie'] !== 'same1') {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
cookies: { requestCookie: 'request1' }
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should not send cookies to the different domain when redirected(msg.cookies)', function(done) {
|
||||
var flow = [{id:'n1',type:'http request',wires:[['n2']],method:'GET',ret:'obj',url:getTestURL('/redirectToDifferentDomain')},
|
||||
{id:"n2", type:"helper"}];
|
||||
receivedCookies = {};
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
var cookies1 = receivedCookies['localhost:'+testPort+'/redirectToDifferentDomain'];
|
||||
var cookies2 = receivedCookies['127.0.0.1:'+testPort+'/redirectReturn'];
|
||||
if ((cookies1 && Object.keys(cookies1).length != 1) ||
|
||||
cookies1['requestCookie'] !== 'request1') {
|
||||
done(new Error('Invalid cookie(path:/rediectToDiffer)'));
|
||||
return;
|
||||
}
|
||||
if (cookies2 && Object.keys(cookies2).length != 0) {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
cookies: { requestCookie: 'request1' }
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should send cookies to the same domain when redirected(msg.headers.cookie)', function(done) {
|
||||
var flow = [{id:'n1',type:'http request',wires:[['n2']],method:'GET',ret:'obj',url:getTestURL('/redirectToSameDomain')},
|
||||
{id:"n2", type:"helper"}];
|
||||
receivedCookies = {};
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
var cookies1 = receivedCookies['localhost:'+testPort+'/redirectToSameDomain'];
|
||||
var cookies2 = receivedCookies['localhost:'+testPort+'/redirectReturn'];
|
||||
if ((cookies1 && Object.keys(cookies1).length != 1) ||
|
||||
cookies1['requestCookie'] !== 'request1') {
|
||||
done(new Error('Invalid cookie(path:/rediectToSame)'));
|
||||
return;
|
||||
}
|
||||
if ((cookies2 && Object.keys(cookies2).length != 2) ||
|
||||
cookies1['requestCookie'] !== 'request1' ||
|
||||
cookies2['redirectToSameDomainCookie'] !== 'same1') {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
headers: { cookie: 'requestCookie=request1' }
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should not send cookies to the different domain when redirected(msg.headers.cookie)', function(done) {
|
||||
var flow = [{id:'n1',type:'http request',wires:[['n2']],method:'GET',ret:'obj',url:getTestURL('/redirectToDifferentDomain')},
|
||||
{id:"n2", type:"helper"}];
|
||||
receivedCookies = {};
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
var cookies1 = receivedCookies['localhost:'+testPort+'/redirectToDifferentDomain'];
|
||||
var cookies2 = receivedCookies['127.0.0.1:'+testPort+'/redirectReturn'];
|
||||
if ((cookies1 && Object.keys(cookies1).length != 1) ||
|
||||
cookies1['requestCookie'] !== 'request1') {
|
||||
done(new Error('Invalid cookie(path:/rediectToDiffer)'));
|
||||
return;
|
||||
}
|
||||
if (cookies2 && Object.keys(cookies2).length != 0) {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
headers: { cookie: 'requestCookie=request1' }
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -114,6 +114,21 @@ describe('context', function() {
|
||||
context2.global.get("foo").should.equal("test");
|
||||
});
|
||||
|
||||
it('context.flow/global are not enumerable', function() {
|
||||
var context1 = Context.get("1","flowA");
|
||||
Object.keys(context1).length.should.equal(0);
|
||||
Object.keys(context1.flow).length.should.equal(0);
|
||||
Object.keys(context1.global).length.should.equal(0);
|
||||
})
|
||||
|
||||
it('context.flow/global cannot be deleted', function() {
|
||||
var context1 = Context.get("1","flowA");
|
||||
delete context1.flow;
|
||||
should.exist(context1.flow);
|
||||
delete context1.global;
|
||||
should.exist(context1.global);
|
||||
})
|
||||
|
||||
it('deletes context',function() {
|
||||
var context = Context.get("1","flowA");
|
||||
should.not.exist(context.get("foo"));
|
||||
@@ -192,15 +207,26 @@ describe('context', function() {
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('returns functionGlobalContext value if store value undefined', function() {
|
||||
Context.init({functionGlobalContext: {foo:"bar"}});
|
||||
Context.load().then(function(){
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flowA");
|
||||
var v = context.global.get('foo');
|
||||
v.should.equal('bar');
|
||||
});
|
||||
})
|
||||
|
||||
it('returns functionGlobalContext sub-value if store value undefined', function() {
|
||||
Context.init({functionGlobalContext: {foo:{bar:123}}});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flowA");
|
||||
var v = context.global.get('foo.bar');
|
||||
should.equal(v,123);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('external context storage',function() {
|
||||
@@ -474,6 +500,23 @@ describe('context', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('should allow the store name to be provide in the key', function(done) {
|
||||
Context.init({contextStorage:contextDefaultStorage});
|
||||
Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
var cb = function(){done("An error occurred")}
|
||||
context.set("#:(test)::foo","bar");
|
||||
context.get("#:(test)::foo");
|
||||
stubGet2.called.should.be.false();
|
||||
stubSet2.called.should.be.false();
|
||||
stubSet.calledWithExactly("1:flow","foo","bar",undefined).should.be.true();
|
||||
stubGet.calledWith("1:flow","foo").should.be.true();
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
|
||||
it('should use default as the alias of other context', function(done) {
|
||||
Context.init({contextStorage:contextAlias});
|
||||
Context.load().then(function(){
|
||||
@@ -580,16 +623,16 @@ describe('context', function() {
|
||||
});
|
||||
|
||||
it('should return multiple functionGlobalContext values if key is an array', function(done) {
|
||||
var fGC = { "foo1": 456, "foo2": 789 };
|
||||
var fGC = { "foo1": 456, "foo2": {"bar":789} };
|
||||
Context.init({contextStorage:memoryStorage, functionGlobalContext:fGC });
|
||||
Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
context.global.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
|
||||
context.global.get(["foo1","foo2.bar","foo3"], "memory", function(err,foo1,foo2,foo3){
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
foo1.should.be.equal(456);
|
||||
foo2.should.be.equal(789);
|
||||
should.equal(foo1, 456);
|
||||
should.equal(foo2, 789);
|
||||
should.not.exist(foo3);
|
||||
done();
|
||||
}
|
||||
|
@@ -98,7 +98,7 @@ describe('memory',function() {
|
||||
context.set("nodeX","three","test3");
|
||||
context.set("nodeX","four","test4");
|
||||
|
||||
var values = context.get("nodeX",["one","unknown"]);
|
||||
var values = context.get("nodeX",["one","unknown.with.multiple.levels"]);
|
||||
values.should.eql(["test1",undefined])
|
||||
})
|
||||
it('should throw error if bad key included in multiple keys', function() {
|
||||
|
Reference in New Issue
Block a user