From e73c7e5f91bcd04f262ad0acd1ac5f1074131cbf Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 21 Jan 2023 21:17:57 +0100 Subject: [PATCH] Even more tests --- ...ternalDetachedSignVerifyRoundTripTest.java | 12 ++++++++++ .../ExternalEncryptDecryptRoundTripTest.java | 23 +++++++++++++------ .../sop/external/ExternalExtractCertTest.java | 3 +++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java index bdab4b5..cf04bd5 100644 --- a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java @@ -228,4 +228,16 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP .isEmpty()); } + @Test + public void verifyMissingCertCausesMissingArg() { + ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses picocli which throws + // UNSUPPORTED_OPTION for missing arg + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + + assertThrows(SOPGPException.MissingArg.class, () -> + getSop().verify() + .signatures(TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8)) + .data(message)); + } + } diff --git a/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java index 41bb861..3011a03 100644 --- a/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java @@ -30,7 +30,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest @Test public void encryptDecryptRoundTripPasswordTest() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() .withPassword("sw0rdf1sh") .plaintext(message) @@ -47,7 +47,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest @Test public void encryptDecryptRoundTripAliceTest() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .plaintext(message) @@ -67,7 +67,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest @Test public void encryptDecryptRoundTripBobTest() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() .withCert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8)) .plaintext(message) @@ -86,7 +86,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest public void encryptDecryptRoundTripCarolTest() throws IOException { ignoreIf("sqop", Is.geq, "0.0.0"); // sqop reports cert not encryption capable - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() .withCert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8)) .plaintext(message) @@ -105,7 +105,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest public void encryptNoArmorThenArmorThenDecryptRoundTrip() throws IOException { ignoreIf("sqop", Is.leq, "0.26.1"); // Invalid data type - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .noArmor() @@ -127,7 +127,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest @Test public void encryptSignDecryptVerifyRoundTripAliceTest() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) @@ -152,7 +152,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest @Test public void encryptSignAsTextDecryptVerifyRoundTripAliceTest() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) @@ -278,4 +278,13 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest } }); } + + @Test + public void missingArgsTest() throws IOException { + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + + assertThrows(SOPGPException.MissingArg.class, () -> getSop().encrypt() + .plaintext(message) + .getBytes()); + } } diff --git a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java index 93357a5..eca144b 100644 --- a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java +++ b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java @@ -35,6 +35,7 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest { @Test public void extractAliceCertFromAliceKeyTest() throws IOException { + ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses old CTB byte[] armoredCert = getSop().extractCert() .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .getBytes(); @@ -43,6 +44,7 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest { @Test public void extractBobsCertFromBobsKeyTest() throws IOException { + ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses old CTB byte[] armoredCert = getSop().extractCert() .key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8)) .getBytes(); @@ -51,6 +53,7 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest { @Test public void extractCarolsCertFromCarolsKeyTest() throws IOException { + ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses old CTB byte[] armoredCert = getSop().extractCert() .key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) .getBytes();