From c63274111b96817b921b210a0e38a2c5b69dda62 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 22 Nov 2022 08:25:50 +0100 Subject: [PATCH] test1662: verify formpost, 301 redirect, no rewind possible Reproduces #9735 and verifies the subsequent fix. The original issue uses a pipe that cannot be rewound, but this test case instead sets a callback without rewind ability to get roughly the same properties but being a much more portable test. --- tests/data/Makefile.inc | 2 +- tests/data/test1662 | 91 ++++++++++++++++++++++++++++++++++++++ tests/libtest/Makefile.inc | 6 +++ tests/libtest/lib1662.c | 91 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 tests/data/test1662 create mode 100644 tests/libtest/lib1662.c diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 6e67e798794496..90c273aeaaf64b 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -208,7 +208,7 @@ test1620 test1621 \ test1630 test1631 test1632 test1633 test1634 test1635 \ \ test1650 test1651 test1652 test1653 test1654 test1655 \ -test1660 test1661 \ +test1660 test1661 test1662 \ \ test1670 test1671 \ \ diff --git a/tests/data/test1662 b/tests/data/test1662 new file mode 100644 index 00000000000000..e0b311b11c588c --- /dev/null +++ b/tests/data/test1662 @@ -0,0 +1,91 @@ + + + +HTTP +HTTP POST + + + +# +# Server-side + + +HTTP/1.1 301 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT +ETag: "21025-dc7-39462498" +Accept-Ranges: bytes +Content-Length: 6 +Location: %TESTNUMBER0002 +Content-Type: text/html +Funny-head: yesyes + +-foo- + + +HTTP/1.1 200 OK +Content-Length: 6 +Connection: close +Funny-head: nono + +-bar- + + + +# +# Client-side + + +Mime +debug + + +http + + +HTTP formpost from callback and a redirect and switch to GET + + +lib%TESTNUMBER + + +http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + +mooaaa + + + +# +# Verify data after the test has been "shot" + + +POST /%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/2000 +Accept: */* +Transfer-Encoding: chunked +Content-Type: multipart/form-data; boundary=------------------------3433323135333231 +Expect: 100-continue + +95 +--------------------------3433323135333231 +Content-Disposition: form-data; name="content"; filename="poetry.txt" +Content-Type: text/plain + +mooaaa +30 + +--------------------------3433323135333231-- + +0 + +GET /%TESTNUMBER0002 HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/2000 +Accept: */* + + + + diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index c1d57ef3b38f79..04f24ab849bd8d 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -62,6 +62,9 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \ lib1550 lib1551 lib1552 lib1553 lib1554 lib1555 lib1556 lib1557 \ lib1558 lib1559 lib1560 lib1564 lib1565 lib1567 lib1568 lib1569 \ lib1591 lib1592 lib1593 lib1594 lib1596 lib1597 \ + \ + lib1662 \ + \ lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 lib1913 \ lib1915 lib1916 lib1917 lib1918 lib1919 \ lib1933 lib1934 lib1935 lib1936 lib1937 lib1938 lib1939 lib1940 \ @@ -667,6 +670,9 @@ lib1596_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1596 lib1597_SOURCES = lib1597.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) lib1597_LDADD = $(TESTUTIL_LIBS) +lib1662_SOURCES = lib1662.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) +lib1662_LDADD = $(TESTUTIL_LIBS) + lib1905_SOURCES = lib1905.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) lib1905_LDADD = $(TESTUTIL_LIBS) lib1905_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/tests/libtest/lib1662.c b/tests/libtest/lib1662.c new file mode 100644 index 00000000000000..c6ddc836c2a4ca --- /dev/null +++ b/tests/libtest/lib1662.c @@ -0,0 +1,91 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2022, 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" + +static char data[]="mooaaa"; + +struct WriteThis { + size_t sizeleft; +}; + +static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) +{ + struct WriteThis *pooh = (struct WriteThis *)userp; + size_t len = strlen(data); + + if(size*nmemb < len) + return 0; + + if(pooh->sizeleft) { + memcpy(ptr, data, strlen(data)); + pooh->sizeleft = 0; + return len; + } + + return 0; /* no more data left to deliver */ +} + + +int test(char *URL) +{ + CURLcode res = CURLE_OK; + CURL *hnd; + curl_mime *mime1; + curl_mimepart *part1; + struct WriteThis pooh = { 1 }; + + mime1 = NULL; + + global_init(CURL_GLOBAL_ALL); + + hnd = curl_easy_init(); + if(hnd) { + curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L); + curl_easy_setopt(hnd, CURLOPT_URL, URL); + curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); + mime1 = curl_mime_init(hnd); + if(mime1) { + part1 = curl_mime_addpart(mime1); + curl_mime_data_cb(part1, -1, read_callback, NULL, NULL, &pooh); + curl_mime_filename(part1, "poetry.txt"); + curl_mime_name(part1, "content"); + curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1); + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/2000"); + curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, + (long)CURL_HTTP_VERSION_2TLS); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + res = curl_easy_perform(hnd); + } + } + + curl_easy_cleanup(hnd); + curl_mime_free(mime1); + curl_global_cleanup(); + return (int)res; +} +