Merge pull request #70 from mozilla/rfk/block-banned-emails

Block all actions for emails that are explicitly banned
This commit is contained in:
Andrew Chilton 2014-10-14 10:15:35 +13:00
Родитель 2c189ec8aa 9665f240eb
Коммит 66f0137a36
2 изменённых файлов: 19 добавлений и 3 удалений

Просмотреть файл

@ -81,8 +81,11 @@ module.exports = function (RATE_LIMIT_INTERVAL_MS, BLOCK_INTERVAL_MS, MAX_EMAILS
EmailRecord.prototype.isBlocked = function () {
var rateLimited = !!(this.rl && (now() - this.rl < RATE_LIMIT_INTERVAL_MS))
var banned = !!(this.bk && (now() - this.bk < BLOCK_INTERVAL_MS))
return rateLimited || banned
return rateLimited || this.isBanned()
}
EmailRecord.prototype.isBanned = function () {
return !!(this.bk && (now() - this.bk < BLOCK_INTERVAL_MS))
}
EmailRecord.prototype.block = function () {
@ -105,7 +108,7 @@ module.exports = function (RATE_LIMIT_INTERVAL_MS, BLOCK_INTERVAL_MS, MAX_EMAILS
}
EmailRecord.prototype.update = function (action) {
if (EMAIL_ACTIONS.indexOf(action) === -1) {
if (!this.isBanned() && EMAIL_ACTIONS.indexOf(action) === -1) {
return 0
}

Просмотреть файл

@ -208,6 +208,19 @@ test(
t.equal(er.update('accountCreate'), 0, 'email action above the email limit')
t.equal(er.isBlocked(), true, 'account is now blocked')
t.equal(er.update('accountCreate'), 0, 'email action in a blocked account')
er.rl = 2000
t.equal(er.isBlocked(), true, 'account is blocked')
t.equal(er.isBanned(), false, 'account is not outright banned')
t.equal(er.update('accountCreate'), 1, 'email action is blocked')
t.equal(er.update('accountLogin'), 0, 'non-email action is not blocked')
er.rl = 0
er.bk = 2000
t.equal(er.isBlocked(), true, 'account is blocked')
t.equal(er.isBanned(), true, 'account is outright banned')
t.equal(er.update('accountCreate'), 1, 'email action is blocked')
t.equal(er.update('accountLogin'), 1, 'non-email action is blocked')
t.end()
}
)