-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DSL for testing verification results
- Loading branch information
1 parent
bb2b4e0
commit aeda534
Showing
8 changed files
with
326 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
sop-java/src/testFixtures/java/sop/testsuite/assertions/VerificationAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
sop-java/src/testFixtures/java/sop/testsuite/assertions/VerificationListAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
sop-java/src/testFixtures/java/sop/testsuite/assertions/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Oops, something went wrong.