From: Daniel Stenberg Date: Sun, 17 Aug 2025 20:24:10 +0000 (+0200) Subject: test1549: verify CURLOPT_COOKIEFILE after expired cookies X-Git-Tag: curl-8_16_0~169 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ba8e7f9db9adf21f1550e72754ce1c65e40a2cd;p=thirdparty%2Fcurl.git test1549: verify CURLOPT_COOKIEFILE after expired cookies Verifies #18299 (de89b86046ee) Closes #18303 --- diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 950cb2544c..71fc94860d 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -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 index 0000000000..bc821e5eba --- /dev/null +++ b/tests/data/test1549 @@ -0,0 +1,59 @@ + + + +HTTP +cookies + + + +# +# Server-side + + +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 + + + +# +# Client-side + + +http + + +http +cookies + + +Receive expired cookies and CURLINFO_COOKIELIST + + +lib%TESTNUMBER + + +http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + +# +# Verify data after the test has been "shot" + + +GET /%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +Accept: */* + + + +URL: http://%HOSTIP:%HTTPPORT/%TESTNUMBER +0 cookies +Test ended with result 0 + + + diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 6f51040c1a..40ec0d1559 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -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 index 0000000000..b7bf010612 --- /dev/null +++ b/tests/libtest/lib1549.c @@ -0,0 +1,76 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 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 "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; +}