From 93df791700a53485017746b1a51ce5244689a6d2 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 21 Jan 2021 14:59:55 +0100 Subject: [PATCH] Test revocation reason related code --- .../key/modification/RevokeSubKeyTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java index d86fe66b..e9b64f6e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java @@ -17,6 +17,7 @@ package org.pgpainless.key.modification; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; @@ -104,4 +105,24 @@ public class RevokeSubKeyTest { assertEquals(SignatureType.KEY_REVOCATION.getCode(), keyRevocation.getSignatureType()); assertEquals(SignatureType.SUBKEY_REVOCATION.getCode(), subkeyRevocation.getSignatureType()); } + + @Test + public void testThrowsIfRevocationReasonTypeMismatch() { + // Key revocation cannot have reason type USER_ID_NO_LONGER_VALID + assertThrows(IllegalArgumentException.class, () -> RevocationAttributes.createKeyRevocation() + .withReason(RevocationAttributes.Reason.USER_ID_NO_LONGER_VALID)); + // Cert revocations cannot have the reason types KEY_SUPERSEDED, KEY_COMPROMIZED, KEY_RETIRED + assertThrows(IllegalArgumentException.class, () -> RevocationAttributes.createCertificateRevocation() + .withReason(RevocationAttributes.Reason.KEY_SUPERSEDED)); + assertThrows(IllegalArgumentException.class, () -> RevocationAttributes.createCertificateRevocation() + .withReason(RevocationAttributes.Reason.KEY_COMPROMISED)); + assertThrows(IllegalArgumentException.class, () -> RevocationAttributes.createCertificateRevocation() + .withReason(RevocationAttributes.Reason.KEY_RETIRED)); + } + + @Test + public void testReasonToString() { + RevocationAttributes.Reason reason = RevocationAttributes.Reason.KEY_COMPROMISED; + assertEquals("2 - KEY_COMPROMISED", reason.toString()); + } }