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

643 issuance verification tests for w3c sd jwt #658

Merged
merged 5 commits into from
Sep 23, 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
@@ -1,5 +1,4 @@
import E2ETestWebService.loadResource

import id.walt.crypto.utils.JsonUtils.toJsonElement
import id.walt.issuer.issuance.IssuanceRequest
import id.walt.oid4vc.data.*
Expand All @@ -15,13 +14,11 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.test.*
import kotlin.test.assertEquals


class AuthorizationCodeFlow(private val client: HttpClient) {

@OptIn(ExperimentalEncodingApi::class)
fun testIssuerAPI() = runBlocking {
lateinit var offerUrl: String
lateinit var issuerState: String
Expand All @@ -32,15 +29,16 @@ class AuthorizationCodeFlow(private val client: HttpClient) {
//
val issuanceRequestIdToken =
Json.decodeFromString<IssuanceRequest>(loadResource("issuance/openbadgecredential-issuance-request-with-authorization-code-flow-and-id-token.json"))
issuerApi.issue(issuanceRequestIdToken) {
issuerApi.jwt(issuanceRequestIdToken) {
offerUrl = it
println("offer: $offerUrl")
}

var offerUrlParams = Url(offerUrl).parameters.toMap()
var offerObj = CredentialOfferRequest.fromHttpParameters(offerUrlParams)
var credOffer = client.get(offerObj.credentialOfferUri!!).body<JsonObject>()
issuerState = credOffer["grants"]!!.jsonObject["authorization_code"]!!.jsonObject["issuer_state"]!!.jsonPrimitive.content
issuerState =
credOffer["grants"]!!.jsonObject["authorization_code"]!!.jsonObject["issuer_state"]!!.jsonPrimitive.content
var authorizationRequest = AuthorizationRequest(
issuerState = issuerState,
clientId = "did:key:xzy",
Expand All @@ -60,7 +58,7 @@ class AuthorizationCodeFlow(private val client: HttpClient) {
type = "openid_credential",
locations = listOf(credOffer["credential_issuer"]!!.jsonPrimitive.content),
format = CredentialFormat.jwt_vc,
credentialDefinition = CredentialDefinition(type = listOf("VerifiableCredential","OpenBadgeCredential"))
credentialDefinition = CredentialDefinition(type = listOf("VerifiableCredential", "OpenBadgeCredential"))
)
)
)
Expand All @@ -77,23 +75,24 @@ class AuthorizationCodeFlow(private val client: HttpClient) {
//
val issuanceRequestVpToken =
Json.decodeFromString<IssuanceRequest>(loadResource("issuance/openbadgecredential-issuance-request-with-authorization-code-flow-and-vp-token.json"))
issuerApi.issue(issuanceRequestVpToken) {
issuerApi.jwt(issuanceRequestVpToken) {
offerUrl = it
println("offer: $offerUrl")
}

offerUrlParams = Url(offerUrl).parameters.toMap()
offerObj = CredentialOfferRequest.fromHttpParameters(offerUrlParams)
credOffer = client.get(offerObj.credentialOfferUri!!).body<JsonObject>()
issuerState = credOffer["grants"]!!.jsonObject["authorization_code"]!!.jsonObject["issuer_state"]!!.jsonPrimitive.content
issuerState =
credOffer["grants"]!!.jsonObject["authorization_code"]!!.jsonObject["issuer_state"]!!.jsonPrimitive.content
authorizationRequest = authorizationRequest.copy(
issuerState = issuerState,
authorizationDetails = listOf(
AuthorizationDetails(
type = "openid_credential",
locations = listOf(credOffer["credential_issuer"]!!.jsonPrimitive.content),
format = CredentialFormat.jwt_vc,
credentialDefinition = CredentialDefinition(type = listOf("VerifiableCredential","OpenBadgeCredential"))
credentialDefinition = CredentialDefinition(type = listOf("VerifiableCredential", "OpenBadgeCredential"))
)
)
)
Expand All @@ -111,23 +110,24 @@ class AuthorizationCodeFlow(private val client: HttpClient) {
//
val issuanceRequestPwd =
Json.decodeFromString<IssuanceRequest>(loadResource("issuance/openbadgecredential-issuance-request-with-authorization-code-flow-and-pwd.json"))
issuerApi.issue(issuanceRequestPwd) {
issuerApi.jwt(issuanceRequestPwd) {
offerUrl = it
println("offer: $offerUrl")
}

offerUrlParams = Url(offerUrl).parameters.toMap()
offerObj = CredentialOfferRequest.fromHttpParameters(offerUrlParams)
credOffer = client.get(offerObj.credentialOfferUri!!).body<JsonObject>()
issuerState = credOffer["grants"]!!.jsonObject["authorization_code"]!!.jsonObject["issuer_state"]!!.jsonPrimitive.content
issuerState =
credOffer["grants"]!!.jsonObject["authorization_code"]!!.jsonObject["issuer_state"]!!.jsonPrimitive.content
authorizationRequest = authorizationRequest.copy(
issuerState = issuerState,
authorizationDetails = listOf(
AuthorizationDetails(
type = "openid_credential",
locations = listOf(credOffer["credential_issuer"]!!.jsonPrimitive.content),
format = CredentialFormat.jwt_vc,
credentialDefinition = CredentialDefinition(type = listOf("VerifiableCredential","OpenBadgeCredential"))
credentialDefinition = CredentialDefinition(type = listOf("VerifiableCredential", "OpenBadgeCredential"))
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions waltid-services/waltid-e2e-tests/src/test/kotlin/DidsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class DidsApi(private val client: HttpClient) {
private val didRegexPattern = "^^did:%s:\\S+\$"
suspend fun list(
wallet: UUID,
size: Int,
expectedDefault: DefaultDidOption,
size: Int? = null,
output: ((List<WalletDid>) -> Unit)? = null
) =
test("/wallet-api/wallet/{wallet}/dids - list DIDs") {
client.get("/wallet-api/wallet/$wallet/dids").expectSuccess().apply {
val dids = body<List<WalletDid>>()
assert(dids.isNotEmpty()) { "Wallet has no DIDs!" }
assert(dids.size == size) { "Wallet has invalid number of DIDs!" }
size?.let { assert(dids.size == it) { "Wallet has invalid number of DIDs!" } }
expectedDefault.whenNone { assert(dids.none { it.default }) }
expectedDefault.whenAny { assertNotNull(dids.single { it.default }) }
expectedDefault.whenSome { did -> assert(dids.single { it.did == did }.default) }
Expand Down
91 changes: 91 additions & 0 deletions waltid-services/waltid-e2e-tests/src/test/kotlin/E2ESdJwtTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import E2ETest.Companion.nameFieldSchemaPresentationRequestPayload
import E2ETest.Companion.sdjwtCredential
import id.walt.issuer.issuance.IssuanceRequest
import id.walt.oid4vc.data.dif.PresentationDefinition
import id.walt.webwallet.db.models.WalletCredential
import id.walt.webwallet.web.controllers.exchange.UsePresentationRequest
import io.ktor.http.*
import io.ktor.server.util.*
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.uuid.UUID

class E2ESdJwtTest(
private val issuerApi: IssuerApi,
private val exchangeApi: ExchangeApi,
private val sessionApi: Verifier.SessionApi,
private val verificationApi: Verifier.VerificationApi,
) {

fun e2e(wallet: UUID, did: String) = runTest {
//region -Issuer / offer url-
lateinit var offerUrl: String
val issuanceRequest = Json.decodeFromJsonElement<IssuanceRequest>(sdjwtCredential)
println("issuance-request:")
println(issuanceRequest)
issuerApi.sdjwt(issuanceRequest) {
offerUrl = it
println("offer: $offerUrl")
}
//endregion -Issuer / offer url-

//region -Exchange / claim-
lateinit var newCredential: WalletCredential
exchangeApi.resolveCredentialOffer(wallet, offerUrl)
exchangeApi.useOfferRequest(wallet, offerUrl, 1) {
newCredential = it.first()
}
//endregion -Exchange / claim-

//region -Verifier / request url-
lateinit var verificationUrl: String
lateinit var verificationId: String
verificationApi.verify(nameFieldSchemaPresentationRequestPayload) {
verificationUrl = it
verificationId = Url(verificationUrl).parameters.getOrFail("state")
}
//endregion -Verifier / request url-

//region -Exchange / presentation-
lateinit var resolvedPresentationOfferString: String
lateinit var presentationDefinition: String
exchangeApi.resolvePresentationRequest(wallet, verificationUrl) {
resolvedPresentationOfferString = it
presentationDefinition = Url(it).parameters.getOrFail("presentation_definition")
}

sessionApi.get(verificationId) {
assert(it.presentationDefinition == PresentationDefinition.fromJSONString(presentationDefinition))
}

exchangeApi.matchCredentialsForPresentationDefinition(
wallet, presentationDefinition, listOf(newCredential.id)
)
exchangeApi.unmatchedCredentialsForPresentationDefinition(wallet, presentationDefinition)
exchangeApi.usePresentationRequest(
wallet = wallet,
request = UsePresentationRequest(
did = did,
presentationRequest = resolvedPresentationOfferString,
selectedCredentials = listOf(newCredential.id),
disclosures = newCredential.disclosures?.let { mapOf(newCredential.id to listOf(it)) },
),
expectStatus = expectFailure,
)

sessionApi.get(verificationId) {
assert(it.tokenResponse?.vpToken?.jsonPrimitive?.contentOrNull?.expectLooksLikeJwt() != null) { "Received no valid token response!" }
assert(it.tokenResponse?.presentationSubmission != null) { "should have a presentation submission after submission" }

assert(it.verificationResult == false) { "overall verification should be valid" }
it.policyResults.let {
require(it != null) { "policyResults should be available after running policies" }
assert(it.size > 1) { "no policies have run" }
}
}
//endregion -Exchange / presentation-
}
}
Loading
Loading