mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +01:00
Add test for CachingSecretKeyRingProtector.replacePassphrase(*)
This commit is contained in:
parent
c4e3e27821
commit
f8968fc075
1 changed files with 29 additions and 0 deletions
|
@ -7,7 +7,9 @@ package org.pgpainless.key.protection;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Iterator;
|
||||
|
@ -22,6 +24,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
||||
|
@ -132,4 +135,30 @@ public class CachingSecretKeyRingProtectorTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddPassphrase_collision() throws PGPException, IOException {
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
|
||||
CachingSecretKeyRingProtector protector = new CachingSecretKeyRingProtector();
|
||||
protector.addPassphrase(secretKeys, TestKeys.CRYPTIE_PASSPHRASE);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
protector.addPassphrase(secretKeys.getPublicKey(), Passphrase.emptyPassphrase()));
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
protector.addPassphrase(secretKeys, Passphrase.fromPassword("anotherPass")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplacePassphrase() throws PGPException, IOException {
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
|
||||
CachingSecretKeyRingProtector protector = new CachingSecretKeyRingProtector();
|
||||
protector.addPassphrase(secretKeys, Passphrase.fromPassword("wrong"));
|
||||
// no throwing
|
||||
protector.replacePassphrase(secretKeys, TestKeys.CRYPTIE_PASSPHRASE);
|
||||
|
||||
for (PGPSecretKey key : secretKeys) {
|
||||
UnlockSecretKey.unlockSecretKey(key, protector);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue