]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: add test1598 for POST with trailers
authorStefan Eissing <stefan@eissing.org>
Wed, 28 Feb 2024 12:20:59 +0000 (13:20 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 28 Feb 2024 22:03:02 +0000 (23:03 +0100)
- test POST fields with trailers and chunked encoding

Ref: #12938
Closes #13009

tests/data/Makefile.inc
tests/data/test1598 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib1598.c [new file with mode: 0644]

index b80ffb618e55b9295b2855114d7de01ae6918947..2d2b87a86405a0ae24740b1651ee3bc63b15a3f9 100644 (file)
@@ -201,7 +201,7 @@ test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \
 test1566 test1567 test1568 test1569 test1570 \
 \
 test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 \
-\
+test1598 \
 test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 \
 test1608 test1609 test1610 test1611 test1612 test1613 test1614 test1615 \
 \
diff --git a/tests/data/test1598 b/tests/data/test1598
new file mode 100644 (file)
index 0000000..eb0ade1
--- /dev/null
@@ -0,0 +1,59 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+CURLOPT_HTTPTRAILER_FUNCTION
+CURLOPT_HTTPTRAILER_DATA
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.0 200 OK swsclose
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+</data>
+</reply>
+# Client-side
+<client>
+<features>
+http
+</features>
+<server>
+http
+</server>
+<name>
+HTTP POST with trailers at the end
+</name>
+<tool>
+lib%TESTNUMBER
+</tool>
+<command>
+http://%HOSTIP:%HTTPPORT/bzz/%TESTNUMBER
+</command>
+<stdin>
+more than one byte
+</stdin>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+POST /bzz/%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+Trailer: my-super-awesome-trailer, my-other-awesome-trailer\r
+Transfer-Encoding: chunked\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+11\r
+xxx=yyy&aaa=bbbbb\r
+0\r
+my-super-awesome-trailer: trail1\r
+my-other-awesome-trailer: trail2\r
+\r
+</protocol>
+</verify>
+</testcase>
index 1a61deb623416bc3c1df559a7e7c164038a8732d..32cc180b02b61bc2a0d2cdcd7c77cc6a2b7f6fd7 100644 (file)
@@ -62,7 +62,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect libprereq      \
  lib1540         lib1542 lib1543         lib1545 \
  lib1550 lib1551 lib1552 lib1553 lib1554 lib1555 lib1556 lib1557 \
  lib1558 lib1559 lib1560 lib1564 lib1565 lib1567 lib1568 lib1569 \
- lib1591 lib1592 lib1593 lib1594 lib1596 lib1597 \
+ lib1591 lib1592 lib1593 lib1594 lib1596 lib1597 lib1598 \
  \
  lib1662 \
  \
@@ -534,6 +534,9 @@ lib1596_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1596
 lib1597_SOURCES = lib1597.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib1597_LDADD = $(TESTUTIL_LIBS)
 
+lib1598_SOURCES = lib1598.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
+lib1598_LDADD = $(TESTUTIL_LIBS)
+
 lib1662_SOURCES = lib1662.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib1662_LDADD = $(TESTUTIL_LIBS)
 
diff --git a/tests/libtest/lib1598.c b/tests/libtest/lib1598.c
new file mode 100644 (file)
index 0000000..63cdfcf
--- /dev/null
@@ -0,0 +1,107 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  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
+ *
+ ***************************************************************************/
+
+/*
+ * This unit test PUT http data over proxy. Proxy header will be different
+ * from server http header
+ */
+
+#include "test.h"
+#include <stdio.h>
+#include "memdebug.h"
+
+/*
+ * carefully not leak memory on OOM
+ */
+static int trailers_callback(struct curl_slist **list, void *userdata)
+{
+  struct curl_slist *nlist = NULL;
+  struct curl_slist *nlist2 = NULL;
+  (void)userdata;
+  nlist = curl_slist_append(*list, "my-super-awesome-trailer: trail1");
+  if(nlist)
+    nlist2 = curl_slist_append(nlist, "my-other-awesome-trailer: trail2");
+  if(nlist2) {
+    *list = nlist2;
+    return CURL_TRAILERFUNC_OK;
+  }
+  else {
+    curl_slist_free_all(nlist);
+    return CURL_TRAILERFUNC_ABORT;
+  }
+}
+
+static const char *post_data = "xxx=yyy&aaa=bbbbb";
+
+int test(char *URL)
+{
+  CURL *curl = NULL;
+  CURLcode res = CURLE_FAILED_INIT;
+  /* http and proxy header list */
+  struct curl_slist *hhl = NULL, *list;
+
+  if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+
+  curl = curl_easy_init();
+  if(!curl) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  hhl = curl_slist_append(hhl, "Trailer: my-super-awesome-trailer,"
+                               " my-other-awesome-trailer");
+  if(!hhl)
+    goto test_cleanup;
+  if(hhl) {
+    list = curl_slist_append(hhl, "Transfer-Encoding: chunked");
+    if(!list)
+      goto test_cleanup;
+    hhl = list;
+  }
+
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(post_data));
+  test_setopt(curl, CURLOPT_POSTFIELDS, post_data);
+  test_setopt(curl, CURLOPT_TRAILERFUNCTION, trailers_callback);
+  test_setopt(curl, CURLOPT_TRAILERDATA, NULL);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+
+  res = curl_easy_perform(curl);
+
+test_cleanup:
+
+  curl_easy_cleanup(curl);
+
+  curl_slist_free_all(hhl);
+
+  curl_global_cleanup();
+
+  return (int)res;
+}