summaryrefslogtreecommitdiff
path: root/tests/libtest
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-12-11 16:08:51 +0100
committerDaniel Stenberg <daniel@haxx.se>2018-12-12 07:58:47 +0100
commit435402cfe3f6e50b08e344211878d800184b5eb8 (patch)
treee4ceb2ca5ba9d6d36821686e10d6eabd2370fbdc /tests/libtest
parentecb2e194d45c92e430bcf133fcee85a8a336cfcb (diff)
downloadcurl-435402cfe3f6e50b08e344211878d800184b5eb8.tar.gz
Curl_follow: extract the Location: header field unvalidated
... when not actually following the redirect. Otherwise we return error for this and an application can't extract the value. Test 1518 added to verify. Reported-by: Pavel Pavlov Fixes #3340 Closes #3364
Diffstat (limited to 'tests/libtest')
-rw-r--r--tests/libtest/Makefile.inc5
-rw-r--r--tests/libtest/lib1518.c74
2 files changed, 78 insertions, 1 deletions
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index 6dc7511f1..080421b26 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -25,7 +25,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
lib1156 \
lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \
- lib1520 lib1521 lib1522 \
+ lib1518 lib1520 lib1521 lib1522 \
lib1525 lib1526 lib1527 lib1528 lib1529 lib1530 lib1531 lib1532 lib1533 \
lib1534 lib1535 lib1536 lib1537 lib1538 \
lib1540 \
@@ -414,6 +414,9 @@ lib1515_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1515
lib1517_SOURCES = lib1517.c $(SUPPORTFILES)
lib1517_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1517
+lib1518_SOURCES = lib1518.c $(SUPPORTFILES)
+lib1518_CPPFLAGS = $(AM_CPPFLAGS)
+
lib1520_SOURCES = lib1520.c $(SUPPORTFILES)
lib1520_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1520
diff --git a/tests/libtest/lib1518.c b/tests/libtest/lib1518.c
new file mode 100644
index 000000000..1751b583d
--- /dev/null
+++ b/tests/libtest/lib1518.c
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2018, 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.haxx.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.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "memdebug.h"
+
+/* Test inspired by github issue 3340 */
+
+int test(char *URL)
+{
+ CURL *curl;
+ CURLcode res = CURLE_OK;
+ long curlResponseCode;
+ long curlRedirectCount;
+ char *effectiveUrl = NULL;
+ char *redirectUrl = NULL;
+
+ curl = curl_easy_init();
+ if(!curl) {
+ fprintf(stderr, "curl_easy_init() failed\n");
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ test_setopt(curl, CURLOPT_URL, URL);
+ /* just to make it explicit and visible in this test: */
+ test_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
+
+ /* Perform the request, res will get the return code */
+ res = curl_easy_perform(curl);
+
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curlResponseCode);
+ curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount);
+ curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl);
+ curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl);
+
+ printf("res: %d\n"
+ "status: %d\n"
+ "redirects: %d\n"
+ "effectiveurl: %s\n"
+ "redirecturl: %s\n",
+ (int)res,
+ (int)curlResponseCode,
+ (int)curlRedirectCount,
+ effectiveUrl,
+ redirectUrl);
+
+test_cleanup:
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+
+ return res;
+}