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:
parent
101378c625
commit
99a9e3a91b
@ -160,6 +160,11 @@ function setFlows(_config,_credentials,type,muteLog,forceStart,user) {
|
||||
var credsDirty;
|
||||
|
||||
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);
|
||||
// A full set of credentials have been provided. Use those instead
|
||||
let credentialSavePromises = [];
|
||||
@ -170,6 +175,7 @@ function setFlows(_config,_credentials,type,muteLog,forceStart,user) {
|
||||
}
|
||||
configSavePromise = Promise.all(credentialSavePromises);
|
||||
credsDirty = true;
|
||||
}
|
||||
} else {
|
||||
// Allow the credential store to remove anything no longer needed
|
||||
credentials.clean(config);
|
||||
|
@ -33,6 +33,7 @@ describe('flows/index', function() {
|
||||
var eventsOn;
|
||||
var credentialsClean;
|
||||
var credentialsLoad;
|
||||
var credentialsAdd;
|
||||
|
||||
var flowCreate;
|
||||
var getType;
|
||||
@ -80,6 +81,7 @@ describe('flows/index', function() {
|
||||
}
|
||||
return Promise.resolve();
|
||||
});
|
||||
credentialsAdd = sinon.stub(credentials,"add", async function(id, conf){})
|
||||
flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) {
|
||||
var id;
|
||||
if (typeof flow === 'undefined') {
|
||||
@ -117,6 +119,7 @@ describe('flows/index', function() {
|
||||
eventsOn.restore();
|
||||
credentialsClean.restore();
|
||||
credentialsLoad.restore();
|
||||
credentialsAdd.restore();
|
||||
flowCreate.restore();
|
||||
|
||||
flows.stopFlows().then(done);
|
||||
@ -196,9 +199,10 @@ describe('flows/index', function() {
|
||||
|
||||
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);
|
||||
credentialsClean.called.should.be.true();
|
||||
credentialsAdd.called.should.be.true();
|
||||
credentialsAdd.lastCall.args[0].should.eql("t1-1");
|
||||
credentialsAdd.lastCall.args[1].should.eql({"a":1});
|
||||
flows.getFlows().flows.should.eql(originalConfig);
|
||||
done();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user