2014-11-04 18:05:29 +01:00
|
|
|
/**
|
2016-03-12 01:03:50 +01:00
|
|
|
* Copyright 2014, 2016 IBM Corp.
|
2014-11-04 18:05:29 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
var should = require("should");
|
2015-11-11 23:11:02 +01:00
|
|
|
var sinon = require("sinon");
|
2014-11-04 18:05:29 +01:00
|
|
|
var request = require("supertest");
|
|
|
|
var express = require("express");
|
2015-03-14 00:37:59 +01:00
|
|
|
var when = require("when");
|
2014-11-04 18:05:29 +01:00
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
|
|
|
var api = require("../../../red/api");
|
|
|
|
|
|
|
|
describe("api index", function() {
|
|
|
|
var app;
|
2015-03-06 23:58:30 +01:00
|
|
|
|
2014-11-04 18:05:29 +01:00
|
|
|
describe("disables editor", function() {
|
|
|
|
before(function() {
|
2015-11-12 10:03:03 +01:00
|
|
|
api.init({},{
|
2015-11-12 08:56:23 +01:00
|
|
|
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:true},
|
2016-10-12 23:30:32 +02:00
|
|
|
events: {on:function(){},removeListener: function(){}},
|
|
|
|
log: {info:function(){},_:function(){}},
|
|
|
|
nodes: {paletteEditorEnabled: function(){return true}}
|
2015-11-11 23:11:02 +01:00
|
|
|
});
|
2015-11-24 23:38:42 +01:00
|
|
|
app = api.adminApp;
|
2014-11-04 18:05:29 +01:00
|
|
|
});
|
2015-03-06 23:58:30 +01:00
|
|
|
|
2014-11-04 18:05:29 +01:00
|
|
|
it('does not serve the editor', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/")
|
|
|
|
.expect(404,done)
|
|
|
|
});
|
|
|
|
it('does not serve icons', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/icons/default.png")
|
|
|
|
.expect(404,done)
|
|
|
|
});
|
2014-11-06 23:59:48 +01:00
|
|
|
it('serves settings', function(done) {
|
2014-11-04 18:05:29 +01:00
|
|
|
request(app)
|
|
|
|
.get("/settings")
|
2014-11-06 23:59:48 +01:00
|
|
|
.expect(200,done)
|
2014-11-04 18:05:29 +01:00
|
|
|
});
|
2015-03-08 16:26:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("can serve auth", function() {
|
2015-11-11 23:11:02 +01:00
|
|
|
var mockList = [
|
|
|
|
'ui','nodes','flows','library','info','theme','locales','credentials'
|
|
|
|
]
|
2015-03-08 16:26:24 +01:00
|
|
|
before(function() {
|
2015-11-11 23:11:02 +01:00
|
|
|
mockList.forEach(function(m) {
|
|
|
|
sinon.stub(require("../../../red/api/"+m),"init",function(){});
|
|
|
|
});
|
2015-03-08 16:26:24 +01:00
|
|
|
});
|
|
|
|
after(function() {
|
2015-11-11 23:11:02 +01:00
|
|
|
mockList.forEach(function(m) {
|
|
|
|
require("../../../red/api/"+m).init.restore();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
before(function() {
|
2015-11-12 10:03:03 +01:00
|
|
|
api.init({},{
|
2015-11-12 08:56:23 +01:00
|
|
|
settings:{httpNodeRoot:true, httpAdminRoot: true, adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}},
|
2015-11-12 10:03:03 +01:00
|
|
|
storage:{getSessions:function(){return when.resolve({})}},
|
|
|
|
events:{on:function(){},removeListener:function(){}}
|
2015-11-11 23:11:02 +01:00
|
|
|
});
|
2015-11-24 23:38:42 +01:00
|
|
|
app = api.adminApp;
|
2015-03-08 16:26:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('it now serves auth', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/auth/login")
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) { return done(err); }
|
|
|
|
res.body.type.should.equal("credentials");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-11-04 18:05:29 +01:00
|
|
|
});
|
2015-03-06 23:58:30 +01:00
|
|
|
|
2016-03-12 01:03:50 +01:00
|
|
|
describe("editor warns if runtime not started", function() {
|
|
|
|
var mockList = [
|
|
|
|
'nodes','flows','library','info','theme','locales','credentials'
|
|
|
|
]
|
|
|
|
before(function() {
|
|
|
|
mockList.forEach(function(m) {
|
|
|
|
sinon.stub(require("../../../red/api/"+m),"init",function(){});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
after(function() {
|
|
|
|
mockList.forEach(function(m) {
|
|
|
|
require("../../../red/api/"+m).init.restore();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serves the editor', function(done) {
|
|
|
|
var errorLog = sinon.spy();
|
|
|
|
api.init({},{
|
|
|
|
log:{audit:function(){},error:errorLog},
|
|
|
|
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false},
|
|
|
|
events:{on:function(){},removeListener:function(){}},
|
|
|
|
isStarted: function() { return false; } // <-----
|
|
|
|
});
|
|
|
|
app = api.adminApp;
|
|
|
|
request(app)
|
|
|
|
.get("/")
|
|
|
|
.expect(503)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
res.text.should.eql("Not started");
|
2016-10-10 14:27:43 +02:00
|
|
|
errorLog.calledOnce.should.be.true();
|
2016-03-12 01:03:50 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-11-04 18:05:29 +01:00
|
|
|
describe("enables editor", function() {
|
2015-11-11 23:11:02 +01:00
|
|
|
|
|
|
|
var mockList = [
|
|
|
|
'nodes','flows','library','info','theme','locales','credentials'
|
|
|
|
]
|
2014-11-04 18:05:29 +01:00
|
|
|
before(function() {
|
2015-11-11 23:11:02 +01:00
|
|
|
mockList.forEach(function(m) {
|
|
|
|
sinon.stub(require("../../../red/api/"+m),"init",function(){});
|
|
|
|
});
|
2014-11-04 18:05:29 +01:00
|
|
|
});
|
|
|
|
after(function() {
|
2015-11-11 23:11:02 +01:00
|
|
|
mockList.forEach(function(m) {
|
|
|
|
require("../../../red/api/"+m).init.restore();
|
|
|
|
})
|
2014-11-04 18:05:29 +01:00
|
|
|
});
|
2015-03-06 23:58:30 +01:00
|
|
|
|
2015-11-11 23:11:02 +01:00
|
|
|
before(function() {
|
2015-11-12 10:03:03 +01:00
|
|
|
api.init({},{
|
2015-11-11 23:11:02 +01:00
|
|
|
log:{audit:function(){}},
|
2015-11-12 08:56:23 +01:00
|
|
|
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false},
|
2016-03-12 01:03:50 +01:00
|
|
|
events:{on:function(){},removeListener:function(){}},
|
|
|
|
isStarted: function() { return true; }
|
2015-11-11 23:11:02 +01:00
|
|
|
});
|
2015-11-24 23:38:42 +01:00
|
|
|
app = api.adminApp;
|
2015-11-11 23:11:02 +01:00
|
|
|
});
|
2014-11-04 18:05:29 +01:00
|
|
|
it('serves the editor', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/")
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
// Index page should probably mention Node-RED somewhere
|
|
|
|
res.text.indexOf("Node-RED").should.not.eql(-1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('serves icons', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/icons/inject.png")
|
|
|
|
.expect("Content-Type", /image\/png/)
|
|
|
|
.expect(200,done)
|
|
|
|
});
|
|
|
|
it('serves settings', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/settings")
|
|
|
|
.expect(200,done)
|
|
|
|
});
|
2015-03-06 23:58:30 +01:00
|
|
|
it('handles page not there', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/foo")
|
|
|
|
.expect(404,done)
|
|
|
|
});
|
2014-11-04 18:05:29 +01:00
|
|
|
});
|
2015-03-06 23:58:30 +01:00
|
|
|
});
|