From e7ff9f0354c359fd3adb2647b98e00bda110e449 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 12 Jan 2020 19:55:34 +0100 Subject: [PATCH] =?UTF-8?q?JUnit=20test=20for=20Email=20selection=20strate?= =?UTF-8?q?gy=C2=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EmailKeyRingSelectionStrategyTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 pgpainless-core/src/test/java/org/pgpainless/key/selection/keyring/EmailKeyRingSelectionStrategyTest.java diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/selection/keyring/EmailKeyRingSelectionStrategyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/selection/keyring/EmailKeyRingSelectionStrategyTest.java new file mode 100644 index 00000000..b11ac827 --- /dev/null +++ b/pgpainless-core/src/test/java/org/pgpainless/key/selection/keyring/EmailKeyRingSelectionStrategyTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2020 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.key.selection.keyring; + +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; + +import java.io.IOException; + +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPPublicKey; +import org.bouncycastle.openpgp.PGPSecretKey; +import org.junit.Test; +import org.pgpainless.key.TestKeys; +import org.pgpainless.key.selection.keyring.impl.Email; + +public class EmailKeyRingSelectionStrategyTest { + + Email.PubRingSelectionStrategy pubKeySelectionStrategy = new Email.PubRingSelectionStrategy(); + Email.SecRingSelectionStrategy secKeySelectionStrategy = new Email.SecRingSelectionStrategy(); + + @Test + public void testMatchingEmailUIDAcceptedOnPubKey() throws IOException { + String uid = ""; + PGPPublicKey key = TestKeys.getEmilPublicKeyRing().getPublicKey(); + + assertTrue(pubKeySelectionStrategy.accept(uid, key)); + } + + @Test + public void testAddressIsFormattedToMatchOnPubKey() throws IOException { + String uid = "emil@email.user"; + PGPPublicKey key = TestKeys.getEmilPublicKeyRing().getPublicKey(); + + assertTrue(pubKeySelectionStrategy.accept(uid, key)); + } + + @Test + public void testPubKeyWithDifferentUIDIsRejected() throws IOException { + String wrongUid = "emilia@email.user"; + PGPPublicKey key = TestKeys.getEmilPublicKeyRing().getPublicKey(); + assertFalse(pubKeySelectionStrategy.accept(wrongUid, key)); + } + + @Test + public void testMatchingEmailUIDAcceptedOnSecKey() throws IOException, PGPException { + String uid = ""; + PGPSecretKey key = TestKeys.getEmilSecretKeyRing().getSecretKey(); + + assertTrue(secKeySelectionStrategy.accept(uid, key)); + } + + @Test + public void testAddressIsFormattedToMatchOnSecKey() throws IOException, PGPException { + String uid = "emil@email.user"; + PGPSecretKey key = TestKeys.getEmilSecretKeyRing().getSecretKey(); + + assertTrue(secKeySelectionStrategy.accept(uid, key)); + } + + @Test + public void testSecKeyWithDifferentUIDIsRejected() throws IOException, PGPException { + String wrongUid = "emilia@email.user"; + PGPSecretKey key = TestKeys.getEmilSecretKeyRing().getSecretKey(); + assertFalse(secKeySelectionStrategy.accept(wrongUid, key)); + } +}