1 package club.wpia.gigi.dbObjects;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.security.GeneralSecurityException;
7 import java.security.KeyPair;
11 import club.wpia.gigi.GigiApiException;
12 import club.wpia.gigi.dbObjects.Certificate.AttachmentType;
13 import club.wpia.gigi.dbObjects.Certificate.CSRType;
14 import club.wpia.gigi.testUtils.ClientBusinessTest;
16 public class TestCertificate extends ClientBusinessTest {
19 public void testSetLoginEnabled() throws GeneralSecurityException, IOException, GigiApiException {
20 KeyPair kp = generateKeypair();
21 String key = generatePEMCSR(kp, "CN=testmail@example.com");
22 Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "testmail@example.com"), Digest.SHA256, key, CSRType.CSR, getClientProfile());
24 assertFalse(c.isLoginEnabled());
25 c.setLoginEnabled(true);
26 assertTrue(c.isLoginEnabled());
27 c.setLoginEnabled(true);
28 assertTrue(c.isLoginEnabled());
29 c.setLoginEnabled(false);
30 assertFalse(c.isLoginEnabled());
31 c.setLoginEnabled(false);
32 assertFalse(c.isLoginEnabled());
36 public void testAttachment() throws GeneralSecurityException, IOException, GigiApiException {
37 KeyPair kp = generateKeypair();
38 String key = generatePEMCSR(kp, "CN=testmail@example.com");
39 Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "testmail@example.com"), Digest.SHA256, key, CSRType.CSR, getClientProfile());
40 assertNull(c.getAttachment(AttachmentType.CRT));
41 assertNull(c.getAttachment(AttachmentType.CSR));
42 c.addAttachment(AttachmentType.CSR, "a");
43 assertNull(c.getAttachment(AttachmentType.CRT));
44 assertEquals("a", c.getAttachment(AttachmentType.CSR));
46 c.addAttachment(AttachmentType.CSR, "different CSR");
47 fail("double add attachment must fail");
48 } catch (GigiApiException e) {
51 assertNull(c.getAttachment(AttachmentType.CRT));
52 assertEquals("a", c.getAttachment(AttachmentType.CSR));
54 c.addAttachment(AttachmentType.CRT, null);
55 fail("attachment must not be null");
56 } catch (GigiApiException e) {
59 assertNull(c.getAttachment(AttachmentType.CRT));
60 assertEquals("a", c.getAttachment(AttachmentType.CSR));
61 c.addAttachment(AttachmentType.CRT, "b");
62 assertEquals("a", c.getAttachment(AttachmentType.CSR));
63 assertEquals("b", c.getAttachment(AttachmentType.CRT));
65 c.addAttachment(AttachmentType.CRT, "different CRT");
66 fail("double add attachment must fail");
67 } catch (GigiApiException e) {
70 assertEquals("a", c.getAttachment(AttachmentType.CSR));
71 assertEquals("b", c.getAttachment(AttachmentType.CRT));