test1549: verify CURLOPT_COOKIEFILE after expired cookies

Verifies #18299 (de89b86046)
Closes #18303
This commit is contained in:
Daniel Stenberg 2025-08-17 22:24:10 +02:00
parent de89b86046
commit 0ba8e7f9db
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 141 additions and 6 deletions

View 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 \

59
tests/data/test1549 Normal file
View file

@ -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>

View 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 \

76
tests/libtest/lib1549.c Normal file
View file

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