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

Fix handling encrypted creds on /flows api

This commit is contained in:
Nick O'Leary 2021-03-06 20:27:51 +00:00
parent 101378c625
commit 99a9e3a91b
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 21 additions and 11 deletions

View File

@ -160,6 +160,11 @@ function setFlows(_config,_credentials,type,muteLog,forceStart,user) {
var credsDirty; var credsDirty;
if (_credentials) { if (_credentials) {
if (_credentials['$']) {
// this is a set of encrypted credentials - pass to load to decrypt
// the complete set
configSavePromise = credentials.load(_credentials);
} else {
credentials.clean(config); credentials.clean(config);
// A full set of credentials have been provided. Use those instead // A full set of credentials have been provided. Use those instead
let credentialSavePromises = []; let credentialSavePromises = [];
@ -170,6 +175,7 @@ function setFlows(_config,_credentials,type,muteLog,forceStart,user) {
} }
configSavePromise = Promise.all(credentialSavePromises); configSavePromise = Promise.all(credentialSavePromises);
credsDirty = true; credsDirty = true;
}
} else { } else {
// Allow the credential store to remove anything no longer needed // Allow the credential store to remove anything no longer needed
credentials.clean(config); credentials.clean(config);

View File

@ -33,6 +33,7 @@ describe('flows/index', function() {
var eventsOn; var eventsOn;
var credentialsClean; var credentialsClean;
var credentialsLoad; var credentialsLoad;
var credentialsAdd;
var flowCreate; var flowCreate;
var getType; var getType;
@ -80,6 +81,7 @@ describe('flows/index', function() {
} }
return Promise.resolve(); return Promise.resolve();
}); });
credentialsAdd = sinon.stub(credentials,"add", async function(id, conf){})
flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) { flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) {
var id; var id;
if (typeof flow === 'undefined') { if (typeof flow === 'undefined') {
@ -117,6 +119,7 @@ describe('flows/index', function() {
eventsOn.restore(); eventsOn.restore();
credentialsClean.restore(); credentialsClean.restore();
credentialsLoad.restore(); credentialsLoad.restore();
credentialsAdd.restore();
flowCreate.restore(); flowCreate.restore();
flows.stopFlows().then(done); flows.stopFlows().then(done);
@ -196,9 +199,10 @@ describe('flows/index', function() {
flows.init({log:mockLog, settings:{},storage:storage}); flows.init({log:mockLog, settings:{},storage:storage});
flows.setFlows(originalConfig,credentials).then(function() { flows.setFlows(originalConfig,credentials).then(function() {
credentialsClean.called.should.be.false(); credentialsClean.called.should.be.true();
credentialsLoad.called.should.be.true(); credentialsAdd.called.should.be.true();
credentialsLoad.lastCall.args[0].should.eql(credentials); credentialsAdd.lastCall.args[0].should.eql("t1-1");
credentialsAdd.lastCall.args[1].should.eql({"a":1});
flows.getFlows().flows.should.eql(originalConfig); flows.getFlows().flows.should.eql(originalConfig);
done(); done();
}); });