Skip to content

Commit

Permalink
test: optional field constraints test
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 9, 2024
1 parent 1b31e5d commit 4e0323a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ object PresentationSubmissionVerification {
}
} yield ()
}
.catchAll { errors =>
// if all paths don't satisfy constraints, but optional, then the field is still valid
// https://identity.foundation/presentation-exchange/spec/v2.1.1/#input-evaluation
if field.optional.getOrElse(false)
then ZIO.unit
else ZIO.fail(errors)
}
.mapError(_ => ClaimNotSatisfyInputConstraint(descriptor.id))
}
.unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object PresentationSubmissionVerificationSpec extends ZIOSpecDefault {
val jwtVc = generateJwtVc(payload)
assertSubmissionVerification("[]", "[]", jwtVc)(succeeds(anything))
},
test("one matching descriptor and submission") {
test("one descriptor and corresponding submission") {
val payload = generateVcPayload(parseUnsafe("""{"name": "alice"}"""))
val jwtVc = generateJwtVc(payload)
assertSubmissionVerification(
Expand Down Expand Up @@ -435,11 +435,64 @@ object PresentationSubmissionVerificationSpec extends ZIOSpecDefault {
""".stripMargin,
jwtVp
)(succeeds(anything))
},
test("descriptor with optional field and submission that omit optional fields") {
val payload = generateVcPayload(parseUnsafe("""{"gpa": 4.00}"""))
val jwtVc = generateJwtVc(payload)
assertSubmissionVerification(
"""[
| {
| "id": "university_degree",
| "constraints": {
| "fields": [
| {
| "path": ["$.vc.credentialSubject.name"],
| "optional": true
| }
| ]
| }
| }
|]
""".stripMargin,
"""[
| {"id": "university_degree", "format": "jwt_vc", "path": "$"}
|]
""".stripMargin,
jwtVc
)(succeeds(anything))
},
test("descriptor with optional field and submission with optional fields that don't satisfy constraints") {
val payload = generateVcPayload(parseUnsafe("""{"name": "alice"}"""))
val jwtVc = generateJwtVc(payload)
assertSubmissionVerification(
"""[
| {
| "id": "university_degree",
| "constraints": {
| "fields": [
| {
| "path": ["$.vc.credentialSubject.name"],
| "optional": true,
| "filter": {
| "type": "string",
| "const": "bob"
| }
| }
| ]
| }
| }
|]
""".stripMargin,
"""[
| {"id": "university_degree", "format": "jwt_vc", "path": "$"}
|]
""".stripMargin,
jwtVc
)(succeeds(anything))
}
/* TODO
* - test for optional field
* - test for format verification failure
*/
)
/* TODO
* - test for format verification failure
*/

}

0 comments on commit 4e0323a

Please sign in to comment.