]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
test2305: send 3 frames, 4097 bytes each, as one message
authorDaniel Stenberg <daniel@haxx.se>
Wed, 8 Feb 2023 12:17:41 +0000 (13:17 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 10 Feb 2023 07:28:59 +0000 (08:28 +0100)
Receive them using a 256 bytes buffer in a loop.

tests/data/DISABLED
tests/data/Makefile.inc
tests/data/test2305 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib2305.c [new file with mode: 0644]

index cc2dc41cba1fd6ee6511f357d1e74f3d4b172b74..b7f02a2163e2dda0197ab9736afcdc8515e8669c 100644 (file)
@@ -77,6 +77,7 @@
 1943
 2301
 2302
+2305
 %endif
 2043
 # Tests that are disabled here for rustls are SUPPOSED to work
index 435ea77ae65ced5c7a6ba149506c873bf71fc795..533325d98f03cfa09dc6185d1d677fae5db66d71 100644 (file)
@@ -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 (file)
index 0000000..7293db3
--- /dev/null
@@ -0,0 +1,59 @@
+<testcase>
+<info>
+<keywords>
+WebSockets
+</keywords>
+</info>
+
+#
+# Sends three 4097 bytes TEXT frames, as one single message
+<reply>
+<data nocheck="yes">
+HTTP/1.1 101 Switching to WebSockets\r
+Server: test-server/fake\r
+Upgrade: websocket\r
+Connection: Upgrade\r
+Something: else\r
+Sec-WebSocket-Accept: HkPsVga7+8LuxM4RGQ5p9tZHeYs=\r
+\r
+%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]%
+</data>
+# allow upgrade
+<servercmd>
+upgrade
+</servercmd>
+</reply>
+
+#
+# Client-side
+<client>
+# require debug for the forced CURL_ENTROPY
+<features>
+debug
+ws
+</features>
+<server>
+http
+</server>
+<name>
+WebSocket curl_ws_recv() loop reading three larger frames
+</name>
+<tool>
+lib%TESTNUMBER
+</tool>
+<command>
+ws://%HOSTIP:%HTTPPORT/%TESTNUMBER log/save%TESTNUMBER
+</command>
+</client>
+
+#
+<verify>
+<file name="log/save%TESTNUMBER">
+%repeat[256 x helothisisdaniel]%
+%repeat[256 x helothisisdaniel]%
+%repeat[256 x helothisisdaniel]%
+</file>
+</verify>
+</testcase>
index 89b81e6a2b3a3aefceb33f48aef78ae357f1e545..c3222abe604ce6631bec291b062d4bbc0058c582 100644 (file)
@@ -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 (file)
index 0000000..8642ed2
--- /dev/null
@@ -0,0 +1,106 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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