upd: rate limit bypassing for test cases
authorFelix Dörre <felix@dogcraft.de>
Mon, 2 May 2016 12:54:07 +0000 (14:54 +0200)
committerFelix Dörre <felix@dogcraft.de>
Mon, 2 May 2016 12:54:07 +0000 (14:54 +0200)
src/org/cacert/gigi/pages/account/certs/CertificateRequest.java
src/org/cacert/gigi/util/RateLimit.java
util-testing/org/cacert/gigi/DevelLauncher.java

index 270c71781d16e0ebabaa23190b7b9e76a8f4577b..eba64f17a484a8dff96078cadd496e5f03a15057 100644 (file)
@@ -431,7 +431,7 @@ public class CertificateRequest {
             throw error;
         }
         try {
-            if (limit.isLimitExceeded(Integer.toString(ctx.getActor().getId()))) {
+            if (RATE_LIMIT.isLimitExceeded(Integer.toString(ctx.getActor().getId()))) {
                 throw new GigiApiException("Rate Limit Exceeded");
             }
             return new Certificate(ctx.getTarget(), ctx.getActor(), subject, selectedDigest, //
@@ -443,7 +443,7 @@ public class CertificateRequest {
     }
 
     // 100 per 10 minutes
-    private static final RateLimit limit = new RateLimit(100, 10 * 60 * 1000);
+    public static final RateLimit RATE_LIMIT = new RateLimit(100, 10 * 60 * 1000);
 
     private String verifyName(GigiApiException error, PropertyTemplate nameTemp, PropertyTemplate wotUserTemp, String verifiedCN) {
         // real names,
index 46098bf5af2e86677640a4a932c5df80c4eb8d7e..65c1668494c05b03ecebd7d15ca5fbed1999031e 100644 (file)
@@ -70,4 +70,9 @@ public class RateLimit {
             }
         }
     }
+
+    public synchronized void bypass() {
+        set.clear();
+        feat.clear();
+    }
 }
index c32b6b30a6c83240735857e2283007119124466b..8c010bdc42bdf3105abd1b3dd9a5b794862e97db 100644 (file)
@@ -32,6 +32,8 @@ import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Template;
 import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.pages.account.certs.CertificateRequest;
+import org.cacert.gigi.pages.main.RegisterPage;
 import org.cacert.gigi.util.AuthorizationContext;
 import org.cacert.gigi.util.ServerConstants;
 import org.kamranzafar.jtar.TarEntry;
@@ -126,6 +128,8 @@ public class DevelLauncher {
                 @Override
                 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
                     ObjectCache.clearAllCaches();
+                    RegisterPage.RATE_LIMIT.bypass();
+                    CertificateRequest.RATE_LIMIT.bypass();
                     resp.getWriter().println("All caches cleared.");
                     System.out.println("Caches cleared.");