Skip to content

Commit

Permalink
test: more unhappy path tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <[email protected]>
  • Loading branch information
Pat Losoponkul committed Sep 10, 2024
1 parent 520edf8 commit 85bbb15
Showing 1 changed file with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.hyperledger.identus.pollux.prex.PresentationSubmissionError.{
InvalidSubmissionId,
SubmissionNotSatisfyInputDescriptors
}
import org.hyperledger.identus.pollux.prex.PresentationSubmissionError.ClaimFormatVerificationFailure
import org.hyperledger.identus.pollux.prex.PresentationSubmissionError.ClaimNotSatisfyInputConstraint
import org.hyperledger.identus.pollux.vc.jwt.{
DID,
ES256KSigner,
Expand Down Expand Up @@ -123,7 +125,12 @@ object PresentationSubmissionVerificationSpec extends ZIOSpecDefault {
JwtPresentation.encodeJwt(payload, issuer)
}

private def assertSubmissionVerification(descriptorsJson: String, descriptorMapJson: String, jwt: JWT)(
private def assertSubmissionVerification(
descriptorsJson: String,
descriptorMapJson: String,
jwt: JWT,
formatVerification: ClaimFormatVerification = noopFormatVerification
)(
assertion: Assertion[Exit[PresentationSubmissionError, Unit]]
) = {
val descriptors = decodeUnsafe[Seq[InputDescriptor]](descriptorsJson)
Expand All @@ -132,7 +139,7 @@ object PresentationSubmissionVerificationSpec extends ZIOSpecDefault {
val ps = basePs.copy(descriptor_map = descriptorMap)
for {
result <- PresentationSubmissionVerification
.verify(pd, ps, ZioJson.Str(jwt.value))(noopFormatVerification)
.verify(pd, ps, ZioJson.Str(jwt.value))(formatVerification)
.exit
} yield assert(result)(assertion)
}
Expand Down Expand Up @@ -292,6 +299,34 @@ object PresentationSubmissionVerificationSpec extends ZIOSpecDefault {
jwtVc,
)(succeeds(anything))
},
test("descriptor and submission that dosn't satisfy the filter") {
val payload = generateVcPayload(parseUnsafe("""{"name": "alice"}"""))
val jwtVc = generateJwtVc(payload)
assertSubmissionVerification(
"""[
| {
| "id": "university_degree",
| "constraints": {
| "fields": [
| {
| "path": ["$.vc.credentialSubject.name"],
| "filter": {
| "type": "string",
| "const": "bob"
| }
| }
| ]
| }
| }
|]
""".stripMargin,
"""[
| {"id": "university_degree", "format": "jwt_vc", "path": "$"}
|]
""".stripMargin,
jwtVc
)(failsWithA[ClaimNotSatisfyInputConstraint])
},
test("descriptor with multiple fields verification") {
val payload = generateVcPayload(parseUnsafe("""{"name": "alice", "degree": "Finance"}"""))
val jwtVc = generateJwtVc(payload)
Expand Down Expand Up @@ -489,10 +524,26 @@ object PresentationSubmissionVerificationSpec extends ZIOSpecDefault {
""".stripMargin,
jwtVc
)(succeeds(anything))
},
test("descriptor and submission that fail the claim format decoding") {
val formatVerification = noopFormatVerification.copy(
jwtVc = _ => ZIO.fail("jwt is missing some required properties")
)
val payload = generateVcPayload(parseUnsafe("""{"name": "alice"}"""))
val jwtVc = generateJwtVc(payload)
assertSubmissionVerification(
"""[
| {"id": "university_degree", "constraints": {}}
|]
""".stripMargin,
"""[
| {"id": "university_degree", "format": "jwt_vc", "path": "$"}
|]
""".stripMargin,
jwtVc,
formatVerification
)(failsWithA[ClaimFormatVerificationFailure])
}
)
/* TODO
* - test for format verification failure
*/

}

0 comments on commit 85bbb15

Please sign in to comment.