Skip to content

Commit

Permalink
impr
Browse files Browse the repository at this point in the history
  • Loading branch information
szysas committed Aug 22, 2023
1 parent 9ee12f3 commit 5be6184
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String?>)
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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"))
}

Expand Down

0 comments on commit 5be6184

Please sign in to comment.