mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +01:00
Add policy tests
This commit is contained in:
parent
7696f120e6
commit
ed8584df95
3 changed files with 193 additions and 1 deletions
|
@ -43,7 +43,7 @@ public final class Policy {
|
|||
CompressionAlgorithmPolicy.defaultCompressionAlgorithmPolicy();
|
||||
private final NotationRegistry notationRegistry = new NotationRegistry();
|
||||
|
||||
private Policy() {
|
||||
Policy() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2021 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pgpainless.policy;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PolicySetterTest {
|
||||
|
||||
@Test
|
||||
public void testSetSignatureHashAlgorithmPolicy_NullFails() {
|
||||
Policy policy = Policy.getInstance();
|
||||
assertThrows(NullPointerException.class, () -> policy.setSignatureHashAlgorithmPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRevocationSignatureHashAlgorithmPolicy_NullFails() {
|
||||
Policy policy = Policy.getInstance();
|
||||
assertThrows(NullPointerException.class, () -> policy.setRevocationSignatureHashAlgorithmPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSymmetricKeyEncryptionAlgorithmPolicy_NullFails() {
|
||||
Policy policy = Policy.getInstance();
|
||||
assertThrows(NullPointerException.class, () -> policy.setSymmetricKeyEncryptionAlgorithmPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSymmetricKeyDecryptionAlgorithmPolicy_NullFails() {
|
||||
Policy policy = Policy.getInstance();
|
||||
assertThrows(NullPointerException.class, () -> policy.setSymmetricKeyDecryptionAlgorithmPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCompressionAlgorithmPolicy_NullFails() {
|
||||
Policy policy = Policy.getInstance();
|
||||
assertThrows(NullPointerException.class, () -> policy.setCompressionAlgorithmPolicy(null));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright 2021 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pgpainless.policy;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
|
||||
public class PolicyTest {
|
||||
|
||||
private static Policy policy;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
policy = new Policy();
|
||||
policy.setCompressionAlgorithmPolicy(new Policy.CompressionAlgorithmPolicy(CompressionAlgorithm.UNCOMPRESSED,
|
||||
Arrays.asList(CompressionAlgorithm.ZIP, CompressionAlgorithm.ZLIB, CompressionAlgorithm.UNCOMPRESSED)));
|
||||
|
||||
policy.setSymmetricKeyEncryptionAlgorithmPolicy(new Policy.SymmetricKeyAlgorithmPolicy(SymmetricKeyAlgorithm.AES_256,
|
||||
Arrays.asList(SymmetricKeyAlgorithm.AES_256, SymmetricKeyAlgorithm.AES_192, SymmetricKeyAlgorithm.AES_128)));
|
||||
|
||||
policy.setSymmetricKeyDecryptionAlgorithmPolicy(new Policy.SymmetricKeyAlgorithmPolicy(SymmetricKeyAlgorithm.AES_256,
|
||||
Arrays.asList(SymmetricKeyAlgorithm.AES_256, SymmetricKeyAlgorithm.AES_192, SymmetricKeyAlgorithm.AES_128, SymmetricKeyAlgorithm.BLOWFISH)));
|
||||
|
||||
policy.setSignatureHashAlgorithmPolicy(new Policy.HashAlgorithmPolicy(HashAlgorithm.SHA512,
|
||||
Arrays.asList(HashAlgorithm.SHA512, HashAlgorithm.SHA384, HashAlgorithm.SHA256)));
|
||||
|
||||
policy.setRevocationSignatureHashAlgorithmPolicy(new Policy.HashAlgorithmPolicy(HashAlgorithm.SHA512,
|
||||
Arrays.asList(HashAlgorithm.SHA512, HashAlgorithm.SHA384, HashAlgorithm.SHA256, HashAlgorithm.SHA224, HashAlgorithm.SHA1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptableCompressionAlgorithm() {
|
||||
assertTrue(policy.getCompressionAlgorithmPolicy().isAcceptable(CompressionAlgorithm.ZIP));
|
||||
assertTrue(policy.getCompressionAlgorithmPolicy().isAcceptable(CompressionAlgorithm.ZIP.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnacceptableCompressionAlgorithm() {
|
||||
assertFalse(policy.getCompressionAlgorithmPolicy().isAcceptable(CompressionAlgorithm.BZIP2));
|
||||
assertFalse(policy.getCompressionAlgorithmPolicy().isAcceptable(CompressionAlgorithm.BZIP2.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultCompressionAlgorithm() {
|
||||
assertEquals(CompressionAlgorithm.UNCOMPRESSED, policy.getCompressionAlgorithmPolicy().defaultCompressionAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptableSymmetricKeyEncryptionAlgorithm() {
|
||||
assertTrue(policy.getSymmetricKeyEncryptionAlgorithmPolicy().isAcceptable(SymmetricKeyAlgorithm.AES_256));
|
||||
assertTrue(policy.getSymmetricKeyEncryptionAlgorithmPolicy().isAcceptable(SymmetricKeyAlgorithm.AES_256.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnAcceptableSymmetricKeyEncryptionAlgorithm() {
|
||||
assertFalse(policy.getSymmetricKeyEncryptionAlgorithmPolicy().isAcceptable(SymmetricKeyAlgorithm.BLOWFISH));
|
||||
assertFalse(policy.getSymmetricKeyEncryptionAlgorithmPolicy().isAcceptable(SymmetricKeyAlgorithm.BLOWFISH.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSymmetricKeyEncryptionAlgorithm() {
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, policy.getSymmetricKeyEncryptionAlgorithmPolicy().getDefaultSymmetricKeyAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptableSymmetricKeyDecryptionAlgorithm() {
|
||||
assertTrue(policy.getSymmetricKeyDecryptionAlgoritmPolicy().isAcceptable(SymmetricKeyAlgorithm.BLOWFISH));
|
||||
assertTrue(policy.getSymmetricKeyDecryptionAlgoritmPolicy().isAcceptable(SymmetricKeyAlgorithm.BLOWFISH.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnAcceptableSymmetricKeyDecryptionAlgorithm() {
|
||||
assertFalse(policy.getSymmetricKeyDecryptionAlgoritmPolicy().isAcceptable(SymmetricKeyAlgorithm.CAMELLIA_128));
|
||||
assertFalse(policy.getSymmetricKeyDecryptionAlgoritmPolicy().isAcceptable(SymmetricKeyAlgorithm.CAMELLIA_128.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptableSignatureHashAlgorithm() {
|
||||
assertTrue(policy.getSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.SHA512));
|
||||
assertTrue(policy.getSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.SHA512.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnacceptableSignatureHashAlgorithm() {
|
||||
assertFalse(policy.getSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.SHA1));
|
||||
assertFalse(policy.getSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.SHA1.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSignatureHashAlgorithm() {
|
||||
assertEquals(HashAlgorithm.SHA512, policy.getSignatureHashAlgorithmPolicy().defaultHashAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptableRevocationSignatureHashAlgorithm() {
|
||||
assertTrue(policy.getRevocationSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.SHA384));
|
||||
assertTrue(policy.getRevocationSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.SHA384.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnacceptableRevocationSignatureHashAlgorithm() {
|
||||
assertFalse(policy.getRevocationSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.RIPEMD160));
|
||||
assertFalse(policy.getRevocationSignatureHashAlgorithmPolicy().isAcceptable(HashAlgorithm.RIPEMD160.getAlgorithmId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultRevocationSignatureHashAlgorithm() {
|
||||
assertEquals(HashAlgorithm.SHA512, policy.getRevocationSignatureHashAlgorithmPolicy().defaultHashAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotationRegistry() {
|
||||
assertFalse(policy.getNotationRegistry().isKnownNotation("notation@pgpainless.org"));
|
||||
policy.getNotationRegistry().addKnownNotation("notation@pgpainless.org");
|
||||
assertTrue(policy.getNotationRegistry().isKnownNotation("notation@pgpainless.org"));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue