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 assertEquals(key, c.getAttachment(AttachmentType.CSR));
43 c.addAttachment(AttachmentType.CSR, "different CSR");
44 fail("double add attachment must fail");
45 } catch (GigiApiException e) {
48 assertNull(c.getAttachment(AttachmentType.CRT));
49 assertEquals(key, c.getAttachment(AttachmentType.CSR));
51 c.addAttachment(AttachmentType.CRT, null);
52 fail("attachment must not be null");
53 } catch (GigiApiException e) {
56 assertNull(c.getAttachment(AttachmentType.CRT));
57 assertEquals(key, c.getAttachment(AttachmentType.CSR));
58 c.addAttachment(AttachmentType.CRT, "b");
59 assertEquals(key, c.getAttachment(AttachmentType.CSR));
60 assertEquals("b", c.getAttachment(AttachmentType.CRT));
62 c.addAttachment(AttachmentType.CRT, "different CRT");
63 fail("double add attachment must fail");
64 } catch (GigiApiException e) {
67 assertEquals(key, c.getAttachment(AttachmentType.CSR));
68 assertEquals("b", c.getAttachment(AttachmentType.CRT));