From f9c7c5063a8152cc5f548124c69e8c28ce6eddd5 Mon Sep 17 00:00:00 2001 From: Babis Routis <127745316+babisRoutis@users.noreply.github.com> Date: Thu, 11 Jan 2024 18:49:24 +0200 Subject: [PATCH] Rename PresentationId to TransactionId (#94) --- .../eudi/verifier/endpoint/VerifierContext.kt | 4 ++-- .../endpoint/adapter/input/web/VerifierApi.kt | 17 ++++++++++------- ...imbus.kt => GenerateTransactionIdNimbus.kt} | 9 +++++---- .../persistence/PresentationInMemoryRepo.kt | 4 ++-- .../verifier/endpoint/domain/Presentation.kt | 12 ++++++------ .../endpoint/port/input/GetWalletResponse.kt | 4 ++-- .../endpoint/port/input/InitTransaction.kt | 11 +++++++---- .../port/input/TimeoutPresentations.kt | 6 +++--- ...sentationId.kt => GenerateTransactionId.kt} | 10 +++++----- .../out/persistence/LoadPresentationById.kt | 4 ++-- .../ec/eudi/verifier/endpoint/TestContext.kt | 14 +++++++------- .../adapter/input/web/VerifierApiClient.kt | 10 +++++----- .../web/WalletResponseDirectPostJwtTest.kt | 4 ++-- ...ponseDirectPostWithIdTokenAndVpTokenTest.kt | 9 +++++---- .../WalletResponseDirectPostWithIdTokenTest.kt | 10 +++++----- .../endpoint/port/input/InitTransactionTest.kt | 18 +++++++++--------- 16 files changed, 77 insertions(+), 69 deletions(-) rename src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/cfg/{GeneratePresentationIdNimbus.kt => GenerateTransactionIdNimbus.kt} (76%) rename src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/cfg/{GeneratePresentationId.kt => GenerateTransactionId.kt} (72%) diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/VerifierContext.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/VerifierContext.kt index 9952dbb2..f9661ce0 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/VerifierContext.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/VerifierContext.kt @@ -28,8 +28,8 @@ import eu.europa.ec.eudi.verifier.endpoint.adapter.input.timer.ScheduleTimeoutPr import eu.europa.ec.eudi.verifier.endpoint.adapter.input.web.StaticContent import eu.europa.ec.eudi.verifier.endpoint.adapter.input.web.VerifierApi import eu.europa.ec.eudi.verifier.endpoint.adapter.input.web.WalletApi -import eu.europa.ec.eudi.verifier.endpoint.adapter.out.cfg.GeneratePresentationIdNimbus import eu.europa.ec.eudi.verifier.endpoint.adapter.out.cfg.GenerateRequestIdNimbus +import eu.europa.ec.eudi.verifier.endpoint.adapter.out.cfg.GenerateTransactionIdNimbus import eu.europa.ec.eudi.verifier.endpoint.adapter.out.jose.GenerateEphemeralEncryptionKeyPairNimbus import eu.europa.ec.eudi.verifier.endpoint.adapter.out.jose.ParseJarmOptionNimbus import eu.europa.ec.eudi.verifier.endpoint.adapter.out.jose.SignRequestObjectNimbus @@ -64,7 +64,7 @@ internal fun beans(clock: Clock) = beans { // // Persistence // - bean { GeneratePresentationIdNimbus(64) } + bean { GenerateTransactionIdNimbus(64) } bean { GenerateRequestIdNimbus(64) } with(PresentationInMemoryRepo()) { bean { loadPresentationById } diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApi.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApi.kt index 35f6743c..5d0a8601 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApi.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApi.kt @@ -16,9 +16,9 @@ package eu.europa.ec.eudi.verifier.endpoint.adapter.input.web import arrow.core.raise.either -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId import eu.europa.ec.eudi.verifier.endpoint.domain.RequestId import eu.europa.ec.eudi.verifier.endpoint.domain.ResponseCode +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId import eu.europa.ec.eudi.verifier.endpoint.port.input.* import kotlinx.serialization.SerializationException import org.slf4j.Logger @@ -49,7 +49,10 @@ class VerifierApi( val input = req.awaitBody() logger.info("Handling InitTransaction nonce=${input.nonce} ... ") either { initTransaction(input) }.fold( - ifRight = { ok().json().bodyValueAndAwait(it) }, + ifRight = { it -> + logger.info("Initiated transaction ${it.transactionId}") + ok().json().bodyValueAndAwait(it) + }, ifLeft = { it.asBadRequest() }, ) } catch (t: SerializationException) { @@ -64,11 +67,11 @@ class VerifierApi( private suspend fun handleGetWalletResponse(req: ServerRequest): ServerResponse { suspend fun found(walletResponse: WalletResponseTO) = ok().json().bodyValueAndAwait(walletResponse) - val presentationId = req.presentationId() + val transactionId = req.transactionId() val responseCode = req.queryParam("response_code").getOrNull()?.let { ResponseCode(it) } - logger.info("Handling GetWalletResponse for $presentationId and response_code: $responseCode ...") - return when (val result = getWalletResponse(presentationId, responseCode)) { + logger.info("Handling GetWalletResponse for $transactionId and response_code: $responseCode ...") + return when (val result = getWalletResponse(transactionId, responseCode)) { is QueryResponse.NotFound -> ServerResponse.notFound().buildAndAwait() is QueryResponse.InvalidState -> badRequest().buildAndAwait() is QueryResponse.Found -> found(result.value) @@ -77,12 +80,12 @@ class VerifierApi( companion object { const val INIT_TRANSACTION_PATH = "/ui/presentations" - const val WALLET_RESPONSE_PATH = "/ui/presentations/{presentationId}" + const val WALLET_RESPONSE_PATH = "/ui/presentations/{transactionId}" /** * Extracts from the request the [RequestId] */ - private fun ServerRequest.presentationId() = PresentationId(pathVariable("presentationId")) + private fun ServerRequest.transactionId() = TransactionId(pathVariable("transactionId")) private suspend fun ValidationError.asBadRequest() = badRequest().json().bodyValueAndAwait(mapOf("error" to this)) } diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/cfg/GeneratePresentationIdNimbus.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/cfg/GenerateTransactionIdNimbus.kt similarity index 76% rename from src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/cfg/GeneratePresentationIdNimbus.kt rename to src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/cfg/GenerateTransactionIdNimbus.kt index d8824a8f..bab28ee3 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/cfg/GeneratePresentationIdNimbus.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/cfg/GenerateTransactionIdNimbus.kt @@ -16,13 +16,14 @@ package eu.europa.ec.eudi.verifier.endpoint.adapter.out.cfg import com.nimbusds.oauth2.sdk.id.Identifier -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId -import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GeneratePresentationId +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId +import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GenerateTransactionId -class GeneratePresentationIdNimbus(private val byteLength: Int) : GeneratePresentationId { +class GenerateTransactionIdNimbus(private val byteLength: Int) : GenerateTransactionId { init { require(byteLength >= 32) { "Value should be greater or equal to 32" } } - override suspend fun invoke(): PresentationId = PresentationId(Identifier(byteLength).value) + + override suspend fun invoke(): TransactionId = TransactionId(Identifier(byteLength).value) } diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/persistence/PresentationInMemoryRepo.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/persistence/PresentationInMemoryRepo.kt index 3b34b46a..9fea5130 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/persistence/PresentationInMemoryRepo.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/out/persistence/PresentationInMemoryRepo.kt @@ -16,7 +16,7 @@ package eu.europa.ec.eudi.verifier.endpoint.adapter.out.persistence import eu.europa.ec.eudi.verifier.endpoint.domain.Presentation -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId import eu.europa.ec.eudi.verifier.endpoint.domain.isExpired import eu.europa.ec.eudi.verifier.endpoint.port.out.persistence.LoadIncompletePresentationsOlderThan import eu.europa.ec.eudi.verifier.endpoint.port.out.persistence.LoadPresentationById @@ -28,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap * An input-memory repository for storing [presentations][Presentation] */ class PresentationInMemoryRepo( - private val presentations: ConcurrentHashMap = ConcurrentHashMap(), + private val presentations: ConcurrentHashMap = ConcurrentHashMap(), ) { val loadPresentationById: LoadPresentationById by lazy { diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/domain/Presentation.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/domain/Presentation.kt index 3e53793c..3451e13e 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/domain/Presentation.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/domain/Presentation.kt @@ -21,7 +21,7 @@ import java.time.Clock import java.time.Instant @JvmInline -value class PresentationId(val value: String) { +value class TransactionId(val value: String) { init { require(value.isNotBlank()) } @@ -130,7 +130,7 @@ sealed interface GetWalletResponseMethod { * The entity that represents the presentation process */ sealed interface Presentation { - val id: PresentationId + val id: TransactionId val initiatedAt: Instant val type: PresentationType @@ -138,7 +138,7 @@ sealed interface Presentation { * A presentation process that has been just requested */ class Requested( - override val id: PresentationId, + override val id: TransactionId, override val initiatedAt: Instant, override val type: PresentationType, val requestId: RequestId, @@ -156,7 +156,7 @@ sealed interface Presentation { * or later on (when using request_uri JAR parameter) */ class RequestObjectRetrieved private constructor( - override val id: PresentationId, + override val id: TransactionId, override val initiatedAt: Instant, override val type: PresentationType, val requestId: RequestId, @@ -192,7 +192,7 @@ sealed interface Presentation { * A presentation process that has been just submitted by the wallet to the verifier backend */ class Submitted private constructor( - override val id: PresentationId, + override val id: TransactionId, override val initiatedAt: Instant, override val type: PresentationType, val requestId: RequestId, @@ -232,7 +232,7 @@ sealed interface Presentation { } class TimedOut private constructor( - override val id: PresentationId, + override val id: TransactionId, override val initiatedAt: Instant, override val type: PresentationType, val requestObjectRetrievedAt: Instant? = null, diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/GetWalletResponse.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/GetWalletResponse.kt index 23e9b7c7..d72c9070 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/GetWalletResponse.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/GetWalletResponse.kt @@ -58,13 +58,13 @@ private fun WalletResponse.toTO(): WalletResponseTO { * Given a [PresentationId] and a [Nonce] returns the [WalletResponse] */ interface GetWalletResponse { - suspend operator fun invoke(presentationId: PresentationId, responseCode: ResponseCode?): QueryResponse + suspend operator fun invoke(presentationId: TransactionId, responseCode: ResponseCode?): QueryResponse } class GetWalletResponseLive( private val loadPresentationById: LoadPresentationById, ) : GetWalletResponse { - override suspend fun invoke(presentationId: PresentationId, responseCode: ResponseCode?): QueryResponse { + override suspend fun invoke(presentationId: TransactionId, responseCode: ResponseCode?): QueryResponse { return when (val presentation = loadPresentationById(presentationId)) { null -> NotFound is Presentation.Submitted -> diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransaction.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransaction.kt index a6fa9d6d..793bb52b 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransaction.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransaction.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@file:OptIn(ExperimentalSerializationApi::class) + package eu.europa.ec.eudi.verifier.endpoint.port.input import arrow.core.raise.Raise @@ -21,11 +23,12 @@ import arrow.core.raise.ensureNotNull import eu.europa.ec.eudi.prex.PresentationDefinition import eu.europa.ec.eudi.verifier.endpoint.domain.* import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.CreateQueryWalletResponseRedirectUri -import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GeneratePresentationId import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GenerateRequestId +import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GenerateTransactionId import eu.europa.ec.eudi.verifier.endpoint.port.out.jose.GenerateEphemeralEncryptionKeyPair import eu.europa.ec.eudi.verifier.endpoint.port.out.jose.SignRequestObject import eu.europa.ec.eudi.verifier.endpoint.port.out.persistence.StorePresentation +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Required import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -112,7 +115,7 @@ enum class ValidationError { */ @Serializable data class JwtSecuredAuthorizationRequestTO( - @Required @SerialName("presentation_id") val presentationId: String, + @Required @SerialName("presentation_id") val transactionId: String, @Required @SerialName("client_id") val clientId: String, @SerialName("request") val request: String? = null, @SerialName("request_uri") val requestUri: String?, @@ -136,7 +139,7 @@ fun interface InitTransaction { * The default implementation of the use case */ class InitTransactionLive( - private val generatePresentationId: GeneratePresentationId, + private val generateTransactionId: GenerateTransactionId, private val generateRequestId: GenerateRequestId, private val storePresentation: StorePresentation, private val signRequestObject: SignRequestObject, @@ -161,7 +164,7 @@ class InitTransactionLive( // Initialize presentation val requestedPresentation = Presentation.Requested( - id = generatePresentationId(), + id = generateTransactionId(), initiatedAt = clock.instant(), requestId = generateRequestId(), type = type, diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/TimeoutPresentations.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/TimeoutPresentations.kt index 5437e018..d9b26e24 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/TimeoutPresentations.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/TimeoutPresentations.kt @@ -16,7 +16,7 @@ package eu.europa.ec.eudi.verifier.endpoint.port.input import eu.europa.ec.eudi.verifier.endpoint.domain.Presentation -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId import eu.europa.ec.eudi.verifier.endpoint.domain.timedOut import eu.europa.ec.eudi.verifier.endpoint.port.out.persistence.LoadIncompletePresentationsOlderThan import eu.europa.ec.eudi.verifier.endpoint.port.out.persistence.StorePresentation @@ -25,7 +25,7 @@ import java.time.Duration fun interface TimeoutPresentations { - suspend operator fun invoke(): List + suspend operator fun invoke(): List } class TimeoutPresentationsLive( @@ -34,7 +34,7 @@ class TimeoutPresentationsLive( private val maxAge: Duration, private val clock: Clock, ) : TimeoutPresentations { - override suspend operator fun invoke(): List { + override suspend operator fun invoke(): List { val expireBefore = clock.instant().minusSeconds(maxAge.toSeconds()) return loadIncompletePresentationsOlderThan(expireBefore).mapNotNull { timeout(it)?.id } } diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/cfg/GeneratePresentationId.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/cfg/GenerateTransactionId.kt similarity index 72% rename from src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/cfg/GeneratePresentationId.kt rename to src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/cfg/GenerateTransactionId.kt index d5fd204a..e9fc6981 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/cfg/GeneratePresentationId.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/cfg/GenerateTransactionId.kt @@ -15,19 +15,19 @@ */ package eu.europa.ec.eudi.verifier.endpoint.port.out.cfg -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId /** - * A port for generating [PresentationId] + * A port for generating [TransactionId] */ -fun interface GeneratePresentationId { - suspend operator fun invoke(): PresentationId +fun interface GenerateTransactionId { + suspend operator fun invoke(): TransactionId companion object { /** * Fixed generator, useful input tests */ - fun fixed(id: PresentationId): GeneratePresentationId = GeneratePresentationId { id } + fun fixed(id: TransactionId): GenerateTransactionId = GenerateTransactionId { id } } } diff --git a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/persistence/LoadPresentationById.kt b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/persistence/LoadPresentationById.kt index 49a8e557..4a23fa59 100644 --- a/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/persistence/LoadPresentationById.kt +++ b/src/main/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/out/persistence/LoadPresentationById.kt @@ -16,11 +16,11 @@ package eu.europa.ec.eudi.verifier.endpoint.port.out.persistence import eu.europa.ec.eudi.verifier.endpoint.domain.Presentation -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId /** * Loads a [Presentation] from a storage */ fun interface LoadPresentationById { - suspend operator fun invoke(presentationProcessById: PresentationId): Presentation? + suspend operator fun invoke(presentationProcessById: TransactionId): Presentation? } diff --git a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/TestContext.kt b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/TestContext.kt index f4754c48..f8dcd8ba 100644 --- a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/TestContext.kt +++ b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/TestContext.kt @@ -32,8 +32,8 @@ import eu.europa.ec.eudi.verifier.endpoint.port.input.GetRequestObjectLive import eu.europa.ec.eudi.verifier.endpoint.port.input.InitTransaction import eu.europa.ec.eudi.verifier.endpoint.port.input.InitTransactionLive import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.CreateQueryWalletResponseRedirectUri -import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GeneratePresentationId import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GenerateRequestId +import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.GenerateTransactionId import org.springframework.boot.test.context.SpringBootTest import org.springframework.context.ApplicationContextInitializer import org.springframework.context.annotation.Configuration @@ -49,13 +49,13 @@ import java.util.* import kotlin.reflect.KClass object TestContext { - val testDate = LocalDate.of(1974, 11, 2).atTime(10, 5, 33) + private val testDate = LocalDate.of(1974, 11, 2).atTime(10, 5, 33) val testClock = Clock.fixed(testDate.toInstant(ZoneOffset.UTC), ZoneOffset.UTC) - val testPresentationId = PresentationId("SamplePresentationId") - val generatedPresentationId = GeneratePresentationId.fixed(testPresentationId) + val testTransactionId = TransactionId("SampleTxId") + private val generatedTransactionId = GenerateTransactionId.fixed(testTransactionId) val testRequestId = RequestId("SampleRequestId") - val generateRequestId = GenerateRequestId.fixed(testRequestId) - val rsaJwk = RSAKeyGenerator(2048) + private val generateRequestId = GenerateRequestId.fixed(testRequestId) + private val rsaJwk = RSAKeyGenerator(2048) .keyUse(KeyUse.SIGNATURE) // indicate the intended use of the key (optional) .keyID(UUID.randomUUID().toString()) // give the key a unique ID (optional) .issueTime(Date()) // issued-at timestamp (optional) @@ -84,7 +84,7 @@ object TestContext { presentationDefinitionByReference: EmbedOption.ByReference, ): InitTransaction = InitTransactionLive( - generatedPresentationId, + generatedTransactionId, generateRequestId, storePresentation, singRequestObject, diff --git a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApiClient.kt b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApiClient.kt index e1dfe70e..601eb776 100644 --- a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApiClient.kt +++ b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/VerifierApiClient.kt @@ -15,8 +15,8 @@ */ package eu.europa.ec.eudi.verifier.endpoint.adapter.input.web -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId import eu.europa.ec.eudi.verifier.endpoint.domain.ResponseCode +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId import eu.europa.ec.eudi.verifier.endpoint.port.input.InitTransactionTO import eu.europa.ec.eudi.verifier.endpoint.port.input.JwtSecuredAuthorizationRequestTO import eu.europa.ec.eudi.verifier.endpoint.port.input.WalletResponseTO @@ -62,9 +62,9 @@ object VerifierApiClient { * - (request) mdocVerification application Internet frontend to Internet Web Service, flow "18 HTTPs POST to response_uri [section B.3.2.2] * - (response) Internet Web Service to mdocVerification application Internet frontend, flow "20 return status and conditionally return data" */ - fun getWalletResponse(client: WebTestClient, presentationId: PresentationId, responseCode: ResponseCode? = null): WalletResponseTO? { + fun getWalletResponse(client: WebTestClient, presentationId: TransactionId, responseCode: ResponseCode? = null): WalletResponseTO? { val walletResponseUri = - VerifierApi.WALLET_RESPONSE_PATH.replace("{presentationId}", presentationId.value) + + VerifierApi.WALLET_RESPONSE_PATH.replace("{transactionId}", presentationId.value) + (responseCode?.let { "?response_code=${it.value}" } ?: "") // when @@ -85,11 +85,11 @@ object VerifierApiClient { fun getWalletResponseNoValidation( client: WebTestClient, - presentationId: PresentationId, + transactionId: TransactionId, responseCode: ResponseCode? = null, ): EntityExchangeResult { val walletResponseUri = - VerifierApi.WALLET_RESPONSE_PATH.replace("{presentationId}", presentationId.value) + + VerifierApi.WALLET_RESPONSE_PATH.replace("{transactionId}", transactionId.value) + (responseCode?.let { "?response_code=${it.value}" } ?: "") // when diff --git a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostJwtTest.kt b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostJwtTest.kt index 06bed9ae..d5728695 100644 --- a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostJwtTest.kt +++ b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostJwtTest.kt @@ -24,8 +24,8 @@ import eu.europa.ec.eudi.verifier.endpoint.VerifierApplicationTest import eu.europa.ec.eudi.verifier.endpoint.adapter.out.jose.nimbusEnc import eu.europa.ec.eudi.verifier.endpoint.adapter.out.jose.nimbusJWSAlgorithm import eu.europa.ec.eudi.verifier.endpoint.domain.JarmOption -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId import eu.europa.ec.eudi.verifier.endpoint.domain.RequestId +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId import eu.europa.ec.eudi.verifier.endpoint.port.input.ResponseModeTO import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest @@ -135,7 +135,7 @@ internal class WalletResponseDirectPostJwtTest { // when val response = VerifierApiClient.getWalletResponse( client, - PresentationId(transactionInitialized.presentationId), + TransactionId(transactionInitialized.transactionId), ) // then assertNotNull(response, "response is null") diff --git a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenAndVpTokenTest.kt b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenAndVpTokenTest.kt index e6db6b44..5b61df47 100644 --- a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenAndVpTokenTest.kt +++ b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenAndVpTokenTest.kt @@ -16,8 +16,8 @@ package eu.europa.ec.eudi.verifier.endpoint.adapter.input.web import eu.europa.ec.eudi.verifier.endpoint.VerifierApplicationTest -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId import eu.europa.ec.eudi.verifier.endpoint.domain.RequestId +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.MethodOrderer.OrderAnnotation import org.junit.jupiter.api.TestMethodOrder @@ -68,7 +68,7 @@ internal class WalletResponseDirectPostWithIdTokenAndVpTokenTest { val initTransaction = VerifierApiClient.loadInitTransactionTO("02-presentationDefinition.json") val transactionInitialized = VerifierApiClient.initTransaction(client, initTransaction) val requestId = RequestId(transactionInitialized.requestUri?.removePrefix("http://localhost:0/wallet/request.jwt/")!!) - val presentationId = transactionInitialized.presentationId + val presentationId = transactionInitialized.transactionId WalletApiClient.getRequestObject(client, transactionInitialized.requestUri!!) val formEncodedBody: MultiValueMap = LinkedMultiValueMap() @@ -97,8 +97,9 @@ internal class WalletResponseDirectPostWithIdTokenAndVpTokenTest { // given val initTransaction = VerifierApiClient.loadInitTransactionTO("02-presentationDefinition.json") val transactionInitialized = VerifierApiClient.initTransaction(client, initTransaction) - val presentationId = PresentationId(transactionInitialized.presentationId) - val requestId = RequestId(transactionInitialized.requestUri?.removePrefix("http://localhost:0/wallet/request.jwt/")!!) + val presentationId = TransactionId(transactionInitialized.transactionId) + val requestId = + RequestId(transactionInitialized.requestUri?.removePrefix("http://localhost:0/wallet/request.jwt/")!!) WalletApiClient.getRequestObject(client, transactionInitialized.requestUri!!) val formEncodedBody: MultiValueMap = LinkedMultiValueMap() diff --git a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenTest.kt b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenTest.kt index e974bcbb..2db15e72 100644 --- a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenTest.kt +++ b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/adapter/input/web/WalletResponseDirectPostWithIdTokenTest.kt @@ -16,9 +16,9 @@ package eu.europa.ec.eudi.verifier.endpoint.adapter.input.web import eu.europa.ec.eudi.verifier.endpoint.VerifierApplicationTest -import eu.europa.ec.eudi.verifier.endpoint.domain.PresentationId import eu.europa.ec.eudi.verifier.endpoint.domain.RequestId import eu.europa.ec.eudi.verifier.endpoint.domain.ResponseCode +import eu.europa.ec.eudi.verifier.endpoint.domain.TransactionId import eu.europa.ec.eudi.verifier.endpoint.port.input.IdTokenTypeTO import eu.europa.ec.eudi.verifier.endpoint.port.input.InitTransactionTO import eu.europa.ec.eudi.verifier.endpoint.port.input.PresentationTypeTO @@ -113,7 +113,7 @@ internal class WalletResponseDirectPostWithIdTokenTest { // when val response = VerifierApiClient.getWalletResponse( client, - PresentationId(transactionInitialized.presentationId), + TransactionId(transactionInitialized.transactionId), ) // then @@ -175,7 +175,7 @@ internal class WalletResponseDirectPostWithIdTokenTest { // when val returnResult = VerifierApiClient.getWalletResponseNoValidation( client, - PresentationId(transactionInitialized.presentationId), + TransactionId(transactionInitialized.transactionId), ResponseCode("yszZvb3IoEnSYcRI7R7xZ01_n59AvhBTdr71uSCaqDaT7kF32spauGdn3KRHg0NiR2qtxA5_JeA4xd-Tu6oqhQ"), ) @@ -209,7 +209,7 @@ internal class WalletResponseDirectPostWithIdTokenTest { // when val returnResult = VerifierApiClient.getWalletResponseNoValidation( client, - PresentationId(transactionInitialized.presentationId), + TransactionId(transactionInitialized.transactionId), ) // then @@ -253,7 +253,7 @@ internal class WalletResponseDirectPostWithIdTokenTest { // when val response = VerifierApiClient.getWalletResponseNoValidation( client, - PresentationId(transactionInitialized.presentationId), + TransactionId(transactionInitialized.transactionId), ResponseCode(responseCode!!), ) diff --git a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransactionTest.kt b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransactionTest.kt index ea586933..a275b153 100644 --- a/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransactionTest.kt +++ b/src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/port/input/InitTransactionTest.kt @@ -31,7 +31,7 @@ import kotlin.test.* class InitTransactionTest { - private val testPresentationId = TestContext.testPresentationId + private val testTransactionId = TestContext.testTransactionId private val uri = URL("https://foo") private val verifierConfig = VerifierConfig( @@ -64,7 +64,7 @@ class InitTransactionTest { assertEquals(jwtSecuredAuthorizationRequest.clientId, verifierConfig.clientIdScheme.clientId) assertNotNull(jwtSecuredAuthorizationRequest.request) assertTrue { - loadPresentationById(testPresentationId)?.let { it is Presentation.RequestObjectRetrieved } ?: false + loadPresentationById(testTransactionId)?.let { it is Presentation.RequestObjectRetrieved } ?: false } } @@ -99,7 +99,7 @@ class InitTransactionTest { assertEquals(jwtSecuredAuthorizationRequest.clientId, verifierConfig.clientIdScheme.clientId) assertEquals(uri.toExternalForm(), jwtSecuredAuthorizationRequest.requestUri) assertTrue { - loadPresentationById(testPresentationId)?.let { it is Presentation.Requested } ?: false + loadPresentationById(testTransactionId)?.let { it is Presentation.Requested } ?: false } } @@ -151,7 +151,7 @@ class InitTransactionTest { val jwtSecuredAuthorizationRequest = either { useCase(input) }.getOrElse { fail("Unexpected $it") } assertEquals(jwtSecuredAuthorizationRequest.clientId, verifierConfig.clientIdScheme.clientId) assertNotNull(jwtSecuredAuthorizationRequest.request) - val presentation = loadPresentationById(testPresentationId) + val presentation = loadPresentationById(testTransactionId) val requestObjectRetrieved = assertIs(presentation) assertEquals(ResponseModeOption.DirectPost, requestObjectRetrieved.responseMode) } @@ -181,7 +181,7 @@ class InitTransactionTest { assertEquals(jwtSecuredAuthorizationRequest.clientId, verifierConfig.clientIdScheme.clientId) assertNull(jwtSecuredAuthorizationRequest.request) assertNotNull(jwtSecuredAuthorizationRequest.requestUri) - val presentation = loadPresentationById(testPresentationId) + val presentation = loadPresentationById(testTransactionId) assertIs(presentation) Unit } @@ -209,7 +209,7 @@ class InitTransactionTest { assertNotNull(jwtSecuredAuthorizationRequest.request) val claims = SignedJWT.parse(jwtSecuredAuthorizationRequest.request).payload!!.toJSONObject()!! assertEquals(uri.toExternalForm(), claims["presentation_definition_uri"]) - val presentation = loadPresentationById(testPresentationId) + val presentation = loadPresentationById(testTransactionId) assertIs(presentation) Unit } @@ -280,7 +280,7 @@ class InitTransactionTest { ) either { useCase(input) }.getOrElse { fail("Unexpected $it") } - val presentation = loadPresentationById(testPresentationId) + val presentation = loadPresentationById(testTransactionId) assertIs(presentation) assertIs(presentation.getWalletResponseMethod) } @@ -302,7 +302,7 @@ class InitTransactionTest { ) either { useCase(input) }.getOrElse { fail("Unexpected $it") } - val presentation = loadPresentationById(testPresentationId) + val presentation = loadPresentationById(testTransactionId) assertIs(presentation) assertIs(presentation.getWalletResponseMethod) } @@ -313,6 +313,6 @@ class InitTransactionTest { ifLeft = { error -> assertEquals(expectedError, error) }, ) - private suspend fun loadPresentationById(id: PresentationId) = + private suspend fun loadPresentationById(id: TransactionId) = TestContext.loadPresentationById(id) }