1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 14:22:05 +01:00

Add tests for PublicKeyAlgorithmPolicy

This commit is contained in:
Paul Schaub 2021-06-11 16:47:22 +02:00
parent 5bb4fd3687
commit a65ea26181
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 25 additions and 0 deletions

View file

@ -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));
}
}

View file

@ -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