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:
@@ -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++) {
|
||||
|
Reference in New Issue
Block a user