diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-10-26 14:22:58 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-10-26 14:22:58 +0000 |
| commit | 915aa676f8d980dcf2bf88154037b6df0edc3b58 (patch) | |
| tree | 1faf54d86f073268088855eade4e50f699b5a178 /test/CookieStorageTest.cc | |
| parent | 8a920ba5e38b8a7c43dc088b1837026e69b078f3 (diff) | |
2008-10-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Treat Cookie object as session cookie if expiry = 0 is given.
With this change, you can specify session scoped cookies in an
external file setting expiry value to 0.
* src/Cookie.cc
* src/Cookie.h
* test/CookieParserTest.cc
* test/CookieStorageTest.cc
* test/CookieTest.cc
Diffstat (limited to 'test/CookieStorageTest.cc')
| -rw-r--r-- | test/CookieStorageTest.cc | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/test/CookieStorageTest.cc b/test/CookieStorageTest.cc index 1952b9b7..2bd05cac 100644 --- a/test/CookieStorageTest.cc +++ b/test/CookieStorageTest.cc @@ -56,7 +56,7 @@ void CookieStorageTest::testStore() CPPUNIT_ASSERT(std::find(st.begin(), st.end(), updateGoodCookie) != st.end()); CPPUNIT_ASSERT(std::find(st.begin(), st.end(), anotherCookie) != st.end()); - Cookie expireGoodCookie("k", "v3", 0, "/", "localhost", false); + Cookie expireGoodCookie("k", "v3", 1, "/", "localhost", false); CPPUNIT_ASSERT(!st.store(expireGoodCookie)); CPPUNIT_ASSERT_EQUAL((size_t)1, st.size()); CPPUNIT_ASSERT(std::find(st.begin(), st.end(), anotherCookie) != st.end()); @@ -70,6 +70,18 @@ void CookieStorageTest::testStore() CPPUNIT_ASSERT(st.store(fromNumericHost)); CPPUNIT_ASSERT_EQUAL((size_t)2, st.size()); CPPUNIT_ASSERT(std::find(st.begin(), st.end(), fromNumericHost) != st.end()); + + Cookie sessionScopedGoodCookie("k", "v3", 0, "/", "localhost", false); + CPPUNIT_ASSERT(st.store(sessionScopedGoodCookie)); + CPPUNIT_ASSERT_EQUAL((size_t)3, st.size()); + CPPUNIT_ASSERT(std::find(st.begin(), st.end(), + sessionScopedGoodCookie) != st.end()); + + Cookie sessionScopedGoodCookie2("k2", "v3", "/", "localhost", false); + CPPUNIT_ASSERT(st.store(sessionScopedGoodCookie2)); + CPPUNIT_ASSERT_EQUAL((size_t)4, st.size()); + CPPUNIT_ASSERT(std::find(st.begin(), st.end(), + sessionScopedGoodCookie2) != st.end()); } void CookieStorageTest::testParseAndStore() @@ -196,22 +208,34 @@ void CookieStorageTest::testLoad_sqlite3() CookieStorage st; #ifdef HAVE_SQLITE3 st.load("cookies.sqlite"); - CPPUNIT_ASSERT_EQUAL((size_t)2, st.size()); - Cookie c = *st.begin(); + CPPUNIT_ASSERT_EQUAL((size_t)3, st.size()); + std::deque<Cookie>::const_iterator i = st.begin(); + Cookie c = *i++; CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName()); CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue()); CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry()); CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain()); CPPUNIT_ASSERT(c.isSecureCookie()); + CPPUNIT_ASSERT(!c.isSessionCookie()); - c = *(st.begin()+1); + c = *i++; + CPPUNIT_ASSERT_EQUAL(std::string("uid"), c.getName()); + CPPUNIT_ASSERT_EQUAL(std::string(""), c.getValue()); + CPPUNIT_ASSERT_EQUAL((time_t)0, c.getExpiry()); + CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), c.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("null_value"), c.getDomain()); + CPPUNIT_ASSERT(!c.isSecureCookie()); + CPPUNIT_ASSERT(c.isSessionCookie()); + + c = *i++; CPPUNIT_ASSERT_EQUAL(std::string("foo"), c.getName()); CPPUNIT_ASSERT_EQUAL(std::string("bar"), c.getValue()); CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry()); CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), c.getPath()); CPPUNIT_ASSERT_EQUAL(std::string("overflow_time_t"), c.getDomain()); CPPUNIT_ASSERT(!c.isSecureCookie()); + CPPUNIT_ASSERT(!c.isSessionCookie()); #else // !HAVE_SQLITE3 try { |
