mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fully remove when.js dependency
This commit is contained in:
parent
beccdac717
commit
5992ed1fab
@ -74,7 +74,6 @@
|
|||||||
"semver": "6.3.0",
|
"semver": "6.3.0",
|
||||||
"tar": "6.0.5",
|
"tar": "6.0.5",
|
||||||
"uglify-js": "3.11.6",
|
"uglify-js": "3.11.6",
|
||||||
"when": "3.7.8",
|
|
||||||
"ws": "6.2.1",
|
"ws": "6.2.1",
|
||||||
"xml2js": "0.4.23"
|
"xml2js": "0.4.23"
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
var apiUtils = require("../util");
|
var apiUtils = require("../util");
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var fspath = require('path');
|
var fspath = require('path');
|
||||||
var when = require('when');
|
|
||||||
|
|
||||||
var runtimeAPI;
|
var runtimeAPI;
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ var express = require("express");
|
|||||||
var bodyParser = require("body-parser");
|
var bodyParser = require("body-parser");
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var passport = require('passport');
|
var passport = require('passport');
|
||||||
var when = require('when');
|
|
||||||
var cors = require('cors');
|
var cors = require('cors');
|
||||||
|
|
||||||
var auth = require("./auth");
|
var auth = require("./auth");
|
||||||
@ -111,11 +110,9 @@ function init(settings,_server,storage,runtimeAPI) {
|
|||||||
* @return {Promise} resolves when the application is ready to handle requests
|
* @return {Promise} resolves when the application is ready to handle requests
|
||||||
* @memberof @node-red/editor-api
|
* @memberof @node-red/editor-api
|
||||||
*/
|
*/
|
||||||
function start() {
|
async function start() {
|
||||||
if (editor) {
|
if (editor) {
|
||||||
return editor.start();
|
return editor.start();
|
||||||
} else {
|
|
||||||
return when.resolve();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,11 +121,10 @@ function start() {
|
|||||||
* @return {Promise} resolves when the application is stopped
|
* @return {Promise} resolves when the application is stopped
|
||||||
* @memberof @node-red/editor-api
|
* @memberof @node-red/editor-api
|
||||||
*/
|
*/
|
||||||
function stop() {
|
async function stop() {
|
||||||
if (editor) {
|
if (editor) {
|
||||||
editor.stop();
|
editor.stop();
|
||||||
}
|
}
|
||||||
return when.resolve();
|
|
||||||
}
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: init,
|
init: init,
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
"passport-http-bearer": "1.0.1",
|
"passport-http-bearer": "1.0.1",
|
||||||
"passport-oauth2-client-password": "0.1.2",
|
"passport-oauth2-client-password": "0.1.2",
|
||||||
"passport": "0.4.1",
|
"passport": "0.4.1",
|
||||||
"when": "3.7.8",
|
|
||||||
"ws": "6.2.1"
|
"ws": "6.2.1"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var fs = require("fs-extra");
|
var fs = require("fs-extra");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var semver = require("semver");
|
var semver = require("semver");
|
||||||
@ -92,7 +91,7 @@ function loadNodeFiles(nodeFiles) {
|
|||||||
nodeFiles[m].nodes[n] = nodeSet;
|
nodeFiles[m].nodes[n] = nodeSet;
|
||||||
nodes.push(nodeSet);
|
nodes.push(nodeSet);
|
||||||
}
|
}
|
||||||
})()));
|
})()).catch(err => {}));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@ -101,7 +100,7 @@ function loadNodeFiles(nodeFiles) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return when.settle(promises).then(function(results) {
|
return Promise.all(promises).then(function(results) {
|
||||||
for (var module in nodeFiles) {
|
for (var module in nodeFiles) {
|
||||||
if (nodeFiles.hasOwnProperty(module)) {
|
if (nodeFiles.hasOwnProperty(module)) {
|
||||||
if (!nodeFiles[module].err) {
|
if (!nodeFiles[module].err) {
|
||||||
@ -293,13 +292,13 @@ function loadNodeSetList(nodes) {
|
|||||||
var promises = [];
|
var promises = [];
|
||||||
nodes.forEach(function(node) {
|
nodes.forEach(function(node) {
|
||||||
if (!node.err) {
|
if (!node.err) {
|
||||||
promises.push(loadNodeSet(node));
|
promises.push(loadNodeSet(node).catch(err => {}));
|
||||||
} else {
|
} else {
|
||||||
promises.push(node);
|
promises.push(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return when.settle(promises).then(function() {
|
return Promise.all(promises).then(function() {
|
||||||
if (settings.available()) {
|
if (settings.available()) {
|
||||||
return registry.saveNodeList();
|
return registry.saveNodeList();
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
var events;
|
|
||||||
var log;
|
var log;
|
||||||
|
|
||||||
var log = require("@node-red/util").log;
|
var log = require("@node-red/util").log;
|
||||||
@ -29,7 +28,6 @@ var iconFileExtensions = [".png", ".gif", ".svg"];
|
|||||||
|
|
||||||
function init(runtime) {
|
function init(runtime) {
|
||||||
settings = runtime.settings;
|
settings = runtime.settings;
|
||||||
events = runtime.events;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isIncluded(name) {
|
function isIncluded(name) {
|
||||||
@ -75,7 +73,6 @@ function getLocalFile(file) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronously walks the directory looking for node files.
|
* Synchronously walks the directory looking for node files.
|
||||||
* Emits 'node-icon-dir' events for an icon dirs found
|
|
||||||
* @param dir the directory to search
|
* @param dir the directory to search
|
||||||
* @return an array of fully-qualified paths to .js files
|
* @return an array of fully-qualified paths to .js files
|
||||||
*/
|
*/
|
||||||
@ -229,7 +226,6 @@ function getModuleNodeFiles(module) {
|
|||||||
try {
|
try {
|
||||||
fs.statSync(examplesDir)
|
fs.statSync(examplesDir)
|
||||||
result.examples = {path:examplesDir};
|
result.examples = {path:examplesDir};
|
||||||
// events.emit("node-examples-dir",{name:pkg.name,path:examplesDir});
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
"@node-red/util": "1.3.0-beta.1",
|
"@node-red/util": "1.3.0-beta.1",
|
||||||
"semver": "6.3.0",
|
"semver": "6.3.0",
|
||||||
"tar": "6.0.5",
|
"tar": "6.0.5",
|
||||||
"uglify-js": "3.11.6",
|
"uglify-js": "3.11.6"
|
||||||
"when": "3.7.8"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require('when');
|
|
||||||
|
|
||||||
var externalAPI = require("./api");
|
var externalAPI = require("./api");
|
||||||
|
|
||||||
var redNodes = require("./nodes");
|
var redNodes = require("./nodes");
|
||||||
@ -197,25 +195,24 @@ function start() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var reinstallAttempts;
|
var reinstallAttempts = 0;
|
||||||
var reinstallTimeout;
|
var reinstallTimeout;
|
||||||
function reinstallModules(moduleList) {
|
function reinstallModules(moduleList) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
var failedModules = [];
|
|
||||||
for (var i=0;i<moduleList.length;i++) {
|
|
||||||
if (settings.autoInstallModules && i != "node-red") {
|
|
||||||
promises.push(redNodes.installModule(moduleList[i].id,moduleList[i].version));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
when.settle(promises).then(function(results) {
|
|
||||||
var reinstallList = [];
|
var reinstallList = [];
|
||||||
for (var i=0;i<results.length;i++) {
|
|
||||||
if (results[i].state === 'rejected') {
|
for (var i=0;i<moduleList.length;i++) {
|
||||||
reinstallList.push(moduleList[i]);
|
if (settings.autoInstallModules && moduleList[i].id != "node-red") {
|
||||||
} else {
|
(function(mod) {
|
||||||
events.emit("runtime-event",{id:"node/added",retain:false,payload:results[i].value.nodes});
|
promises.push(redNodes.installModule(mod.id,mod.version).then(m => {
|
||||||
|
events.emit("runtime-event",{id:"node/added",retain:false,payload:m.nodes});
|
||||||
|
}).catch(err => {
|
||||||
|
reinstallList.push(mod);
|
||||||
|
}));
|
||||||
|
})(moduleList[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Promise.all(promises).then(function(results) {
|
||||||
if (reinstallList.length > 0) {
|
if (reinstallList.length > 0) {
|
||||||
reinstallAttempts++;
|
reinstallAttempts++;
|
||||||
// First 5 at 1x timeout, next 5 at 2x, next 5 at 4x, then 8x
|
// First 5 at 1x timeout, next 5 at 2x, next 5 at 4x, then 8x
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var runtime;
|
var runtime;
|
||||||
var settings;
|
var settings;
|
||||||
@ -60,7 +59,7 @@ var api = module.exports = {
|
|||||||
/**
|
/**
|
||||||
* Sets the credentials from storage.
|
* Sets the credentials from storage.
|
||||||
*/
|
*/
|
||||||
load: function (credentials) {
|
load: async function (credentials) {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
var credentialsEncrypted = credentials.hasOwnProperty("$") && Object.keys(credentials).length === 1;
|
var credentialsEncrypted = credentials.hasOwnProperty("$") && Object.keys(credentials).length === 1;
|
||||||
|
|
||||||
@ -77,7 +76,7 @@ var api = module.exports = {
|
|||||||
// Case 4: credentialSecret set
|
// Case 4: credentialSecret set
|
||||||
// - use it
|
// - use it
|
||||||
|
|
||||||
var setupEncryptionPromise = when.resolve();
|
var setupEncryptionPromise = Promise.resolve();
|
||||||
|
|
||||||
var projectKey = false;
|
var projectKey = false;
|
||||||
var activeProject;
|
var activeProject;
|
||||||
@ -134,7 +133,7 @@ var api = module.exports = {
|
|||||||
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
||||||
var error = new Error("Failed to decrypt credentials");
|
var error = new Error("Failed to decrypt credentials");
|
||||||
error.code = "credentials_load_failed";
|
error.code = "credentials_load_failed";
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
@ -163,7 +162,7 @@ var api = module.exports = {
|
|||||||
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
||||||
var error = new Error("Failed to decrypt credentials");
|
var error = new Error("Failed to decrypt credentials");
|
||||||
error.code = "credentials_load_failed";
|
error.code = "credentials_load_failed";
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
@ -217,9 +216,9 @@ var api = module.exports = {
|
|||||||
// This is a project with a bad key. Mark it as invalid
|
// This is a project with a bad key. Mark it as invalid
|
||||||
// TODO: this delves too deep into Project structure
|
// TODO: this delves too deep into Project structure
|
||||||
activeProject.credentialSecretInvalid = true;
|
activeProject.credentialSecretInvalid = true;
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
// These are encrypted credentials
|
// These are encrypted credentials
|
||||||
try {
|
try {
|
||||||
@ -235,9 +234,9 @@ var api = module.exports = {
|
|||||||
// This is a project with a bad key. Mark it as invalid
|
// This is a project with a bad key. Mark it as invalid
|
||||||
// TODO: this delves too deep into Project structure
|
// TODO: this delves too deep into Project structure
|
||||||
activeProject.credentialSecretInvalid = true;
|
activeProject.credentialSecretInvalid = true;
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
credentialCache = credentials;
|
credentialCache = credentials;
|
||||||
@ -257,12 +256,11 @@ var api = module.exports = {
|
|||||||
* @param creds an object of credential key/value pairs
|
* @param creds an object of credential key/value pairs
|
||||||
* @return a promise for backwards compatibility TODO: can this be removed?
|
* @return a promise for backwards compatibility TODO: can this be removed?
|
||||||
*/
|
*/
|
||||||
add: function (id, creds) {
|
add: async function (id, creds) {
|
||||||
if (!credentialCache.hasOwnProperty(id) || JSON.stringify(creds) !== JSON.stringify(credentialCache[id])) {
|
if (!credentialCache.hasOwnProperty(id) || JSON.stringify(creds) !== JSON.stringify(credentialCache[id])) {
|
||||||
credentialCache[id] = creds;
|
credentialCache[id] = creds;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
return when.resolve();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -293,7 +291,7 @@ var api = module.exports = {
|
|||||||
* @param config a flow config
|
* @param config a flow config
|
||||||
* @return a promise for the saving of credentials to storage
|
* @return a promise for the saving of credentials to storage
|
||||||
*/
|
*/
|
||||||
clean: function (config) {
|
clean: async function (config) {
|
||||||
var existingIds = {};
|
var existingIds = {};
|
||||||
config.forEach(function(n) {
|
config.forEach(function(n) {
|
||||||
existingIds[n.id] = true;
|
existingIds[n.id] = true;
|
||||||
@ -313,7 +311,6 @@ var api = module.exports = {
|
|||||||
if (deletedCredentials) {
|
if (deletedCredentials) {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
return when.resolve();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -432,7 +429,7 @@ var api = module.exports = {
|
|||||||
getKeyType: function() {
|
getKeyType: function() {
|
||||||
return encryptionKeyType;
|
return encryptionKeyType;
|
||||||
},
|
},
|
||||||
export: function() {
|
export: async function() {
|
||||||
var result = credentialCache;
|
var result = credentialCache;
|
||||||
|
|
||||||
if (encryptionEnabled) {
|
if (encryptionEnabled) {
|
||||||
@ -455,7 +452,7 @@ var api = module.exports = {
|
|||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return when.resolve(result);
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var clone = require("clone");
|
var clone = require("clone");
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var clone = require("clone");
|
var clone = require("clone");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var log = require("@node-red/util").log; // TODO: separate module
|
var log = require("@node-red/util").log; // TODO: separate module
|
||||||
@ -90,10 +89,10 @@ var persistentSettings = {
|
|||||||
globalSettings[prop] = clone(value);
|
globalSettings[prop] = clone(value);
|
||||||
try {
|
try {
|
||||||
assert.deepEqual(current,value);
|
assert.deepEqual(current,value);
|
||||||
return when.resolve();
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return storage.saveSettings(clone(globalSettings));
|
return storage.saveSettings(clone(globalSettings));
|
||||||
}
|
}
|
||||||
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
delete: function(prop) {
|
delete: function(prop) {
|
||||||
if (localSettings.hasOwnProperty(prop)) {
|
if (localSettings.hasOwnProperty(prop)) {
|
||||||
@ -106,7 +105,7 @@ var persistentSettings = {
|
|||||||
delete globalSettings[prop];
|
delete globalSettings[prop];
|
||||||
return storage.saveSettings(clone(globalSettings));
|
return storage.saveSettings(clone(globalSettings));
|
||||||
}
|
}
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|
||||||
available: function() {
|
available: function() {
|
||||||
@ -180,7 +179,6 @@ var persistentSettings = {
|
|||||||
userSettings[username] = settings;
|
userSettings[username] = settings;
|
||||||
try {
|
try {
|
||||||
assert.deepEqual(current,settings);
|
assert.deepEqual(current,settings);
|
||||||
return when.resolve();
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
globalSettings.users = userSettings;
|
globalSettings.users = userSettings;
|
||||||
return storage.saveSettings(clone(globalSettings));
|
return storage.saveSettings(clone(globalSettings));
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require('when');
|
|
||||||
var Path = require('path');
|
var Path = require('path');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
|
||||||
@ -50,15 +49,13 @@ function is_malicious(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var storageModuleInterface = {
|
var storageModuleInterface = {
|
||||||
init: function(_runtime) {
|
init: async function(_runtime) {
|
||||||
runtime = _runtime;
|
runtime = _runtime;
|
||||||
try {
|
// Any errors thrown by the module will get passed up to the called
|
||||||
|
// as a rejected promise
|
||||||
storageModule = moduleSelector(runtime.settings);
|
storageModule = moduleSelector(runtime.settings);
|
||||||
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
|
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
|
||||||
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
|
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
|
||||||
} catch (e) {
|
|
||||||
return when.reject(e);
|
|
||||||
}
|
|
||||||
if (!!storageModule.projects) {
|
if (!!storageModule.projects) {
|
||||||
var projectsEnabled = false;
|
var projectsEnabled = false;
|
||||||
if (runtime.settings.hasOwnProperty("editorTheme") && runtime.settings.editorTheme.hasOwnProperty("projects")) {
|
if (runtime.settings.hasOwnProperty("editorTheme") && runtime.settings.editorTheme.hasOwnProperty("projects")) {
|
||||||
@ -73,7 +70,7 @@ var storageModuleInterface = {
|
|||||||
}
|
}
|
||||||
return storageModule.init(runtime.settings,runtime);
|
return storageModule.init(runtime.settings,runtime);
|
||||||
},
|
},
|
||||||
getFlows: function() {
|
getFlows: async function() {
|
||||||
return storageModule.getFlows().then(function(flows) {
|
return storageModule.getFlows().then(function(flows) {
|
||||||
return storageModule.getCredentials().then(function(creds) {
|
return storageModule.getCredentials().then(function(creds) {
|
||||||
var result = {
|
var result = {
|
||||||
@ -85,14 +82,14 @@ var storageModuleInterface = {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
saveFlows: function(config, user) {
|
saveFlows: async function(config, user) {
|
||||||
var flows = config.flows;
|
var flows = config.flows;
|
||||||
var credentials = config.credentials;
|
var credentials = config.credentials;
|
||||||
var credentialSavePromise;
|
var credentialSavePromise;
|
||||||
if (config.credentialsDirty) {
|
if (config.credentialsDirty) {
|
||||||
credentialSavePromise = storageModule.saveCredentials(credentials);
|
credentialSavePromise = storageModule.saveCredentials(credentials);
|
||||||
} else {
|
} else {
|
||||||
credentialSavePromise = when.resolve();
|
credentialSavePromise = Promise.resolve();
|
||||||
}
|
}
|
||||||
delete config.credentialsDirty;
|
delete config.credentialsDirty;
|
||||||
|
|
||||||
@ -105,64 +102,60 @@ var storageModuleInterface = {
|
|||||||
// getCredentials: function() {
|
// getCredentials: function() {
|
||||||
// return storageModule.getCredentials();
|
// return storageModule.getCredentials();
|
||||||
// },
|
// },
|
||||||
saveCredentials: function(credentials) {
|
saveCredentials: async function(credentials) {
|
||||||
return storageModule.saveCredentials(credentials);
|
return storageModule.saveCredentials(credentials);
|
||||||
},
|
},
|
||||||
getSettings: function() {
|
getSettings: async function() {
|
||||||
if (settingsAvailable) {
|
if (settingsAvailable) {
|
||||||
return storageModule.getSettings();
|
return storageModule.getSettings();
|
||||||
} else {
|
} else {
|
||||||
return when.resolve(null);
|
return null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveSettings: function(settings) {
|
saveSettings: async function(settings) {
|
||||||
if (settingsAvailable) {
|
if (settingsAvailable) {
|
||||||
return settingsSaveMutex.runExclusive(() => storageModule.saveSettings(settings))
|
return settingsSaveMutex.runExclusive(() => storageModule.saveSettings(settings))
|
||||||
} else {
|
|
||||||
return when.resolve();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSessions: function() {
|
getSessions: async function() {
|
||||||
if (sessionsAvailable) {
|
if (sessionsAvailable) {
|
||||||
return storageModule.getSessions();
|
return storageModule.getSessions();
|
||||||
} else {
|
} else {
|
||||||
return when.resolve(null);
|
return null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveSessions: function(sessions) {
|
saveSessions: async function(sessions) {
|
||||||
if (sessionsAvailable) {
|
if (sessionsAvailable) {
|
||||||
return storageModule.saveSessions(sessions);
|
return storageModule.saveSessions(sessions);
|
||||||
} else {
|
|
||||||
return when.resolve();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Library Functions */
|
/* Library Functions */
|
||||||
|
|
||||||
getLibraryEntry: function(type, path) {
|
getLibraryEntry: async function(type, path) {
|
||||||
if (is_malicious(path)) {
|
if (is_malicious(path)) {
|
||||||
var err = new Error();
|
var err = new Error();
|
||||||
err.code = "forbidden";
|
err.code = "forbidden";
|
||||||
return when.reject(err);
|
throw err;
|
||||||
}
|
}
|
||||||
return storageModule.getLibraryEntry(type, path);
|
return storageModule.getLibraryEntry(type, path);
|
||||||
},
|
},
|
||||||
saveLibraryEntry: function(type, path, meta, body) {
|
saveLibraryEntry: async function(type, path, meta, body) {
|
||||||
if (is_malicious(path)) {
|
if (is_malicious(path)) {
|
||||||
var err = new Error();
|
var err = new Error();
|
||||||
err.code = "forbidden";
|
err.code = "forbidden";
|
||||||
return when.reject(err);
|
throw err;
|
||||||
}
|
}
|
||||||
return storageModule.saveLibraryEntry(type, path, meta, body);
|
return storageModule.saveLibraryEntry(type, path, meta, body);
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Deprecated functions */
|
/* Deprecated functions */
|
||||||
getAllFlows: function() {
|
getAllFlows: async function() {
|
||||||
if (storageModule.hasOwnProperty("getAllFlows")) {
|
if (storageModule.hasOwnProperty("getAllFlows")) {
|
||||||
return storageModule.getAllFlows();
|
return storageModule.getAllFlows();
|
||||||
} else {
|
} else {
|
||||||
if (libraryFlowsCachedResult) {
|
if (libraryFlowsCachedResult) {
|
||||||
return Promise.resolve(libraryFlowsCachedResult);
|
return libraryFlowsCachedResult;
|
||||||
} else {
|
} else {
|
||||||
return listFlows("/").then(function(result) {
|
return listFlows("/").then(function(result) {
|
||||||
libraryFlowsCachedResult = result;
|
libraryFlowsCachedResult = result;
|
||||||
@ -175,7 +168,7 @@ var storageModuleInterface = {
|
|||||||
if (is_malicious(fn)) {
|
if (is_malicious(fn)) {
|
||||||
var err = new Error();
|
var err = new Error();
|
||||||
err.code = "forbidden";
|
err.code = "forbidden";
|
||||||
return when.reject(err);
|
throw err;
|
||||||
}
|
}
|
||||||
if (storageModule.hasOwnProperty("getFlow")) {
|
if (storageModule.hasOwnProperty("getFlow")) {
|
||||||
return storageModule.getFlow(fn);
|
return storageModule.getFlow(fn);
|
||||||
@ -188,7 +181,7 @@ var storageModuleInterface = {
|
|||||||
if (is_malicious(fn)) {
|
if (is_malicious(fn)) {
|
||||||
var err = new Error();
|
var err = new Error();
|
||||||
err.code = "forbidden";
|
err.code = "forbidden";
|
||||||
return when.reject(err);
|
throw err;
|
||||||
}
|
}
|
||||||
libraryFlowsCachedResult = null;
|
libraryFlowsCachedResult = null;
|
||||||
if (storageModule.hasOwnProperty("saveFlow")) {
|
if (storageModule.hasOwnProperty("saveFlow")) {
|
||||||
@ -204,40 +197,36 @@ var storageModuleInterface = {
|
|||||||
|
|
||||||
function listFlows(path) {
|
function listFlows(path) {
|
||||||
return storageModule.getLibraryEntry("flows",path).then(function(res) {
|
return storageModule.getLibraryEntry("flows",path).then(function(res) {
|
||||||
return when.promise(function(resolve) {
|
const promises = [];
|
||||||
var promises = [];
|
|
||||||
res.forEach(function(r) {
|
res.forEach(function(r) {
|
||||||
if (typeof r === "string") {
|
if (typeof r === "string") {
|
||||||
promises.push(listFlows(Path.join(path,r)));
|
promises.push(listFlows(Path.join(path,r)));
|
||||||
} else {
|
} else {
|
||||||
promises.push(when.resolve(r));
|
promises.push(Promise.resolve(r));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var i=0;
|
return Promise.all(promises).then(res2 => {
|
||||||
when.settle(promises).then(function(res2) {
|
let i = 0;
|
||||||
var result = {};
|
const result = {};
|
||||||
res2.forEach(function(r) {
|
res2.forEach(function(r) {
|
||||||
// TODO: name||fn
|
// TODO: name||fn
|
||||||
if (r.value.fn) {
|
if (r.fn) {
|
||||||
var name = r.value.name;
|
var name = r.name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
name = r.value.fn.replace(/\.json$/, "");
|
name = r.fn.replace(/\.json$/, "");
|
||||||
}
|
}
|
||||||
result.f = result.f || [];
|
result.f = result.f || [];
|
||||||
result.f.push(name);
|
result.f.push(name);
|
||||||
} else {
|
} else {
|
||||||
result.d = result.d || {};
|
result.d = result.d || {};
|
||||||
result.d[res[i]] = r.value;
|
result.d[res[i]] = r;
|
||||||
//console.log(">",r.value);
|
//console.log(">",r.value);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
resolve(result);
|
return result;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = storageModuleInterface;
|
module.exports = storageModuleInterface;
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var when = require('when');
|
|
||||||
var fspath = require("path");
|
var fspath = require("path");
|
||||||
var nodeFn = require('when/node/function');
|
|
||||||
|
|
||||||
var util = require("./util");
|
var util = require("./util");
|
||||||
|
|
||||||
@ -90,14 +88,14 @@ function getLibraryEntry(type,path) {
|
|||||||
var rootPath = fspath.join(libDir,type,path);
|
var rootPath = fspath.join(libDir,type,path);
|
||||||
|
|
||||||
// don't create the folder if it does not exist - we are only reading....
|
// don't create the folder if it does not exist - we are only reading....
|
||||||
return nodeFn.call(fs.lstat, rootPath).then(function(stats) {
|
return fs.lstat(rootPath).then(function(stats) {
|
||||||
if (stats.isFile()) {
|
if (stats.isFile()) {
|
||||||
return getFileBody(root,path);
|
return getFileBody(root,path);
|
||||||
}
|
}
|
||||||
if (path.substr(-1) == '/') {
|
if (path.substr(-1) == '/') {
|
||||||
path = path.substr(0,path.length-1);
|
path = path.substr(0,path.length-1);
|
||||||
}
|
}
|
||||||
return nodeFn.call(fs.readdir, rootPath).then(function(fns) {
|
return fs.readdir(rootPath).then(function(fns) {
|
||||||
var dirs = [];
|
var dirs = [];
|
||||||
var files = [];
|
var files = [];
|
||||||
fns.sort().filter(function(fn) {
|
fns.sort().filter(function(fn) {
|
||||||
@ -143,21 +141,19 @@ function getLibraryEntry(type,path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: function(_settings) {
|
init: async function(_settings) {
|
||||||
settings = _settings;
|
settings = _settings;
|
||||||
libDir = fspath.join(settings.userDir,"lib");
|
libDir = fspath.join(settings.userDir,"lib");
|
||||||
libFlowsDir = fspath.join(libDir,"flows");
|
libFlowsDir = fspath.join(libDir,"flows");
|
||||||
if (!settings.readOnly) {
|
if (!settings.readOnly) {
|
||||||
return fs.ensureDir(libFlowsDir);
|
return fs.ensureDir(libFlowsDir);
|
||||||
} else {
|
|
||||||
return when.resolve();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getLibraryEntry: getLibraryEntry,
|
getLibraryEntry: getLibraryEntry,
|
||||||
|
|
||||||
saveLibraryEntry: function(type,path,meta,body) {
|
saveLibraryEntry: async function(type,path,meta,body) {
|
||||||
if (settings.readOnly) {
|
if (settings.readOnly) {
|
||||||
return when.resolve();
|
return;
|
||||||
}
|
}
|
||||||
if (type === "flows" && !path.endsWith(".json")) {
|
if (type === "flows" && !path.endsWith(".json")) {
|
||||||
path += ".json";
|
path += ".json";
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
|
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var when = require('when');
|
|
||||||
var fspath = require("path");
|
var fspath = require("path");
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
|
|
||||||
@ -108,12 +107,12 @@ Project.prototype.load = function () {
|
|||||||
// package.json isn't valid JSON... is a merge underway?
|
// package.json isn't valid JSON... is a merge underway?
|
||||||
project.package = {};
|
project.package = {};
|
||||||
}
|
}
|
||||||
}));
|
}).catch(err => {})); //
|
||||||
if (missingFiles.indexOf('README.md') === -1) {
|
if (missingFiles.indexOf('README.md') === -1) {
|
||||||
project.paths['README.md'] = fspath.join(project.paths.root,"README.md");
|
project.paths['README.md'] = fspath.join(project.paths.root,"README.md");
|
||||||
promises.push(fs.readFile(fspath.join(project.path,project.paths['README.md']),"utf8").then(function(content) {
|
promises.push(fs.readFile(fspath.join(project.path,project.paths['README.md']),"utf8").then(function(content) {
|
||||||
project.description = content;
|
project.description = content;
|
||||||
}));
|
}).catch(err => {}));
|
||||||
} else {
|
} else {
|
||||||
project.description = "";
|
project.description = "";
|
||||||
}
|
}
|
||||||
@ -133,9 +132,9 @@ Project.prototype.load = function () {
|
|||||||
// project.paths.credentialsFile = fspath.join(project.path,"flow_cred.json");
|
// project.paths.credentialsFile = fspath.join(project.path,"flow_cred.json");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
promises.push(project.loadRemotes());
|
promises.push(project.loadRemotes().catch(err => {}));
|
||||||
|
|
||||||
return when.settle(promises).then(function(results) {
|
return Promise.all(promises).then(function(results) {
|
||||||
return project;
|
return project;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -239,7 +238,7 @@ Project.prototype.isMerging = function() {
|
|||||||
return this.merging;
|
return this.merging;
|
||||||
}
|
}
|
||||||
|
|
||||||
Project.prototype.update = function (user, data) {
|
Project.prototype.update = async function (user, data) {
|
||||||
var username;
|
var username;
|
||||||
if (!user) {
|
if (!user) {
|
||||||
username = "_";
|
username = "_";
|
||||||
@ -279,7 +278,7 @@ Project.prototype.update = function (user, data) {
|
|||||||
this.credentialSecret !== existingSecret) { // key doesn't match provided existing key
|
this.credentialSecret !== existingSecret) { // key doesn't match provided existing key
|
||||||
var e = new Error("Cannot change credentialSecret without current key");
|
var e = new Error("Cannot change credentialSecret without current key");
|
||||||
e.code = "missing_current_credential_key";
|
e.code = "missing_current_credential_key";
|
||||||
return when.reject(e);
|
throw e;
|
||||||
}
|
}
|
||||||
this.credentialSecret = secret;
|
this.credentialSecret = secret;
|
||||||
|
|
||||||
@ -292,7 +291,7 @@ Project.prototype.update = function (user, data) {
|
|||||||
if (this.missingFiles.indexOf('package.json') !== -1) {
|
if (this.missingFiles.indexOf('package.json') !== -1) {
|
||||||
if (!data.files || !data.files.package) {
|
if (!data.files || !data.files.package) {
|
||||||
// Cannot update a project that doesn't have a known package.json
|
// Cannot update a project that doesn't have a known package.json
|
||||||
return Promise.reject("Cannot update project with missing package.json");
|
throw new Error("Cannot update project with missing package.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +301,7 @@ Project.prototype.update = function (user, data) {
|
|||||||
// We have a package file. It could be one that doesn't exist yet,
|
// We have a package file. It could be one that doesn't exist yet,
|
||||||
// or it does exist and we need to load it.
|
// or it does exist and we need to load it.
|
||||||
if (!/package\.json$/.test(data.files.package)) {
|
if (!/package\.json$/.test(data.files.package)) {
|
||||||
return Promise.reject("Invalid package file: "+data.files.package)
|
return new Error("Invalid package file: "+data.files.package)
|
||||||
}
|
}
|
||||||
var root = data.files.package.substring(0,data.files.package.length-12);
|
var root = data.files.package.substring(0,data.files.package.length-12);
|
||||||
this.paths.root = root;
|
this.paths.root = root;
|
||||||
@ -391,20 +390,20 @@ Project.prototype.update = function (user, data) {
|
|||||||
modifyRemotesPromise = modifyRemotesPromise.then(function() {
|
modifyRemotesPromise = modifyRemotesPromise.then(function() {
|
||||||
return project.loadRemotes();
|
return project.loadRemotes();
|
||||||
});
|
});
|
||||||
promises.push(modifyRemotesPromise);
|
promises.push(modifyRemotesPromise.catch(err => {}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (saveSettings) {
|
if (saveSettings) {
|
||||||
promises.push(settings.set("projects",globalProjectSettings));
|
promises.push(settings.set("projects",globalProjectSettings).catch(err => {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
var modifiedFiles = [];
|
var modifiedFiles = [];
|
||||||
|
|
||||||
if (saveREADME) {
|
if (saveREADME) {
|
||||||
promises.push(util.writeFile(fspath.join(this.path,this.paths['README.md']), this.description));
|
promises.push(util.writeFile(fspath.join(this.path,this.paths['README.md']), this.description).catch(err => {}));
|
||||||
modifiedFiles.push('README.md');
|
modifiedFiles.push('README.md');
|
||||||
}
|
}
|
||||||
if (savePackage) {
|
if (savePackage) {
|
||||||
@ -416,10 +415,10 @@ Project.prototype.update = function (user, data) {
|
|||||||
}
|
}
|
||||||
this.package = Object.assign(currentPackage,this.package);
|
this.package = Object.assign(currentPackage,this.package);
|
||||||
return util.writeFile(fspath.join(project.path,this.paths['package.json']), JSON.stringify(this.package,"",4));
|
return util.writeFile(fspath.join(project.path,this.paths['package.json']), JSON.stringify(this.package,"",4));
|
||||||
}));
|
}).catch(err => {}));
|
||||||
modifiedFiles.push('package.json');
|
modifiedFiles.push('package.json');
|
||||||
}
|
}
|
||||||
return when.settle(promises).then(function(res) {
|
return Promise.all(promises).then(function(res) {
|
||||||
var gitSettings = getUserGitSettings(user) || {};
|
var gitSettings = getUserGitSettings(user) || {};
|
||||||
var workflowMode = (gitSettings.workflow||{}).mode || "manual";
|
var workflowMode = (gitSettings.workflow||{}).mode || "manual";
|
||||||
if (workflowMode === 'auto') {
|
if (workflowMode === 'auto') {
|
||||||
@ -944,32 +943,17 @@ function createDefaultProject(user, project) {
|
|||||||
}
|
}
|
||||||
function checkProjectFiles(project) {
|
function checkProjectFiles(project) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
var paths = [];
|
var missing = [];
|
||||||
for (var file in defaultFileSet) {
|
for (var file in defaultFileSet) {
|
||||||
if (defaultFileSet.hasOwnProperty(file)) {
|
if (defaultFileSet.hasOwnProperty(file)) {
|
||||||
paths.push(file);
|
(function(f) {
|
||||||
promises.push(fs.stat(fspath.join(project.path,project.paths.root,file)));
|
promises.push(fs.stat(fspath.join(project.path,project.paths.root,f)).catch(err => {
|
||||||
|
missing.push(f);
|
||||||
|
}));
|
||||||
|
})(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return when.settle(promises).then(function(results) {
|
return Promise.all(promises).then(() => missing);
|
||||||
var missing = [];
|
|
||||||
results.forEach(function(result,i) {
|
|
||||||
if (result.state === 'rejected') {
|
|
||||||
missing.push(paths[i]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return missing;
|
|
||||||
}).then(function(missing) {
|
|
||||||
// if (createMissing) {
|
|
||||||
// var promises = [];
|
|
||||||
// missing.forEach(function(file) {
|
|
||||||
// promises.push(util.writeFile(fspath.join(projectPath,file),defaultFileSet[file](project)));
|
|
||||||
// });
|
|
||||||
// return promises;
|
|
||||||
// } else {
|
|
||||||
return missing;
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
function createProject(user, metadata) {
|
function createProject(user, metadata) {
|
||||||
var username;
|
var username;
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var when = require('when');
|
|
||||||
var fspath = require("path");
|
var fspath = require("path");
|
||||||
var nodeFn = require('when/node/function');
|
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
|
||||||
var storageSettings = require("../settings");
|
var storageSettings = require("../settings");
|
||||||
@ -223,7 +221,6 @@ function loadProject(name) {
|
|||||||
|
|
||||||
function getProject(user, name) {
|
function getProject(user, name) {
|
||||||
checkActiveProject(name);
|
checkActiveProject(name);
|
||||||
//return when.resolve(activeProject.info);
|
|
||||||
return Promise.resolve(activeProject.export());
|
return Promise.resolve(activeProject.export());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +492,7 @@ var flowsFileBackup;
|
|||||||
var credentialsFile;
|
var credentialsFile;
|
||||||
var credentialsFileBackup;
|
var credentialsFileBackup;
|
||||||
|
|
||||||
function getFlows() {
|
async function getFlows() {
|
||||||
if (!initialFlowLoadComplete) {
|
if (!initialFlowLoadComplete) {
|
||||||
initialFlowLoadComplete = true;
|
initialFlowLoadComplete = true;
|
||||||
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
|
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
|
||||||
@ -522,25 +519,25 @@ function getFlows() {
|
|||||||
log.warn("Project repository is empty");
|
log.warn("Project repository is empty");
|
||||||
error = new Error("Project repository is empty");
|
error = new Error("Project repository is empty");
|
||||||
error.code = "project_empty";
|
error.code = "project_empty";
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
if (activeProject.missingFiles && activeProject.missingFiles.indexOf('package.json') !== -1) {
|
if (activeProject.missingFiles && activeProject.missingFiles.indexOf('package.json') !== -1) {
|
||||||
log.warn("Project missing package.json");
|
log.warn("Project missing package.json");
|
||||||
error = new Error("Project missing package.json");
|
error = new Error("Project missing package.json");
|
||||||
error.code = "missing_package_file";
|
error.code = "missing_package_file";
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
if (!activeProject.getFlowFile()) {
|
if (!activeProject.getFlowFile()) {
|
||||||
log.warn("Project has no flow file");
|
log.warn("Project has no flow file");
|
||||||
error = new Error("Project has no flow file");
|
error = new Error("Project has no flow file");
|
||||||
error.code = "missing_flow_file";
|
error.code = "missing_flow_file";
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
if (activeProject.isMerging()) {
|
if (activeProject.isMerging()) {
|
||||||
log.warn("Project has unmerged changes");
|
log.warn("Project has unmerged changes");
|
||||||
error = new Error("Project has unmerged changes. Cannot load flows");
|
error = new Error("Project has unmerged changes. Cannot load flows");
|
||||||
error.code = "git_merge_conflict";
|
error.code = "git_merge_conflict";
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -554,14 +551,14 @@ function getFlows() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveFlows(flows, user) {
|
async function saveFlows(flows, user) {
|
||||||
if (settings.readOnly) {
|
if (settings.readOnly) {
|
||||||
return when.resolve();
|
return
|
||||||
}
|
}
|
||||||
if (activeProject && activeProject.isMerging()) {
|
if (activeProject && activeProject.isMerging()) {
|
||||||
var error = new Error("Project has unmerged changes. Cannot deploy new flows");
|
var error = new Error("Project has unmerged changes. Cannot deploy new flows");
|
||||||
error.code = "git_merge_conflict";
|
error.code = "git_merge_conflict";
|
||||||
return when.reject(error);
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
flowsFileExists = true;
|
flowsFileExists = true;
|
||||||
@ -589,9 +586,9 @@ function getCredentials() {
|
|||||||
return util.readFile(credentialsFile,credentialsFileBackup,{},'credentials');
|
return util.readFile(credentialsFile,credentialsFileBackup,{},'credentials');
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveCredentials(credentials) {
|
async function saveCredentials(credentials) {
|
||||||
if (settings.readOnly) {
|
if (settings.readOnly) {
|
||||||
return when.resolve();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var credentialData;
|
var credentialData;
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var when = require('when');
|
|
||||||
var fspath = require("path");
|
var fspath = require("path");
|
||||||
var keygen = require("./keygen");
|
var keygen = require("./keygen");
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require('when');
|
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var fspath = require("path");
|
var fspath = require("path");
|
||||||
|
|
||||||
@ -30,8 +29,8 @@ module.exports = {
|
|||||||
settings = _settings;
|
settings = _settings;
|
||||||
sessionsFile = fspath.join(settings.userDir,".sessions.json");
|
sessionsFile = fspath.join(settings.userDir,".sessions.json");
|
||||||
},
|
},
|
||||||
getSessions: function() {
|
getSessions: async function() {
|
||||||
return when.promise(function(resolve,reject) {
|
return new Promise(function(resolve,reject) {
|
||||||
fs.readFile(sessionsFile,'utf8',function(err,data){
|
fs.readFile(sessionsFile,'utf8',function(err,data){
|
||||||
if (!err) {
|
if (!err) {
|
||||||
try {
|
try {
|
||||||
@ -44,9 +43,9 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
saveSessions: function(sessions) {
|
saveSessions: async function(sessions) {
|
||||||
if (settings.readOnly) {
|
if (settings.readOnly) {
|
||||||
return when.resolve();
|
return;
|
||||||
}
|
}
|
||||||
return util.writeFile(sessionsFile,JSON.stringify(sessions));
|
return util.writeFile(sessionsFile,JSON.stringify(sessions));
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
"clone": "2.1.2",
|
"clone": "2.1.2",
|
||||||
"express": "4.17.1",
|
"express": "4.17.1",
|
||||||
"fs-extra": "8.1.0",
|
"fs-extra": "8.1.0",
|
||||||
"json-stringify-safe": "5.0.1",
|
"json-stringify-safe": "5.0.1"
|
||||||
"when": "3.7.8"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
var i18n = require("i18next");
|
var i18n = require("i18next");
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
@ -38,16 +37,16 @@ var initPromise;
|
|||||||
*/
|
*/
|
||||||
function registerMessageCatalogs(catalogs) {
|
function registerMessageCatalogs(catalogs) {
|
||||||
var promises = catalogs.map(function(catalog) {
|
var promises = catalogs.map(function(catalog) {
|
||||||
return registerMessageCatalog(catalog.namespace,catalog.dir,catalog.file);
|
return registerMessageCatalog(catalog.namespace,catalog.dir,catalog.file).catch(err => {});
|
||||||
});
|
});
|
||||||
return when.settle(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a message catalog with i18n.
|
* Register a message catalog with i18n.
|
||||||
* @memberof @node-red/util_i18n
|
* @memberof @node-red/util_i18n
|
||||||
*/
|
*/
|
||||||
function registerMessageCatalog(namespace,dir,file) {
|
async function registerMessageCatalog(namespace,dir,file) {
|
||||||
return initPromise.then(function() {
|
return initPromise.then(function() {
|
||||||
return new Promise((resolve,reject) => {
|
return new Promise((resolve,reject) => {
|
||||||
resourceMap[namespace] = { basedir:dir, file:file, lngs: []};
|
resourceMap[namespace] = { basedir:dir, file:file, lngs: []};
|
||||||
@ -147,7 +146,7 @@ function init() {
|
|||||||
if (!initPromise) {
|
if (!initPromise) {
|
||||||
// Keep this as a 'when' promise as top-level red.js uses 'otherwise'
|
// Keep this as a 'when' promise as top-level red.js uses 'otherwise'
|
||||||
// and embedded users of NR may have copied that.
|
// and embedded users of NR may have copied that.
|
||||||
initPromise = when.promise((resolve,reject) => {
|
initPromise = new Promise((resolve,reject) => {
|
||||||
i18n.use(MessageFileLoader);
|
i18n.use(MessageFileLoader);
|
||||||
var opt = {
|
var opt = {
|
||||||
// debug: true,
|
// debug: true,
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
"json-stringify-safe": "5.0.1",
|
"json-stringify-safe": "5.0.1",
|
||||||
"jsonata": "1.8.4",
|
"jsonata": "1.8.4",
|
||||||
"lodash.clonedeep": "^4.5.0",
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"moment-timezone": "0.5.32",
|
"moment-timezone": "0.5.32"
|
||||||
"when": "3.7.8"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
packages/node_modules/node-red/lib/red.js
vendored
23
packages/node_modules/node-red/lib/red.js
vendored
@ -92,11 +92,32 @@ module.exports = {
|
|||||||
* @memberof node-red
|
* @memberof node-red
|
||||||
*/
|
*/
|
||||||
start: function() {
|
start: function() {
|
||||||
return runtime.start().then(function() {
|
// The top level red.js has always used 'otherwise' on the promise returned
|
||||||
|
// here. This is a non-standard promise function coming from our early use
|
||||||
|
// of the when.js library.
|
||||||
|
// We want to remove all dependency on when.js as native Promises now exist.
|
||||||
|
// But we have the issue that some embedders of Node-RED may have copied our
|
||||||
|
// top-level red.js a bit too much.
|
||||||
|
//
|
||||||
|
let startPromise = runtime.start().then(function() {
|
||||||
if (apiEnabled) {
|
if (apiEnabled) {
|
||||||
return api.start();
|
return api.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
startPromise._then = startPromise.then;
|
||||||
|
startPromise.then = function(resolve,reject) {
|
||||||
|
var inner = startPromise._then(resolve,reject);
|
||||||
|
inner.otherwise = function(cb) {
|
||||||
|
redUtil.log.error("**********************************************");
|
||||||
|
redUtil.log.error("* Deprecated call to RED.start().otherwise() *");
|
||||||
|
redUtil.log.error("* This will be removed in Node-RED 2.x *");
|
||||||
|
redUtil.log.error("* Use RED.start().catch() instead *")
|
||||||
|
redUtil.log.error("**********************************************");
|
||||||
|
return inner.catch(cb);
|
||||||
|
}
|
||||||
|
return inner;
|
||||||
|
}
|
||||||
|
return startPromise;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Stop the Node-RED application.
|
* Stop the Node-RED application.
|
||||||
|
3
packages/node_modules/node-red/red.js
vendored
3
packages/node_modules/node-red/red.js
vendored
@ -429,7 +429,7 @@ httpsPromise.then(function(startupHttps) {
|
|||||||
} else {
|
} else {
|
||||||
RED.log.info(RED.log._("server.headless-mode"));
|
RED.log.info(RED.log._("server.headless-mode"));
|
||||||
}
|
}
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
RED.log.error(RED.log._("server.failed-to-start"));
|
RED.log.error(RED.log._("server.failed-to-start"));
|
||||||
if (err.stack) {
|
if (err.stack) {
|
||||||
RED.log.error(err.stack);
|
RED.log.error(err.stack);
|
||||||
@ -468,4 +468,5 @@ httpsPromise.then(function(startupHttps) {
|
|||||||
|
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
console.log("Failed to get https settings: " + err);
|
console.log("Failed to get https settings: " + err);
|
||||||
|
console.log(err.stack)
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var https = require("https");
|
var https = require("https");
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var ws = require("ws");
|
var ws = require("ws");
|
||||||
var when = require("when");
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var helper = require("node-red-node-test-helper");
|
var helper = require("node-red-node-test-helper");
|
||||||
var websocketNode = require("nr-test-utils").require("@node-red/nodes/core/network/22-websocket.js");
|
var websocketNode = require("nr-test-utils").require("@node-red/nodes/core/network/22-websocket.js");
|
||||||
@ -27,7 +26,7 @@ function getWsUrl(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createClient(listenerid) {
|
function createClient(listenerid) {
|
||||||
return when.promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var node = helper.getNode(listenerid);
|
var node = helper.getNode(listenerid);
|
||||||
var url = getWsUrl(node.path);
|
var url = getWsUrl(node.path);
|
||||||
var sock = new ws(url);
|
var sock = new ws(url);
|
||||||
@ -300,23 +299,33 @@ describe('websocket Node', function() {
|
|||||||
{ id: "n2", type: "websocket out", server: "n1" },
|
{ id: "n2", type: "websocket out", server: "n1" },
|
||||||
{ id: "n3", type: "helper", wires: [["n2"]] }];
|
{ id: "n3", type: "helper", wires: [["n2"]] }];
|
||||||
helper.load(websocketNode, flow, function() {
|
helper.load(websocketNode, flow, function() {
|
||||||
var def1 = when.defer(),
|
Promise.all([createClient("n1"), createClient("n1")]).then(function(socks) {
|
||||||
def2 = when.defer();
|
var promises = [
|
||||||
when.all([createClient("n1"), createClient("n1")]).then(function(socks) {
|
new Promise((resolve,reject) => {
|
||||||
socks[0].on("message", function(msg, flags) {
|
socks[0].on("message", function(msg, flags) {
|
||||||
|
try {
|
||||||
msg.should.equal("hello");
|
msg.should.equal("hello");
|
||||||
def1.resolve();
|
resolve();
|
||||||
|
} catch(err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}),
|
||||||
|
new Promise((resolve,reject) => {
|
||||||
socks[1].on("message", function(msg, flags) {
|
socks[1].on("message", function(msg, flags) {
|
||||||
|
try {
|
||||||
msg.should.equal("hello");
|
msg.should.equal("hello");
|
||||||
def2.resolve();
|
resolve();
|
||||||
|
} catch(err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
];
|
||||||
helper.getNode("n3").send({
|
helper.getNode("n3").send({
|
||||||
payload: "hello"
|
payload: "hello"
|
||||||
});
|
});
|
||||||
return when.all([def1.promise, def2.promise]).then(function() {
|
return Promise.all(promises).then(() => {done()});
|
||||||
done();
|
|
||||||
});
|
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,6 @@ var request = require('supertest');
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require('body-parser');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var when = require('when');
|
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ var request = require('supertest');
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require('body-parser');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var when = require('when');
|
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var when = require("when");
|
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
|
|
||||||
var passport = require("passport");
|
var passport = require("passport");
|
||||||
@ -60,7 +59,7 @@ describe("api/auth/index",function() {
|
|||||||
describe("revoke", function() {
|
describe("revoke", function() {
|
||||||
it("revokes a token", function(done) {
|
it("revokes a token", function(done) {
|
||||||
var revokeToken = sinon.stub(Tokens,"revoke",function() {
|
var revokeToken = sinon.stub(Tokens,"revoke",function() {
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
var req = { body: { token: "abcdef" } };
|
var req = { body: { token: "abcdef" } };
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var when = require('when');
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
@ -37,7 +36,7 @@ describe("api/auth/strategies", function() {
|
|||||||
|
|
||||||
it('Handles authentication failure',function(done) {
|
it('Handles authentication failure',function(done) {
|
||||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.passwordTokenExchange({},"user","password","scope",function(err,token) {
|
strategies.passwordTokenExchange({},"user","password","scope",function(err,token) {
|
||||||
@ -53,7 +52,7 @@ describe("api/auth/strategies", function() {
|
|||||||
|
|
||||||
it('Handles scope overreach',function(done) {
|
it('Handles scope overreach',function(done) {
|
||||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||||
return when.resolve({username:"user",permissions:"read"});
|
return Promise.resolve({username:"user",permissions:"read"});
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.passwordTokenExchange({},"user","password","*",function(err,token) {
|
strategies.passwordTokenExchange({},"user","password","*",function(err,token) {
|
||||||
@ -69,14 +68,14 @@ describe("api/auth/strategies", function() {
|
|||||||
|
|
||||||
it('Creates new token on authentication success',function(done) {
|
it('Creates new token on authentication success',function(done) {
|
||||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||||
return when.resolve({username:"user",permissions:"*"});
|
return Promise.resolve({username:"user",permissions:"*"});
|
||||||
});
|
});
|
||||||
var tokenDetails = {};
|
var tokenDetails = {};
|
||||||
var tokenCreate = sinon.stub(Tokens,"create",function(username,client,scope) {
|
var tokenCreate = sinon.stub(Tokens,"create",function(username,client,scope) {
|
||||||
tokenDetails.username = username;
|
tokenDetails.username = username;
|
||||||
tokenDetails.client = client;
|
tokenDetails.client = client;
|
||||||
tokenDetails.scope = scope;
|
tokenDetails.scope = scope;
|
||||||
return when.resolve({accessToken: "123456"});
|
return Promise.resolve({accessToken: "123456"});
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.passwordTokenExchange({id:"myclient"},"user","password","read",function(err,token) {
|
strategies.passwordTokenExchange({id:"myclient"},"user","password","read",function(err,token) {
|
||||||
@ -100,7 +99,7 @@ describe("api/auth/strategies", function() {
|
|||||||
describe("Anonymous Strategy", function() {
|
describe("Anonymous Strategy", function() {
|
||||||
it('Succeeds if anon user enabled',function(done) {
|
it('Succeeds if anon user enabled',function(done) {
|
||||||
var userDefault = sinon.stub(Users,"default",function() {
|
var userDefault = sinon.stub(Users,"default",function() {
|
||||||
return when.resolve("anon");
|
return Promise.resolve("anon");
|
||||||
});
|
});
|
||||||
strategies.anonymousStrategy._success = strategies.anonymousStrategy.success;
|
strategies.anonymousStrategy._success = strategies.anonymousStrategy.success;
|
||||||
strategies.anonymousStrategy.success = function(user) {
|
strategies.anonymousStrategy.success = function(user) {
|
||||||
@ -113,7 +112,7 @@ describe("api/auth/strategies", function() {
|
|||||||
});
|
});
|
||||||
it('Fails if anon user not enabled',function(done) {
|
it('Fails if anon user not enabled',function(done) {
|
||||||
var userDefault = sinon.stub(Users,"default",function() {
|
var userDefault = sinon.stub(Users,"default",function() {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
strategies.anonymousStrategy._fail = strategies.anonymousStrategy.fail;
|
strategies.anonymousStrategy._fail = strategies.anonymousStrategy.fail;
|
||||||
strategies.anonymousStrategy.fail = function(err) {
|
strategies.anonymousStrategy.fail = function(err) {
|
||||||
@ -132,7 +131,7 @@ describe("api/auth/strategies", function() {
|
|||||||
describe("Tokens Strategy", function() {
|
describe("Tokens Strategy", function() {
|
||||||
it('Succeeds if tokens user enabled custom header',function(done) {
|
it('Succeeds if tokens user enabled custom header',function(done) {
|
||||||
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
||||||
return when.resolve("tokens-"+token);
|
return Promise.resolve("tokens-"+token);
|
||||||
});
|
});
|
||||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||||
return "x-test-token";
|
return "x-test-token";
|
||||||
@ -148,7 +147,7 @@ describe("api/auth/strategies", function() {
|
|||||||
});
|
});
|
||||||
it('Succeeds if tokens user enabled default header',function(done) {
|
it('Succeeds if tokens user enabled default header',function(done) {
|
||||||
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
||||||
return when.resolve("tokens-"+token);
|
return Promise.resolve("tokens-"+token);
|
||||||
});
|
});
|
||||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||||
return "authorization";
|
return "authorization";
|
||||||
@ -164,7 +163,7 @@ describe("api/auth/strategies", function() {
|
|||||||
});
|
});
|
||||||
it('Fails if tokens user not enabled',function(done) {
|
it('Fails if tokens user not enabled',function(done) {
|
||||||
var userTokens = sinon.stub(Users,"tokens",function() {
|
var userTokens = sinon.stub(Users,"tokens",function() {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||||
return "authorization";
|
return "authorization";
|
||||||
@ -187,7 +186,7 @@ describe("api/auth/strategies", function() {
|
|||||||
describe("Bearer Strategy", function() {
|
describe("Bearer Strategy", function() {
|
||||||
it('Rejects invalid token',function(done) {
|
it('Rejects invalid token',function(done) {
|
||||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.bearerStrategy("1234",function(err,user) {
|
strategies.bearerStrategy("1234",function(err,user) {
|
||||||
@ -204,10 +203,10 @@ describe("api/auth/strategies", function() {
|
|||||||
});
|
});
|
||||||
it('Accepts valid token',function(done) {
|
it('Accepts valid token',function(done) {
|
||||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||||
return when.resolve({user:"user",scope:"scope"});
|
return Promise.resolve({user:"user",scope:"scope"});
|
||||||
});
|
});
|
||||||
var getUser = sinon.stub(Users,"get",function(username) {
|
var getUser = sinon.stub(Users,"get",function(username) {
|
||||||
return when.resolve("aUser");
|
return Promise.resolve("aUser");
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.bearerStrategy("1234",function(err,user,opts) {
|
strategies.bearerStrategy("1234",function(err,user,opts) {
|
||||||
@ -226,10 +225,10 @@ describe("api/auth/strategies", function() {
|
|||||||
});
|
});
|
||||||
it('Fail if no user for token',function(done) {
|
it('Fail if no user for token',function(done) {
|
||||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||||
return when.resolve({user:"user",scope:"scope"});
|
return Promise.resolve({user:"user",scope:"scope"});
|
||||||
});
|
});
|
||||||
var getUser = sinon.stub(Users,"get",function(username) {
|
var getUser = sinon.stub(Users,"get",function(username) {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.bearerStrategy("1234",function(err,user,opts) {
|
strategies.bearerStrategy("1234",function(err,user,opts) {
|
||||||
@ -252,7 +251,7 @@ describe("api/auth/strategies", function() {
|
|||||||
it('Accepts valid client',function(done) {
|
it('Accepts valid client',function(done) {
|
||||||
var testClient = {id:"node-red-editor",secret:"not_available"};
|
var testClient = {id:"node-red-editor",secret:"not_available"};
|
||||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||||
return when.resolve(testClient);
|
return Promise.resolve(testClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.clientPasswordStrategy(testClient.id,testClient.secret,function(err,client) {
|
strategies.clientPasswordStrategy(testClient.id,testClient.secret,function(err,client) {
|
||||||
@ -270,7 +269,7 @@ describe("api/auth/strategies", function() {
|
|||||||
it('Rejects invalid client secret',function(done) {
|
it('Rejects invalid client secret',function(done) {
|
||||||
var testClient = {id:"node-red-editor",secret:"not_available"};
|
var testClient = {id:"node-red-editor",secret:"not_available"};
|
||||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||||
return when.resolve(testClient);
|
return Promise.resolve(testClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
strategies.clientPasswordStrategy(testClient.id,"invalid_secret",function(err,client) {
|
strategies.clientPasswordStrategy(testClient.id,"invalid_secret",function(err,client) {
|
||||||
@ -287,7 +286,7 @@ describe("api/auth/strategies", function() {
|
|||||||
});
|
});
|
||||||
it('Rejects invalid client id',function(done) {
|
it('Rejects invalid client id',function(done) {
|
||||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) {
|
strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) {
|
||||||
try {
|
try {
|
||||||
@ -305,7 +304,7 @@ describe("api/auth/strategies", function() {
|
|||||||
var userAuthentication;
|
var userAuthentication;
|
||||||
it('Blocks after 5 failures',function(done) {
|
it('Blocks after 5 failures',function(done) {
|
||||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
for (var z=0; z<5; z++) {
|
for (var z=0; z<5; z++) {
|
||||||
strategies.passwordTokenExchange({},"user","badpassword","scope",function(err,token) {
|
strategies.passwordTokenExchange({},"user","badpassword","scope",function(err,token) {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var when = require("when");
|
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
@ -35,7 +34,7 @@ describe("api/auth/tokens", function() {
|
|||||||
it('returns a valid token', function(done) {
|
it('returns a valid token', function(done) {
|
||||||
Tokens.init({},{
|
Tokens.init({},{
|
||||||
getSessions:function() {
|
getSessions:function() {
|
||||||
return when.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
return Promise.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
Tokens.get("1234").then(function(token) {
|
Tokens.get("1234").then(function(token) {
|
||||||
@ -52,7 +51,7 @@ describe("api/auth/tokens", function() {
|
|||||||
it('returns null for an invalid token', function(done) {
|
it('returns null for an invalid token', function(done) {
|
||||||
Tokens.init({},{
|
Tokens.init({},{
|
||||||
getSessions:function() {
|
getSessions:function() {
|
||||||
return when.resolve({});
|
return Promise.resolve({});
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
Tokens.get("1234").then(function(token) {
|
Tokens.get("1234").then(function(token) {
|
||||||
@ -66,11 +65,11 @@ describe("api/auth/tokens", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('returns null for an expired token', function(done) {
|
it('returns null for an expired token', function(done) {
|
||||||
var saveSessions = sinon.stub().returns(when.resolve());
|
var saveSessions = sinon.stub().returns(Promise.resolve());
|
||||||
var expiryTime = Date.now()+50;
|
var expiryTime = Date.now()+50;
|
||||||
Tokens.init({},{
|
Tokens.init({},{
|
||||||
getSessions:function() {
|
getSessions:function() {
|
||||||
return when.resolve({"1234":{"user":"fred","expires":expiryTime}});
|
return Promise.resolve({"1234":{"user":"fred","expires":expiryTime}});
|
||||||
},
|
},
|
||||||
saveSessions: saveSessions
|
saveSessions: saveSessions
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
@ -103,7 +102,7 @@ describe("api/auth/tokens", function() {
|
|||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
getSessions:function() {
|
getSessions:function() {
|
||||||
return when.resolve({});
|
return Promise.resolve({});
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
Tokens.get("1234").then(function(token) {
|
Tokens.get("1234").then(function(token) {
|
||||||
@ -124,11 +123,11 @@ describe("api/auth/tokens", function() {
|
|||||||
var savedSession;
|
var savedSession;
|
||||||
Tokens.init({sessionExpiryTime: 10},{
|
Tokens.init({sessionExpiryTime: 10},{
|
||||||
getSessions:function() {
|
getSessions:function() {
|
||||||
return when.resolve({});
|
return Promise.resolve({});
|
||||||
},
|
},
|
||||||
saveSessions:function(sess) {
|
saveSessions:function(sess) {
|
||||||
savedSession = sess;
|
savedSession = sess;
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var expectedExpiryTime = Date.now()+10000;
|
var expectedExpiryTime = Date.now()+10000;
|
||||||
@ -159,11 +158,11 @@ describe("api/auth/tokens", function() {
|
|||||||
var savedSession;
|
var savedSession;
|
||||||
Tokens.init({},{
|
Tokens.init({},{
|
||||||
getSessions:function() {
|
getSessions:function() {
|
||||||
return when.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
return Promise.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
||||||
},
|
},
|
||||||
saveSessions:function(sess) {
|
saveSessions:function(sess) {
|
||||||
savedSession = sess;
|
savedSession = sess;
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
Tokens.revoke("1234").then(function() {
|
Tokens.revoke("1234").then(function() {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var when = require('when');
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
@ -144,12 +143,12 @@ describe("api/auth/users", function() {
|
|||||||
Users.init({
|
Users.init({
|
||||||
type:"credentials",
|
type:"credentials",
|
||||||
users:function(username) {
|
users:function(username) {
|
||||||
return when.resolve({'username':'dave','permissions':'read'});
|
return Promise.resolve({'username':'dave','permissions':'read'});
|
||||||
},
|
},
|
||||||
authenticate: function(username,password) {
|
authenticate: function(username,password) {
|
||||||
authUsername = username;
|
authUsername = username;
|
||||||
authPassword = password;
|
authPassword = password;
|
||||||
return when.resolve({'username':'pete','permissions':'write'});
|
return Promise.resolve({'username':'pete','permissions':'write'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -18,7 +18,6 @@ var should = require("should");
|
|||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
const stoppable = require('stoppable');
|
const stoppable = require('stoppable');
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var app = express();
|
var app = express();
|
||||||
@ -59,7 +58,7 @@ describe("api/editor/comms", function() {
|
|||||||
var url;
|
var url;
|
||||||
var port;
|
var port;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||||
comms.init(server, {}, {comms: mockComms});
|
comms.init(server, {}, {comms: mockComms});
|
||||||
server.listen(listenPort, address);
|
server.listen(listenPort, address);
|
||||||
@ -165,7 +164,7 @@ describe("api/editor/comms", function() {
|
|||||||
var url;
|
var url;
|
||||||
var port;
|
var port;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||||
comms.init(server, {httpAdminRoot:"/adminPath"}, {comms: mockComms});
|
comms.init(server, {httpAdminRoot:"/adminPath"}, {comms: mockComms});
|
||||||
server.listen(listenPort, address);
|
server.listen(listenPort, address);
|
||||||
@ -203,7 +202,7 @@ describe("api/editor/comms", function() {
|
|||||||
var url;
|
var url;
|
||||||
var port;
|
var port;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||||
comms.init(server, {httpAdminRoot:"/adminPath/"}, {comms: mockComms});
|
comms.init(server, {httpAdminRoot:"/adminPath/"}, {comms: mockComms});
|
||||||
server.listen(listenPort, address);
|
server.listen(listenPort, address);
|
||||||
@ -241,7 +240,7 @@ describe("api/editor/comms", function() {
|
|||||||
var url;
|
var url;
|
||||||
var port;
|
var port;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||||
comms.init(server, {httpAdminRoot:"adminPath"}, {comms: mockComms});
|
comms.init(server, {httpAdminRoot:"adminPath"}, {comms: mockComms});
|
||||||
server.listen(listenPort, address);
|
server.listen(listenPort, address);
|
||||||
@ -279,7 +278,7 @@ describe("api/editor/comms", function() {
|
|||||||
var url;
|
var url;
|
||||||
var port;
|
var port;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||||
comms.init(server, {webSocketKeepAliveTime: 100}, {comms: mockComms});
|
comms.init(server, {webSocketKeepAliveTime: 100}, {comms: mockComms});
|
||||||
server.listen(listenPort, address);
|
server.listen(listenPort, address);
|
||||||
@ -345,28 +344,28 @@ describe("api/editor/comms", function() {
|
|||||||
var getToken;
|
var getToken;
|
||||||
var getUserToken;
|
var getUserToken;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
getDefaultUser = sinon.stub(Users,"default",function() { return when.resolve(null);});
|
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||||
getUser = sinon.stub(Users,"get", function(username) {
|
getUser = sinon.stub(Users,"get", function(username) {
|
||||||
if (username == "fred") {
|
if (username == "fred") {
|
||||||
return when.resolve({permissions:"read"});
|
return Promise.resolve({permissions:"read"});
|
||||||
} else {
|
} else {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getUserToken = sinon.stub(Users,"tokens", function(token) {
|
getUserToken = sinon.stub(Users,"tokens", function(token) {
|
||||||
if (token == "abcde") {
|
if (token == "abcde") {
|
||||||
return when.resolve({user:"wilma", permissions:"*"})
|
return Promise.resolve({user:"wilma", permissions:"*"})
|
||||||
} else {
|
} else {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getToken = sinon.stub(Tokens,"get",function(token) {
|
getToken = sinon.stub(Tokens,"get",function(token) {
|
||||||
if (token == "1234") {
|
if (token == "1234") {
|
||||||
return when.resolve({user:"fred",scope:["*"]});
|
return Promise.resolve({user:"fred",scope:["*"]});
|
||||||
} else if (token == "5678") {
|
} else if (token == "5678") {
|
||||||
return when.resolve({user:"barney",scope:["*"]});
|
return Promise.resolve({user:"barney",scope:["*"]});
|
||||||
} else {
|
} else {
|
||||||
return when.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -484,7 +483,7 @@ describe("api/editor/comms", function() {
|
|||||||
var port;
|
var port;
|
||||||
var getDefaultUser;
|
var getDefaultUser;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
getDefaultUser = sinon.stub(Users,"default",function() { return when.resolve({permissions:"read"});});
|
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve({permissions:"read"});});
|
||||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||||
comms.init(server, {adminAuth:{}}, {comms: mockComms});
|
comms.init(server, {adminAuth:{}}, {comms: mockComms});
|
||||||
server.listen(listenPort, address);
|
server.listen(listenPort, address);
|
||||||
|
@ -18,7 +18,6 @@ var should = require("should");
|
|||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var when = require('when');
|
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
|
|
||||||
|
@ -28,10 +28,6 @@ var auth = NR_TEST_UTILS.require("@node-red/editor-api/lib/auth");
|
|||||||
|
|
||||||
var log = NR_TEST_UTILS.require("@node-red/util").log;
|
var log = NR_TEST_UTILS.require("@node-red/util").log;
|
||||||
|
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
|
|
||||||
|
|
||||||
describe("api/editor/index", function() {
|
describe("api/editor/index", function() {
|
||||||
var app;
|
var app;
|
||||||
describe("disabled the editor", function() {
|
describe("disabled the editor", function() {
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
var should = require("should");
|
var should = require("should");
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var when = require('when');
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
@ -18,7 +18,6 @@ var should = require("should");
|
|||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var request = require("supertest");
|
var request = require("supertest");
|
||||||
var express = require("express");
|
var express = require("express");
|
||||||
var when = require("when");
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
var should = require("should");
|
var should = require("should");
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var when = require("when");
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
@ -51,7 +50,7 @@ describe('red/registry/index', function() {
|
|||||||
describe('#addModule', function() {
|
describe('#addModule', function() {
|
||||||
it('loads the module and returns its info', function(done) {
|
it('loads the module and returns its info', function(done) {
|
||||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}));
|
}));
|
||||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||||
return "info";
|
return "info";
|
||||||
@ -63,7 +62,7 @@ describe('red/registry/index', function() {
|
|||||||
});
|
});
|
||||||
it('rejects if loader rejects', function(done) {
|
it('rejects if loader rejects', function(done) {
|
||||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||||
return when.reject("error");
|
return Promise.reject("error");
|
||||||
}));
|
}));
|
||||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||||
return "info";
|
return "info";
|
||||||
@ -80,7 +79,7 @@ describe('red/registry/index', function() {
|
|||||||
describe('#enableNode',function() {
|
describe('#enableNode',function() {
|
||||||
it('enables a node set',function(done) {
|
it('enables a node set',function(done) {
|
||||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}));
|
}));
|
||||||
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
||||||
return {id:"node-set",loaded:true};
|
return {id:"node-set",loaded:true};
|
||||||
@ -104,14 +103,14 @@ describe('red/registry/index', function() {
|
|||||||
|
|
||||||
it('triggers a node load',function(done) {
|
it('triggers a node load',function(done) {
|
||||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}));
|
}));
|
||||||
var calls = 0;
|
var calls = 0;
|
||||||
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
||||||
// loaded=false on first call, true on subsequent
|
// loaded=false on first call, true on subsequent
|
||||||
return {id:"node-set",loaded:(calls++>0)};
|
return {id:"node-set",loaded:(calls++>0)};
|
||||||
}));
|
}));
|
||||||
stubs.push(sinon.stub(loader,"loadNodeSet",function(){return when.resolve();}));
|
stubs.push(sinon.stub(loader,"loadNodeSet",function(){return Promise.resolve();}));
|
||||||
stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo"));
|
stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo"));
|
||||||
|
|
||||||
registry.enableNode("node-set").then(function(ns) {
|
registry.enableNode("node-set").then(function(ns) {
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var when = require("when");
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var EventEmitter = require('events');
|
var EventEmitter = require('events');
|
||||||
@ -185,7 +184,7 @@ describe('nodes/registry/installer', function() {
|
|||||||
initInstaller(p)
|
initInstaller(p)
|
||||||
|
|
||||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||||
return when.resolve(nodeInfo);
|
return Promise.resolve(nodeInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
installer.installModule("this_wont_exist").then(function(info) {
|
installer.installModule("this_wont_exist").then(function(info) {
|
||||||
@ -216,7 +215,7 @@ describe('nodes/registry/installer', function() {
|
|||||||
it("succeeds when path is valid node-red module", function(done) {
|
it("succeeds when path is valid node-red module", function(done) {
|
||||||
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
||||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||||
return when.resolve(nodeInfo);
|
return Promise.resolve(nodeInfo);
|
||||||
});
|
});
|
||||||
var resourcesDir = path.resolve(path.join(__dirname,"resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
var resourcesDir = path.resolve(path.join(__dirname,"resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
||||||
|
|
||||||
@ -246,7 +245,7 @@ describe('nodes/registry/installer', function() {
|
|||||||
initInstaller(p)
|
initInstaller(p)
|
||||||
|
|
||||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||||
return when.resolve(nodeInfo);
|
return Promise.resolve(nodeInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
installer.installModule("this_wont_exist",null,"https://example/foo-0.1.1.tgz").then(function(info) {
|
installer.installModule("this_wont_exist",null,"https://example/foo-0.1.1.tgz").then(function(info) {
|
||||||
@ -259,19 +258,20 @@ describe('nodes/registry/installer', function() {
|
|||||||
describe("uninstalls module", function() {
|
describe("uninstalls module", function() {
|
||||||
it("rejects invalid module names", function(done) {
|
it("rejects invalid module names", function(done) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
promises.push(installer.uninstallModule("this_wont_exist "));
|
var rejectedCount = 0;
|
||||||
promises.push(installer.uninstallModule("this_wont_exist;no_it_really_wont"));
|
|
||||||
when.settle(promises).then(function(results) {
|
promises.push(installer.uninstallModule("this_wont_exist ").catch(() => {rejectedCount++}));
|
||||||
results[0].state.should.be.eql("rejected");
|
promises.push(installer.uninstallModule("this_wont_exist;no_it_really_wont").catch(() => {rejectedCount++}));
|
||||||
results[1].state.should.be.eql("rejected");
|
Promise.all(promises).then(function() {
|
||||||
|
rejectedCount.should.eql(2);
|
||||||
done();
|
done();
|
||||||
});
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects with generic error", function(done) {
|
it("rejects with generic error", function(done) {
|
||||||
var nodeInfo = [{module:"foo",types:["a"]}];
|
var nodeInfo = [{module:"foo",types:["a"]}];
|
||||||
var removeModule = sinon.stub(registry,"removeModule",function(md) {
|
var removeModule = sinon.stub(registry,"removeModule",function(md) {
|
||||||
return when.resolve(nodeInfo);
|
return Promise.resolve(nodeInfo);
|
||||||
});
|
});
|
||||||
var res = {
|
var res = {
|
||||||
code: 1,
|
code: 1,
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var when = require("when");
|
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs-extra");
|
var fs = require("fs-extra");
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var when = require("when");
|
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var when = require("when");
|
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
|
|
||||||
function stubSettings(s,available,initialConfig) {
|
function stubSettings(s,available,initialConfig) {
|
||||||
s.available = function() {return available;};
|
s.available = function() {return available;};
|
||||||
s.set = sinon.spy(function(s,v) { return when.resolve();});
|
s.set = sinon.spy(function(s,v) { return Promise.resolve();});
|
||||||
s.get = function(s) { return initialConfig;};
|
s.get = function(s) { return initialConfig;};
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -95,7 +94,7 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
it('migrates legacy format', function(done) {
|
it('migrates legacy format', function(done) {
|
||||||
var legacySettings = {
|
var legacySettings = {
|
||||||
available: function() { return true; },
|
available: function() { return true; },
|
||||||
set: sinon.stub().returns(when.resolve()),
|
set: sinon.stub().returns(Promise.resolve()),
|
||||||
get: function() { return {
|
get: function() { return {
|
||||||
"123": {
|
"123": {
|
||||||
"name": "72-sentiment.js",
|
"name": "72-sentiment.js",
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// A test node that exports a function which returns a resolving promise
|
// A test node that exports a function which returns a resolving promise
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
return when.promise(function(resolve,reject) {
|
return new Promise(function(resolve,reject) {
|
||||||
function TestNode(n) {}
|
function TestNode(n) {}
|
||||||
RED.nodes.registerType("test-node-2",TestNode);
|
RED.nodes.registerType("test-node-2",TestNode);
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// A test node that exports a function which returns a rejecting promise
|
// A test node that exports a function which returns a rejecting promise
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
return when.promise(function(resolve,reject) {
|
return new Promise(function(resolve,reject) {
|
||||||
reject("fail");
|
reject("fail");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,6 @@ var request = require('supertest');
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require('body-parser');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var when = require('when');
|
|
||||||
|
|
||||||
var nodes = require("../../../../red/api/admin/nodes");
|
var nodes = require("../../../../red/api/admin/nodes");
|
||||||
var apiUtil = require("../../../../red/api/util");
|
var apiUtil = require("../../../../red/api/util");
|
||||||
@ -418,7 +417,7 @@ describe("api/admin/nodes", function() {
|
|||||||
nodes:{
|
nodes:{
|
||||||
getModuleInfo: function(id) { return null; },
|
getModuleInfo: function(id) { return null; },
|
||||||
installModule: function() {
|
installModule: function() {
|
||||||
return when.resolve({
|
return Promise.resolve({
|
||||||
name:"foo",
|
name:"foo",
|
||||||
nodes:[{id:"123"}]
|
nodes:[{id:"123"}]
|
||||||
});
|
});
|
||||||
@ -446,7 +445,7 @@ describe("api/admin/nodes", function() {
|
|||||||
nodes:{
|
nodes:{
|
||||||
getModuleInfo: function(id) { return {nodes:{id:"123"}}; },
|
getModuleInfo: function(id) { return {nodes:{id:"123"}}; },
|
||||||
installModule: function() {
|
installModule: function() {
|
||||||
return when.resolve({id:"123"});
|
return Promise.resolve({id:"123"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -468,7 +467,7 @@ describe("api/admin/nodes", function() {
|
|||||||
nodes:{
|
nodes:{
|
||||||
getModuleInfo: function(id) { return null },
|
getModuleInfo: function(id) { return null },
|
||||||
installModule: function() {
|
installModule: function() {
|
||||||
return when.reject(new Error("test error"));
|
return Promise.reject(new Error("test error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -492,7 +491,7 @@ describe("api/admin/nodes", function() {
|
|||||||
installModule: function() {
|
installModule: function() {
|
||||||
var err = new Error("test error");
|
var err = new Error("test error");
|
||||||
err.code = 404;
|
err.code = 404;
|
||||||
return when.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -533,7 +532,7 @@ describe("api/admin/nodes", function() {
|
|||||||
nodes:{
|
nodes:{
|
||||||
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
||||||
getNodeInfo: function() { return null },
|
getNodeInfo: function() { return null },
|
||||||
uninstallModule: function() { return when.resolve({id:"123"});}
|
uninstallModule: function() { return Promise.resolve({id:"123"});}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
@ -572,7 +571,7 @@ describe("api/admin/nodes", function() {
|
|||||||
nodes:{
|
nodes:{
|
||||||
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
||||||
getNodeInfo: function() { return null },
|
getNodeInfo: function() { return null },
|
||||||
uninstallModule: function() { return when.reject(new Error("test error"));}
|
uninstallModule: function() { return Promise.reject(new Error("test error"));}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
@ -686,7 +685,7 @@ describe("api/admin/nodes", function() {
|
|||||||
settings:{available:function(){return true}},
|
settings:{available:function(){return true}},
|
||||||
nodes:{
|
nodes:{
|
||||||
getNodeInfo: function() { return {id:"123",enabled: false} },
|
getNodeInfo: function() { return {id:"123",enabled: false} },
|
||||||
enableNode: function() { return when.resolve({id:"123",enabled: true,types:['a']}); }
|
enableNode: function() { return Promise.resolve({id:"123",enabled: true,types:['a']}); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
@ -709,7 +708,7 @@ describe("api/admin/nodes", function() {
|
|||||||
settings:{available:function(){return true}},
|
settings:{available:function(){return true}},
|
||||||
nodes:{
|
nodes:{
|
||||||
getNodeInfo: function() { return {id:"123",enabled: true} },
|
getNodeInfo: function() { return {id:"123",enabled: true} },
|
||||||
disableNode: function() { return when.resolve({id:"123",enabled: false,types:['a']}); }
|
disableNode: function() { return Promise.resolve({id:"123",enabled: false,types:['a']}); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
@ -729,8 +728,8 @@ describe("api/admin/nodes", function() {
|
|||||||
|
|
||||||
describe('no-ops if already in the right state', function() {
|
describe('no-ops if already in the right state', function() {
|
||||||
function run(state,done) {
|
function run(state,done) {
|
||||||
var enableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: true,types:['a']}) });
|
var enableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: true,types:['a']}) });
|
||||||
var disableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: false,types:['a']}) });
|
var disableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: false,types:['a']}) });
|
||||||
|
|
||||||
initNodes({
|
initNodes({
|
||||||
settings:{available:function(){return true}},
|
settings:{available:function(){return true}},
|
||||||
@ -768,8 +767,8 @@ describe("api/admin/nodes", function() {
|
|||||||
|
|
||||||
describe('does not no-op if err on node', function() {
|
describe('does not no-op if err on node', function() {
|
||||||
function run(state,done) {
|
function run(state,done) {
|
||||||
var enableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: true,types:['a']}) });
|
var enableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: true,types:['a']}) });
|
||||||
var disableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: false,types:['a']}) });
|
var disableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: false,types:['a']}) });
|
||||||
|
|
||||||
initNodes({
|
initNodes({
|
||||||
settings:{available:function(){return true}},
|
settings:{available:function(){return true}},
|
||||||
@ -811,11 +810,11 @@ describe("api/admin/nodes", function() {
|
|||||||
var enableNode = sinon.stub();
|
var enableNode = sinon.stub();
|
||||||
enableNode.onFirstCall().returns((function() {
|
enableNode.onFirstCall().returns((function() {
|
||||||
n1.enabled = true;
|
n1.enabled = true;
|
||||||
return when.resolve(n1);
|
return Promise.resolve(n1);
|
||||||
})());
|
})());
|
||||||
enableNode.onSecondCall().returns((function() {
|
enableNode.onSecondCall().returns((function() {
|
||||||
n2.enabled = true;
|
n2.enabled = true;
|
||||||
return when.resolve(n2);
|
return Promise.resolve(n2);
|
||||||
})());
|
})());
|
||||||
enableNode.returns(null);
|
enableNode.returns(null);
|
||||||
initNodes({
|
initNodes({
|
||||||
@ -849,11 +848,11 @@ describe("api/admin/nodes", function() {
|
|||||||
var disableNode = sinon.stub();
|
var disableNode = sinon.stub();
|
||||||
disableNode.onFirstCall().returns((function() {
|
disableNode.onFirstCall().returns((function() {
|
||||||
n1.enabled = false;
|
n1.enabled = false;
|
||||||
return when.resolve(n1);
|
return Promise.resolve(n1);
|
||||||
})());
|
})());
|
||||||
disableNode.onSecondCall().returns((function() {
|
disableNode.onSecondCall().returns((function() {
|
||||||
n2.enabled = false;
|
n2.enabled = false;
|
||||||
return when.resolve(n2);
|
return Promise.resolve(n2);
|
||||||
})());
|
})());
|
||||||
disableNode.returns(null);
|
disableNode.returns(null);
|
||||||
initNodes({
|
initNodes({
|
||||||
@ -886,11 +885,11 @@ describe("api/admin/nodes", function() {
|
|||||||
var node = {id:"123",enabled:state,types:['a']};
|
var node = {id:"123",enabled:state,types:['a']};
|
||||||
var enableNode = sinon.spy(function(id) {
|
var enableNode = sinon.spy(function(id) {
|
||||||
node.enabled = true;
|
node.enabled = true;
|
||||||
return when.resolve(node);
|
return Promise.resolve(node);
|
||||||
});
|
});
|
||||||
var disableNode = sinon.spy(function(id) {
|
var disableNode = sinon.spy(function(id) {
|
||||||
node.enabled = false;
|
node.enabled = false;
|
||||||
return when.resolve(node);
|
return Promise.resolve(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
initNodes({
|
initNodes({
|
||||||
@ -933,11 +932,11 @@ describe("api/admin/nodes", function() {
|
|||||||
var node = {id:"123",enabled:state,types:['a'],err:"foo"};
|
var node = {id:"123",enabled:state,types:['a'],err:"foo"};
|
||||||
var enableNode = sinon.spy(function(id) {
|
var enableNode = sinon.spy(function(id) {
|
||||||
node.enabled = true;
|
node.enabled = true;
|
||||||
return when.resolve(node);
|
return Promise.resolve(node);
|
||||||
});
|
});
|
||||||
var disableNode = sinon.spy(function(id) {
|
var disableNode = sinon.spy(function(id) {
|
||||||
node.enabled = false;
|
node.enabled = false;
|
||||||
return when.resolve(node);
|
return Promise.resolve(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
initNodes({
|
initNodes({
|
||||||
|
@ -588,7 +588,6 @@ var comms = require("../../../../red/api/editor/comms");
|
|||||||
var info = require("../../../../red/api/editor/settings");
|
var info = require("../../../../red/api/editor/settings");
|
||||||
var auth = require("../../../../red/api/auth");
|
var auth = require("../../../../red/api/auth");
|
||||||
var sshkeys = require("../../../../red/api/editor/sshkeys");
|
var sshkeys = require("../../../../red/api/editor/sshkeys");
|
||||||
var when = require("when");
|
|
||||||
var bodyParser = require("body-parser");
|
var bodyParser = require("body-parser");
|
||||||
var fs = require("fs-extra");
|
var fs = require("fs-extra");
|
||||||
var fspath = require("path");
|
var fspath = require("path");
|
||||||
@ -611,11 +610,11 @@ describe("api/editor/sshkeys", function() {
|
|||||||
exportNodeSettings:function(){},
|
exportNodeSettings:function(){},
|
||||||
storage: {
|
storage: {
|
||||||
getSessions: function(){
|
getSessions: function(){
|
||||||
return when.resolve(session_data);
|
return Promise.resolve(session_data);
|
||||||
},
|
},
|
||||||
setSessions: function(_session) {
|
setSessions: function(_session) {
|
||||||
session_data = _session;
|
session_data = _session;
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var when = require("when");
|
|
||||||
var clone = require("clone");
|
var clone = require("clone");
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
|
|
||||||
@ -65,13 +64,13 @@ describe('flows/index', function() {
|
|||||||
conf.forEach(function(n) {
|
conf.forEach(function(n) {
|
||||||
delete n.credentials;
|
delete n.credentials;
|
||||||
});
|
});
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
credentialsLoad = sinon.stub(credentials,"load",function(creds) {
|
credentialsLoad = sinon.stub(credentials,"load",function(creds) {
|
||||||
if (creds && creds.hasOwnProperty("$") && creds['$'] === "fail") {
|
if (creds && creds.hasOwnProperty("$") && creds['$'] === "fail") {
|
||||||
return when.reject("creds error");
|
return Promise.reject("creds error");
|
||||||
}
|
}
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) {
|
flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) {
|
||||||
var id;
|
var id;
|
||||||
@ -101,7 +100,7 @@ describe('flows/index', function() {
|
|||||||
storage = {
|
storage = {
|
||||||
saveFlows: function(conf) {
|
saveFlows: function(conf) {
|
||||||
storage.conf = conf;
|
storage.conf = conf;
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -145,10 +144,10 @@ describe('flows/index', function() {
|
|||||||
var loadStorage = {
|
var loadStorage = {
|
||||||
saveFlows: function(conf) {
|
saveFlows: function(conf) {
|
||||||
loadStorage.conf = conf;
|
loadStorage.conf = conf;
|
||||||
return when.resolve(456);
|
return Promise.resolve(456);
|
||||||
},
|
},
|
||||||
getFlows: function() {
|
getFlows: function() {
|
||||||
return when.resolve({flows:originalConfig,rev:123})
|
return Promise.resolve({flows:originalConfig,rev:123})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flows.init({log:mockLog, settings:{},storage:loadStorage});
|
flows.init({log:mockLog, settings:{},storage:loadStorage});
|
||||||
@ -207,7 +206,7 @@ describe('flows/index', function() {
|
|||||||
newConfig.push({id:"t2",type:"tab"});
|
newConfig.push({id:"t2",type:"tab"});
|
||||||
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
events.once('flows:started',function() {
|
events.once('flows:started',function() {
|
||||||
flows.setFlows(newConfig,"nodes").then(function() {
|
flows.setFlows(newConfig,"nodes").then(function() {
|
||||||
@ -235,7 +234,7 @@ describe('flows/index', function() {
|
|||||||
newConfig.push({id:"t2",type:"tab"});
|
newConfig.push({id:"t2",type:"tab"});
|
||||||
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
|
|
||||||
events.once('flows:started',function() {
|
events.once('flows:started',function() {
|
||||||
@ -277,7 +276,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
flows.init({log:mockLog, settings:{},storage:storage});
|
flows.init({log:mockLog, settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
@ -297,7 +296,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
|
|
||||||
events.once('flows:started',function() {
|
events.once('flows:started',function() {
|
||||||
@ -317,7 +316,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
|
|
||||||
flows.init({log:mockLog, settings:{},storage:storage});
|
flows.init({log:mockLog, settings:{},storage:storage});
|
||||||
@ -336,7 +335,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
flows.init({log:mockLog, settings:{},storage:storage});
|
flows.init({log:mockLog, settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
@ -370,7 +369,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
flows.init({log:mockLog, settings:{},storage:storage});
|
flows.init({log:mockLog, settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
@ -394,7 +393,7 @@ describe('flows/index', function() {
|
|||||||
// {id:"t1",type:"tab"}
|
// {id:"t1",type:"tab"}
|
||||||
// ];
|
// ];
|
||||||
// storage.getFlows = function() {
|
// storage.getFlows = function() {
|
||||||
// return when.resolve({flows:originalConfig});
|
// return Promise.resolve({flows:originalConfig});
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// events.once('flows:started',function() {
|
// events.once('flows:started',function() {
|
||||||
@ -419,7 +418,7 @@ describe('flows/index', function() {
|
|||||||
// {id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
// {id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
||||||
// ];
|
// ];
|
||||||
// storage.getFlows = function() {
|
// storage.getFlows = function() {
|
||||||
// return when.resolve({flows:originalConfig});
|
// return Promise.resolve({flows:originalConfig});
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// events.once('flows:started',function() {
|
// events.once('flows:started',function() {
|
||||||
@ -447,7 +446,7 @@ describe('flows/index', function() {
|
|||||||
// {id:"t1",type:"tab"}
|
// {id:"t1",type:"tab"}
|
||||||
// ];
|
// ];
|
||||||
// storage.getFlows = function() {
|
// storage.getFlows = function() {
|
||||||
// return when.resolve({flows:originalConfig});
|
// return Promise.resolve({flows:originalConfig});
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// events.once('flows:started',function() {
|
// events.once('flows:started',function() {
|
||||||
@ -473,7 +472,7 @@ describe('flows/index', function() {
|
|||||||
// {id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
// {id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
||||||
// ];
|
// ];
|
||||||
// storage.getFlows = function() {
|
// storage.getFlows = function() {
|
||||||
// return when.resolve({flows:originalConfig});
|
// return Promise.resolve({flows:originalConfig});
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// events.once('flows:started',function() {
|
// events.once('flows:started',function() {
|
||||||
@ -548,7 +547,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
flows.init({log:mockLog, settings:{},storage:storage});
|
flows.init({log:mockLog, settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
@ -572,10 +571,10 @@ describe('flows/index', function() {
|
|||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve({flows:originalConfig});
|
return Promise.resolve({flows:originalConfig});
|
||||||
}
|
}
|
||||||
storage.setFlows = function() {
|
storage.setFlows = function() {
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
flows.init({log:mockLog, settings:{},storage:storage});
|
flows.init({log:mockLog, settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var when = require("when");
|
|
||||||
var clone = require("clone");
|
var clone = require("clone");
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
var flowUtil = NR_TEST_UTILS.require("@node-red/runtime/lib/flows/util");
|
var flowUtil = NR_TEST_UTILS.require("@node-red/runtime/lib/flows/util");
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var when = require("when");
|
|
||||||
var util = require("util");
|
var util = require("util");
|
||||||
|
|
||||||
var NR_TEST_UTILS = require("nr-test-utils");
|
var NR_TEST_UTILS = require("nr-test-utils");
|
||||||
@ -228,11 +227,11 @@ describe('red/runtime/nodes/credentials', function() {
|
|||||||
},
|
},
|
||||||
set: function(key,value) {
|
set: function(key,value) {
|
||||||
settings[key] = value;
|
settings[key] = value;
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
delete: function(key) {
|
delete: function(key) {
|
||||||
delete settings[key];
|
delete settings[key];
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
var should = require("should");
|
var should = require("should");
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var when = require("when");
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var inherits = require("util").inherits;
|
var inherits = require("util").inherits;
|
||||||
|
|
||||||
@ -47,11 +46,11 @@ describe("red/nodes/index", function() {
|
|||||||
var testCredentials = {"tab1":{"b":1, "c":"2", "d":"$(foo)"}};
|
var testCredentials = {"tab1":{"b":1, "c":"2", "d":"$(foo)"}};
|
||||||
var storage = {
|
var storage = {
|
||||||
getFlows: function() {
|
getFlows: function() {
|
||||||
return when({red:123,flows:testFlows,credentials:testCredentials});
|
return Promise.resolve({red:123,flows:testFlows,credentials:testCredentials});
|
||||||
},
|
},
|
||||||
saveFlows: function(conf) {
|
saveFlows: function(conf) {
|
||||||
should.deepEqual(testFlows, conf.flows);
|
should.deepEqual(testFlows, conf.flows);
|
||||||
return when.resolve(123);
|
return Promise.resolve(123);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -182,12 +181,12 @@ describe("red/nodes/index", function() {
|
|||||||
fs.remove(userDir,function(err) {
|
fs.remove(userDir,function(err) {
|
||||||
fs.mkdir(userDir,function() {
|
fs.mkdir(userDir,function() {
|
||||||
sinon.stub(index, 'load', function() {
|
sinon.stub(index, 'load', function() {
|
||||||
return when.promise(function(resolve,reject){
|
return new Promise(function(resolve,reject){
|
||||||
resolve([]);
|
resolve([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
sinon.stub(localfilesystem, 'getCredentials', function() {
|
sinon.stub(localfilesystem, 'getCredentials', function() {
|
||||||
return when.promise(function(resolve,reject) {
|
return new Promise(function(resolve,reject) {
|
||||||
resolve({"tab1":{"b":1,"c":2}});
|
resolve({"tab1":{"b":1,"c":2}});
|
||||||
});
|
});
|
||||||
}) ;
|
}) ;
|
||||||
@ -282,7 +281,7 @@ describe("red/nodes/index", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
sinon.stub(registry,"disableNode",function(id) {
|
sinon.stub(registry,"disableNode",function(id) {
|
||||||
return when.resolve(randomNodeInfo);
|
return Promise.resolve(randomNodeInfo);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
var when = require("when");
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var paff = require('path');
|
var paff = require('path');
|
||||||
|
|
||||||
@ -79,16 +78,16 @@ describe("red/storage/index", function() {
|
|||||||
},
|
},
|
||||||
getFlows : function() {
|
getFlows : function() {
|
||||||
calledFlagGetFlows = true;
|
calledFlagGetFlows = true;
|
||||||
return when.resolve([]);
|
return Promise.resolve([]);
|
||||||
},
|
},
|
||||||
saveFlows : function (flows) {
|
saveFlows : function (flows) {
|
||||||
flows.should.be.an.Array();
|
flows.should.be.an.Array();
|
||||||
flows.should.have.lengthOf(0);
|
flows.should.have.lengthOf(0);
|
||||||
return when.resolve("");
|
return Promise.resolve("");
|
||||||
},
|
},
|
||||||
getCredentials : function() {
|
getCredentials : function() {
|
||||||
calledFlagGetCredentials = true;
|
calledFlagGetCredentials = true;
|
||||||
return when.resolve({});
|
return Promise.resolve({});
|
||||||
},
|
},
|
||||||
saveCredentials : function(credentials) {
|
saveCredentials : function(credentials) {
|
||||||
credentials.should.be.true();
|
credentials.should.be.true();
|
||||||
@ -147,7 +146,7 @@ describe("red/storage/index", function() {
|
|||||||
storage.getLibraryEntry(true, "name");
|
storage.getLibraryEntry(true, "name");
|
||||||
storage.saveLibraryEntry(true, "name", true, true);
|
storage.saveLibraryEntry(true, "name", true, true);
|
||||||
|
|
||||||
when.settle(promises).then(function() {
|
Promise.all(promises).then(function() {
|
||||||
try {
|
try {
|
||||||
calledInit.should.be.true();
|
calledInit.should.be.true();
|
||||||
calledFlagGetFlows.should.be.true();
|
calledFlagGetFlows.should.be.true();
|
||||||
@ -174,11 +173,11 @@ describe("red/storage/index", function() {
|
|||||||
getLibraryEntry : function(type, path) {
|
getLibraryEntry : function(type, path) {
|
||||||
if (type === "flows") {
|
if (type === "flows") {
|
||||||
if (path === "/" || path === "\\") {
|
if (path === "/" || path === "\\") {
|
||||||
return when.resolve(["a",{fn:"test.json"}]);
|
return Promise.resolve(["a",{fn:"test.json"}]);
|
||||||
} else if (path == "/a" || path == "\\a") {
|
} else if (path == "/a" || path == "\\a") {
|
||||||
return when.resolve([{fn:"test2.json"}]);
|
return Promise.resolve([{fn:"test2.json"}]);
|
||||||
} else if (path == paff.join("","a","test2.json")) {
|
} else if (path == paff.join("","a","test2.json")) {
|
||||||
return when.resolve("test content");
|
return Promise.resolve("test content");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -187,7 +186,7 @@ describe("red/storage/index", function() {
|
|||||||
savePath = path;
|
savePath = path;
|
||||||
saveContent = body;
|
saveContent = body;
|
||||||
saveMeta = meta;
|
saveMeta = meta;
|
||||||
return when.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user