Skip to content

Commit

Permalink
chore: minor structural improvements in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chsavvaidis committed Nov 29, 2024
1 parent 52719f9 commit 51809df
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions waltid-services/waltid-e2e-tests/src/test/kotlin/IssuerD10.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,39 @@ class IssuerDraft10(private val client: HttpClient) {
assertNotNull(credOffer.credentials)
assertNotNull(credOffer.grants)

val issuerMetadataUrl = getCIProviderMetadataUrl(credOffer.credentialIssuer)

val issuerMetadataUrl = getCIProviderMetadataUrl(credOffer.credentialIssuer)
val rawJsonMetadata = client.get(issuerMetadataUrl).bodyAsText()
val jsonElementMetadata = Json.parseToJsonElement(rawJsonMetadata)
assertTrue(jsonElementMetadata.jsonObject["credentials_supported"] is JsonArray, "Expected credentials_supported to be a JsonArray")
assertTrue(jsonElementMetadata.jsonObject["credentials_supported"] is JsonArray, "Expected credentials_supported in Open ID Provider Metadata to be a JsonArray")

val issuerMetadata = OpenIDProviderMetadata.fromJSONString(rawJsonMetadata) as OpenIDProviderMetadata.Draft10

assertNull(issuerMetadata.authorizationServer)
assertContains(issuerMetadata.grantTypesSupported, GrantType.authorization_code)
assertContains(issuerMetadata.grantTypesSupported, GrantType.pre_authorized_code)
assertNotNull(issuerMetadata.jwksUri)
assertTrue(issuerMetadata.credentialSupported!!.keys.all { it.toIntOrNull() != null }, "Expected credentials_supported keys to be array indices (e.g., '0', '1')")

assertEquals(issuerMetadata.issuer, credOffer.credentialIssuer)
assertEquals(issuerMetadata.credentialIssuer, credOffer.credentialIssuer)
assertEquals(issuerMetadata.credentialIssuer, credOffer.credentialIssuer)

val rawJsonJwks = client.get(issuerMetadata.jwksUri!!).bodyAsText()

val keysArray = Json.parseToJsonElement(rawJsonJwks).jsonObject["keys"]?.jsonArray
?: throw AssertionError("JWKS response must contain a 'keys' array")

assertTrue(
keysArray.any { key ->
key.jsonObject.run {
this["kty"]?.jsonPrimitive?.content == "EC" &&
this["crv"]?.jsonPrimitive?.content == "P-256"
}
},
"JWKS must contain at least one key with 'kty': 'EC' and 'crv': 'P-256'"
)


val matchingCredential = issuerMetadata.credentialSupported
?.values
?.find { it.id == issuanceReq.credentialConfigurationId }
Expand All @@ -70,31 +89,9 @@ class IssuerDraft10(private val client: HttpClient) {
matchingCredential.format
)

assertNull(issuerMetadata.authorizationServer)

assertContains(issuerMetadata.grantTypesSupported, GrantType.authorization_code)
assertContains(issuerMetadata.grantTypesSupported, GrantType.pre_authorized_code)

assertNotNull(issuerMetadata.jwksUri)

val rawJsonJwks = client.get(issuerMetadata.jwksUri!!).bodyAsText()

val keysArray = Json.parseToJsonElement(rawJsonJwks).jsonObject["keys"]?.jsonArray
?: throw AssertionError("JWKS response must contain a 'keys' array")

assertTrue(
keysArray.any { key ->
key.jsonObject.run {
this["kty"]?.jsonPrimitive?.content == "EC" &&
this["crv"]?.jsonPrimitive?.content == "P-256"
}
},
"JWKS must contain at least one key with 'kty': 'EC' and 'crv': 'P-256'"
)
issuerState = credOffer.grants[GrantType.authorization_code.name]!!.issuerState!!

issuerState = credOffer.grants["authorization_code"]!!.issuerState!!

println(issuerState)
val authorizationRequest = AuthorizationRequest(
issuerState = issuerState,
clientId = "did:key:xzy",
Expand Down Expand Up @@ -128,8 +125,6 @@ class IssuerDraft10(private val client: HttpClient) {
assertNotNull(authJarTokenRequest.request)
val requestJwt = authJarTokenRequest.request!!.decodeJws()

println(requestJwt)

val keyId = requestJwt.header[JWTClaims.Header.keyID]!!.jsonPrimitive.content
assertNotNull(keyId)

Expand Down

0 comments on commit 51809df

Please sign in to comment.