diff --git a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js index ce2dab9ef..2833341c6 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js @@ -161,7 +161,8 @@ class Flow { for (let i = 0; i < configNodes.length; i++) { const node = this.flow.configs[configNodes[i]] if (node.type === 'global-config' && node.env) { - const nodeEnv = await flowUtil.evaluateEnvProperties(this, node.env, credentials.get(node.id)) + const globalCreds = credentials.get(node.id)?.map || {} + const nodeEnv = await flowUtil.evaluateEnvProperties(this, node.env, globalCreds) this._env = { ...this._env, ...nodeEnv } } } diff --git a/test/unit/@node-red/runtime/lib/flows/Flow_spec.js b/test/unit/@node-red/runtime/lib/flows/Flow_spec.js index 167691074..61cee1f99 100644 --- a/test/unit/@node-red/runtime/lib/flows/Flow_spec.js +++ b/test/unit/@node-red/runtime/lib/flows/Flow_spec.js @@ -26,6 +26,7 @@ var flowUtils = NR_TEST_UTILS.require("@node-red/runtime/lib/flows/util"); var Flow = NR_TEST_UTILS.require("@node-red/runtime/lib/flows/Flow"); var flows = NR_TEST_UTILS.require("@node-red/runtime/lib/flows"); var Node = NR_TEST_UTILS.require("@node-red/runtime/lib/nodes/Node"); +var credentials = NR_TEST_UTILS.require("@node-red/runtime/lib/nodes/credentials"); var hooks = NR_TEST_UTILS.require("@node-red/util/lib/hooks"); var typeRegistry = NR_TEST_UTILS.require("@node-red/registry"); @@ -61,6 +62,7 @@ describe('Flow', function() { this.scope = n.scope; var node = this; this.foo = n.foo; + this.bar = n.bar; this.handled = 0; this.stopped = false; currentNodes[node.id] = node; @@ -1372,13 +1374,24 @@ describe('Flow', function() { it("global flow can access global-config defined environment variables", async function () { after(function() { delete process.env.V0; + credentials.get.restore() }) + + sinon.stub(credentials,"get").callsFake(function(id) { + if (id === 'gc') { + return { map: { GC_CRED: 'gc_cred' }} + } + return null + }) + const config = flowUtils.parseConfig([ {id:"gc", type:"global-config", env:[ - {"name": "GC0", value: "3+4", type: "jsonata"} + {"name": "GC0", value: "3+4", type: "jsonata"}, + {"name": "GC_CRED", type: "cred"}, + ]}, {id:"t1",type:"tab" }, - {id:"1",x:10,y:10,z:"t1",type:"test",foo:"${GC0}",wires:[]}, + {id:"1",x:10,y:10,z:"t1",type:"test",foo:"${GC0}", bar:"${GC_CRED}", wires:[]}, ]); // Two-arg call - makes this the global flow that handles global-config nodes const globalFlow = Flow.create({getSetting:v=>process.env[v]},config); @@ -1390,6 +1403,7 @@ describe('Flow', function() { var activeNodes = flow.getActiveNodes(); activeNodes["1"].foo.should.equal(7); + activeNodes["1"].bar.should.equal('gc_cred'); await flow.stop() await globalFlow.stop()