From f987fa13ea5581d5c6c6320836829632190dd800 Mon Sep 17 00:00:00 2001 From: Andrey Bezugliy Date: Mon, 10 Apr 2017 17:41:20 +0300 Subject: [PATCH 1/5] Resolve dir argument of getLocalNodeFiles function (#1216) * Resolve dir argument of getLocalNodeFiles function The getLocalNodeFiles is called 3 times. Each time it called, the callee needs to resolve the dir argument. That was not done for several of calls, and local modules (specified in the "nodesDir" setting) were not returned to client because of that. This fix will allow to make sure the dir is consistently resolved. * Several changes in "localfilesystem_spec.js": - Changed checkNodes to verify that every node's file property is resolved, i.e. containst absolute path, not relative. - Added a unit-test "Finds nodes in settings.nodesDir (string,relative path)" --- red/runtime/nodes/registry/localfilesystem.js | 4 +++- .../runtime/nodes/registry/localfilesystem_spec.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/red/runtime/nodes/registry/localfilesystem.js b/red/runtime/nodes/registry/localfilesystem.js index 8e76fc79e..acb054749 100644 --- a/red/runtime/nodes/registry/localfilesystem.js +++ b/red/runtime/nodes/registry/localfilesystem.js @@ -67,6 +67,8 @@ function getLocalFile(file) { * @return an array of fully-qualified paths to .js files */ function getLocalNodeFiles(dir) { + dir = path.resolve(dir); + var result = []; var files = []; try { @@ -205,7 +207,7 @@ function getNodeFiles(disableNodePathScan) { if (settings.coreNodesDir) { nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir)); - var defaultLocalesPath = path.resolve(path.join(settings.coreNodesDir,"core","locales")); + var defaultLocalesPath = path.join(settings.coreNodesDir,"core","locales"); i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json"); } diff --git a/test/red/runtime/nodes/registry/localfilesystem_spec.js b/test/red/runtime/nodes/registry/localfilesystem_spec.js index 6bfdbde9a..bffdf291e 100644 --- a/test/red/runtime/nodes/registry/localfilesystem_spec.js +++ b/test/red/runtime/nodes/registry/localfilesystem_spec.js @@ -36,6 +36,7 @@ describe("red/nodes/registry/localfilesystem",function() { for (var i=0;i Date: Mon, 10 Apr 2017 16:11:01 +0100 Subject: [PATCH 2/5] Toggling debug node enabled/disabled state should set state dirty Fixes #1203 --- nodes/core/core/58-debug.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nodes/core/core/58-debug.html b/nodes/core/core/58-debug.html index c421c0604..5eab64fad 100644 --- a/nodes/core/core/58-debug.html +++ b/nodes/core/core/58-debug.html @@ -83,6 +83,19 @@ url: "debug/"+this.id+"/"+(this.active?"enable":"disable"), type: "POST", success: function(resp, textStatus, xhr) { + var historyEvent = { + t:'edit', + node:node, + changes:{ + active: !node.active + }, + dirty:node.dirty, + changed:node.changed + }; + node.changed = true; + RED.nodes.dirty(true); + RED.history.push(historyEvent); + if (xhr.status == 200) { RED.notify(node._("debug.notification.activated",{label:label}),"success"); } else if (xhr.status == 201) { From 08d21ccba79cf87fd015a9214d7816b9edd2ddd2 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 10 Apr 2017 21:45:04 +0100 Subject: [PATCH 3/5] Clone credentials when passing to node Fixes #1198 --- red/runtime/nodes/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/red/runtime/nodes/index.js b/red/runtime/nodes/index.js index 2be0b467c..40b467501 100644 --- a/red/runtime/nodes/index.js +++ b/red/runtime/nodes/index.js @@ -17,6 +17,7 @@ var when = require("when"); var path = require("path"); var fs = require("fs"); +var clone = require("clone"); var registry = require("./registry"); var credentials = require("./credentials"); @@ -69,6 +70,7 @@ function createNode(node,def) { } var creds = credentials.get(id); if (creds) { + creds = clone(creds); //console.log("Attaching credentials to ",node.id); // allow $(foo) syntax to substitute env variables for credentials also... for (var p in creds) { From 301ac279ff1b18f88dd0cc0e8b2ed1d2f7753b56 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 10 Apr 2017 21:59:59 +0100 Subject: [PATCH 4/5] Handle IncomingMessage/ServerResponse object types in debug Fixes #1202 --- nodes/core/core/58-debug.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nodes/core/core/58-debug.js b/nodes/core/core/58-debug.js index 4e8588322..514ce09e0 100644 --- a/nodes/core/core/58-debug.js +++ b/nodes/core/core/58-debug.js @@ -100,6 +100,10 @@ module.exports = function(RED) { var seenAts = []; try { msg.format = msg.msg.constructor.name || "Object"; + // Handle special case of msg.req/res objects from HTTP In node + if (msg.format === "IncomingMessage" || msg.format === "ServerResponse") { + msg.format = "Object"; + } } catch(err) { msg.format = "Object"; } @@ -116,7 +120,7 @@ module.exports = function(RED) { msg.msg = msg.msg.slice(0,debuglength); } } - if (isArray || (msg.format === "Object")) { + if (isArray || msg.format === "Object") { msg.msg = safeJSONStringify(msg.msg, function(key, value) { if (key === '_req' || key === '_res') { return "[internal]" From 36e1b2ba085d423517d36932d87b9309b115ddf2 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 11 Apr 2017 14:48:19 +0100 Subject: [PATCH 5/5] Don't process subscription for unauthenticated comms link Fixes #851 --- red/api/comms.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/red/api/comms.js b/red/api/comms.js index cb785e239..6f5618ecf 100644 --- a/red/api/comms.js +++ b/red/api/comms.js @@ -132,14 +132,14 @@ function start() { if (anonymousUser) { log.audit({event: "comms.auth",user:anonymousUser}); completeConnection(anonymousUser.permissions,false); + //TODO: duplicated code - pull non-auth message handling out + if (msg.subscribe) { + handleRemoteSubscription(ws,msg.subscribe); + } } else { log.audit({event: "comms.auth.fail"}); completeConnection(null,false); } - //TODO: duplicated code - pull non-auth message handling out - if (msg.subscribe) { - handleRemoteSubscription(ws,msg.subscribe); - } } } });