diff --git a/waltid-services/waltid-e2e-tests/src/test/kotlin/AuthorizationCodeFlow.kt b/waltid-services/waltid-e2e-tests/src/test/kotlin/AuthorizationCodeFlow.kt index 3417e7a4e..18ce91e3a 100644 --- a/waltid-services/waltid-e2e-tests/src/test/kotlin/AuthorizationCodeFlow.kt +++ b/waltid-services/waltid-e2e-tests/src/test/kotlin/AuthorizationCodeFlow.kt @@ -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.* @@ -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 @@ -32,7 +29,7 @@ class AuthorizationCodeFlow(private val client: HttpClient) { // val issuanceRequestIdToken = Json.decodeFromString(loadResource("issuance/openbadgecredential-issuance-request-with-authorization-code-flow-and-id-token.json")) - issuerApi.issue(issuanceRequestIdToken) { + issuerApi.jwt(issuanceRequestIdToken) { offerUrl = it println("offer: $offerUrl") } @@ -40,7 +37,8 @@ class AuthorizationCodeFlow(private val client: HttpClient) { var offerUrlParams = Url(offerUrl).parameters.toMap() var offerObj = CredentialOfferRequest.fromHttpParameters(offerUrlParams) var credOffer = client.get(offerObj.credentialOfferUri!!).body() - 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", @@ -60,7 +58,7 @@ class AuthorizationCodeFlow(private val client: HttpClient) { type = "openid_credential", locations = listOf(credOffer["credential_issuer"]!!.jsonPrimitive.content), format = CredentialFormat.jwt_vc, - types = listOf("VerifiableCredential","OpenBadgeCredential") + types = listOf("VerifiableCredential", "OpenBadgeCredential") ) ) ) @@ -77,7 +75,7 @@ class AuthorizationCodeFlow(private val client: HttpClient) { // val issuanceRequestVpToken = Json.decodeFromString(loadResource("issuance/openbadgecredential-issuance-request-with-authorization-code-flow-and-vp-token.json")) - issuerApi.issue(issuanceRequestVpToken) { + issuerApi.jwt(issuanceRequestVpToken) { offerUrl = it println("offer: $offerUrl") } @@ -85,7 +83,8 @@ class AuthorizationCodeFlow(private val client: HttpClient) { offerUrlParams = Url(offerUrl).parameters.toMap() offerObj = CredentialOfferRequest.fromHttpParameters(offerUrlParams) credOffer = client.get(offerObj.credentialOfferUri!!).body() - 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( @@ -93,7 +92,7 @@ class AuthorizationCodeFlow(private val client: HttpClient) { type = "openid_credential", locations = listOf(credOffer["credential_issuer"]!!.jsonPrimitive.content), format = CredentialFormat.jwt_vc, - types = listOf("VerifiableCredential","OpenBadgeCredential") + types = listOf("VerifiableCredential", "OpenBadgeCredential") ) ) ) @@ -111,7 +110,7 @@ class AuthorizationCodeFlow(private val client: HttpClient) { // val issuanceRequestPwd = Json.decodeFromString(loadResource("issuance/openbadgecredential-issuance-request-with-authorization-code-flow-and-pwd.json")) - issuerApi.issue(issuanceRequestPwd) { + issuerApi.jwt(issuanceRequestPwd) { offerUrl = it println("offer: $offerUrl") } @@ -119,7 +118,8 @@ class AuthorizationCodeFlow(private val client: HttpClient) { offerUrlParams = Url(offerUrl).parameters.toMap() offerObj = CredentialOfferRequest.fromHttpParameters(offerUrlParams) credOffer = client.get(offerObj.credentialOfferUri!!).body() - 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( @@ -127,7 +127,7 @@ class AuthorizationCodeFlow(private val client: HttpClient) { type = "openid_credential", locations = listOf(credOffer["credential_issuer"]!!.jsonPrimitive.content), format = CredentialFormat.jwt_vc, - types = listOf("VerifiableCredential","OpenBadgeCredential") + types = listOf("VerifiableCredential", "OpenBadgeCredential") ) ) ) diff --git a/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ESdJwtTest.kt b/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ESdJwtTest.kt index fd1adbb0a..5a26ca29d 100644 --- a/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ESdJwtTest.kt +++ b/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ESdJwtTest.kt @@ -74,7 +74,7 @@ class E2ESdJwtTest( selectedCredentials = listOf(newCredential.id), disclosures = newCredential.disclosures?.let { mapOf(newCredential.id to listOf(it)) }, ), - expectStatus = HttpResponse::expectFailure, + expectStatus = expectFailure, ) sessionApi.get(verificationId) { diff --git a/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ETest.kt b/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ETest.kt index b825cfa3f..efafd5b61 100644 --- a/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ETest.kt +++ b/waltid-services/waltid-e2e-tests/src/test/kotlin/E2ETest.kt @@ -339,17 +339,17 @@ class E2ETest { fun String.expectLooksLikeJwt(): String = also { assert(startsWith("ey") && count { it == '.' } == 2) { "Does not look like JWT" } } -suspend fun HttpResponse.expectSuccess(): HttpResponse = also { - assert(status.isSuccess()) { "HTTP status is non-successful for response: $it, body is ${it.bodyAsText()}" } + +val expectSuccess: suspend HttpResponse.() -> HttpResponse = { + assert(this.status.isSuccess()) { "HTTP status is non-successful for response: $this, body is ${this.bodyAsText()}" }; this } -fun HttpResponse.expectRedirect(): HttpResponse = also { - assert(status == HttpStatusCode.Found) { "HTTP status is non-successful" } +val expectRedirect: HttpResponse.() -> HttpResponse = { + assert(this.status == HttpStatusCode.Found) { "HTTP status is non-successful" }; this } -//todo: temporary -fun HttpResponse.expectFailure(): HttpResponse = also { - assert(!status.isSuccess()) { "HTTP status is successful" } +val expectFailure: HttpResponse.() -> HttpResponse = { + assert(!status.isSuccess()) { "HTTP status is successful" }; this } fun JsonElement.tryGetData(key: String): JsonElement? = key.split('.').let { diff --git a/waltid-services/waltid-e2e-tests/src/test/kotlin/ExchangeApi.kt b/waltid-services/waltid-e2e-tests/src/test/kotlin/ExchangeApi.kt index 93a834795..3592ff105 100644 --- a/waltid-services/waltid-e2e-tests/src/test/kotlin/ExchangeApi.kt +++ b/waltid-services/waltid-e2e-tests/src/test/kotlin/ExchangeApi.kt @@ -62,7 +62,8 @@ class ExchangeApi(private val client: HttpClient) { }.expectSuccess().apply { val matched = body>() assert(matched.size == expectedCredentialIds.size) { "presentation definition should match $expectedCredentialIds credential(s), but have ${matched.size}" } - assert(matched.map { it.id }.containsAll(expectedCredentialIds)) { "matched credentials does not contain all of the expected ones" } + assert(matched.map { it.id } + .containsAll(expectedCredentialIds)) { "matched credentials does not contain all of the expected ones" } output?.invoke(matched) } } @@ -86,7 +87,7 @@ class ExchangeApi(private val client: HttpClient) { suspend fun usePresentationRequest( wallet: UUID, request: UsePresentationRequest, - expectStatus: HttpResponse.() -> HttpResponse = HttpResponse::expectSuccess + expectStatus: suspend HttpResponse.() -> HttpResponse = expectSuccess ) = test("/wallet-api/wallet/{wallet}/exchange/usePresentationRequest - present credentials") { client.post("/wallet-api/wallet/$wallet/exchange/usePresentationRequest") { setBody(request) diff --git a/waltid-services/waltid-e2e-tests/src/test/kotlin/LspPotentialWallet.kt b/waltid-services/waltid-e2e-tests/src/test/kotlin/LspPotentialWallet.kt index 582dc0cda..d9254d416 100644 --- a/waltid-services/waltid-e2e-tests/src/test/kotlin/LspPotentialWallet.kt +++ b/waltid-services/waltid-e2e-tests/src/test/kotlin/LspPotentialWallet.kt @@ -3,21 +3,15 @@ import id.walt.credentials.vc.vcs.W3CVC import id.walt.crypto.keys.KeyGenerationRequest import id.walt.crypto.keys.KeySerialization import id.walt.crypto.keys.KeyType -import id.walt.crypto.keys.jwk.JWKKey -import id.walt.crypto.utils.JsonUtils.toJsonElement import id.walt.issuer.issuance.IssuanceExamples import id.walt.issuer.issuance.IssuanceRequest -import id.walt.issuer.issuance.createCredentialOfferUri import id.walt.issuer.lspPotential.LspPotentialIssuanceInterop import id.walt.oid4vc.data.AuthenticationMethod import id.walt.oid4vc.data.CredentialFormat import id.walt.oid4vc.data.CredentialOffer import id.walt.oid4vc.data.OpenIDProviderMetadata -import id.walt.oid4vc.data.dif.VCFormat import id.walt.oid4vc.requests.AuthorizationRequest -import id.walt.verifier.lspPotential.LspPotentialVerificationInterop import id.walt.webwallet.db.models.WalletCredential -import id.walt.webwallet.db.models.WalletDid import id.walt.webwallet.web.controllers.UsePresentationRequest import io.ktor.client.* import io.ktor.client.call.* @@ -202,7 +196,7 @@ class LspPotentialWallet(val client: HttpClient, val walletId: String) { // === find matching credential === val matchingCreds = client.post("/wallet-api/wallet/$walletId/exchange/matchCredentialsForPresentationDefinition") { setBody(parsedRequest.presentationDefinition!!) - }.expectSuccess().let { response -> response.body>()} + }.expectSuccess().body>() assertNotEquals(0, matchingCreds.size) client.post("/wallet-api/wallet/$walletId/exchange/usePresentationRequest") {