From f6e523685b41c12050c84b9791cfe0a259871b9d Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 25 Jul 2018 16:53:00 +0200 Subject: [PATCH] Improve tests --- .../java/org/pgpainless/BouncycastleExportSubkeys.java | 8 ++------ .../test/java/org/pgpainless/ImportExportKeyTest.java | 10 ++-------- .../test/java/org/pgpainless/KeyRingSubKeyFixTest.java | 8 +------- .../src/test/java/org/pgpainless/LengthTest.java | 6 +++--- .../java/org/pgpainless/OpenPgpV4FingerprintTest.java | 2 +- .../src/test/java/org/pgpainless/TestKeys.java | 2 +- 6 files changed, 10 insertions(+), 26 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/BouncycastleExportSubkeys.java b/pgpainless-core/src/test/java/org/pgpainless/BouncycastleExportSubkeys.java index 512d2639..76547318 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/BouncycastleExportSubkeys.java +++ b/pgpainless-core/src/test/java/org/pgpainless/BouncycastleExportSubkeys.java @@ -15,13 +15,11 @@ */ package org.pgpainless; -import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.Security; import java.util.Date; import org.bouncycastle.bcpg.CompressionAlgorithmTags; @@ -46,12 +44,10 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBu import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair; import org.junit.Test; -public class BouncycastleExportSubkeys { +public class BouncycastleExportSubkeys extends AbstractPGPainlessTest { @Test - public void testExportImport() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, PGPException, IOException { - Security.addProvider(new BouncyCastleProvider()); - + public void testExportImport() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, PGPException { KeyPairGenerator generator; KeyPair pair; diff --git a/pgpainless-core/src/test/java/org/pgpainless/ImportExportKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/ImportExportKeyTest.java index edcd2784..9ead5553 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/ImportExportKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/ImportExportKeyTest.java @@ -21,11 +21,9 @@ import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.Security; import java.util.Arrays; import java.util.Iterator; -import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPPublicKeyRing; @@ -34,14 +32,10 @@ import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; import org.junit.Test; import org.pgpainless.key.collection.PGPKeyRing; -public class ImportExportKeyTest { - - static { - Security.addProvider(new BouncyCastleProvider()); - } +public class ImportExportKeyTest extends AbstractPGPainlessTest { /** - * This test is failing. Not sure if a bug in BC or in my code... + * Test the export and import of a key ring with sub keys. * @throws PGPException very * @throws NoSuchAlgorithmException much * @throws NoSuchProviderException some diff --git a/pgpainless-core/src/test/java/org/pgpainless/KeyRingSubKeyFixTest.java b/pgpainless-core/src/test/java/org/pgpainless/KeyRingSubKeyFixTest.java index 46e0cb50..43bcfd45 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/KeyRingSubKeyFixTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/KeyRingSubKeyFixTest.java @@ -21,10 +21,8 @@ import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.Security; import java.util.Arrays; -import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; @@ -33,11 +31,7 @@ import org.pgpainless.key.collection.PGPKeyRing; import org.pgpainless.util.BCUtil; import org.pgpainless.util.KeyRingSubKeyFix; -public class KeyRingSubKeyFixTest { - - static { - Security.addProvider(new BouncyCastleProvider()); - } +public class KeyRingSubKeyFixTest extends AbstractPGPainlessTest { @Test public void test() diff --git a/pgpainless-core/src/test/java/org/pgpainless/LengthTest.java b/pgpainless-core/src/test/java/org/pgpainless/LengthTest.java index 0b730d65..7b4dd2c2 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/LengthTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/LengthTest.java @@ -66,11 +66,11 @@ public class LengthTest extends AbstractPGPainlessTest { // @Test public void RsaRsa4096() - throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, + throws PGPException, IOException { LOGGER.log(Level.INFO, "\nRSA-4096 -> RSA-4096"); - PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("simplejid@server.tld", RsaLength._4096); - PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("otherjid@other.srv", RsaLength._4096); + PGPKeyRing sender = PGPainless.readKeyRing().keyRing(TestKeys.JULIET_PUB, TestKeys.JULIET_SEC); + PGPKeyRing recipient = PGPainless.readKeyRing().keyRing(TestKeys.ROMEO_PUB, TestKeys.ROMEO_SEC); encryptDecryptForSecretKeyRings(sender, recipient); } diff --git a/pgpainless-core/src/test/java/org/pgpainless/OpenPgpV4FingerprintTest.java b/pgpainless-core/src/test/java/org/pgpainless/OpenPgpV4FingerprintTest.java index 0886dbf2..f3d5f5e8 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/OpenPgpV4FingerprintTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/OpenPgpV4FingerprintTest.java @@ -24,7 +24,7 @@ import org.bouncycastle.openpgp.PGPPublicKey; import org.junit.Test; import org.pgpainless.key.OpenPgpV4Fingerprint; -public class OpenPgpV4FingerprintTest { +public class OpenPgpV4FingerprintTest extends AbstractPGPainlessTest { @Test(expected = IllegalArgumentException.class) public void fpTooShort() { diff --git a/pgpainless-core/src/test/java/org/pgpainless/TestKeys.java b/pgpainless-core/src/test/java/org/pgpainless/TestKeys.java index e4a821bb..fbc4585e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/TestKeys.java +++ b/pgpainless-core/src/test/java/org/pgpainless/TestKeys.java @@ -27,7 +27,7 @@ import org.bouncycastle.openpgp.PGPUtil; import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator; import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; -public class TestKeys { +public class TestKeys extends AbstractPGPainlessTest { private static final KeyFingerPrintCalculator calc = new BcKeyFingerprintCalculator(); private static PGPSecretKeyRing julietSecretKeyRing = null;