mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
Add tests for PublicKeyAlgorithmPolicy
This commit is contained in:
parent
5bb4fd3687
commit
a65ea26181
2 changed files with 25 additions and 0 deletions
|
@ -15,9 +15,14 @@
|
|||
*/
|
||||
package org.pgpainless.policy;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
|
||||
public class PolicySetterTest {
|
||||
|
||||
|
@ -50,4 +55,21 @@ public class PolicySetterTest {
|
|||
Policy policy = Policy.getInstance();
|
||||
assertThrows(NullPointerException.class, () -> policy.setCompressionAlgorithmPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPublicKeyAlgorithmPolicy_NullFails() {
|
||||
Policy policy = Policy.getInstance();
|
||||
assertThrows(NullPointerException.class, () -> policy.setPublicKeyAlgorithmPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonRegisteredPublicKeyAlgorithm() {
|
||||
Policy policy = new Policy();
|
||||
Map<PublicKeyAlgorithm, Integer> acceptableAlgorithms = new HashMap<>();
|
||||
acceptableAlgorithms.put(PublicKeyAlgorithm.RSA_GENERAL, 2000);
|
||||
policy.setPublicKeyAlgorithmPolicy(new Policy.PublicKeyAlgorithmPolicy(acceptableAlgorithms));
|
||||
|
||||
// Policy does not contain ECDSA
|
||||
assertFalse(policy.getPublicKeyAlgorithmPolicy().isAcceptable(PublicKeyAlgorithm.ECDSA, 256));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,12 +136,15 @@ public class PolicyTest {
|
|||
@Test
|
||||
public void testAcceptablePublicKeyAlgorithm() {
|
||||
assertTrue(policy.getPublicKeyAlgorithmPolicy().isAcceptable(PublicKeyAlgorithm.ECDSA, 256));
|
||||
assertTrue(policy.getPublicKeyAlgorithmPolicy().isAcceptable(PublicKeyAlgorithm.ECDSA.getAlgorithmId(), 256));
|
||||
assertTrue(policy.getPublicKeyAlgorithmPolicy().isAcceptable(PublicKeyAlgorithm.RSA_GENERAL, 3072));
|
||||
assertTrue(policy.getPublicKeyAlgorithmPolicy().isAcceptable(PublicKeyAlgorithm.RSA_GENERAL.getAlgorithmId(), 3072));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnacceptablePublicKeyAlgorithm() {
|
||||
assertFalse(policy.getPublicKeyAlgorithmPolicy().isAcceptable(PublicKeyAlgorithm.RSA_GENERAL, 1024));
|
||||
assertFalse(policy.getPublicKeyAlgorithmPolicy().isAcceptable(PublicKeyAlgorithm.RSA_GENERAL.getAlgorithmId(), 1024));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue