mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-26 00:52:07 +01:00
Add DSL for testing verification results
This commit is contained in:
parent
bb2b4e03fb
commit
aeda534f37
8 changed files with 326 additions and 95 deletions
|
@ -7,6 +7,7 @@ package sop.util;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import sop.Verification;
|
import sop.Verification;
|
||||||
import sop.enums.SignatureMode;
|
import sop.enums.SignatureMode;
|
||||||
|
import sop.testsuite.assertions.VerificationAssert;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -21,12 +22,37 @@ public class VerificationTest {
|
||||||
String certFP = "4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B";
|
String certFP = "4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B";
|
||||||
Verification verification = new Verification(signDate, keyFP, certFP);
|
Verification verification = new Verification(signDate, keyFP, certFP);
|
||||||
assertEquals("2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B", verification.toString());
|
assertEquals("2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B", verification.toString());
|
||||||
|
|
||||||
|
VerificationAssert.assertThatVerification(verification)
|
||||||
|
.issuedBy(certFP)
|
||||||
|
.isBySigningKey(keyFP)
|
||||||
|
.isCreatedAt(signDate)
|
||||||
|
.hasMode(null)
|
||||||
|
.hasDescription(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void limitedParsingTest() {
|
public void limitedParsingTest() {
|
||||||
String string = "2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B";
|
String string = "2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B";
|
||||||
Verification verification = Verification.fromString(string);
|
Verification verification = Verification.fromString(string);
|
||||||
assertEquals(string, verification.toString());
|
assertEquals(string, verification.toString());
|
||||||
|
VerificationAssert.assertThatVerification(verification)
|
||||||
|
.isCreatedAt(UTCUtil.parseUTCDate("2022-11-07T15:01:24Z"))
|
||||||
|
.issuedBy("F9E6F53F7201C60A87064EAB0B27F2B0760A1209", "4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B")
|
||||||
|
.hasMode(null)
|
||||||
|
.hasDescription(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parsingWithModeTest() {
|
||||||
|
String string = "2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B mode:text";
|
||||||
|
Verification verification = Verification.fromString(string);
|
||||||
|
assertEquals(string, verification.toString());
|
||||||
|
VerificationAssert.assertThatVerification(verification)
|
||||||
|
.isCreatedAt(UTCUtil.parseUTCDate("2022-11-07T15:01:24Z"))
|
||||||
|
.issuedBy("F9E6F53F7201C60A87064EAB0B27F2B0760A1209", "4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B")
|
||||||
|
.hasMode(SignatureMode.text)
|
||||||
|
.hasDescription(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -37,9 +63,13 @@ public class VerificationTest {
|
||||||
SignatureMode mode = SignatureMode.binary;
|
SignatureMode mode = SignatureMode.binary;
|
||||||
String description = "certificate from dkg.asc";
|
String description = "certificate from dkg.asc";
|
||||||
Verification verification = new Verification(signDate, keyFP, certFP, mode, description);
|
Verification verification = new Verification(signDate, keyFP, certFP, mode, description);
|
||||||
|
|
||||||
assertEquals("2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B mode:binary certificate from dkg.asc", verification.toString());
|
assertEquals("2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B mode:binary certificate from dkg.asc", verification.toString());
|
||||||
assertEquals(SignatureMode.binary, verification.getSignatureMode());
|
VerificationAssert.assertThatVerification(verification)
|
||||||
assertEquals(description, verification.getDescription());
|
.isCreatedAt(signDate)
|
||||||
|
.issuedBy(keyFP, certFP)
|
||||||
|
.hasMode(SignatureMode.binary)
|
||||||
|
.hasDescription(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,5 +82,10 @@ public class VerificationTest {
|
||||||
string = "2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B certificate from dkg.asc";
|
string = "2022-11-07T15:01:24Z F9E6F53F7201C60A87064EAB0B27F2B0760A1209 4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B certificate from dkg.asc";
|
||||||
verification = Verification.fromString(string);
|
verification = Verification.fromString(string);
|
||||||
assertEquals(string, verification.toString());
|
assertEquals(string, verification.toString());
|
||||||
|
VerificationAssert.assertThatVerification(verification)
|
||||||
|
.isCreatedAt(UTCUtil.parseUTCDate("2022-11-07T15:01:24Z"))
|
||||||
|
.issuedBy("F9E6F53F7201C60A87064EAB0B27F2B0760A1209", "4E2C78519512C2AE9A8BFE7EB3298EB2FBE5F51B")
|
||||||
|
.hasMode(null)
|
||||||
|
.hasDescription("certificate from dkg.asc");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,14 @@
|
||||||
|
|
||||||
package sop.testsuite;
|
package sop.testsuite;
|
||||||
|
|
||||||
import sop.Verification;
|
|
||||||
import sop.util.UTCUtil;
|
import sop.util.UTCUtil;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class JUtils {
|
public class JUtils {
|
||||||
|
@ -157,66 +156,12 @@ public class JUtils {
|
||||||
return string.getBytes(StandardCharsets.UTF_8);
|
return string.getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertSignedBy(List<Verification> verifications, String primaryFingerprint) {
|
public static void assertDateEquals(Date expected, Date actual) {
|
||||||
for (Verification verification : verifications) {
|
assertEquals(UTCUtil.formatUTCDate(expected), UTCUtil.formatUTCDate(actual));
|
||||||
if (verification.getSigningCertFingerprint().equals(primaryFingerprint)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verifications.isEmpty()) {
|
|
||||||
fail("Verification list is empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
fail("Verification list does not contain verification by cert " + primaryFingerprint + ":\n" +
|
|
||||||
Arrays.toString(verifications.toArray(new Verification[0])));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertSignedBy(List<Verification> verifications, String signingFingerprint, String primaryFingerprint) {
|
public static boolean dateEquals(Date expected, Date actual) {
|
||||||
for (Verification verification : verifications) {
|
return UTCUtil.formatUTCDate(expected).equals(UTCUtil.formatUTCDate(actual));
|
||||||
if (verification.getSigningCertFingerprint().equals(primaryFingerprint) && verification.getSigningKeyFingerprint().equals(signingFingerprint)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verifications.isEmpty()) {
|
|
||||||
fail("Verification list is empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
fail("Verification list does not contain verification by key " + signingFingerprint + " on cert " + primaryFingerprint + ":\n" +
|
|
||||||
Arrays.toString(verifications.toArray(new Verification[0])));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertSignedBy(List<Verification> verifications, String primaryFingerprint, Date signatureDate) {
|
|
||||||
for (Verification verification : verifications) {
|
|
||||||
if (verification.getSigningCertFingerprint().equals(primaryFingerprint) &&
|
|
||||||
verification.getCreationTime().equals(signatureDate)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verifications.isEmpty()) {
|
|
||||||
fail("Verification list is empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
fail("Verification list does not contain verification by cert " + primaryFingerprint + " made at " + UTCUtil.formatUTCDate(signatureDate) + ":\n" +
|
|
||||||
Arrays.toString(verifications.toArray(new Verification[0])));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void assertSignedBy(List<Verification> verifications, String signingFingerprint, String primaryFingerprint, Date signatureDate) {
|
|
||||||
for (Verification verification : verifications) {
|
|
||||||
if (verification.getSigningCertFingerprint().equals(primaryFingerprint) &&
|
|
||||||
verification.getSigningKeyFingerprint().equals(signingFingerprint) &&
|
|
||||||
verification.getCreationTime().equals(signatureDate)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verifications.isEmpty()) {
|
|
||||||
fail("Verification list is empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
fail("Verification list does not contain verification by key" + signingFingerprint + " on cert " + primaryFingerprint + " made at " + UTCUtil.formatUTCDate(signatureDate) + ":\n" +
|
|
||||||
Arrays.toString(verifications.toArray(new Verification[0])));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.testsuite.assertions;
|
||||||
|
|
||||||
|
import sop.Verification;
|
||||||
|
import sop.enums.SignatureMode;
|
||||||
|
import sop.testsuite.JUtils;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public final class VerificationAssert {
|
||||||
|
|
||||||
|
private final Verification verification;
|
||||||
|
|
||||||
|
public static VerificationAssert assertThatVerification(Verification verification) {
|
||||||
|
return new VerificationAssert(verification);
|
||||||
|
}
|
||||||
|
|
||||||
|
private VerificationAssert(Verification verification) {
|
||||||
|
this.verification = verification;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert issuedBy(String signingKeyFingerprint, String primaryFingerprint) {
|
||||||
|
return isBySigningKey(signingKeyFingerprint)
|
||||||
|
.issuedBy(primaryFingerprint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert issuedBy(String primaryFingerprint) {
|
||||||
|
assertEquals(primaryFingerprint, verification.getSigningCertFingerprint());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert isBySigningKey(String signingKeyFingerprint) {
|
||||||
|
assertEquals(signingKeyFingerprint, verification.getSigningKeyFingerprint());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert isCreatedAt(Date creationDate) {
|
||||||
|
JUtils.assertDateEquals(creationDate, verification.getCreationTime());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert hasDescription(String description) {
|
||||||
|
assertEquals(description, verification.getDescription());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert hasDescriptionOrNull(String description) {
|
||||||
|
if (verification.getDescription() == null) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasDescription(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert hasMode(SignatureMode mode) {
|
||||||
|
assertEquals(mode, verification.getSignatureMode());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert hasModeOrNull(SignatureMode mode) {
|
||||||
|
if (verification.getSignatureMode() == null) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return hasMode(mode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.testsuite.assertions;
|
||||||
|
|
||||||
|
import sop.Verification;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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 static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
public final class VerificationListAssert {
|
||||||
|
|
||||||
|
private final List<Verification> verificationList = new ArrayList<>();
|
||||||
|
|
||||||
|
private VerificationListAssert(List<Verification> verifications) {
|
||||||
|
this.verificationList.addAll(verifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VerificationListAssert assertThatVerificationList(List<Verification> verifications) {
|
||||||
|
return new VerificationListAssert(verifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationListAssert isEmpty() {
|
||||||
|
assertTrue(verificationList.isEmpty());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationListAssert isNotEmpty() {
|
||||||
|
assertFalse(verificationList.isEmpty());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationListAssert sizeEquals(int size) {
|
||||||
|
assertEquals(size, verificationList.size());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationAssert hasSingleItem() {
|
||||||
|
sizeEquals(1);
|
||||||
|
return VerificationAssert.assertThatVerification(verificationList.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationListAssert containsVerificationByCert(String primaryFingerprint) {
|
||||||
|
for (Verification verification : verificationList) {
|
||||||
|
if (primaryFingerprint.equals(verification.getSigningCertFingerprint())) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail("No verification was issued by certificate " + primaryFingerprint);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerificationListAssert containsVerificationBy(String signingKeyFingerprint, String primaryFingerprint) {
|
||||||
|
for (Verification verification : verificationList) {
|
||||||
|
if (primaryFingerprint.equals(verification.getSigningCertFingerprint()) &&
|
||||||
|
signingKeyFingerprint.equals(verification.getSigningKeyFingerprint())) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fail("No verification was issued by key " + signingKeyFingerprint + " of cert " + primaryFingerprint);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DSL for assertions on SOP objects.
|
||||||
|
*/
|
||||||
|
package sop.testsuite.assertions;
|
|
@ -11,9 +11,11 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
import sop.Verification;
|
import sop.Verification;
|
||||||
import sop.enums.SignAs;
|
import sop.enums.SignAs;
|
||||||
|
import sop.enums.SignatureMode;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
import sop.testsuite.JUtils;
|
import sop.testsuite.JUtils;
|
||||||
import sop.testsuite.TestData;
|
import sop.testsuite.TestData;
|
||||||
|
import sop.testsuite.assertions.VerificationListAssert;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -21,7 +23,6 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||||
|
@ -47,8 +48,11 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||||
|
.hasModeOrNull(SignatureMode.binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -68,8 +72,11 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||||
|
.hasModeOrNull(SignatureMode.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -83,8 +90,10 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE);
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -103,8 +112,10 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -123,8 +134,10 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -146,7 +159,10 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -170,8 +186,10 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.signatures(armored)
|
.signatures(armored)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -202,6 +220,21 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.data(message));
|
.data(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("provideInstances")
|
||||||
|
public void signWithAliceVerifyWithBobThrowsNoSignature(SOP sop) throws IOException {
|
||||||
|
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
byte[] signatures = sop.detachedSign()
|
||||||
|
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.data(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
|
.getBytes();
|
||||||
|
|
||||||
|
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||||
|
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.signatures(signatures)
|
||||||
|
.data(message));
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideInstances")
|
@MethodSource("provideInstances")
|
||||||
|
@ -229,11 +262,15 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(sop.verify()
|
List<Verification> verificationList = sop.verify()
|
||||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message)
|
.data(message);
|
||||||
.isEmpty());
|
|
||||||
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -247,4 +284,29 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||||
.data(message));
|
.data(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("provideInstances")
|
||||||
|
public void signVerifyWithMultipleKeys(SOP sop) throws IOException {
|
||||||
|
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
byte[] signatures = sop.detachedSign()
|
||||||
|
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.data(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
|
.getBytes();
|
||||||
|
|
||||||
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
|
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.signatures(signatures)
|
||||||
|
.data(message);
|
||||||
|
|
||||||
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.sizeEquals(2)
|
||||||
|
.containsVerificationBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||||
|
.containsVerificationBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,10 @@ import sop.DecryptionResult;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
import sop.Verification;
|
import sop.Verification;
|
||||||
import sop.enums.EncryptAs;
|
import sop.enums.EncryptAs;
|
||||||
|
import sop.enums.SignatureMode;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
import sop.testsuite.JUtils;
|
|
||||||
import sop.testsuite.TestData;
|
import sop.testsuite.TestData;
|
||||||
|
import sop.testsuite.assertions.VerificationListAssert;
|
||||||
import sop.util.UTCUtil;
|
import sop.util.UTCUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -25,8 +26,6 @@ import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
@ -142,6 +141,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.mode(EncryptAs.Binary)
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
|
@ -156,9 +156,13 @@ public class EncryptDecryptTest extends AbstractSOPTest {
|
||||||
|
|
||||||
DecryptionResult result = bytesAndResult.getResult();
|
DecryptionResult result = bytesAndResult.getResult();
|
||||||
assertNotNull(result.getSessionKey().get());
|
assertNotNull(result.getSessionKey().get());
|
||||||
|
|
||||||
List<Verification> verificationList = result.getVerifications();
|
List<Verification> verificationList = result.getVerifications();
|
||||||
assertEquals(1, verificationList.size());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||||
|
.hasModeOrNull(SignatureMode.binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -183,9 +187,12 @@ public class EncryptDecryptTest extends AbstractSOPTest {
|
||||||
|
|
||||||
DecryptionResult result = bytesAndResult.getResult();
|
DecryptionResult result = bytesAndResult.getResult();
|
||||||
assertNotNull(result.getSessionKey().get());
|
assertNotNull(result.getSessionKey().get());
|
||||||
|
|
||||||
List<Verification> verificationList = result.getVerifications();
|
List<Verification> verificationList = result.getVerifications();
|
||||||
assertEquals(1, verificationList.size());
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||||
|
.hasModeOrNull(SignatureMode.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -216,8 +223,10 @@ public class EncryptDecryptTest extends AbstractSOPTest {
|
||||||
.ciphertext(ciphertext)
|
.ciphertext(ciphertext)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertFalse(bytesAndResult.getResult().getVerifications().isEmpty());
|
List<Verification> verifications = bytesAndResult.getResult().getVerifications();
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
VerificationListAssert.assertThatVerificationList(verifications)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -247,6 +256,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
|
||||||
.ciphertext(message)
|
.ciphertext(message)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
|
// Some implementations do not throw NoSignature and instead return an empty list.
|
||||||
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
||||||
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
||||||
}
|
}
|
||||||
|
@ -280,6 +290,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
|
||||||
.ciphertext(message)
|
.ciphertext(message)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
|
// Some implementations do not throw NoSignature and instead return an empty list.
|
||||||
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
||||||
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,11 @@ import sop.ByteArrayAndResult;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
import sop.Verification;
|
import sop.Verification;
|
||||||
import sop.enums.InlineSignAs;
|
import sop.enums.InlineSignAs;
|
||||||
|
import sop.enums.SignatureMode;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
import sop.testsuite.JUtils;
|
import sop.testsuite.JUtils;
|
||||||
import sop.testsuite.TestData;
|
import sop.testsuite.TestData;
|
||||||
|
import sop.testsuite.assertions.VerificationListAssert;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -51,8 +53,12 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
|
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -74,8 +80,12 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
|
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -97,8 +107,12 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
|
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||||
|
.hasModeOrNull(SignatureMode.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -111,8 +125,13 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
JUtils.assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, signatureDate);
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.isCreatedAt(signatureDate)
|
||||||
|
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -161,8 +180,12 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
|
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
JUtils.assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -183,8 +206,12 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
|
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
JUtils.assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.isNotEmpty()
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -205,7 +232,9 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
JUtils.assertSignedBy(verificationList, TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||||
|
.hasSingleItem()
|
||||||
|
.issuedBy(TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue