Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Test JWT OBJECT as Issuer #1343

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ case class CredentialSchema(
`type`: String
)

case class CredentialIssuer(id: String)
case class CredentialIssuer(
id: String,
`type`: String
)

sealed trait CredentialPayload {
def maybeSub: Option[String]
Expand Down Expand Up @@ -216,7 +219,8 @@ object CredentialPayload {
(credentialIssuer: CredentialIssuer) =>
Json
.obj(
("id", credentialIssuer.id.asJson)
("id", credentialIssuer.id.asJson),
("type", credentialIssuer.`type`.asJson)
)

implicit val credentialStatusPurposeEncoder: Encoder[StatusPurpose] = (a: StatusPurpose) => a.toString.asJson
Expand Down Expand Up @@ -334,8 +338,9 @@ object CredentialPayload {
(c: HCursor) =>
for {
id <- c.downField("id").as[String]
`type` <- c.downField("type").as[String]
} yield {
CredentialIssuer(id = id)
CredentialIssuer(id = id, `type` = `type`)
}

implicit val credentialStatusPurposeDecoder: Decoder[StatusPurpose] = (c: HCursor) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object JWTVerificationTest extends ZIOSpecDefault {
|}
|""".stripMargin

private def createJwtCredential(issuer: IssuerWithKey): JWT = {
private def createJwtCredential(issuer: IssuerWithKey, issuerAsObject: Boolean = false): JWT = {
val validFrom = Instant.parse("2010-01-05T00:00:00Z") // ISSUANCE DATE
val jwtCredentialNbf = Instant.parse("2010-01-01T00:00:00Z") // ISSUANCE DATE
val validUntil = Instant.parse("2010-01-09T00:00:00Z") // EXPIRATION DATE
Expand All @@ -81,7 +81,10 @@ object JWTVerificationTest extends ZIOSpecDefault {
maybeTermsOfUse = None,
maybeValidFrom = Some(validFrom),
maybeValidUntil = Some(validUntil),
maybeIssuer = Some(Left(issuer.issuer.did.toString))
maybeIssuer = Some(
if (issuerAsObject) Right(CredentialIssuer(issuer.issuer.did.toString, "Profile"))
else Left(issuer.issuer.did.toString)
)
),
nbf = jwtCredentialNbf, // ISSUANCE DATE
aud = Set.empty,
Expand Down Expand Up @@ -199,6 +202,21 @@ object JWTVerificationTest extends ZIOSpecDefault {
)
} yield assertTrue(validation.fold(_ => false, _ => true))
},
test("validate issuer happy path") {
val issuer = createUser("did:prism:issuer")
val jwtCredential = createJwtCredential(issuer, false)
val jwtCredentialWithObjectIssuer = createJwtCredential(issuer, true)
for {
jwt <- JwtCredential
.decodeJwt(jwtCredential)
jwtWithObjectIssuer <- JwtCredential
.decodeJwt(jwtCredentialWithObjectIssuer)
jwtWithObjectIssuerIssuer = jwtWithObjectIssuer.vc.maybeIssuer.get.toOption.get.id
jwtIssuer = jwt.vc.maybeIssuer.get.left.toOption.get
} yield assertTrue(
jwtWithObjectIssuerIssuer.equals(jwtIssuer)
)
},
test("validate dates should fail given after valid until") {
val issuer = createUser("did:prism:issuer")
val jwtCredential = createJwtCredential(issuer)
Expand Down
Loading