]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java
upd: redesign of find cert result page
[gigi.git] / tests / club / wpia / gigi / pages / admin / TestSEAdminPageCertSearch.java
index 6feaafcf51613eba70b3bd3baf49f09ad70f061a..0d556419bbdd8095139b60928eda63925bce1f39 100644 (file)
@@ -1,5 +1,6 @@
 package club.wpia.gigi.pages.admin;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
@@ -19,19 +20,17 @@ import club.wpia.gigi.dbObjects.Certificate.CertificateStatus;
 import club.wpia.gigi.dbObjects.Certificate.RevocationType;
 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.output.template.Template;
 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.testUtils.SEClientTest;
 import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
 import club.wpia.gigi.util.ServerConstants;
 import club.wpia.gigi.util.ServerConstants.Host;
 
-public class TestSEAdminPageCertSearch extends ClientTest {
+public class TestSEAdminPageCertSearch extends SEClientTest {
 
     private Certificate c;
 
@@ -40,10 +39,6 @@ public class TestSEAdminPageCertSearch extends ClientTest {
     private int id;
 
     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";
         id = createVerifiedUser("fn", "ln", certMail, TEST_PASSWORD);
         c = createCertificate();
@@ -52,13 +47,13 @@ public class TestSEAdminPageCertSearch extends ClientTest {
     @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"));
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + 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"));
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), uc.getHeaderField("Location"));
     }
 
     @Test
@@ -71,9 +66,9 @@ public class TestSEAdminPageCertSearch extends ClientTest {
     }
 
     @Test
-    public void testRevoke() throws IOException, GeneralSecurityException, GigiApiException, InterruptedException {
+    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("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), conn.getHeaderField("Location"));
         for (int i = 0; i < 2; i++) {
             TestMail tm = getMailReceiver().receive(i == 0 ? ServerConstants.getSupportMailAddress() : certMail);
             assertThat(tm.getMessage(), CoreMatchers.containsString(certMail));
@@ -95,6 +90,24 @@ public class TestSEAdminPageCertSearch extends ClientTest {
         assertThat(result, CoreMatchers.containsString("N/A"));
     }
 
+    @Test
+    public void testShowDraft() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException {
+        KeyPair kp = generateKeypair();
+        String key = generatePEMCSR(kp, "CN=" + certMail);
+        Certificate c1 = new Certificate(u, u, Certificate.buildDN("CN", certMail), Digest.SHA512, key, CSRType.CSR, getClientProfile(), new Certificate.SubjectAlternateName(SANType.EMAIL, certMail));
+        URLConnection uc = post(cookie, FindCertPage.PATH, "certType=email&process=Next&cert=" + URLEncoder.encode(certMail, "UTF-8"), 0);
+        String result = IOUtils.readURL(uc);
+        assertThat(result, CoreMatchers.containsString(c.getSerial()));
+        assertThat(result, CoreMatchers.containsString("Draft"));
+
+        await(c1.issue(null, "2y", u));
+        uc = post(cookie, FindCertPage.PATH, "certType=email&process=Next&cert=" + URLEncoder.encode(certMail, "UTF-8"), 0);
+        result = IOUtils.readURL(uc);
+        assertThat(result, CoreMatchers.containsString(c.getSerial()));
+        assertThat(result, CoreMatchers.containsString(c1.getSerial()));
+        assertThat(result, not(CoreMatchers.containsString("Draft")));
+    }
+
     private Certificate createCertificate() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException {
         User u1 = User.getById(id);
         KeyPair kp = generateKeypair();