فهرست منبع

Set old cookie's creation-time to new cookie on replacement

As described in http://tools.ietf.org/html/rfc6265#section-5.3
Tatsuhiro Tsujikawa 12 سال پیش
والد
کامیت
9e7579b475
2فایلهای تغییر یافته به همراه16 افزوده شده و 5 حذف شده
  1. 1 0
      src/CookieStorage.cc
  2. 15 5
      test/CookieStorageTest.cc

+ 1 - 0
src/CookieStorage.cc

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

+ 15 - 5
test/CookieStorageTest.cc

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