Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(settings): Fix reloading of nested settings from mecmached (#133)…
Browse files Browse the repository at this point in the history
…; r=vbudhram
  • Loading branch information
rfk committed Oct 3, 2016
1 parent 029111d commit 101062c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/limits.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ module.exports = function (config, mc, log) {
this.ipRateLimitBanDurationMs = settings.ipRateLimitBanDurationSeconds * 1000
this.maxAccountStatusCheck = settings.maxAccountStatusCheck
this.badLoginErrnoWeights = settings.badLoginErrnoWeights || {}
this.maxChecksPerUid = settings.uidRateLimit.maxChecks
this.uidRateLimitBanDurationMs = settings.uidRateLimit.banDurationSeconds * 1000
this.uidRateLimitIntervalMs = settings.uidRateLimit.limitIntervalSeconds * 1000
this.uidRateLimit = settings.uidRateLimit || {}
this.maxChecksPerUid = this.uidRateLimit.maxChecks
this.uidRateLimitBanDurationMs = this.uidRateLimit.banDurationSeconds * 1000
this.uidRateLimitIntervalMs = this.uidRateLimit.limitIntervalSeconds * 1000
return this
}

Expand Down
37 changes: 36 additions & 1 deletion test/remote/config_update_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ test(
})
.then(function (bis) {
x = bis
return mcHelper.setLimits({ blockIntervalSeconds: bis + 1, uidRateLimit:{} })
return mcHelper.setLimits({ blockIntervalSeconds: bis + 1 })
})
.then(function (settings) {
t.equal(x + 1, settings.blockIntervalSeconds, 'helper sees the change')
// Wait for background polling to detect the new value in memcache
return Promise.delay(1010)
})
.then(function() {
Expand All @@ -76,6 +77,38 @@ test(
}
)

test(
'change nested limits',
function (t) {
var x = null
return client.getAsync('/limits')
.spread(function (req, res, obj) {
// This is derived from uidRateLimit.maxChecks
return obj.maxChecksPerUid
})
.then(function (mcpuid) {
x = mcpuid
return mcHelper.setLimits({ uidRateLimit: { maxChecks: mcpuid + 1 } })
})
.then(function (settings) {
t.equal(x + 1, settings.maxChecksPerUid, 'helper sees the change')
// Wait for background polling to detect the new value in memcache
return Promise.delay(1010)
})
.then(function() {
return client.getAsync('/limits')
})
.spread(function (req, res, obj) {
t.equal(x + 1, obj.maxChecksPerUid, 'server sees the change')
t.end()
})
.catch(function (err) {
t.fail(err)
t.end()
})
}
)

test(
'change allowedIPs',
function (t) {
Expand All @@ -88,6 +121,7 @@ test(
})
.then(function (ips) {
t.deepEqual(x, ips, 'helper sees the change')
// Wait for background polling to detect the new value in memcache
return Promise.delay(1010)
})
.then(function() {
Expand Down Expand Up @@ -116,6 +150,7 @@ test(
})
.then(function (ips) {
t.deepEqual(x, ips, 'helper sees the change')
// Wait for background polling to detect the new value in memcache
return Promise.delay(1010)
})
.then(function() {
Expand Down

0 comments on commit 101062c

Please sign in to comment.