]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
test1549: verify CURLOPT_COOKIEFILE after expired cookies
authorDaniel Stenberg <daniel@haxx.se>
Sun, 17 Aug 2025 20:24:10 +0000 (22:24 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 17 Aug 2025 20:52:18 +0000 (22:52 +0200)
Verifies #18299 (de89b86046ee)
Closes #18303

tests/data/Makefile.am
tests/data/test1549 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib1549.c [new file with mode: 0644]

index 950cb2544c5c5fe830ffc2d02a7fbad2ff1c6d70..71fc94860d4a416223d90448346a2081ab462d41 100644 (file)
@@ -203,11 +203,11 @@ test1516 test1517 test1518 test1519 test1520 test1521 test1522 test1523 \
 test1524 test1525 test1526 test1527 test1528 test1529 test1530 test1531 \
 test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 \
 test1540 test1541 test1542 test1543 test1544 test1545 test1546 test1547 \
-test1548 \
-test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 \
-test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \
-test1566 test1567 test1568 test1569 test1570 test1571 test1572 test1573 \
-test1574 test1575 test1576 test1577 test1578 test1579 test1580 test1581 \
+test1548 test1549 test1550 test1551 test1552 test1553 test1554 test1555 \
+test1556 test1557 test1558 test1559 test1560 test1561 test1562 test1563 \
+test1564 test1565 test1566 test1567 test1568 test1569 test1570 test1571 \
+test1572 test1573 test1574 test1575 test1576 test1577 test1578 test1579 \
+test1580 test1581 \
 \
 test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 \
 test1598 test1599 test1600 test1601 test1602 test1603 test1604 test1605 \
diff --git a/tests/data/test1549 b/tests/data/test1549
new file mode 100644 (file)
index 0000000..bc821e5
--- /dev/null
@@ -0,0 +1,59 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+cookies
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data crlf="yes">
+HTTP/1.1 200 OK
+Content-Length: 6
+Content-Type: text/plain
+Set-Cookie: c1=123; Path=/; Expires=Thu, 12 Feb 2000 00:00:00 GMT
+Set-Cookie: c2=456; Path=/; Expires=Thu, 12 Feb 2000 00:00:00 GMT;
+
+hello
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<features>
+http
+cookies
+</features>
+<name>
+Receive expired cookies and CURLINFO_COOKIELIST
+</name>
+<tool>
+lib%TESTNUMBER
+</tool>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol crlf="yes">
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</protocol>
+<stderr mode="text">
+URL: http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+0 cookies
+Test ended with result 0
+</stderr>
+</verify>
+</testcase>
index 6f51040c1a44514b7bcd4e4089903a79b06634f8..40ec0d1559d5297a865e0ff1ebe3c8fe7ebc8279 100644 (file)
@@ -82,7 +82,7 @@ TESTS_C = \
   lib1522.c lib1523.c           lib1525.c lib1526.c lib1527.c lib1528.c \
   lib1529.c lib1530.c lib1531.c lib1532.c lib1533.c lib1534.c lib1535.c \
   lib1536.c lib1537.c lib1538.c           lib1540.c lib1541.c lib1542.c \
-  lib1545.c                                         lib1550.c lib1551.c \
+  lib1545.c                               lib1549.c lib1550.c lib1551.c \
   lib1552.c lib1553.c lib1554.c lib1555.c lib1556.c lib1557.c lib1558.c \
   lib1559.c lib1560.c                               lib1564.c lib1565.c \
   lib1567.c lib1568.c lib1569.c           lib1571.c \
diff --git a/tests/libtest/lib1549.c b/tests/libtest/lib1549.c
new file mode 100644 (file)
index 0000000..b7bf010
--- /dev/null
@@ -0,0 +1,76 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  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 "first.h"
+
+#include "testtrace.h"
+#include "memdebug.h"
+
+static CURLcode test_lib1549(const char *URL)
+{
+  CURLcode res;
+  CURL *curl;
+
+  if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    curl_mfprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  curl = curl_easy_init();
+  if(!curl) {
+    curl_mfprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_COOKIEFILE, "");
+
+  res = curl_easy_perform(curl);
+
+  if(!res) {
+    /* extract all known cookies */
+    struct curl_slist *cookies = NULL;
+    int num = 0;
+    res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
+    if(!res && cookies) {
+      /* a linked list of cookies in cookie file format */
+      struct curl_slist *each = cookies;
+      while(each) {
+        printf("%s\n", each->data);
+        each = each->next;
+        num++;
+      }
+      /* we must free these cookies when we are done */
+      curl_slist_free_all(cookies);
+    }
+    fprintf(stderr, "%d cookies\n", num);
+  }
+test_cleanup:
+
+  curl_easy_cleanup(curl);
+  curl_global_cleanup();
+
+  return res;
+}