Skip to content

Commit

Permalink
test1662: verify formpost, 301 redirect, no rewind possible
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bagder committed Nov 25, 2022
1 parent 1b39731 commit cde8f28
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/data/Makefile.inc
Expand Up @@ -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 \
\
Expand Down
67 changes: 67 additions & 0 deletions tests/data/test1662
@@ -0,0 +1,67 @@
<testcase><testcase>
<info>
<keywords>
HTTP
HTTP POST
</keywords>
</info>

#
# Server-side
<reply>
<data nocheck="yes">
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-
</data>
<data2 nocheck="yes">
HTTP/1.1 200 OK
Content-Length: 6
Connection: close
Funny-head: nono

-bar-
</data2>
</reply>

#
# Client-side
<client>
<features>
Mime
debug
</features>
<server>
http
</server>
<name>
HTTP formpost from callback and a redirect and switch to GET
</name>
<tool>
lib%TESTNUMBER
</tool>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER
</command>
</client>

#
# Verify data after the test has been "shot"
<verify>

# This does not verify the protocol because the sending of data might be
# aborted early making it hard to check properly.
<stdout>
-bar-
</stdout>
</verify>
</testcase>
6 changes: 6 additions & 0 deletions tests/libtest/Makefile.inc
Expand Up @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down
91 changes: 91 additions & 0 deletions tests/libtest/lib1662.c
@@ -0,0 +1,91 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2022, 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"

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;
}

0 comments on commit cde8f28

Please sign in to comment.