]> WPIA git - gigi.git/commitdiff
Add: simple test for reping rate limiting.
authorFelix Dörre <felix@dogcraft.de>
Sat, 31 Jan 2015 23:58:11 +0000 (00:58 +0100)
committerFelix Dörre <felix@dogcraft.de>
Sat, 31 Jan 2015 23:58:11 +0000 (00:58 +0100)
tests/org/cacert/gigi/ping/TestHTTP.java

index dffab08f2413a05bfbe8fdc4f44934cf2f124e5b..64c9cd650e3e618d7c51cd194f3b70158554e7b1 100644 (file)
@@ -1,5 +1,6 @@
 package org.cacert.gigi.ping;
 
 package org.cacert.gigi.ping;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
 import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
@@ -13,6 +14,10 @@ import java.util.regex.Pattern;
 
 import javax.naming.NamingException;
 
 
 import javax.naming.NamingException;
 
+import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.Domain;
+import org.cacert.gigi.dbObjects.DomainPingConfiguration;
+import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
@@ -34,21 +39,21 @@ public class TestHTTP extends PingTest {
     }
 
     @Test
     }
 
     @Test
-    public void httpAndMailSuccess() throws IOException, InterruptedException, SQLException {
+    public void httpAndMailSuccess() throws Exception {
         testEmailAndHTTP(0, 0, true, true);
     }
 
     @Test
         testEmailAndHTTP(0, 0, true, true);
     }
 
     @Test
-    public void httpFailKeyAndMailSuccess() throws IOException, InterruptedException, SQLException {
+    public void httpFailKeyAndMailSuccess() throws Exception {
         testEmailAndHTTP(1, 0, false, true);
     }
 
     @Test
         testEmailAndHTTP(1, 0, false, true);
     }
 
     @Test
-    public void httpFailValAndMailFail() throws IOException, InterruptedException, SQLException {
+    public void httpFailValAndMailFail() throws Exception {
         testEmailAndHTTP(2, 1, false, false);
     }
 
         testEmailAndHTTP(2, 1, false, false);
     }
 
-    public void testEmailAndHTTP(int httpVariant, int emailVariant, boolean successHTTP, boolean successMail) throws IOException, InterruptedException, SQLException {
+    public void testEmailAndHTTP(int httpVariant, int emailVariant, boolean successHTTP, boolean successMail) throws IOException, InterruptedException, SQLException, GigiApiException {
 
         String test = getTestProps().getProperty("domain.http");
         assumeNotNull(test);
 
         String test = getTestProps().getProperty("domain.http");
         assumeNotNull(test);
@@ -78,6 +83,23 @@ public class TestHTTP extends PingTest {
         assertTrue(newcontent, !successHTTP ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successMail ^ pat.matcher(newcontent).find());
         assertTrue(newcontent, !successHTTP ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successMail ^ pat.matcher(newcontent).find());
+
+        if (successHTTP) { // give it a second try
+            int id = Integer.parseInt(u2.toString().replaceFirst("^.*/([0-9]+)$", "$1"));
+            Domain d = Domain.getById(id);
+            DomainPingConfiguration dpc = null;
+            for (DomainPingConfiguration conf : d.getConfiguredPings()) {
+                if (conf.getType() == PingType.HTTP) {
+                    dpc = conf;
+                    break;
+                }
+            }
+            if (dpc == null) {
+                fail("Http config not found");
+            }
+            String res = executeBasicWebInteraction(cookie, u2.getPath(), "configId=" + dpc.getId());
+            assertThat(res, containsString("only allowed after"));
+        }
     }
 
     private String readHTTP(String token) throws IOException {
     }
 
     private String readHTTP(String token) throws IOException {