-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mineme0110 <[email protected]>
- Loading branch information
1 parent
3a23f1b
commit 4c8719c
Showing
2 changed files
with
100 additions
and
1 deletion.
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
99 changes: 99 additions & 0 deletions
99
pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JwtPresentationTest.scala
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,99 @@ | ||
package org.hyperledger.identus.pollux.vc.jwt | ||
|
||
import zio.test.* | ||
import zio.test.ZIOSpecDefault | ||
|
||
object JwtPresentationTest extends ZIOSpecDefault { | ||
val jwt = JWT( | ||
"eyJraWQiOiJteS1hdXRoLWtleSIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2SyJ9.eyJpc3MiOiJkaWQ6cHJpc206YjgwZjAxMTZhYWY2OTI5MGRkMzJiZDE0OTNmN2IxYWJhMDM5OTYyM2JkNDk5Mzk3NTRjNThhNGNmZTU4M2QwYzpDcGNDQ3BRQ0VqOEtDMjE1TFdGMWRHZ3RhMlY1RUFSS0xnb0pjMlZqY0RJMU5tc3hFaUVDQnViQkpoNDhRNjhqOTJZS3NjMVFqQ0prOHFvRXBMamRoejNRRVFzRWpWRVNTZ29XYlhrdGEyVjVMV0Z6YzJWeWRHbHZiazFsZEdodlpCQUNTaTRLQ1hObFkzQXlOVFpyTVJJaEFoTENSMkhTa3NOWUh2Y0dCUWZzQVZrdDNFa1pMSVpMVEhYcFc4ckJRRHI5RWpzS0IyMWhjM1JsY2pBUUFVb3VDZ2x6WldOd01qVTJhekVTSVFMRC10d3c1SklVbzA2dXQ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XJGRzAtSUk5NGo4ZmlUS0xYcWRpQ1NXNEN3Il19LCJub25jZSI6IjExYzkxNDkzLTAxYjMtNGM0ZC1hYzM2LWIzMzZiYWI1YmRkZiJ9.d5bzOLV-kQZvCceoFppqlPRG7aK3mo9sZVCj5_sPqIMvOqzAbxTOPyfI459GFKpeF8ApsNwJyx9jED_cRaqqiQ" | ||
) | ||
val domain = Some("https://prism-verifier.com") | ||
val challenge = Some("11c91493-01b3-4c4d-ac36-b336bab5bddf") | ||
val schemaIdAndTrustedIssuers = Seq( | ||
CredentialSchemaAndTrustedIssuersConstraint( | ||
schemaId = "http://192.168.1.86:8000/cloud-agent/schema-registry/schemas/633a68f7-4e7b-3073-a9a0-8ae964da5967", | ||
trustedIssuers = Some( | ||
Seq( | ||
"did:prism:0fee41fdd6807763ccc539c29841a418c76a89b3f8cd6da89de2a3d1a04571f5:CpsCCpgCEkYKFW15LWtleS1hdXRoZW50aWNhdGlvbhAESisKB0VkMjU1MTkSIDuyET1hCAuCvk3Onogl38cMiJnx_jkLYSNwWMIAntlLEkcKFm15LWtleS1hc3NlcnRpb25NZXRob2QQAkorCgdFZDI1NTE5EiCZARInSdRJDK-ELrqWod1wNOHhutwZRDKJ-o5AfHrbrRI7CgdtYXN0ZXIwEAFKLgoJc2VjcDI1NmsxEiEDG1msucsUsdQO-nYprQX4oAXZHW2c8PRWzRdStk6085IaSAoOYWdlbnQtYmFzZS11cmwSEExpbmtlZFJlc291cmNlVjEaJGh0dHA6Ly8xOTIuMTY4LjEuODY6ODAwMC9jbG91ZC1hZ2VudA" | ||
) | ||
) | ||
) | ||
) | ||
override def spec = suite("JWTVerificationSpec")( | ||
test("validate true when issuer is trusted") { | ||
val validation = JwtPresentation.validatePresentation( | ||
jwt, | ||
domain, | ||
challenge, | ||
schemaIdAndTrustedIssuers | ||
) | ||
assertTrue(validation.fold(_ => false, _ => true)) | ||
}, | ||
test("fail when issuer is not trusted") { | ||
val trustedIssuer = "did:prism:issuer" | ||
val schemaIdAndTrustedIssuers = Seq( | ||
CredentialSchemaAndTrustedIssuersConstraint( | ||
schemaId = | ||
"http://192.168.1.86:8000/cloud-agent/schema-registry/schemas/633a68f7-4e7b-3073-a9a0-8ae964da5967", | ||
trustedIssuers = Some( | ||
Seq( | ||
trustedIssuer | ||
) | ||
) | ||
) | ||
) | ||
val validation = JwtPresentation.validatePresentation( | ||
jwt, | ||
domain, | ||
challenge, | ||
schemaIdAndTrustedIssuers | ||
) | ||
assertTrue(validation.fold(_ => true, _ => false)) | ||
assertTrue(validation.fold(chunk => chunk.mkString.contains(trustedIssuer), _ => false)) | ||
}, | ||
test("fail when schema ID doesn't match") { | ||
val expectedSchemaId = "http://192.168.1.86:8000/cloud-agent/schema-registry/schemas/schemaId" | ||
val schemaIdAndTrustedIssuers = Seq( | ||
CredentialSchemaAndTrustedIssuersConstraint( | ||
schemaId = expectedSchemaId, | ||
trustedIssuers = Some( | ||
Seq( | ||
"did:prism:0fee41fdd6807763ccc539c29841a418c76a89b3f8cd6da89de2a3d1a04571f5:CpsCCpgCEkYKFW15LWtleS1hdXRoZW50aWNhdGlvbhAESisKB0VkMjU1MTkSIDuyET1hCAuCvk3Onogl38cMiJnx_jkLYSNwWMIAntlLEkcKFm15LWtleS1hc3NlcnRpb25NZXRob2QQAkorCgdFZDI1NTE5EiCZARInSdRJDK-ELrqWod1wNOHhutwZRDKJ-o5AfHrbrRI7CgdtYXN0ZXIwEAFKLgoJc2VjcDI1NmsxEiEDG1msucsUsdQO-nYprQX4oAXZHW2c8PRWzRdStk6085IaSAoOYWdlbnQtYmFzZS11cmwSEExpbmtlZFJlc291cmNlVjEaJGh0dHA6Ly8xOTIuMTY4LjEuODY6ODAwMC9jbG91ZC1hZ2VudA" | ||
) | ||
) | ||
) | ||
) | ||
val validation = JwtPresentation.validatePresentation( | ||
jwt, | ||
domain, | ||
challenge, | ||
schemaIdAndTrustedIssuers | ||
) | ||
assertTrue(validation.fold(_ => true, _ => false)) | ||
assertTrue(validation.fold(chunk => chunk.mkString.contains(expectedSchemaId), _ => false)) | ||
}, | ||
test("fail when domain validation fails") { | ||
val domain = Some("domain") | ||
val validation = JwtPresentation.validatePresentation( | ||
jwt, | ||
domain, | ||
challenge, | ||
schemaIdAndTrustedIssuers | ||
) | ||
assertTrue(validation.fold(_ => true, _ => false)) | ||
assertTrue(validation.fold(chunk => chunk.mkString.contains("domain/Audience dont match"), _ => false)) | ||
}, | ||
test("fail when challenge validation fails") { | ||
val challenge = Some("challenge") | ||
val validation = JwtPresentation.validatePresentation( | ||
jwt, | ||
domain, | ||
challenge, | ||
schemaIdAndTrustedIssuers | ||
) | ||
assertTrue(validation.fold(_ => true, _ => false)) | ||
assertTrue(validation.fold(chunk => chunk.mkString.contains("Challenge/Nonce dont match"), _ => false)) | ||
} | ||
) | ||
|
||
} |