diff options
| -rw-r--r-- | src/sp/transport/ws/ws_test.c | 54 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/ws.c | 59 |
3 files changed, 54 insertions, 60 deletions
diff --git a/src/sp/transport/ws/ws_test.c b/src/sp/transport/ws/ws_test.c index 514a2d3f..2e1300b3 100644 --- a/src/sp/transport/ws/ws_test.c +++ b/src/sp/transport/ws/ws_test.c @@ -195,6 +195,57 @@ test_ws_no_tls(void) NUTS_CLOSE(s0); } +static void +check_props_v4(nng_msg *msg) +{ + nng_pipe p; + size_t z; + nng_sockaddr la; + nng_sockaddr ra; + bool b; + + p = nng_msg_get_pipe(msg); + NUTS_TRUE(nng_pipe_id(p) > 0); + NUTS_PASS(nng_pipe_get_addr(p, NNG_OPT_LOCADDR, &la)); + NUTS_FAIL(nng_pipe_get_size(p, NNG_OPT_LOCADDR, &z), NNG_EBADTYPE); + NUTS_TRUE(la.s_family == NNG_AF_INET); + NUTS_TRUE(la.s_in.sa_port != 0); + NUTS_TRUE(la.s_in.sa_addr == htonl(0x7f000001)); + + NUTS_PASS(nng_pipe_get_addr(p, NNG_OPT_REMADDR, &ra)); + NUTS_TRUE(ra.s_family == NNG_AF_INET); + NUTS_TRUE(ra.s_in.sa_port != 0); + NUTS_TRUE(ra.s_in.sa_addr == htonl(0x7f000001)); + NUTS_TRUE(ra.s_in.sa_port != la.s_in.sa_port); + NUTS_FAIL(nng_pipe_get_size(p, NNG_OPT_REMADDR, &z), NNG_EBADTYPE); + + NUTS_PASS(nng_pipe_get_bool(p, NNG_OPT_TCP_KEEPALIVE, &b)); + NUTS_TRUE(b == false); // default + + NUTS_PASS(nng_pipe_get_bool(p, NNG_OPT_TCP_NODELAY, &b)); + NUTS_TRUE(b); // default + + // Request Header + char *buf = NULL; + NUTS_PASS(nng_pipe_get_string(p, NNG_OPT_WS_REQUEST_HEADERS, &buf)); + NUTS_TRUE(strstr(buf, "Sec-WebSocket-Key") != NULL); + nng_strfree(buf); + + // Response Header + NUTS_PASS(nng_pipe_get_string(p, NNG_OPT_WS_RESPONSE_HEADERS, &buf)); + NUTS_TRUE(strstr(buf, "Sec-WebSocket-Accept") != NULL); + nng_strfree(buf); +} + +void +test_ws_props_v4(void) +{ + nuts_tran_msg_props("ws", check_props_v4); +} + +NUTS_DECLARE_TRAN_TESTS(ws) +NUTS_DECLARE_TRAN_TESTS(ws6) + TEST_LIST = { { "ws url path filters", test_ws_url_path_filters }, { "ws wild card port", test_wild_card_port }, @@ -202,5 +253,8 @@ TEST_LIST = { { "ws empty host", test_empty_host }, { "ws recv max", test_ws_recv_max }, { "ws no tls", test_ws_no_tls }, + NUTS_INSERT_TRAN_TESTS(ws), + { "ws msg props", test_ws_props_v4 }, + NUTS_INSERT_TRAN_TESTS(ws6), { NULL, NULL }, }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 62b64167..272ba78e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -132,7 +132,6 @@ add_nng_test(nonblock 60) add_nng_test(scalability 20 ON) add_nng_test(synch 5) add_nng_test(tcpsupp 10) -add_nng_test(ws 30) add_nng_test(wss 30) add_nng_test1(zt 60 NNG_TRANSPORT_ZEROTIER) diff --git a/tests/ws.c b/tests/ws.c deleted file mode 100644 index 041fe4d0..00000000 --- a/tests/ws.c +++ /dev/null @@ -1,59 +0,0 @@ -// -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> -// Copyright 2018 Capitar IT Group BV <info@capitar.com> -// -// This software is supplied under the terms of the MIT License, a -// copy of which should be located in the distribution where this -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#ifndef _WIN32 -#include <arpa/inet.h> -#endif - -#include <nng/nng.h> -#include <nng/protocol/pair1/pair.h> - -#include "convey.h" -#include "stubs.h" -#include "trantest.h" - -static int -check_props_v4(nng_msg *msg) -{ - nng_pipe p; - nng_sockaddr la; - nng_sockaddr ra; - char *buf; - - p = nng_msg_get_pipe(msg); - So(nng_pipe_id(p) > 0); - - So(nng_pipe_get_addr(p, NNG_OPT_LOCADDR, &la) == 0); - So(la.s_family == NNG_AF_INET); - So(la.s_in.sa_port == htons(trantest_port - 1)); - So(la.s_in.sa_port != 0); - So(la.s_in.sa_addr == htonl(0x7f000001)); - - So(nng_pipe_get_addr(p, NNG_OPT_REMADDR, &ra) == 0); - So(ra.s_family == NNG_AF_INET); - So(ra.s_in.sa_port != 0); - So(ra.s_in.sa_addr == htonl(0x7f000001)); - - // Request Header - buf = NULL; - So(nng_pipe_get_string(p, NNG_OPT_WS_REQUEST_HEADERS, &buf) == 0); - So(strstr(buf, "Sec-WebSocket-Key") != NULL); - nng_strfree(buf); - - // Response Header - So(nng_pipe_get_string(p, NNG_OPT_WS_RESPONSE_HEADERS, &buf) == 0); - So(strstr(buf, "Sec-WebSocket-Accept") != NULL); - nng_strfree(buf); - - return (0); -} - -TestMain("WebSocket Transport", - { trantest_test_extended("ws://127.0.0.1:", check_props_v4); }) |
