add: tests for support certificates view
authorFelix Dörre <felix@dogcraft.de>
Fri, 18 Aug 2017 21:47:02 +0000 (23:47 +0200)
committerFelix Dörre <felix@dogcraft.de>
Fri, 18 Aug 2017 21:47:02 +0000 (23:47 +0200)
Change-Id: Ib56cb3ac8e08c217e4398f2171f253b02f0b130e

tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java [new file with mode: 0644]

diff --git a/tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java b/tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java
new file mode 100644 (file)
index 0000000..a42aef8
--- /dev/null
@@ -0,0 +1,78 @@
+package club.wpia.gigi.pages.admin;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.security.GeneralSecurityException;
+import java.security.KeyPair;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+
+import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.Certificate;
+import club.wpia.gigi.dbObjects.Certificate.CSRType;
+import club.wpia.gigi.dbObjects.Certificate.CertificateStatus;
+import club.wpia.gigi.dbObjects.Certificate.SANType;
+import club.wpia.gigi.dbObjects.Digest;
+import club.wpia.gigi.dbObjects.Group;
+import club.wpia.gigi.dbObjects.User;
+import club.wpia.gigi.pages.account.certs.Certificates;
+import club.wpia.gigi.pages.admin.support.FindCertPage;
+import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage;
+import club.wpia.gigi.testUtils.ClientTest;
+import club.wpia.gigi.testUtils.IOUtils;
+import club.wpia.gigi.util.ServerConstants;
+import club.wpia.gigi.util.ServerConstants.Host;
+
+public class TestSEAdminPageCertSearch extends ClientTest {
+
+    private Certificate c;
+
+    private String certMail;
+
+    public TestSEAdminPageCertSearch() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
+        grant(u, Group.SUPPORTER);
+        cookie = login(email, TEST_PASSWORD);
+        assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
+
+        certMail = uniq + "_certOwner@example.com";
+        int id = createVerifiedUser("fn", "ln", certMail, TEST_PASSWORD);
+        User u1 = User.getById(id);
+        KeyPair kp = generateKeypair();
+        String key = generatePEMCSR(kp, "CN=" + certMail);
+        c = new Certificate(u1, u1, Certificate.buildDN("CN", certMail), Digest.SHA512, key, CSRType.CSR, getClientProfile(), new Certificate.SubjectAlternateName(SANType.EMAIL, certMail));
+        await(c.issue(null, "2y", u));
+    }
+
+    @Test
+    public void testSerialSearch() throws IOException {
+        URLConnection uc = post(cookie, FindCertPage.PATH, "certType=serial&process=Next&cert=" + c.getSerial(), 0);
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), uc.getHeaderField("Location"));
+    }
+
+    @Test
+    public void testEmailSearch() throws IOException {
+        URLConnection uc = post(cookie, FindCertPage.PATH, "certType=email&process=Next&cert=" + URLEncoder.encode(certMail, "UTF-8"), 0);
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), uc.getHeaderField("Location"));
+    }
+
+    @Test
+    public void testDetails() throws IOException {
+        String s = IOUtils.readURL(get(Certificates.SUPPORT_PATH + "/" + c.getSerial()));
+        assertThat(s, CoreMatchers.containsString("SHA512"));
+        assertThat(s, CoreMatchers.containsString(certMail));
+        assertThat(s, CoreMatchers.containsString(c.getSerial()));
+        assertThat(s, CoreMatchers.containsString("ISSUED"));
+    }
+
+    @Test
+    public void testRevoke() throws IOException {
+        URLConnection conn = post(Certificates.SUPPORT_PATH + "/" + c.getSerial(), "action=revoke");
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), conn.getHeaderField("Location"));
+        assertEquals(CertificateStatus.REVOKED, c.getStatus());
+    }
+
+}