mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Update to latest sinon
This commit is contained in:
@@ -45,35 +45,35 @@ describe("api/admin/index", function() {
|
||||
};
|
||||
before(function() {
|
||||
mockList.forEach(function(m) {
|
||||
sinon.stub(m,"init",function(){});
|
||||
sinon.stub(m,"init").callsFake(function(){});
|
||||
});
|
||||
sinon.stub(auth,"needsPermission", function(permission) {
|
||||
sinon.stub(auth,"needsPermission").callsFake(function(permission) {
|
||||
return function(req,res,next) {
|
||||
permissionChecks[permission] = (permissionChecks[permission]||0)+1;
|
||||
next();
|
||||
};
|
||||
});
|
||||
|
||||
sinon.stub(flows,"get",stubApp);
|
||||
sinon.stub(flows,"post",stubApp);
|
||||
sinon.stub(flows,"get").callsFake(stubApp);
|
||||
sinon.stub(flows,"post").callsFake(stubApp);
|
||||
|
||||
sinon.stub(flow,"get",stubApp);
|
||||
sinon.stub(flow,"post",stubApp);
|
||||
sinon.stub(flow,"delete",stubApp);
|
||||
sinon.stub(flow,"put",stubApp);
|
||||
sinon.stub(flow,"get").callsFake(stubApp);
|
||||
sinon.stub(flow,"post").callsFake(stubApp);
|
||||
sinon.stub(flow,"delete").callsFake(stubApp);
|
||||
sinon.stub(flow,"put").callsFake(stubApp);
|
||||
|
||||
sinon.stub(nodes,"getAll",stubApp);
|
||||
sinon.stub(nodes,"post",stubApp);
|
||||
sinon.stub(nodes,"getModule",stubApp);
|
||||
sinon.stub(nodes,"putModule",stubApp);
|
||||
sinon.stub(nodes,"delete",stubApp);
|
||||
sinon.stub(nodes,"getSet",stubApp);
|
||||
sinon.stub(nodes,"putSet",stubApp);
|
||||
sinon.stub(nodes,"getModuleCatalog",stubApp);
|
||||
sinon.stub(nodes,"getModuleCatalogs",stubApp);
|
||||
sinon.stub(nodes,"getAll").callsFake(stubApp);
|
||||
sinon.stub(nodes,"post").callsFake(stubApp);
|
||||
sinon.stub(nodes,"getModule").callsFake(stubApp);
|
||||
sinon.stub(nodes,"putModule").callsFake(stubApp);
|
||||
sinon.stub(nodes,"delete").callsFake(stubApp);
|
||||
sinon.stub(nodes,"getSet").callsFake(stubApp);
|
||||
sinon.stub(nodes,"putSet").callsFake(stubApp);
|
||||
sinon.stub(nodes,"getModuleCatalog").callsFake(stubApp);
|
||||
sinon.stub(nodes,"getModuleCatalogs").callsFake(stubApp);
|
||||
|
||||
sinon.stub(context,"get",stubApp);
|
||||
sinon.stub(context,"delete",stubApp);
|
||||
sinon.stub(context,"get").callsFake(stubApp);
|
||||
sinon.stub(context,"delete").callsFake(stubApp);
|
||||
});
|
||||
after(function() {
|
||||
mockList.forEach(function(m) {
|
||||
|
@@ -41,7 +41,7 @@ describe("api/admin/nodes", function() {
|
||||
app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.putSet);
|
||||
app.get("/getIcons",nodes.getIcons);
|
||||
app.delete(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,nodes.delete);
|
||||
sinon.stub(apiUtil,"determineLangFromHeaders", function() {
|
||||
sinon.stub(apiUtil,"determineLangFromHeaders").callsFake(function() {
|
||||
return "en-US";
|
||||
});
|
||||
});
|
||||
|
@@ -29,7 +29,7 @@ var theme = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme");
|
||||
|
||||
describe("api/editor/settings", function() {
|
||||
before(function() {
|
||||
sinon.stub(theme,"settings",function() { return { existing: 123, test: 456 };});
|
||||
sinon.stub(theme,"settings").callsFake(function() { return { existing: 123, test: 456 };});
|
||||
app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.get("/settings",info.runtimeSettings);
|
||||
|
@@ -58,7 +58,7 @@ describe("api/auth/index",function() {
|
||||
|
||||
describe("revoke", function() {
|
||||
it("revokes a token", function(done) {
|
||||
var revokeToken = sinon.stub(Tokens,"revoke",function() {
|
||||
var revokeToken = sinon.stub(Tokens,"revoke").callsFake(function() {
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
@@ -79,8 +79,8 @@ describe("api/auth/index",function() {
|
||||
|
||||
describe("login", function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(Tokens,"init",function(){});
|
||||
sinon.stub(Users,"init",function(){});
|
||||
sinon.stub(Tokens,"init").callsFake(function(){});
|
||||
sinon.stub(Users,"init").callsFake(function(){});
|
||||
});
|
||||
afterEach(function() {
|
||||
Tokens.init.restore();
|
||||
@@ -119,8 +119,8 @@ describe("api/auth/index",function() {
|
||||
});
|
||||
describe("needsPermission", function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(Tokens,"init",function(){});
|
||||
sinon.stub(Users,"init",function(){});
|
||||
sinon.stub(Tokens,"init").callsFake(function(){});
|
||||
sinon.stub(Users,"init").callsFake(function(){});
|
||||
});
|
||||
afterEach(function() {
|
||||
Tokens.init.restore();
|
||||
@@ -135,7 +135,7 @@ describe("api/auth/index",function() {
|
||||
|
||||
|
||||
it('no-ops if adminAuth not set', function(done) {
|
||||
sinon.stub(passport,"authenticate",function(scopes,opts) {
|
||||
sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
|
||||
return function(req,res,next) {
|
||||
}
|
||||
});
|
||||
@@ -147,12 +147,12 @@ describe("api/auth/index",function() {
|
||||
})
|
||||
});
|
||||
it('skips auth if req.user undefined', function(done) {
|
||||
sinon.stub(passport,"authenticate",function(scopes,opts) {
|
||||
sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
|
||||
return function(req,res,next) {
|
||||
next();
|
||||
}
|
||||
});
|
||||
sinon.stub(Permissions,"hasPermission",function(perm) { return true });
|
||||
sinon.stub(Permissions,"hasPermission").callsFake(function(perm) { return true });
|
||||
auth.init({adminAuth:{}});
|
||||
var func = auth.needsPermission("foo");
|
||||
func({user:null},{},function() {
|
||||
@@ -167,12 +167,12 @@ describe("api/auth/index",function() {
|
||||
});
|
||||
|
||||
it('passes for valid user permission', function(done) {
|
||||
sinon.stub(passport,"authenticate",function(scopes,opts) {
|
||||
sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
|
||||
return function(req,res,next) {
|
||||
next();
|
||||
}
|
||||
});
|
||||
sinon.stub(Permissions,"hasPermission",function(perm) { return true });
|
||||
sinon.stub(Permissions,"hasPermission").callsFake(function(perm) { return true });
|
||||
auth.init({adminAuth:{}});
|
||||
var func = auth.needsPermission("foo");
|
||||
func({user:true,authInfo: { scope: "read"}},{},function() {
|
||||
@@ -189,12 +189,12 @@ describe("api/auth/index",function() {
|
||||
});
|
||||
|
||||
it('rejects for invalid user permission', function(done) {
|
||||
sinon.stub(passport,"authenticate",function(scopes,opts) {
|
||||
sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
|
||||
return function(req,res,next) {
|
||||
next();
|
||||
}
|
||||
});
|
||||
sinon.stub(Permissions,"hasPermission",function(perm) { return false });
|
||||
sinon.stub(Permissions,"hasPermission").callsFake(function(perm) { return false });
|
||||
auth.init({adminAuth:{}});
|
||||
var func = auth.needsPermission("foo");
|
||||
func({user:true,authInfo: { scope: "read"}},{
|
||||
|
@@ -35,7 +35,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
|
||||
it('Handles authentication failure',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
|
||||
it('Handles scope overreach',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
|
||||
return Promise.resolve({username:"user",permissions:"read"});
|
||||
});
|
||||
|
||||
@@ -67,11 +67,11 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
|
||||
it('Creates new token on authentication success',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
|
||||
return Promise.resolve({username:"user",permissions:"*"});
|
||||
});
|
||||
var tokenDetails = {};
|
||||
var tokenCreate = sinon.stub(Tokens,"create",function(username,client,scope) {
|
||||
var tokenCreate = sinon.stub(Tokens,"create").callsFake(function(username,client,scope) {
|
||||
tokenDetails.username = username;
|
||||
tokenDetails.client = client;
|
||||
tokenDetails.scope = scope;
|
||||
@@ -98,7 +98,7 @@ describe("api/auth/strategies", function() {
|
||||
|
||||
describe("Anonymous Strategy", function() {
|
||||
it('Succeeds if anon user enabled',function(done) {
|
||||
var userDefault = sinon.stub(Users,"default",function() {
|
||||
var userDefault = sinon.stub(Users,"default").callsFake(function() {
|
||||
return Promise.resolve("anon");
|
||||
});
|
||||
strategies.anonymousStrategy._success = strategies.anonymousStrategy.success;
|
||||
@@ -111,7 +111,7 @@ describe("api/auth/strategies", function() {
|
||||
strategies.anonymousStrategy.authenticate({});
|
||||
});
|
||||
it('Fails if anon user not enabled',function(done) {
|
||||
var userDefault = sinon.stub(Users,"default",function() {
|
||||
var userDefault = sinon.stub(Users,"default").callsFake(function() {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
strategies.anonymousStrategy._fail = strategies.anonymousStrategy.fail;
|
||||
@@ -130,10 +130,10 @@ describe("api/auth/strategies", function() {
|
||||
|
||||
describe("Tokens Strategy", function() {
|
||||
it('Succeeds if tokens user enabled custom header',function(done) {
|
||||
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
||||
var userTokens = sinon.stub(Users,"tokens").callsFake(function(token) {
|
||||
return Promise.resolve("tokens-"+token);
|
||||
});
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader").callsFake(function(token) {
|
||||
return "x-test-token";
|
||||
});
|
||||
strategies.tokensStrategy._success = strategies.tokensStrategy.success;
|
||||
@@ -146,10 +146,10 @@ describe("api/auth/strategies", function() {
|
||||
strategies.tokensStrategy.authenticate({headers:{"x-test-token":"1234"}});
|
||||
});
|
||||
it('Succeeds if tokens user enabled default header',function(done) {
|
||||
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
||||
var userTokens = sinon.stub(Users,"tokens").callsFake(function(token) {
|
||||
return Promise.resolve("tokens-"+token);
|
||||
});
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader").callsFake(function(token) {
|
||||
return "authorization";
|
||||
});
|
||||
strategies.tokensStrategy._success = strategies.tokensStrategy.success;
|
||||
@@ -162,10 +162,10 @@ describe("api/auth/strategies", function() {
|
||||
strategies.tokensStrategy.authenticate({headers:{"authorization":"Bearer 1234"}});
|
||||
});
|
||||
it('Fails if tokens user not enabled',function(done) {
|
||||
var userTokens = sinon.stub(Users,"tokens",function() {
|
||||
var userTokens = sinon.stub(Users,"tokens").callsFake(function() {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader").callsFake(function(token) {
|
||||
return "authorization";
|
||||
});
|
||||
strategies.tokensStrategy._fail = strategies.tokensStrategy.fail;
|
||||
@@ -185,7 +185,7 @@ describe("api/auth/strategies", function() {
|
||||
|
||||
describe("Bearer Strategy", function() {
|
||||
it('Rejects invalid token',function(done) {
|
||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
var getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
@@ -202,10 +202,10 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
});
|
||||
it('Accepts valid token',function(done) {
|
||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
var getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
|
||||
return Promise.resolve({user:"user",scope:"scope"});
|
||||
});
|
||||
var getUser = sinon.stub(Users,"get",function(username) {
|
||||
var getUser = sinon.stub(Users,"get").callsFake(function(username) {
|
||||
return Promise.resolve("aUser");
|
||||
});
|
||||
|
||||
@@ -224,10 +224,10 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
});
|
||||
it('Fail if no user for token',function(done) {
|
||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
var getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
|
||||
return Promise.resolve({user:"user",scope:"scope"});
|
||||
});
|
||||
var getUser = sinon.stub(Users,"get",function(username) {
|
||||
var getUser = sinon.stub(Users,"get").callsFake(function(username) {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
@@ -250,7 +250,7 @@ describe("api/auth/strategies", function() {
|
||||
describe("Client Password Strategy", function() {
|
||||
it('Accepts valid client',function(done) {
|
||||
var testClient = {id:"node-red-editor",secret:"not_available"};
|
||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||
var getClient = sinon.stub(Clients,"get").callsFake(function(client) {
|
||||
return Promise.resolve(testClient);
|
||||
});
|
||||
|
||||
@@ -268,7 +268,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
it('Rejects invalid client secret',function(done) {
|
||||
var testClient = {id:"node-red-editor",secret:"not_available"};
|
||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||
var getClient = sinon.stub(Clients,"get").callsFake(function(client) {
|
||||
return Promise.resolve(testClient);
|
||||
});
|
||||
|
||||
@@ -285,7 +285,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
});
|
||||
it('Rejects invalid client id',function(done) {
|
||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||
var getClient = sinon.stub(Clients,"get").callsFake(function(client) {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) {
|
||||
@@ -303,7 +303,7 @@ describe("api/auth/strategies", function() {
|
||||
|
||||
var userAuthentication;
|
||||
it('Blocks after 5 failures',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
for (var z=0; z<5; z++) {
|
||||
|
@@ -58,7 +58,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -126,7 +126,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {disableEditor:true}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -164,7 +164,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {httpAdminRoot:"/adminPath"}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -202,7 +202,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {httpAdminRoot:"/adminPath/"}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -240,7 +240,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {httpAdminRoot:"adminPath"}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -278,7 +278,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {webSocketKeepAliveTime: 100}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -344,22 +344,22 @@ describe("api/editor/comms", function() {
|
||||
var getToken;
|
||||
var getUserToken;
|
||||
before(function(done) {
|
||||
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
getUser = sinon.stub(Users,"get", function(username) {
|
||||
getDefaultUser = sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
|
||||
getUser = sinon.stub(Users,"get").callsFake(function(username) {
|
||||
if (username == "fred") {
|
||||
return Promise.resolve({permissions:"read"});
|
||||
} else {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
getUserToken = sinon.stub(Users,"tokens", function(token) {
|
||||
getUserToken = sinon.stub(Users,"tokens").callsFake(function(token) {
|
||||
if (token == "abcde") {
|
||||
return Promise.resolve({user:"wilma", permissions:"*"})
|
||||
} else {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
|
||||
if (token == "1234") {
|
||||
return Promise.resolve({user:"fred",scope:["*"]});
|
||||
} else if (token == "5678") {
|
||||
@@ -483,7 +483,7 @@ describe("api/editor/comms", function() {
|
||||
var port;
|
||||
var getDefaultUser;
|
||||
before(function(done) {
|
||||
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve({permissions:"read"});});
|
||||
getDefaultUser = sinon.stub(Users,"default").callsFake(function() { return Promise.resolve({permissions:"read"});});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {adminAuth:{}}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
|
@@ -32,8 +32,8 @@ describe("api/editor/index", function() {
|
||||
var app;
|
||||
describe("disabled the editor", function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(comms,'init', function(){});
|
||||
sinon.stub(info,'init', function(){});
|
||||
sinon.stub(comms,'init').callsFake(function(){});
|
||||
sinon.stub(info,'init').callsFake(function(){});
|
||||
});
|
||||
afterEach(function() {
|
||||
comms.init.restore();
|
||||
@@ -54,13 +54,13 @@ describe("api/editor/index", function() {
|
||||
var errors = [];
|
||||
var session_data = {};
|
||||
before(function() {
|
||||
sinon.stub(auth,'needsPermission',function(permission) {
|
||||
sinon.stub(auth,'needsPermission').callsFake(function(permission) {
|
||||
return function(req,res,next) { next(); }
|
||||
});
|
||||
mockList.forEach(function(m) {
|
||||
sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/"+m),"init",function(){});
|
||||
sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/"+m),"init").callsFake(function(){});
|
||||
});
|
||||
sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme"),"app",function(){ return express()});
|
||||
sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme"),"app").callsFake(function(){ return express()});
|
||||
});
|
||||
after(function() {
|
||||
mockList.forEach(function(m) {
|
||||
@@ -72,7 +72,7 @@ describe("api/editor/index", function() {
|
||||
});
|
||||
|
||||
before(function() {
|
||||
sinon.stub(log,"error",function(err) { errors.push(err)})
|
||||
sinon.stub(log,"error").callsFake(function(err) { errors.push(err)})
|
||||
app = editorApi.init({},{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false,exportNodeSettings:function(){}},{
|
||||
isStarted: () => Promise.resolve(isStarted)
|
||||
});
|
||||
|
@@ -50,9 +50,9 @@ describe("api/editor/locales", function() {
|
||||
locales.init({});
|
||||
|
||||
// bit of a mess of internal workings
|
||||
sinon.stub(i18n.i,'changeLanguage',function(lang,callback) { if (callback) {callback();}});
|
||||
sinon.stub(i18n.i,'changeLanguage').callsFake(function(lang,callback) { if (callback) {callback();}});
|
||||
if (i18n.i.getResourceBundle) {
|
||||
sinon.stub(i18n.i,'getResourceBundle',function(lang, namespace) {return {namespace:namespace, lang:lang};});
|
||||
sinon.stub(i18n.i,'getResourceBundle').callsFake(function(lang, namespace) {return {namespace:namespace, lang:lang};});
|
||||
} else {
|
||||
// If i18n.init has not been called, then getResourceBundle isn't
|
||||
// defined - so hardcode a stub
|
||||
@@ -121,7 +121,7 @@ describe("api/editor/locales", function() {
|
||||
// var app;
|
||||
// before(function() {
|
||||
// // bit of a mess of internal workings
|
||||
// sinon.stub(i18n,'catalog',function(namespace, lang) {
|
||||
// sinon.stub(i18n,'catalog').callsFake(function(namespace, lang) {
|
||||
// return {
|
||||
// "node-red": "should not return",
|
||||
// "test-module-a-id": "test-module-a-catalog",
|
||||
|
@@ -29,7 +29,7 @@ var theme = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme");
|
||||
|
||||
describe("api/editor/settings", function() {
|
||||
before(function() {
|
||||
sinon.stub(theme,"settings",function() { return { existing: 123, test: 456 };});
|
||||
sinon.stub(theme,"settings").callsFake(function() { return { existing: 123, test: 456 };});
|
||||
app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.get("/settings/user",function(req,res,next) {req.user = "fred"; next()}, info.userSettings);
|
||||
|
@@ -27,7 +27,7 @@ var theme = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme");
|
||||
|
||||
describe("api/editor/theme", function () {
|
||||
beforeEach(function () {
|
||||
sinon.stub(fs, "statSync", function () { return true; });
|
||||
sinon.stub(fs, "statSync").callsFake(function () { return true; });
|
||||
});
|
||||
afterEach(function () {
|
||||
theme.init({settings: {}});
|
||||
|
@@ -31,18 +31,18 @@ var apiAdmin = NR_TEST_UTILS.require("@node-red/editor-api/lib/admin");
|
||||
|
||||
describe("api/index", function() {
|
||||
var beforeEach = function() {
|
||||
sinon.stub(apiAuth,"init",function(){});
|
||||
sinon.stub(apiEditor,"init",function(){
|
||||
sinon.stub(apiAuth,"init").callsFake(function(){});
|
||||
sinon.stub(apiEditor,"init").callsFake(function(){
|
||||
var app = express();
|
||||
app.get("/editor",function(req,res) { res.status(200).end(); });
|
||||
return app;
|
||||
});
|
||||
sinon.stub(apiAdmin,"init",function(){
|
||||
sinon.stub(apiAdmin,"init").callsFake(function(){
|
||||
var app = express();
|
||||
app.get("/admin",function(req,res) { res.status(200).end(); });
|
||||
return app;
|
||||
});
|
||||
sinon.stub(apiAuth,"login",function(req,res){
|
||||
sinon.stub(apiAuth,"login").callsFake(function(req,res){
|
||||
res.status(200).end();
|
||||
});
|
||||
};
|
||||
@@ -115,7 +115,7 @@ describe("api/index", function() {
|
||||
describe('initialises api with authentication enabled', function(done) {
|
||||
|
||||
it('enables an oauth/openID based authentication mechanism',function(done) {
|
||||
const stub = sinon.stub(apiAuth, 'genericStrategy', function(){});
|
||||
const stub = sinon.stub(apiAuth, 'genericStrategy').callsFake(function(){});
|
||||
const adminAuth = { type: 'strategy', strategy: {} }
|
||||
api.init({ httpAdminRoot: true, adminAuth },{},{},{});
|
||||
should(stub.called).be.ok();
|
||||
@@ -159,7 +159,7 @@ describe("api/index", function() {
|
||||
describe('editor start', function (done) {
|
||||
|
||||
it('cannot be started when editor is disabled', function (done) {
|
||||
const stub = sinon.stub(apiEditor, 'start', function () {
|
||||
const stub = sinon.stub(apiEditor, 'start').callsFake(function () {
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
api.init({ httpAdminRoot: true, disableEditor: true }, {}, {}, {});
|
||||
|
@@ -33,8 +33,8 @@ describe("api/util", function() {
|
||||
var app;
|
||||
before(function() {
|
||||
app = express();
|
||||
sinon.stub(log,'error',function(msg) {loggedError = msg;});
|
||||
sinon.stub(log,'audit',function(event) {loggedEvent = event;});
|
||||
sinon.stub(log,'error').callsFake(function(msg) {loggedError = msg;});
|
||||
sinon.stub(log,'audit').callsFake(function(event) {loggedEvent = event;});
|
||||
app.get("/tooLarge", function(req,res) {
|
||||
var err = new Error();
|
||||
err.message = "request entity too large";
|
||||
|
Reference in New Issue
Block a user