1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-26 12:58:02 +01:00

Add RevokeUserIdsTest

This commit is contained in:
Paul Schaub 2021-12-27 13:49:31 +01:00
parent a0e9c1f555
commit d0ef8581e8
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 34 additions and 0 deletions

View file

@ -7,6 +7,8 @@ SPDX-License-Identifier: CC0-1.0
## 1.0.0-rc9-SNAPSHOT
- When key has both direct-key sig + primary user-id sig: resolve expiration date to earliest expiration
- Add `SecretKeyRingEditor.removeUserId()` convenience methods that do soft-revoke the user-id.
- Add `SelectUserId.byEmail()` which also matches the plain email address
## 1.0.0-rc8
- `KeyRingInfo.getPrimaryUserId()`: return first user-id when no primary user-id is found

View file

@ -14,6 +14,7 @@ import java.util.NoSuchElementException;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.key.info.KeyRingInfo;
@ -54,6 +55,37 @@ public class RevokeUserIdsTest {
assertFalse(info.isUserIdValid("Alice <alice@example.org>"));
}
@Test
public void removeUserId() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("Alice <alice@pgpainless.org>", null);
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
secretKeys = PGPainless.modifyKeyRing(secretKeys)
.addUserId("Allice <alice@example.org>", protector)
.addUserId("Alice <alice@example.org>", protector)
.done();
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
assertTrue(info.isUserIdValid("Allice <alice@example.org>"));
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
secretKeys = PGPainless.modifyKeyRing(secretKeys)
.removeUserId("Allice <alice@example.org>", protector)
.done();
info = PGPainless.inspectKeyRing(secretKeys);
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
assertFalse(info.isUserIdValid("Allice <alice@example.org>"));
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
PGPSignature revocation = info.getUserIdRevocation("Allice <alice@example.org>");
assertFalse(RevocationAttributes.Reason.isHardRevocation(
revocation.getHashedSubPackets().getRevocationReason().getRevocationReason()));
}
@Test
public void emptySelectionYieldsNoSuchElementException() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()