]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/dbObjects/TestCertificate.java
add: handling of who issued a certificate
[gigi.git] / tests / club / wpia / gigi / dbObjects / TestCertificate.java
index 519bd59e8acc98ac196f429bb97584295b910976..0b4d6549d962ceb255ad924d3622a74ac6f3c021 100644 (file)
@@ -9,8 +9,7 @@ import java.security.KeyPair;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
-import club.wpia.gigi.dbObjects.Certificate;
-import club.wpia.gigi.dbObjects.Digest;
+import club.wpia.gigi.dbObjects.Certificate.AttachmentType;
 import club.wpia.gigi.dbObjects.Certificate.CSRType;
 import club.wpia.gigi.testUtils.ClientBusinessTest;
 
@@ -32,4 +31,50 @@ public class TestCertificate extends ClientBusinessTest {
         c.setLoginEnabled(false);
         assertFalse(c.isLoginEnabled());
     }
+
+    @Test
+    public void testAttachment() throws GeneralSecurityException, IOException, GigiApiException {
+        KeyPair kp = generateKeypair();
+        String key = generatePEMCSR(kp, "CN=testmail@example.com");
+        Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "testmail@example.com"), Digest.SHA256, key, CSRType.CSR, getClientProfile());
+        assertNull(c.getAttachment(AttachmentType.CRT));
+        assertEquals(key, c.getAttachment(AttachmentType.CSR));
+        try {
+            c.addAttachment(AttachmentType.CSR, "different CSR");
+            fail("double add attachment must fail");
+        } catch (GigiApiException e) {
+            // expected
+        }
+        assertNull(c.getAttachment(AttachmentType.CRT));
+        assertEquals(key, c.getAttachment(AttachmentType.CSR));
+        try {
+            c.addAttachment(AttachmentType.CRT, null);
+            fail("attachment must not be null");
+        } catch (GigiApiException e) {
+            // expected
+        }
+        assertNull(c.getAttachment(AttachmentType.CRT));
+        assertEquals(key, c.getAttachment(AttachmentType.CSR));
+        c.addAttachment(AttachmentType.CRT, "b");
+        assertEquals(key, c.getAttachment(AttachmentType.CSR));
+        assertEquals("b", c.getAttachment(AttachmentType.CRT));
+        try {
+            c.addAttachment(AttachmentType.CRT, "different CRT");
+            fail("double add attachment must fail");
+        } catch (GigiApiException e) {
+            // expected
+        }
+        assertEquals(key, c.getAttachment(AttachmentType.CSR));
+        assertEquals("b", c.getAttachment(AttachmentType.CRT));
+    }
+
+    @Test
+    public void testActor() throws GeneralSecurityException, IOException, GigiApiException {
+        KeyPair kp = generateKeypair();
+        String key = generatePEMCSR(kp, "CN=testmail@example.com");
+        Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "testmail@example.com"), Digest.SHA256, key, CSRType.CSR, getClientProfile());
+
+        assertEquals(u, c.getActor());
+        assertEquals("AB", c.getActor().getInitials());
+    }
 }