few more tests for permissions and strategies

reset log flags at end of log test
This commit is contained in:
dceejay
2015-03-07 13:22:21 +00:00
parent 69f85bd688
commit acc0e0875b
6 changed files with 72 additions and 27 deletions

View File

@@ -29,6 +29,9 @@ function hasPermission(user,permission) {
if (user.permissions == "read") {
return readRE.test(permission);
}
else {
return false; // anything not allowed is disallowed
}
}
module.exports = {

View File

@@ -61,11 +61,12 @@ var loginSignUpWindow = 36000000; // 10 minutes
var passwordTokenExchange = function(client, username, password, scope, done) {
var now = Date.now();
loginAttempts = loginAttempts.filter(function(logEntry) {
return logEntry.time + loginSignUpWindow > now;
return logEntry.time + loginSignUpWindow > now;
});
loginAttempts.push({time:now, user:username});
var attemptCount = 0;
loginAttempts.forEach(function(logEntry) {
/* istanbul ignore else */
if (logEntry.user == username) {
attemptCount++;
}
@@ -75,11 +76,11 @@ var passwordTokenExchange = function(client, username, password, scope, done) {
done(new Error("Too many login attempts. Wait 10 minutes and try again"),false);
return;
}
Users.authenticate(username,password).then(function(user) {
if (user) {
loginAttempts = loginAttempts.filter(function(logEntry) {
return logEntry.user !== username;
return logEntry.user !== username;
});
Tokens.create(username,client.id,scope).then(function(tokens) {
// TODO: audit log