diff --git a/red/api/editor/index.js b/red/api/editor/index.js index 07d3f7e0a..e27d03d6c 100644 --- a/red/api/editor/index.js +++ b/red/api/editor/index.js @@ -23,7 +23,7 @@ var info = require("./settings"); var auth = require("../auth"); var nodes = require("../admin/nodes"); // TODO: move /icons into here -var needsPermission = auth.needsPermission; +var needsPermission; var runtime; var log; var apiUtil = require("../util"); @@ -41,6 +41,7 @@ module.exports = { init: function(server, _runtime) { runtime = _runtime; log = runtime.log; + needsPermission = auth.needsPermission; var settings = runtime.settings; if (!settings.disableEditor) { info.init(runtime); diff --git a/red/runtime/storage/localfilesystem/projects/index.js b/red/runtime/storage/localfilesystem/projects/index.js index f1ddad831..b4dac444f 100644 --- a/red/runtime/storage/localfilesystem/projects/index.js +++ b/red/runtime/storage/localfilesystem/projects/index.js @@ -29,6 +29,7 @@ var Projects = require("./Project"); var settings; var runtime; +var log; var projectsEnabled = true; var projectLogMessages = []; diff --git a/test/red/api/editor/index_spec.js b/test/red/api/editor/index_spec.js index d1b1b0cae..b6b93964c 100644 --- a/test/red/api/editor/index_spec.js +++ b/test/red/api/editor/index_spec.js @@ -47,12 +47,15 @@ describe("api/editor/index", function() { }); describe("enables the editor", function() { var mockList = [ - 'library','theme','locales','credentials','comms' + 'library','theme','locales','credentials','comms',"settings" ] var isStarted = true; var errors = []; var session_data = {}; before(function() { + sinon.stub(auth,'needsPermission',function(permission) { + return function(req,res,next) { next(); } + }); mockList.forEach(function(m) { sinon.stub(require("../../../../red/api/editor/"+m),"init",function(){}); }); @@ -63,28 +66,10 @@ describe("api/editor/index", function() { require("../../../../red/api/editor/"+m).init.restore(); }) require("../../../../red/api/editor/theme").app.restore(); + auth.needsPermission.restore(); }); before(function() { - auth.init({ - settings:{ - adminAuth: { - default: { - permissions: ['read'] - } - }, - storage: { - getSessions: function(){ - return when.resolve(session_data); - }, - setSessions: function(_session) { - session_data = _session; - return when.resolve(); - } - }, - log:{audit:function(){},error:function(msg){errors.push(msg)}} - } - }); app = editorApi.init({},{ log:{audit:function(){},error:function(msg){errors.push(msg)}}, settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false,exportNodeSettings:function(){}}, @@ -132,14 +117,14 @@ describe("api/editor/index", function() { done(); }); }); - it('GET /settings', function(done) { - request(app).get("/settings").expect(200).end(function(err,res) { - if (err) { - return done(err); - } - // permissionChecks.should.have.property('settings.read',1); - done(); - }) - }); + // it('GET /settings', function(done) { + // request(app).get("/settings").expect(200).end(function(err,res) { + // if (err) { + // return done(err); + // } + // // permissionChecks.should.have.property('settings.read',1); + // done(); + // }) + // }); }); }); diff --git a/test/red/api/editor/settings_spec.js b/test/red/api/editor/settings_spec.js index cb864d38b..efcf239f6 100644 --- a/test/red/api/editor/settings_spec.js +++ b/test/red/api/editor/settings_spec.js @@ -48,9 +48,11 @@ describe("api/editor/settings", function() { } }, nodes: { - paletteEditorEnabled: function() { return true; } + paletteEditorEnabled: function() { return true; }, + getCredentialKeyType: function() { return "test-key-type"} }, - log: { error: console.error } + log: { error: console.error }, + storage: {} }); request(app) .get("/settings") @@ -65,7 +67,45 @@ describe("api/editor/settings", function() { res.body.should.have.property("editorTheme",{test:456}); res.body.should.have.property("testNodeSetting","helloWorld"); res.body.should.not.have.property("foo",123); - + res.body.should.have.property("flowEncryptionType","test-key-type"); + done(); + }); + }); + it('includes project settings if projects available', function(done) { + info.init({ + settings: { + foo: 123, + httpNodeRoot: "testHttpNodeRoot", + version: "testVersion", + paletteCategories :["red","blue","green"], + exportNodeSettings: function(obj) { + obj.testNodeSetting = "helloWorld"; + } + }, + nodes: { + paletteEditorEnabled: function() { return true; }, + getCredentialKeyType: function() { return "test-key-type"} + }, + log: { error: console.error }, + storage: { + projects: { + getActiveProject: () => 'test-active-project', + getFlowFilename: () => 'test-flow-file', + getCredentialsFilename: () => 'test-creds-file' + } + } + }); + request(app) + .get("/settings") + .expect(200) + .end(function(err,res) { + if (err) { + return done(err); + } + res.body.should.have.property("project","test-active-project"); + res.body.should.have.property("files"); + res.body.files.should.have.property("flow",'test-flow-file'); + res.body.files.should.have.property("credentials",'test-creds-file'); done(); }); }); @@ -78,9 +118,13 @@ describe("api/editor/settings", function() { exportNodeSettings: function() {} }, nodes: { - paletteEditorEnabled: function() { return false; } + paletteEditorEnabled: function() { return false; }, + getCredentialKeyType: function() { return "test-key-type"} + }, - log: { error: console.error } + log: { error: console.error }, + storage: {} + }); request(app) .get("/settings") diff --git a/test/red/api/index_spec.js b/test/red/api/index_spec.js index 09dd9a11c..103949dea 100644 --- a/test/red/api/index_spec.js +++ b/test/red/api/index_spec.js @@ -73,10 +73,10 @@ describe("api/index", function() { }); }); after(afterEach); - it('exposes the editor',function() { + it('exposes the editor',function(done) { request(api.adminApp).get("/editor").expect(200).end(done); }) - it('exposes the admin api',function() { + it('exposes the admin api',function(done) { request(api.adminApp).get("/admin").expect(200).end(done); }) it('exposes the auth api',function(done) { @@ -92,10 +92,10 @@ describe("api/index", function() { }); }); after(afterEach); - it('does not expose the editor',function() { + it('does not expose the editor',function(done) { request(api.adminApp).get("/editor").expect(404).end(done); }) - it('exposes the admin api',function() { + it('exposes the admin api',function(done) { request(api.adminApp).get("/admin").expect(200).end(done); }) it('exposes the auth api',function(done) { diff --git a/test/red/runtime/nodes/index_spec.js b/test/red/runtime/nodes/index_spec.js index b76378784..a854e592c 100644 --- a/test/red/runtime/nodes/index_spec.js +++ b/test/red/runtime/nodes/index_spec.js @@ -136,7 +136,7 @@ describe("red/nodes/index", function() { var userDir = path.join(__dirname,".testUserHome"); before(function(done) { - sinon.stub(log,"log"); + sinon.stub(log,"log",function(){}); fs.remove(userDir,function(err) { fs.mkdir(userDir,function() { sinon.stub(index, 'load', function() { @@ -159,7 +159,7 @@ describe("red/nodes/index", function() { }); after(function(done) { - fs.remove(userDir,function() {; + fs.remove(userDir,function() { runtime.stop().then(function() { index.load.restore(); localfilesystem.getCredentials.restore(); diff --git a/test/red/runtime/storage/localfilesystem/index_spec.js b/test/red/runtime/storage/localfilesystem/index_spec.js index d568e1596..aa9e15af6 100644 --- a/test/red/runtime/storage/localfilesystem/index_spec.js +++ b/test/red/runtime/storage/localfilesystem/index_spec.js @@ -26,7 +26,9 @@ describe('storage/localfilesystem', function() { var mockRuntime = { log:{ _:function() { return "placeholder message"}, - info: function() { } + info: function() { }, + warn: function() { }, + trace: function() {} } }; var userDir = path.join(__dirname,".testUserHome"); @@ -290,7 +292,7 @@ describe('storage/localfilesystem', function() { it('should fsync the flows file',function(done) { var flowFile = 'test.json'; var flowFilePath = path.join(userDir,flowFile); - localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { + localfilesystem.init({userDir:userDir, flowFile:flowFilePath}, mockRuntime).then(function() { sinon.spy(fs,"fsync"); localfilesystem.saveFlows(testFlow).then(function() { fs.fsync.callCount.should.eql(1); @@ -307,7 +309,7 @@ describe('storage/localfilesystem', function() { it('should log fsync errors and continue',function(done) { var flowFile = 'test.json'; var flowFilePath = path.join(userDir,flowFile); - localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { + localfilesystem.init({userDir:userDir, flowFile:flowFilePath}, mockRuntime).then(function() { sinon.stub(fs,"fsync", function(fd, cb) { cb(new Error()); });