mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Allow credentials to be provided as part of /flows api
This commit is contained in:
@@ -53,7 +53,7 @@ describe("runtime-api/flows", function() {
|
||||
var loadFlows;
|
||||
var reloadError = false;
|
||||
beforeEach(function() {
|
||||
setFlows = sinon.spy(function(flows,type) {
|
||||
setFlows = sinon.spy(function(flows,credentials,type) {
|
||||
if (flows[0] === "error") {
|
||||
var err = new Error("error");
|
||||
err.code = "error";
|
||||
@@ -91,7 +91,19 @@ describe("runtime-api/flows", function() {
|
||||
result.should.eql({rev:"newRev"});
|
||||
setFlows.called.should.be.true();
|
||||
setFlows.lastCall.args[0].should.eql([4,5,6]);
|
||||
setFlows.lastCall.args[1].should.eql("full");
|
||||
setFlows.lastCall.args[2].should.eql("full");
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
it("includes credentials when part of the request", function(done) {
|
||||
flows.setFlows({
|
||||
flows: {flows:[4,5,6], credentials: {$:"creds"}},
|
||||
}).then(function(result) {
|
||||
result.should.eql({rev:"newRev"});
|
||||
setFlows.called.should.be.true();
|
||||
setFlows.lastCall.args[0].should.eql([4,5,6]);
|
||||
setFlows.lastCall.args[1].should.eql({$:"creds"});
|
||||
setFlows.lastCall.args[2].should.eql("full");
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
@@ -103,7 +115,7 @@ describe("runtime-api/flows", function() {
|
||||
result.should.eql({rev:"newRev"});
|
||||
setFlows.called.should.be.true();
|
||||
setFlows.lastCall.args[0].should.eql([4,5,6]);
|
||||
setFlows.lastCall.args[1].should.eql("nodes");
|
||||
setFlows.lastCall.args[2].should.eql("nodes");
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
@@ -125,7 +137,7 @@ describe("runtime-api/flows", function() {
|
||||
result.should.eql({rev:"newRev"});
|
||||
setFlows.called.should.be.true();
|
||||
setFlows.lastCall.args[0].should.eql([4,5,6]);
|
||||
setFlows.lastCall.args[1].should.eql("nodes");
|
||||
setFlows.lastCall.args[2].should.eql("nodes");
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
@@ -67,7 +67,10 @@ describe('flows/index', function() {
|
||||
});
|
||||
return when.resolve();
|
||||
});
|
||||
credentialsLoad = sinon.stub(credentials,"load",function() {
|
||||
credentialsLoad = sinon.stub(credentials,"load",function(creds) {
|
||||
if (creds && creds.hasOwnProperty("$") && creds['$'] === "fail") {
|
||||
return when.reject("creds error");
|
||||
}
|
||||
return when.resolve();
|
||||
});
|
||||
flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) {
|
||||
@@ -177,6 +180,23 @@ describe('flows/index', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('sets the full flow including credentials', function(done) {
|
||||
var originalConfig = [
|
||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
var credentials = {"t1-1":{"a":1}};
|
||||
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
flows.setFlows(originalConfig,credentials).then(function() {
|
||||
credentialsClean.called.should.be.false();
|
||||
credentialsLoad.called.should.be.true();
|
||||
credentialsLoad.lastCall.args[0].should.eql(credentials);
|
||||
flows.getFlows().flows.should.eql(originalConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('updates existing flows with partial deployment - nodes', function(done) {
|
||||
var originalConfig = [
|
||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||
@@ -235,6 +255,20 @@ describe('flows/index', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns error if it cannot decrypt credentials', function(done) {
|
||||
var originalConfig = [
|
||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
var credentials = {"$":"fail"};
|
||||
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
flows.setFlows(originalConfig,credentials).then(function() {
|
||||
done("Unexpected success when credentials couldn't be decrypted")
|
||||
}).catch(function(err) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#load', function() {
|
||||
|
Reference in New Issue
Block a user