Clear rate limit in smoke tests

This commit is contained in:
James Allen 2015-02-05 10:18:18 +00:00
parent e35d80211e
commit 366a0403a6
2 changed files with 27 additions and 23 deletions

View file

@ -10,3 +10,6 @@ module.exports =
ratelimit.addCount opts.subjectName, opts.timeInterval, (err, callCount)->
shouldProcess = callCount < opts.throttle
callback(err, shouldProcess)
clearRateLimit: (endpointName, subject, callback) ->
rclient.del "#{endpointName}:#{subject}", callback

View file

@ -14,31 +14,32 @@ describe "Opening", ->
before (done) ->
require("../../../app/js/Features/Security/LoginRateLimiter.js").recordSuccessfulLogin Settings.smokeTest.user, ->
command = """
curl -H "X-Forwarded-Proto: https" -c #{cookeFilePath} #{buildUrl('register')}
"""
child.exec command, (err, stdout, stderr)->
if err? then done(err)
csrfMatches = stdout.match("<input name=\"_csrf\" type=\"hidden\" value=\"(.*?)\">")
if !csrfMatches?
logger.err stdout:stdout, "smoke test: does not have csrf token"
return done("smoke test: does not have csrf token")
csrf = csrfMatches[1]
require("../../../app/js/infrastructure/RateLimiter.js").clearRateLimit "open-project", "#{Settings.smokeTest.projectId}:#{Settings.smokeTest.userId}", ->
command = """
curl -H "X-Forwarded-Proto: https" -c #{cookeFilePath} #{buildUrl('register')}
"""
child.exec command, (err, stdout, stderr)->
if err? then done(err)
csrfMatches = stdout.match("<input name=\"_csrf\" type=\"hidden\" value=\"(.*?)\">")
if !csrfMatches?
logger.err stdout:stdout, "smoke test: does not have csrf token"
return done("smoke test: does not have csrf token")
csrf = csrfMatches[1]
# Change cookie to be non secure so curl will send it
fs = require("fs")
fs.readFile cookeFilePath, "utf8", (err, data) ->
return done(err) if err
firstTrue = data.indexOf("TRUE")
secondTrue = data.indexOf("TRUE", firstTrue+4)
result = data.slice(0, secondTrue)+"FALSE"+data.slice(secondTrue+4)
fs.writeFile cookeFilePath, result, "utf8", (err) ->
# Change cookie to be non secure so curl will send it
fs = require("fs")
fs.readFile cookeFilePath, "utf8", (err, data) ->
return done(err) if err
firstTrue = data.indexOf("TRUE")
secondTrue = data.indexOf("TRUE", firstTrue+4)
result = data.slice(0, secondTrue)+"FALSE"+data.slice(secondTrue+4)
fs.writeFile cookeFilePath, result, "utf8", (err) ->
return done(err) if err
command = """
curl -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d '{"_csrf":"#{csrf}", "email":"#{Settings.smokeTest.user}", "password":"#{Settings.smokeTest.password}"}' #{buildUrl('register')}
"""
child.exec command, done
command = """
curl -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d '{"_csrf":"#{csrf}", "email":"#{Settings.smokeTest.user}", "password":"#{Settings.smokeTest.password}"}' #{buildUrl('register')}
"""
child.exec command, done
after (done)->
command = """