From 5be618474dc1fcb6a1b51cf8c637998d39edd791 Mon Sep 17 00:00:00 2001 From: Szymon Sasin Date: Tue, 22 Aug 2023 09:00:05 +0300 Subject: [PATCH] impr --- .../kotlin/org/opencoap/ssl/netty/DtlsChannelHandler.kt | 9 ++++++--- .../opencoap/ssl/netty/SessionAuthenticationContext.kt | 2 +- .../src/test/kotlin/org/opencoap/ssl/netty/NettyTest.kt | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/DtlsChannelHandler.kt b/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/DtlsChannelHandler.kt index 8ac00585..6b58dad1 100644 --- a/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/DtlsChannelHandler.kt +++ b/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/DtlsChannelHandler.kt @@ -91,10 +91,13 @@ class DtlsChannelHandler @JvmOverloads constructor( when (msg) { is DatagramPacket -> write(msg, promise, ctx) is SessionAuthenticationContext -> { - if (dtlsServer.putSessionAuthenticationContext(msg.adr, msg.key, msg.value)) { + msg.map.forEach { (key, value) -> + if (!dtlsServer.putSessionAuthenticationContext(msg.adr, key, value)) { + promise.setFailure(SslException("Session does not exists")) + } + } + if (!promise.isDone) { promise.setSuccess() - } else { - promise.setFailure(SslException("Session does not exists")) } } diff --git a/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/SessionAuthenticationContext.kt b/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/SessionAuthenticationContext.kt index 37404e7d..bec02ffb 100644 --- a/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/SessionAuthenticationContext.kt +++ b/kotlin-mbedtls-netty/src/main/kotlin/org/opencoap/ssl/netty/SessionAuthenticationContext.kt @@ -18,4 +18,4 @@ package org.opencoap.ssl.netty import java.net.InetSocketAddress -data class SessionAuthenticationContext(val adr: InetSocketAddress, val key: String, val value: String?) +data class SessionAuthenticationContext(val adr: InetSocketAddress, val map: Map) diff --git a/kotlin-mbedtls-netty/src/test/kotlin/org/opencoap/ssl/netty/NettyTest.kt b/kotlin-mbedtls-netty/src/test/kotlin/org/opencoap/ssl/netty/NettyTest.kt index b1422b6e..229174fa 100644 --- a/kotlin-mbedtls-netty/src/test/kotlin/org/opencoap/ssl/netty/NettyTest.kt +++ b/kotlin-mbedtls-netty/src/test/kotlin/org/opencoap/ssl/netty/NettyTest.kt @@ -180,7 +180,7 @@ class NettyTest { assertEquals("ECHO:hi", client.receive(5.seconds).await()) // when - srvChannel.writeAndFlush(SessionAuthenticationContext(client.localAddress(), "AUTH", "007:")).get() + srvChannel.writeAndFlush(SessionAuthenticationContext(client.localAddress(), mapOf("AUTH" to "007:"))).get() // then assertTrue(client.send("hi").await()) @@ -192,7 +192,7 @@ class NettyTest { @Test fun `should fail to forward authentication context for non existing client`() { assertThatThrownBy { - srvChannel.writeAndFlush(SessionAuthenticationContext(localAddress(1), "AUTH", "007:")).get() + srvChannel.writeAndFlush(SessionAuthenticationContext(localAddress(1), mapOf("AUTH" to "007:"))).get() }.hasRootCause(SslException("Session does not exists")) }