diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-09-20 00:24:03 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-09-20 00:24:03 +0900 |
| commit | 9e7579b475e322ec86ff986e3371fea3fd5c857e (patch) | |
| tree | 3d4ccbce5f9dfd4ba369da48b2e9c364e6a6dce3 /test/CookieStorageTest.cc | |
| parent | c6eb9701731c8edf5b8b1525cef12014e7cd8ad6 (diff) | |
Set old cookie's creation-time to new cookie on replacement
As described in http://tools.ietf.org/html/rfc6265#section-5.3
Diffstat (limited to 'test/CookieStorageTest.cc')
| -rw-r--r-- | test/CookieStorageTest.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/test/CookieStorageTest.cc b/test/CookieStorageTest.cc index e88332b8..5da98374 100644 --- a/test/CookieStorageTest.cc +++ b/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); |
