From 5a9a04d556772b0281108a5455e0fa2aa5c9bbe3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 8 Feb 2023 13:17:41 +0100 Subject: [PATCH] test2305: send 3 frames, 4097 bytes each, as one message Receive them using a 256 bytes buffer in a loop. --- tests/data/DISABLED | 1 + tests/data/Makefile.inc | 2 +- tests/data/test2305 | 59 +++++++++++++++++++++ tests/libtest/Makefile.inc | 5 +- tests/libtest/lib2305.c | 106 +++++++++++++++++++++++++++++++++++++ 5 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 tests/data/test2305 create mode 100644 tests/libtest/lib2305.c diff --git a/tests/data/DISABLED b/tests/data/DISABLED index cc2dc41cba..b7f02a2163 100644 --- a/tests/data/DISABLED +++ b/tests/data/DISABLED @@ -77,6 +77,7 @@ 1943 2301 2302 +2305 %endif 2043 # Tests that are disabled here for rustls are SUPPOSED to work diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 435ea77ae6..533325d98f 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -242,7 +242,7 @@ test2100 \ \ test2200 test2201 test2202 test2203 test2204 test2205 \ \ -test2300 test2301 test2302 test2303 test2304 \ +test2300 test2301 test2302 test2303 test2304 test2305 \ \ test2400 test2401 test2402 \ \ diff --git a/tests/data/test2305 b/tests/data/test2305 new file mode 100644 index 0000000000..7293db36c3 --- /dev/null +++ b/tests/data/test2305 @@ -0,0 +1,59 @@ + + + +WebSockets + + + +# +# Sends three 4097 bytes TEXT frames, as one single message + + +HTTP/1.1 101 Switching to WebSockets +Server: test-server/fake +Upgrade: websocket +Connection: Upgrade +Something: else +Sec-WebSocket-Accept: HkPsVga7+8LuxM4RGQ5p9tZHeYs= + +%hex[%01%7e%10%01]hex%%repeat[256 x helothisisdaniel]% +%hex[%01%7e%10%01]hex%%repeat[256 x helothisisdaniel]% +%hex[%81%7e%10%01]hex%%repeat[256 x helothisisdaniel]% + +# allow upgrade + +upgrade + + + +# +# Client-side + +# require debug for the forced CURL_ENTROPY + +debug +ws + + +http + + +WebSocket curl_ws_recv() loop reading three larger frames + + +lib%TESTNUMBER + + +ws://%HOSTIP:%HTTPPORT/%TESTNUMBER log/save%TESTNUMBER + + + +# + + +%repeat[256 x helothisisdaniel]% +%repeat[256 x helothisisdaniel]% +%repeat[256 x helothisisdaniel]% + + + diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 89b81e6a2b..c3222abe60 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -69,7 +69,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \ lib1915 lib1916 lib1917 lib1918 lib1919 \ lib1933 lib1934 lib1935 lib1936 lib1937 lib1938 lib1939 lib1940 \ lib1945 lib1946 lib1947 lib1948 lib1955 lib1956 lib1957 lib1958 lib1959 \ - lib2301 lib2302 lib2304 \ + lib2301 lib2302 lib2304 lib2305 \ lib2402 \ lib2502 \ lib3010 lib3025 lib3026 lib3027 \ @@ -800,6 +800,9 @@ lib2302_LDADD = $(TESTUTIL_LIBS) lib2304_SOURCES = lib2304.c $(SUPPORTFILES) lib2304_LDADD = $(TESTUTIL_LIBS) +lib2305_SOURCES = lib2305.c $(SUPPORTFILES) $(TESTUTIL) $(TSTTRACE) +lib2305_LDADD = $(TESTUTIL_LIBS) + lib2402_SOURCES = lib2402.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) lib2402_LDADD = $(TESTUTIL_LIBS) lib2402_CPPFLAGS = $(AM_CPPFLAGS) -DLIB2402 diff --git a/tests/libtest/lib2305.c b/tests/libtest/lib2305.c new file mode 100644 index 0000000000..8642ed2794 --- /dev/null +++ b/tests/libtest/lib2305.c @@ -0,0 +1,106 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +#include "test.h" +#include "testtrace.h" + +#ifdef USE_WEBSOCKETS + +/* just close the connection */ +static void websocket_close(CURL *curl) +{ + size_t sent; + CURLcode result = + curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE); + fprintf(stderr, + "ws: curl_ws_send returned %u, sent %u\n", (int)result, (int)sent); +} + +static void websocket(CURL *curl) +{ + char buffer[256]; + struct curl_ws_frame *meta; + size_t nread; + size_t i = 0; + FILE *save = fopen(libtest_arg2, FOPEN_WRITETEXT); + if(!save) + return; + + /* Three 4097-bytes frames are expected, 12291 bytes */ + while(i < 12291) { + CURLcode result = + curl_ws_recv(curl, buffer, sizeof(buffer), &nread, &meta); + if(result) { + printf("curl_ws_recv returned %d\n", (int)result); + return; + } + printf("%u: nread %u Age %u Flags %x " + "Offset %" CURL_FORMAT_CURL_OFF_T " " + "Bytesleft %" CURL_FORMAT_CURL_OFF_T "\n", + (int)i, + nread, meta->age, meta->flags, meta->offset, meta->bytesleft); + i += meta->len; + fwrite(buffer, 1, nread, save); + } + fclose(save); + + websocket_close(curl); +} + +extern struct libtest_trace_cfg libtest_debug_config; + +int test(char *URL) +{ + CURL *curl; + CURLcode res = CURLE_OK; + + global_init(CURL_GLOBAL_ALL); + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, URL); + + /* use the callback style */ + curl_easy_setopt(curl, CURLOPT_USERAGENT, "websocket/2304"); + libtest_debug_config.nohex = 1; + libtest_debug_config.tracetime = 1; + curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &libtest_debug_config); + curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */ + res = curl_easy_perform(curl); + fprintf(stderr, "curl_easy_perform() returned %u\n", (int)res); + if(res == CURLE_OK) + websocket(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + curl_global_cleanup(); + return (int)res; +} + +#else +NO_SUPPORT_BUILT_IN +#endif -- 2.47.2