1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

Test revocation reason related code

This commit is contained in:
Paul Schaub 2021-01-21 14:59:55 +01:00
parent 87eab2fb9a
commit 93df791700
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -17,6 +17,7 @@ package org.pgpainless.key.modification;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; 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 static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException; import java.io.IOException;
@ -104,4 +105,24 @@ public class RevokeSubKeyTest {
assertEquals(SignatureType.KEY_REVOCATION.getCode(), keyRevocation.getSignatureType()); assertEquals(SignatureType.KEY_REVOCATION.getCode(), keyRevocation.getSignatureType());
assertEquals(SignatureType.SUBKEY_REVOCATION.getCode(), subkeyRevocation.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());
}
} }