]> WPIA git - gigi.git/commitdiff
add: test case verifying certificate overview.
authorFelix Dörre <felix@dogcraft.de>
Mon, 9 Nov 2015 08:48:10 +0000 (09:48 +0100)
committerFelix Dörre <felix@dogcraft.de>
Mon, 9 Nov 2015 08:48:10 +0000 (09:48 +0100)
tests/org/cacert/gigi/TestCertificate.java
tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java
tests/org/cacert/gigi/testUtils/ClientTest.java
tests/org/cacert/gigi/testUtils/ConfiguredTest.java
tests/org/cacert/gigi/testUtils/ManagedTest.java

index 63aa908f8e7ca367564a08c763e7a9e9398f6c12..6ec26d424bc25e610039f67ffe0e638e6ece52c0 100644 (file)
@@ -19,6 +19,8 @@ import org.cacert.gigi.dbObjects.Certificate.SubjectAlternateName;
 import org.cacert.gigi.dbObjects.CertificateProfile;
 import org.cacert.gigi.dbObjects.Digest;
 import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.pages.account.certs.Certificates;
+import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Test;
 
@@ -101,14 +103,19 @@ public class TestCertificate extends ManagedTest {
         testFails(CertificateStatus.DRAFT, c);
         c.issue(null, "2y", u).waitFor(60000);
 
+        String cookie = login(u.getEmail(), TEST_PASSWORD);
         testFails(CertificateStatus.ISSUED, c);
         X509Certificate cert = c.cert();
         assertNotNull(login(pk, cert));
+        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:revoked|issued)</td>"));
+        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:revoked|issued)</td>"));
         c.revoke().waitFor(60000);
 
         testFails(CertificateStatus.REVOKED, c);
         assertNull(login(pk, cert));
 
+        assertEquals(0, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:revoked|issued)</td>"));
+        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:revoked|issued)</td>"));
     }
 
     private void testFails(CertificateStatus status, Certificate c) throws IOException, GeneralSecurityException, SQLException, GigiApiException {
index 4d70f7776a3b3c077c1b729ac57250b4c8501589..b554a2c3390e1ff1782d586fe1dfdc2162d621e1 100644 (file)
@@ -49,20 +49,20 @@ public class TestSEAdminPageDetails extends ClientTest {
         int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
 
         String userCookie = login(email, TEST_PASSWORD);
-        assertEquals("Först", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+        assertEquals("Först", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
         // User can change his name
         assertNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
-        assertEquals("Kurti", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+        assertEquals("Kurti", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
         // But when assurer
         makeAssurer(id);
         // User cannot change his name, and the form changed
         assertNotNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti2&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
-        assertNull(getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
-        assertEquals("Kurti", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+        assertNull(getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
+        assertEquals("Kurti", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
 
         // but support still can
         assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti3&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0));
-        assertEquals("Kurti3", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+        assertEquals("Kurti3", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
 
     }
 
@@ -104,11 +104,11 @@ public class TestSEAdminPageDetails extends ClientTest {
     }
 
     private int logCountAdmin(int id) throws IOException {
-        return getLogEntryCount(IOUtils.readURL(get(UserHistory.SUPPORT_PATH.replace("*", Integer.toString(id)), 0)));
+        return getLogEntryCount(IOUtils.readURL(get(UserHistory.SUPPORT_PATH.replace("*", Integer.toString(id)))));
     }
 
     private int logCountUser(String cookie) throws IOException {
-        return getLogEntryCount(IOUtils.readURL(get(cookie, UserHistory.PATH, 0)));
+        return getLogEntryCount(IOUtils.readURL(get(cookie, UserHistory.PATH)));
     }
 
     private int getLogEntryCount(String readURL) {
index 5b565093752dc2da9adae939ddf0eaf8c59d3227..923fd97a70486ecdd14348a1aaefffd2a33e6330 100644 (file)
@@ -48,11 +48,7 @@ public abstract class ClientTest extends ManagedTest {
     }
 
     public HttpURLConnection get(String path) throws IOException {
-        return get(path, 0);
-    }
-
-    public HttpURLConnection get(String path, int formIndex) throws IOException {
-        return get(cookie, path, formIndex);
+        return get(cookie, path);
     }
 
 }
index f8098ed8f0da886944600f118fd7e1551e1ee55e..72461038453e1b4ebdf46e397b420cb57a756f3a 100644 (file)
@@ -12,6 +12,8 @@ import java.security.KeyPairGenerator;
 import java.security.Signature;
 import java.util.Properties;
 import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.util.PEM;
@@ -97,4 +99,13 @@ public abstract class ConfiguredTest {
         return "test" + System.currentTimeMillis() + "a" + (count++) + "u";
     }
 
+    public static int countRegex(String text, String pattern) {
+        Pattern p = Pattern.compile(pattern);
+        Matcher m = p.matcher(text);
+        int i = 0;
+        while (m.find()) {
+            i++;
+        }
+        return i;
+    }
 }
index 28628cb852b11374d50bcb2ee123817c0eefd4c8..0ae9f9a7b1de8bf4ca777502885509e8aef4428f 100644 (file)
@@ -473,7 +473,7 @@ public class ManagedTest extends ConfiguredTest {
         return (HttpURLConnection) uc;
     }
 
-    public HttpURLConnection get(String cookie, String path, int formIndex) throws IOException {
+    public HttpURLConnection get(String cookie, String path) throws IOException {
         URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
         uc.addRequestProperty("Cookie", cookie);
         return (HttpURLConnection) uc;