From 366a0403a63a99683f628b8904a00dc08f350334 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 5 Feb 2015 10:18:18 +0000 Subject: [PATCH] Clear rate limit in smoke tests --- .../coffee/infrastructure/RateLimiter.coffee | 5 ++- .../web/test/smoke/coffee/SmokeTests.coffee | 45 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/services/web/app/coffee/infrastructure/RateLimiter.coffee b/services/web/app/coffee/infrastructure/RateLimiter.coffee index cd0df4c43e..7c84fc9db7 100644 --- a/services/web/app/coffee/infrastructure/RateLimiter.coffee +++ b/services/web/app/coffee/infrastructure/RateLimiter.coffee @@ -9,4 +9,7 @@ module.exports = ratelimit = redback.createRateLimit(opts.endpointName) ratelimit.addCount opts.subjectName, opts.timeInterval, (err, callCount)-> shouldProcess = callCount < opts.throttle - callback(err, shouldProcess) \ No newline at end of file + callback(err, shouldProcess) + + clearRateLimit: (endpointName, subject, callback) -> + rclient.del "#{endpointName}:#{subject}", callback \ No newline at end of file diff --git a/services/web/test/smoke/coffee/SmokeTests.coffee b/services/web/test/smoke/coffee/SmokeTests.coffee index c2fce1b2d0..a882db1998 100644 --- a/services/web/test/smoke/coffee/SmokeTests.coffee +++ b/services/web/test/smoke/coffee/SmokeTests.coffee @@ -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("") - 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("") + 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 = """