mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Fix tests
This commit is contained in:
parent
69f802d442
commit
7991af06d4
4 changed files with 18 additions and 14 deletions
|
@ -175,7 +175,10 @@ public class ModifyKeys {
|
||||||
assertEquals(4, info.getPublicKeys().size());
|
assertEquals(4, info.getPublicKeys().size());
|
||||||
List<OpenPGPCertificate.OpenPGPComponentKey> encryptionSubkeys = info.getEncryptionSubkeys(EncryptionPurpose.COMMUNICATIONS);
|
List<OpenPGPCertificate.OpenPGPComponentKey> encryptionSubkeys = info.getEncryptionSubkeys(EncryptionPurpose.COMMUNICATIONS);
|
||||||
assertEquals(2, encryptionSubkeys.size());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
package org.pgpainless.key;
|
package org.pgpainless.key;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
|
@ -68,7 +67,7 @@ public class TestMergeCertificate {
|
||||||
"-----END PGP SIGNATURE-----";
|
"-----END PGP SIGNATURE-----";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRevocationStateWithDifferentRevocationsMerged() throws IOException, PGPException {
|
public void testRevocationStateWithDifferentRevocationsMerged() throws IOException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,7 @@ public class OldSignatureSubpacketsArePreservedOnNewSigTest {
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
@ExtendWith(TestAllImplementations.class)
|
@ExtendWith(TestAllImplementations.class)
|
||||||
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig()
|
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig() {
|
||||||
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
|
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||||
.simpleEcKeyRing("Alice <alice@wonderland.lit>");
|
.simpleEcKeyRing("Alice <alice@wonderland.lit>");
|
||||||
|
|
||||||
|
|
|
@ -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.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.util.Date;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
|
@ -26,7 +25,7 @@ import org.pgpainless.util.selection.userid.SelectUserId;
|
||||||
public class RevokeUserIdsTest {
|
public class RevokeUserIdsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void revokeWithSelectUserId() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
public void revokeWithSelectUserId() throws PGPException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||||
|
@ -41,7 +40,9 @@ public class RevokeUserIdsTest {
|
||||||
assertTrue(info.isUserIdValid("Allice <alice@example.org>"));
|
assertTrue(info.isUserIdValid("Allice <alice@example.org>"));
|
||||||
assertTrue(info.isUserIdValid("Alice <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(
|
.revokeUserIds(
|
||||||
SelectUserId.containsEmailAddress("alice@example.org"),
|
SelectUserId.containsEmailAddress("alice@example.org"),
|
||||||
protector,
|
protector,
|
||||||
|
@ -50,14 +51,14 @@ public class RevokeUserIdsTest {
|
||||||
.withoutDescription())
|
.withoutDescription())
|
||||||
.done();
|
.done();
|
||||||
|
|
||||||
info = PGPainless.inspectKeyRing(secretKeys);
|
info = PGPainless.inspectKeyRing(secretKeys, n1);
|
||||||
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
|
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
|
||||||
assertFalse(info.isUserIdValid("Allice <alice@example.org>"));
|
assertFalse(info.isUserIdValid("Allice <alice@example.org>"));
|
||||||
assertFalse(info.isUserIdValid("Alice <alice@example.org>"));
|
assertFalse(info.isUserIdValid("Alice <alice@example.org>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeUserId() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
public void removeUserId() throws PGPException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||||
|
@ -72,11 +73,13 @@ public class RevokeUserIdsTest {
|
||||||
assertTrue(info.isUserIdValid("Allice <alice@example.org>"));
|
assertTrue(info.isUserIdValid("Allice <alice@example.org>"));
|
||||||
assertTrue(info.isUserIdValid("Alice <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)
|
.removeUserId("Allice <alice@example.org>", protector)
|
||||||
.done();
|
.done();
|
||||||
|
|
||||||
info = PGPainless.inspectKeyRing(secretKeys);
|
info = PGPainless.inspectKeyRing(secretKeys, n1);
|
||||||
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
|
assertTrue(info.isUserIdValid("Alice <alice@pgpainless.org>"));
|
||||||
assertFalse(info.isUserIdValid("Allice <alice@example.org>"));
|
assertFalse(info.isUserIdValid("Allice <alice@example.org>"));
|
||||||
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
|
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
|
||||||
|
@ -89,7 +92,7 @@ public class RevokeUserIdsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptySelectionYieldsNoSuchElementException() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
public void emptySelectionYieldsNoSuchElementException() {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue