1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 10:19:39 +02:00

Fix tests

This commit is contained in:
Paul Schaub 2025-02-07 13:19:56 +01:00
parent 7217eda924
commit d889d37de5
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 18 additions and 14 deletions

View file

@ -175,7 +175,10 @@ public class ModifyKeys {
assertEquals(4, info.getPublicKeys().size());
List<OpenPGPCertificate.OpenPGPComponentKey> encryptionSubkeys = info.getEncryptionSubkeys(EncryptionPurpose.COMMUNICATIONS);
assertEquals(2, encryptionSubkeys.size());
UnlockSecretKey.unlockSecretKey(secretKey.getSecretKey(encryptionSubkeys.get(1).getKeyIdentifier()), subkeyPassphrase);
OpenPGPCertificate.OpenPGPComponentKey addedKey = encryptionSubkeys.stream()
.filter(it -> !it.getKeyIdentifier().matches(encryptionSubkeyId)).findFirst()
.get();
UnlockSecretKey.unlockSecretKey(secretKey.getSecretKey(addedKey.getKeyIdentifier()), subkeyPassphrase);
}
/**

View file

@ -4,7 +4,6 @@
package org.pgpainless.key;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
@ -68,7 +67,7 @@ public class TestMergeCertificate {
"-----END PGP SIGNATURE-----";
@Test
public void testRevocationStateWithDifferentRevocationsMerged() throws IOException, PGPException {
public void testRevocationStateWithDifferentRevocationsMerged() throws IOException {
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);

View file

@ -28,8 +28,7 @@ public class OldSignatureSubpacketsArePreservedOnNewSigTest {
@TestTemplate
@ExtendWith(TestAllImplementations.class)
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig()
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig() {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.simpleEcKeyRing("Alice <alice@wonderland.lit>");

View file

@ -9,8 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.NoSuchElementException;
import org.bouncycastle.openpgp.PGPException;
@ -26,7 +25,7 @@ import org.pgpainless.util.selection.userid.SelectUserId;
public class RevokeUserIdsTest {
@Test
public void revokeWithSelectUserId() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
public void revokeWithSelectUserId() throws PGPException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("Alice <alice@pgpainless.org>");
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
@ -41,7 +40,9 @@ public class RevokeUserIdsTest {
assertTrue(info.isUserIdValid("Allice <alice@example.org>"));
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
secretKeys = PGPainless.modifyKeyRing(secretKeys)
Date n1 = new Date(info.getCreationDate().getTime() + 1000); // 1 sec later
secretKeys = PGPainless.modifyKeyRing(secretKeys, n1)
.revokeUserIds(
SelectUserId.containsEmailAddress("alice@example.org"),
protector,
@ -50,14 +51,14 @@ public class RevokeUserIdsTest {
.withoutDescription())
.done();
info = PGPainless.inspectKeyRing(secretKeys);
info = PGPainless.inspectKeyRing(secretKeys, n1);
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
assertFalse(info.isUserIdValid("Allice <alice@example.org>"));
assertFalse(info.isUserIdValid("Alice <alice@example.org>"));
}
@Test
public void removeUserId() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
public void removeUserId() throws PGPException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("Alice <alice@pgpainless.org>");
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
@ -72,11 +73,13 @@ public class RevokeUserIdsTest {
assertTrue(info.isUserIdValid("Allice <alice@example.org>"));
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
secretKeys = PGPainless.modifyKeyRing(secretKeys)
Date n1 = new Date(info.getCreationDate().getTime() + 1000);
secretKeys = PGPainless.modifyKeyRing(secretKeys, n1)
.removeUserId("Allice <alice@example.org>", protector)
.done();
info = PGPainless.inspectKeyRing(secretKeys);
info = PGPainless.inspectKeyRing(secretKeys, n1);
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
assertFalse(info.isUserIdValid("Allice <alice@example.org>"));
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
@ -89,7 +92,7 @@ public class RevokeUserIdsTest {
}
@Test
public void emptySelectionYieldsNoSuchElementException() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
public void emptySelectionYieldsNoSuchElementException() {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("Alice <alice@pgpainless.org>");