X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2FdbObjects%2FTestCertificate.java;h=694bc491c8f514550664419d54528cecf9273b72;hp=519bd59e8acc98ac196f429bb97584295b910976;hb=c4c60e1b9446e5ab69b8431ce71a2fbe11d47ef5;hpb=8822b2ffdda7eb4109415a7867388a321ea6b56f diff --git a/tests/club/wpia/gigi/dbObjects/TestCertificate.java b/tests/club/wpia/gigi/dbObjects/TestCertificate.java index 519bd59e..694bc491 100644 --- a/tests/club/wpia/gigi/dbObjects/TestCertificate.java +++ b/tests/club/wpia/gigi/dbObjects/TestCertificate.java @@ -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,43 @@ 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)); + assertNull(c.getAttachment(AttachmentType.CSR)); + c.addAttachment(AttachmentType.CSR, "a"); + assertNull(c.getAttachment(AttachmentType.CRT)); + assertEquals("a", 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("a", 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("a", c.getAttachment(AttachmentType.CSR)); + c.addAttachment(AttachmentType.CRT, "b"); + assertEquals("a", 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("a", c.getAttachment(AttachmentType.CSR)); + assertEquals("b", c.getAttachment(AttachmentType.CRT)); + } }