From f08957ec73e9c982852bb88bcd13780ff0bad06e Mon Sep 17 00:00:00 2001 From: Shawn Zurbrigg <44981601+shawnzurbrigg@users.noreply.github.com> Date: Mon, 12 May 2025 10:38:09 -0400 Subject: [PATCH] Create a WebSocketsTest function to repro query argument issues - we're seeing query arguments being added to the url twice right now - we're currently working around by adding a `&` to the end of the url, which ends up parsing the arguments twice (but at least the parsed values are correct) --- .../test/kotlin/misk/web/WebSocketsTest.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/misk/src/test/kotlin/misk/web/WebSocketsTest.kt b/misk/src/test/kotlin/misk/web/WebSocketsTest.kt index 84e45dac4e7..aba3a9624ca 100644 --- a/misk/src/test/kotlin/misk/web/WebSocketsTest.kt +++ b/misk/src/test/kotlin/misk/web/WebSocketsTest.kt @@ -67,6 +67,23 @@ internal class WebSocketsTest { assertThat(logCollector.takeMessages(RequestLoggingInterceptor::class)).isEmpty() } + @Test + fun queryArgumentsAreParsedCorrectly() { + val client = OkHttpClient() + + val request = Request.Builder() + .url( + jettyService.httpServerUrl + .resolve("/echo-with-query-args?first=this&second=that&second=those")!! + ) + .build() + + val webSocket = client.newWebSocket(request, listener) + + webSocket.send("hello") + assertEquals("ACK hello: this [that, those]", listener.takeMessage()) + } + class TestModule : KAbstractModule() { override fun configure() { install(WebServerTestingModule()) @@ -106,4 +123,21 @@ class EchoWebSocket @Inject constructor() : WebAction { override fun toString() = "EchoListener" } } + + @ConnectWebSocket("/echo-with-query-args") + @LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0) + fun echoWithQueryArgs( + @QueryParam("first") first: String?, + @QueryParam("second") second: List, + @Suppress("UNUSED_PARAMETER") webSocket: WebSocket + ): WebSocketListener { + return object : WebSocketListener() { + override fun onMessage(webSocket: WebSocket, text: String) { + webSocket.send("ACK $text: $first $second") + } + + override fun toString() = "EchoListener" + } + } + }