mirror of
https://github.com/aria2/aria2.git
synced 2025-01-01 15:44:55 +00:00
Set old cookie's creation-time to new cookie on replacement
As described in http://tools.ietf.org/html/rfc6265#section-5.3
This commit is contained in:
parent
c6eb970173
commit
9e7579b475
@ -126,6 +126,7 @@ bool DomainNode::addCookie(std::unique_ptr<Cookie> cookie, time_t now)
|
||||
cookies_->erase(i);
|
||||
return false;
|
||||
} else {
|
||||
cookie->setCreationTime((*i)->getCreationTime());
|
||||
*i = std::move(cookie);
|
||||
return true;
|
||||
}
|
||||
|
@ -66,10 +66,12 @@ std::vector<const Cookie*> dumpCookie(const CookieStorage& st)
|
||||
|
||||
void CookieStorageTest::testStore()
|
||||
{
|
||||
time_t now = 1000;
|
||||
time_t now = 999;
|
||||
auto st = CookieStorage{};
|
||||
auto goodCookie = []() {
|
||||
return createCookie("k", "v", "localhost", true, "/", false);
|
||||
auto goodCookie = [&]() {
|
||||
auto c = createCookie("k", "v", "localhost", true, "/", false);
|
||||
c->setCreationTime(now);
|
||||
return c;
|
||||
};
|
||||
CPPUNIT_ASSERT(st.store(goodCookie(), now));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, st.size());
|
||||
@ -83,13 +85,21 @@ void CookieStorageTest::testStore()
|
||||
CPPUNIT_ASSERT(st.contains(*anotherCookie()));
|
||||
CPPUNIT_ASSERT(st.contains(*goodCookie()));
|
||||
|
||||
auto updateGoodCookie = []() {
|
||||
return createCookie("k", "v2", "localhost", true, "/", false);
|
||||
++now;
|
||||
auto updateGoodCookie = [&]() {
|
||||
auto c = createCookie("k", "v2", "localhost", true, "/", false);
|
||||
c->setCreationTime(now);
|
||||
return c;
|
||||
};
|
||||
CPPUNIT_ASSERT(st.store(updateGoodCookie(), now));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
|
||||
CPPUNIT_ASSERT(st.contains(*updateGoodCookie()));
|
||||
CPPUNIT_ASSERT(st.contains(*anotherCookie()));
|
||||
auto cookies = st.criteriaFind("localhost", "/", now, false);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, cookies.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("v2"), cookies[0]->getValue());
|
||||
// New cookie's creation time must match old cookie's creation time.
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)999, cookies[0]->getCreationTime());
|
||||
|
||||
auto expireGoodCookie = []() {
|
||||
return createCookie("k", "v3", 0, "localhost", true, "/", false);
|
||||
|
Loading…
Reference in New Issue
Block a user