From 7b8df9f6e4ce14040017796f2a44acddfef34a52 Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Mon, 28 Oct 2024 00:37:52 +0100 Subject: [PATCH] fix: Libraries compatibility: openapi generator, kotlinx coroutines and ktor client --- gradle/libs.versions.toml | 2 +- .../fed/client/service/OIDFClientServices.kt | 2 +- .../fed/client/trustchain/TrustChain.js.kt | 10 ++++----- .../client/trustchain/TrustChainTest.js.kt | 22 +++++++++---------- .../oid/fed/common/mime/JsonUrlEncoder.kt | 1 + 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a40f880d..e81cceda 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ junit = "4.13.2" kotlin = "2.0.0" ktor = "2.3.11" kotlinxSerialization = "1.7.1" -kotlinxCoroutines = "1.9.0" +kotlinxCoroutines = "1.8.0" springboot = "3.3.1" springDependencyManagement = "1.1.5" kermitLogging = "2.0.4" diff --git a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/service/OIDFClientServices.kt b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/service/OIDFClientServices.kt index 39294980..b79800a9 100644 --- a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/service/OIDFClientServices.kt +++ b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/service/OIDFClientServices.kt @@ -24,7 +24,7 @@ object DefaultCallbacks { fun fetchService(): CallbackType { if (fetchCallbackService == null) { - throw IllegalStateException("No default Crypto Platform Callback implementation was registered") + throw IllegalStateException("No default Fetch Platform Callback implementation was registered") } return fetchCallbackService as CallbackType } diff --git a/modules/openid-federation-client/src/jsMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.js.kt b/modules/openid-federation-client/src/jsMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.js.kt index ccf20169..10893312 100644 --- a/modules/openid-federation-client/src/jsMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.js.kt +++ b/modules/openid-federation-client/src/jsMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.js.kt @@ -91,7 +91,7 @@ class DefaultTrustChainJSImpl( ) : ITrustChainCallbackServiceJS, ITrustChainCallbackMarkerType { override fun resolve( entityIdentifier: String, trustAnchors: Array, maxDepth: Int - ): Promise?> = CoroutineScope(context = CoroutineName("")).async { + ): Promise?> = CoroutineScope(context = CoroutineName(TRUST_CHAIN_SERVICE_JS_SCOPE)).async { val cache = SimpleCache() val chain: MutableList = arrayListOf() return@async try { @@ -109,7 +109,7 @@ class DefaultTrustChainJSImpl( cache: SimpleCache, depth: Int, maxDepth: Int - ): Promise?> = CoroutineScope(context = CoroutineName("TEST")).async { + ): Promise?> = CoroutineScope(context = CoroutineName(TRUST_CHAIN_SERVICE_JS_SCOPE)).async { if (depth == maxDepth) return@async null val entityConfigurationJwt = fetchService(fetchService ?: DefaultCallbacks.fetchService()).fetchStatement( @@ -171,7 +171,7 @@ class DefaultTrustChainJSImpl( cache: SimpleCache, depth: Int, maxDepth: Int - ): Promise?> = CoroutineScope(context = CoroutineName("TEST")).async { + ): Promise?> = CoroutineScope(context = CoroutineName(TRUST_CHAIN_SERVICE_JS_SCOPE)).async { try { val authorityConfigurationEndpoint = getEntityConfigurationEndpoint(authority) @@ -260,8 +260,8 @@ class DefaultTrustChainJSImpl( if (authorityEntityConfiguration.authorityHints?.isNotEmpty() == true) { chain.add(subordinateStatementJwt) val result = - buildTrustChainRecursive(authority, trustAnchors, chain, cache, depth, maxDepth) - if (result != null) return@async result.await() + buildTrustChainRecursive(authority, trustAnchors, chain, cache, depth, maxDepth).await() + if (result != null) return@async result chain.removeLast() } } catch (_: Exception) { diff --git a/modules/openid-federation-client/src/jsTest/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChainTest.js.kt b/modules/openid-federation-client/src/jsTest/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChainTest.js.kt index 3d5e0814..f6dcd45b 100644 --- a/modules/openid-federation-client/src/jsTest/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChainTest.js.kt +++ b/modules/openid-federation-client/src/jsTest/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChainTest.js.kt @@ -72,32 +72,32 @@ actual class TrustChainTest { val trustChain = client.resolveTrustChainJS( "https://spid.wbss.it/Spid/oidc/rp/ipasv_lt", arrayOf("https://oidc.registry.servizicie.interno.gov.it") - ) + ).await() assertNotNull(trustChain) - assertEquals(4, trustChain.await()?.size ?: 0) + assertEquals(4, trustChain.size) assertEquals( - trustChain.await()?.get(0), + trustChain[0], mockResponses.find { it[0] == "https://spid.wbss.it/Spid/oidc/rp/ipasv_lt/.well-known/openid-federation" } ?.get(1) ) assertEquals( - trustChain.await()?.get(1), + trustChain[1], mockResponses.find { it[0] == "https://spid.wbss.it/Spid/oidc/sa/fetch?sub=https://spid.wbss.it/Spid/oidc/rp/ipasv_lt" } ?.get(1) ) assertEquals( - trustChain.await()?.get(2), + trustChain[2], mockResponses.find { it[0] == "https://oidc.registry.servizicie.interno.gov.it/fetch?sub=https://spid.wbss.it/Spid/oidc/sa" } ?.get(1) ) assertEquals( - trustChain.await()?.get(3), + trustChain[3], mockResponses.find { it[0] == "https://oidc.registry.servizicie.interno.gov.it/.well-known/openid-federation" } ?.get(1) ) @@ -105,23 +105,23 @@ actual class TrustChainTest { val trustChain2 = client.resolveTrustChainJS( "https://spid.wbss.it/Spid/oidc/sa", arrayOf("https://oidc.registry.servizicie.interno.gov.it") - ) + ).await() assertNotNull(trustChain2) - assertEquals(3, trustChain2.await()?.size ?: 0) + assertEquals(3, trustChain2.size) assertEquals( - trustChain2.await()?.get(0), + trustChain2[0], mockResponses.find { it[0] == "https://spid.wbss.it/Spid/oidc/sa/.well-known/openid-federation" }?.get(1) ) assertEquals( - trustChain2.await()?.get(1), + trustChain2[1], mockResponses.find { it[0] == "https://oidc.registry.servizicie.interno.gov.it/fetch?sub=https://spid.wbss.it/Spid/oidc/sa" } ?.get(1) ) assertEquals( - trustChain2.await()?.get(2), + trustChain2[2], mockResponses.find { it[0] == "https://oidc.registry.servizicie.interno.gov.it/.well-known/openid-federation" } ?.get(1) ) diff --git a/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/mime/JsonUrlEncoder.kt b/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/mime/JsonUrlEncoder.kt index f04edf77..479882dc 100644 --- a/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/mime/JsonUrlEncoder.kt +++ b/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/mime/JsonUrlEncoder.kt @@ -78,6 +78,7 @@ fun T.toUrlEncodedJsonValue(serializer: KSerializer): String { * input An URL encoded input string * @return Decoded String */ +@ExperimentalJsExport @JsExport fun urlDecodeValue(input: String): String { return buildString {