Skip to content

Commit

Permalink
Even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Jan 21, 2023
1 parent 9cf6301 commit e73c7e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,16 @@ public void signWithProtectedKeyAndMultiplePassphrasesTest()
.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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,7 +47,7 @@ public void encryptDecryptRoundTripPasswordTest() throws IOException {

@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)
Expand All @@ -67,7 +67,7 @@ public void encryptDecryptRoundTripAliceTest() throws IOException {

@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)
Expand All @@ -86,7 +86,7 @@ public void encryptDecryptRoundTripBobTest() throws IOException {
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)
Expand All @@ -105,7 +105,7 @@ public void encryptDecryptRoundTripCarolTest() throws IOException {
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()
Expand All @@ -127,7 +127,7 @@ public void encryptNoArmorThenArmorThenDecryptRoundTrip() throws IOException {

@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))
Expand All @@ -152,7 +152,7 @@ public void encryptSignDecryptVerifyRoundTripAliceTest() throws IOException {

@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))
Expand Down Expand Up @@ -278,4 +278,13 @@ public void decryptVerifyNotBeforeTest() {
}
});
}

@Test
public void missingArgsTest() throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);

assertThrows(SOPGPException.MissingArg.class, () -> getSop().encrypt()
.plaintext(message)
.getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void extractArmoredCertFromArmoredKeyTest() throws IOException {

@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();
Expand All @@ -43,6 +44,7 @@ public void extractAliceCertFromAliceKeyTest() throws IOException {

@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();
Expand All @@ -51,6 +53,7 @@ public void extractBobsCertFromBobsKeyTest() throws IOException {

@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();
Expand Down

0 comments on commit e73c7e5

Please sign in to comment.