-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: sdjwt e2e test, exchange-api, verifier-api
# Conflicts: # waltid-services/waltid-e2e-tests/src/test/kotlin/E2ETest.kt
- Loading branch information
1 parent
152deab
commit fa39a60
Showing
5 changed files
with
161 additions
and
131 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
waltid-services/waltid-e2e-tests/src/test/kotlin/E2ESdJwtTest.kt
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,92 @@ | ||
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.UsePresentationRequest | ||
import io.ktor.client.statement.* | ||
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 = HttpResponse::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- | ||
} | ||
} |
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
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
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
23 changes: 23 additions & 0 deletions
23
.../src/test/resources/presentation/openbadgecredential-name-field-presentation-request.json
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,23 @@ | ||
{ | ||
"request_credentials": [ | ||
{ | ||
"credential": "OpenBadgeCredential", | ||
"policies": [ | ||
{ | ||
"policy": "schema", | ||
"args": { | ||
"type": "object", | ||
"required": [ | ||
"name" | ||
], | ||
"properties": { | ||
"name": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |