|
@@ -8,7 +8,6 @@
|
|
|
#include "Exception.h"
|
|
|
#include "util.h"
|
|
|
#include "TimeA2.h"
|
|
|
-#include "CookieParser.h"
|
|
|
#include "RecoverableException.h"
|
|
|
#include "File.h"
|
|
|
#include "TestUtil.h"
|
|
@@ -21,6 +20,7 @@ class CookieStorageTest:public CppUnit::TestFixture {
|
|
|
CPPUNIT_TEST(testStore);
|
|
|
CPPUNIT_TEST(testParseAndStore);
|
|
|
CPPUNIT_TEST(testCriteriaFind);
|
|
|
+ CPPUNIT_TEST(testCriteriaFind_cookieOrder);
|
|
|
CPPUNIT_TEST(testLoad);
|
|
|
CPPUNIT_TEST(testLoad_sqlite3);
|
|
|
CPPUNIT_TEST(testLoad_fileNotfound);
|
|
@@ -39,6 +39,7 @@ public:
|
|
|
void testStore();
|
|
|
void testParseAndStore();
|
|
|
void testCriteriaFind();
|
|
|
+ void testCriteriaFind_cookieOrder();
|
|
|
void testLoad();
|
|
|
void testLoad_sqlite3();
|
|
|
void testLoad_fileNotfound();
|
|
@@ -60,113 +61,111 @@ void CookieStorageTest::dumpCookie
|
|
|
|
|
|
void CookieStorageTest::testStore()
|
|
|
{
|
|
|
+ time_t now = 1000;
|
|
|
CookieStorage st;
|
|
|
- Cookie goodCookie("k", "v", "/", "localhost", false);
|
|
|
- CPPUNIT_ASSERT(st.store(goodCookie));
|
|
|
+ Cookie goodCookie(createCookie("k", "v", "localhost", true, "/", false));
|
|
|
+ CPPUNIT_ASSERT(st.store(goodCookie, now));
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, st.size());
|
|
|
CPPUNIT_ASSERT(st.contains(goodCookie));
|
|
|
|
|
|
- Cookie anotherCookie("k", "v", "/", "mirror", true);
|
|
|
- CPPUNIT_ASSERT(st.store(anotherCookie));
|
|
|
+ Cookie anotherCookie(createCookie("k", "v", "mirror", true, "/", true));
|
|
|
+ CPPUNIT_ASSERT(st.store(anotherCookie, now));
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
|
|
|
CPPUNIT_ASSERT(st.contains(anotherCookie));
|
|
|
CPPUNIT_ASSERT(st.contains(goodCookie));
|
|
|
|
|
|
- Cookie updateGoodCookie("k", "v2", "/", "localhost", false);
|
|
|
- CPPUNIT_ASSERT(st.store(goodCookie));
|
|
|
+ Cookie updateGoodCookie(createCookie("k", "v2", "localhost", true,
|
|
|
+ "/", false));
|
|
|
+ CPPUNIT_ASSERT(st.store(updateGoodCookie, now));
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
|
|
|
CPPUNIT_ASSERT(st.contains(updateGoodCookie));
|
|
|
CPPUNIT_ASSERT(st.contains(anotherCookie));
|
|
|
|
|
|
- Cookie expireGoodCookie("k", "v3", 1, "/", "localhost", false);
|
|
|
- CPPUNIT_ASSERT(!st.store(expireGoodCookie));
|
|
|
+ Cookie expireGoodCookie(createCookie("k", "v3", 0, "localhost", true,
|
|
|
+ "/", false));
|
|
|
+ CPPUNIT_ASSERT(!st.store(expireGoodCookie, now));
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, st.size());
|
|
|
CPPUNIT_ASSERT(st.contains(anotherCookie));
|
|
|
|
|
|
- Cookie badCookie("", "", "/", "localhost", false);
|
|
|
- CPPUNIT_ASSERT(!st.store(badCookie));
|
|
|
- CPPUNIT_ASSERT_EQUAL((size_t)1, st.size());
|
|
|
- CPPUNIT_ASSERT(st.contains(anotherCookie));
|
|
|
-
|
|
|
- Cookie fromNumericHost("k", "v", "/", "192.168.1.1", false);
|
|
|
- CPPUNIT_ASSERT(st.store(fromNumericHost));
|
|
|
+ Cookie fromNumericHost(createCookie("k", "v", "192.168.1.1", true,
|
|
|
+ "/", false));
|
|
|
+ CPPUNIT_ASSERT(st.store(fromNumericHost, now));
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
|
|
|
CPPUNIT_ASSERT(st.contains(fromNumericHost));
|
|
|
-
|
|
|
- Cookie sessionScopedGoodCookie("k", "v3", 0, "/", "localhost", false);
|
|
|
- CPPUNIT_ASSERT(st.store(sessionScopedGoodCookie));
|
|
|
- CPPUNIT_ASSERT_EQUAL((size_t)3, st.size());
|
|
|
- CPPUNIT_ASSERT(st.contains(sessionScopedGoodCookie));
|
|
|
-
|
|
|
- Cookie sessionScopedGoodCookie2("k2", "v3", "/", "localhost", false);
|
|
|
- CPPUNIT_ASSERT(st.store(sessionScopedGoodCookie2));
|
|
|
- CPPUNIT_ASSERT_EQUAL((size_t)4, st.size());
|
|
|
- CPPUNIT_ASSERT(st.contains(sessionScopedGoodCookie2));
|
|
|
}
|
|
|
|
|
|
void CookieStorageTest::testParseAndStore()
|
|
|
{
|
|
|
CookieStorage st;
|
|
|
-
|
|
|
+ time_t now = 1000;
|
|
|
std::string localhostCookieStr = "k=v;"
|
|
|
- " expires=Fri, 2038-01-01 00:00:00 GMT; path=/; domain=localhost;";
|
|
|
-
|
|
|
- CPPUNIT_ASSERT(st.parseAndStore(localhostCookieStr,
|
|
|
- "localhost", "/downloads"));
|
|
|
- CPPUNIT_ASSERT(!st.parseAndStore(localhostCookieStr,
|
|
|
- "mirror", "/downloads"));
|
|
|
-
|
|
|
- CPPUNIT_ASSERT(!st.parseAndStore(localhostCookieStr,
|
|
|
- "127.0.0.1", "/downloads"));
|
|
|
+ " expires=Fri, 01 Jan 2038 00:00:00 GMT; path=/; domain=localhost;";
|
|
|
+ CPPUNIT_ASSERT
|
|
|
+ (st.parseAndStore(localhostCookieStr, "localhost", "/downloads", now));
|
|
|
+ CPPUNIT_ASSERT
|
|
|
+ (!st.parseAndStore(localhostCookieStr, "mirror", "/downloads", now));
|
|
|
+ CPPUNIT_ASSERT
|
|
|
+ (!st.parseAndStore(localhostCookieStr, "127.0.0.1", "/downloads", now));
|
|
|
|
|
|
std::string numericHostCookieStr = "k=v;"
|
|
|
- " expires=Fri, 2038-01-01 00:00:00 GMT; path=/; domain=192.168.1.1;";
|
|
|
- CPPUNIT_ASSERT(st.parseAndStore(numericHostCookieStr, "192.168.1.1", "/"));
|
|
|
+ " expires=Fri, 01 Jan 2038 00:00:00 GMT; path=/; domain=192.168.1.1;";
|
|
|
+ CPPUNIT_ASSERT
|
|
|
+ (st.parseAndStore(numericHostCookieStr, "192.168.1.1", "/", now));
|
|
|
|
|
|
// No domain and no path are specified.
|
|
|
std::string noDomainPathCookieStr = "k=v";
|
|
|
CPPUNIT_ASSERT
|
|
|
- (st.parseAndStore(noDomainPathCookieStr, "aria2.sf.net", "/downloads"));
|
|
|
+ (st.parseAndStore(noDomainPathCookieStr,
|
|
|
+ "aria2.sf.net", "/downloads", now));
|
|
|
}
|
|
|
|
|
|
void CookieStorageTest::testCriteriaFind()
|
|
|
{
|
|
|
CookieStorage st;
|
|
|
-
|
|
|
- Cookie alpha("alpha", "ALPHA", "/", ".aria2.org", false);
|
|
|
- Cookie bravo("bravo", "BRAVO", Time().getTime()+60, "/foo", ".aria2.org",
|
|
|
- false);
|
|
|
- Cookie charlie("charlie", "CHARLIE", "/", ".aria2.org", true);
|
|
|
- Cookie delta("delta", "DELTA", "/foo/bar", ".aria2.org", false);
|
|
|
- Cookie echo("echo", "ECHO", "/", "www.dl.aria2.org", false);
|
|
|
- Cookie foxtrot("foxtrot", "FOXTROT", "/", ".sf.net", false);
|
|
|
- Cookie golf("golf", "GOLF", "/", "192.168.1.1", false);
|
|
|
- Cookie hotel1("hotel", "HOTEL1", "/", "samename.x", false);
|
|
|
- Cookie hotel2("hotel", "HOTEL2", "/hotel", "samename.x", false);
|
|
|
- Cookie hotel3("hotel", "HOTEL3", "/bar/wine", "samename.x", false);
|
|
|
- Cookie hotel4("hotel", "HOTEL4", "/bar/", "samename.x", false);
|
|
|
- Cookie india1("india", "INDIA1", "/foo", "default.domain", false);
|
|
|
- india1.markOriginServerOnly();
|
|
|
- Cookie india2("india", "INDIA2", "/", "default.domain", false);
|
|
|
- Cookie juliet1("juliet", "JULIET1", "/foo", "localhost", false);
|
|
|
- juliet1.markOriginServerOnly();
|
|
|
- Cookie juliet2("juliet", "JULIET2", "/", "localhost", false);
|
|
|
-
|
|
|
- CPPUNIT_ASSERT(st.store(alpha));
|
|
|
- CPPUNIT_ASSERT(st.store(bravo));
|
|
|
- CPPUNIT_ASSERT(st.store(charlie));
|
|
|
- CPPUNIT_ASSERT(st.store(delta));
|
|
|
- CPPUNIT_ASSERT(st.store(echo));
|
|
|
- CPPUNIT_ASSERT(st.store(foxtrot));
|
|
|
- CPPUNIT_ASSERT(st.store(golf));
|
|
|
- CPPUNIT_ASSERT(st.store(hotel1));
|
|
|
- CPPUNIT_ASSERT(st.store(hotel2));
|
|
|
- CPPUNIT_ASSERT(st.store(hotel3));
|
|
|
- CPPUNIT_ASSERT(st.store(hotel4));
|
|
|
- CPPUNIT_ASSERT(st.store(india1));
|
|
|
- CPPUNIT_ASSERT(st.store(india2));
|
|
|
- CPPUNIT_ASSERT(st.store(juliet1));
|
|
|
- CPPUNIT_ASSERT(st.store(juliet2));
|
|
|
+ time_t now = 1000;
|
|
|
+
|
|
|
+ Cookie alpha(createCookie("alpha", "ALPHA", "aria2.org", false, "/", false));
|
|
|
+ Cookie bravo(createCookie("bravo", "BRAVO", 1060, "aria2.org", false,
|
|
|
+ "/foo", false));
|
|
|
+ Cookie charlie(createCookie("charlie", "CHARLIE", "aria2.org", false,
|
|
|
+ "/", true));
|
|
|
+ Cookie delta(createCookie("delta", "DELTA", "aria2.org", false,
|
|
|
+ "/foo/bar", false));
|
|
|
+ Cookie echo(createCookie("echo", "ECHO", "www.dl.aria2.org", false,
|
|
|
+ "/", false));
|
|
|
+ Cookie foxtrot(createCookie("foxtrot", "FOXTROT", "sf.net", false,
|
|
|
+ "/", false));
|
|
|
+ Cookie golf(createCookie("golf", "GOLF", "192.168.1.1", true,
|
|
|
+ "/", false));
|
|
|
+ Cookie hotel1(createCookie("hotel", "HOTEL1", "samename.x", false,
|
|
|
+ "/", false));
|
|
|
+ Cookie hotel2(createCookie("hotel", "HOTEL2", "samename.x", false,
|
|
|
+ "/hotel", false));
|
|
|
+ Cookie hotel3(createCookie("hotel", "HOTEL3", "samename.x", false,
|
|
|
+ "/bar/wine", false));
|
|
|
+ Cookie hotel4(createCookie("hotel", "HOTEL4", "samename.x", false,
|
|
|
+ "/bar/", false));
|
|
|
+ Cookie india1(createCookie("india", "INDIA1", "default.domain", true,
|
|
|
+ "/foo", false));
|
|
|
+ Cookie india2(createCookie("india", "INDIA2", "default.domain", false,
|
|
|
+ "/", false));
|
|
|
+ Cookie juliet1(createCookie("juliet", "JULIET1", "localhost", true,
|
|
|
+ "/foo", false));
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT(st.store(alpha, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(bravo, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(charlie, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(delta, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(echo, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(foxtrot, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(golf, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(hotel1, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(hotel2, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(hotel3, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(hotel4, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(india1, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(india2, now));
|
|
|
+ CPPUNIT_ASSERT(st.store(juliet1, now));
|
|
|
|
|
|
std::vector<Cookie> aria2Slash = st.criteriaFind("www.dl.aria2.org", "/",
|
|
|
0, false);
|
|
@@ -186,7 +185,7 @@ void CookieStorageTest::testCriteriaFind()
|
|
|
!= aria2SlashFoo.end());
|
|
|
|
|
|
std::vector<Cookie> aria2Expires = st.criteriaFind("www.dl.aria2.org", "/foo",
|
|
|
- Time().getTime()+120,
|
|
|
+ 1120,
|
|
|
false);
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, aria2Expires.size());
|
|
|
CPPUNIT_ASSERT(std::find(aria2Expires.begin(), aria2Expires.end(), alpha)
|
|
@@ -220,23 +219,47 @@ void CookieStorageTest::testCriteriaFind()
|
|
|
defaultDomainCookies =
|
|
|
st.criteriaFind("sub.default.domain", "/foo", 0, false);
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, defaultDomainCookies.size());
|
|
|
-
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("INDIA2"),
|
|
|
+ defaultDomainCookies[0].getValue());
|
|
|
|
|
|
// localhost.local case
|
|
|
std::vector<Cookie> localDomainCookies =
|
|
|
st.criteriaFind("localhost", "/foo", 0, false);
|
|
|
- CPPUNIT_ASSERT_EQUAL((size_t)2, localDomainCookies.size());
|
|
|
+ CPPUNIT_ASSERT_EQUAL((size_t)1, localDomainCookies.size());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JULIET1"),
|
|
|
localDomainCookies[0].getValue());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("JULIET2"),
|
|
|
- localDomainCookies[1].getValue());
|
|
|
+}
|
|
|
+
|
|
|
+void CookieStorageTest::testCriteriaFind_cookieOrder()
|
|
|
+{
|
|
|
+ CookieStorage st;
|
|
|
+ Cookie a(createCookie("a", "0", "host", true, "/", false));
|
|
|
+ a.setCreationTime(1000);
|
|
|
+ Cookie b(createCookie("b", "0", "host", true, "/foo", false));
|
|
|
+ b.setCreationTime(5000);
|
|
|
+ Cookie c(createCookie("c", "0", "host", true, "/foo", false));
|
|
|
+ c.setCreationTime(4000);
|
|
|
+ Cookie d(createCookie("d", "0", "host", true, "/foo/bar", false));
|
|
|
+ d.setCreationTime(6000);
|
|
|
+
|
|
|
+ st.store(a, 0);
|
|
|
+ st.store(b, 0);
|
|
|
+ st.store(c, 0);
|
|
|
+ st.store(d, 0);
|
|
|
+
|
|
|
+ std::vector<Cookie> cookies = st.criteriaFind("host", "/foo/bar", 0, false);
|
|
|
+ CPPUNIT_ASSERT_EQUAL((size_t)4, cookies.size());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("d"), cookies[0].getName());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("c"), cookies[1].getName());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("b"), cookies[2].getName());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("a"), cookies[3].getName());
|
|
|
}
|
|
|
|
|
|
void CookieStorageTest::testLoad()
|
|
|
{
|
|
|
CookieStorage st;
|
|
|
|
|
|
- st.load("nscookietest.txt");
|
|
|
+ st.load("nscookietest.txt", 1001);
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, st.size());
|
|
|
|
|
@@ -244,72 +267,71 @@ void CookieStorageTest::testLoad()
|
|
|
dumpCookie(cookies, st);
|
|
|
|
|
|
Cookie c = cookies[0];
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
|
|
|
+ CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, c.getExpiryTime());
|
|
|
+ CPPUNIT_ASSERT(!c.getPersistent());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.getPath());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), c.getDomain());
|
|
|
+ CPPUNIT_ASSERT(c.getHostOnly());
|
|
|
+ CPPUNIT_ASSERT(!c.getSecure());
|
|
|
+
|
|
|
+ c = cookies[1];
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.getName());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), c.getValue());
|
|
|
- CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
|
|
|
+ CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiryTime());
|
|
|
+ CPPUNIT_ASSERT(c.getPersistent());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string(".example.org"), c.getDomain());
|
|
|
- CPPUNIT_ASSERT(!c.isSecureCookie());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("example.org"), c.getDomain());
|
|
|
+ CPPUNIT_ASSERT(!c.getHostOnly());
|
|
|
+ CPPUNIT_ASSERT(!c.getSecure());
|
|
|
|
|
|
- c = cookies[1];
|
|
|
+ c = cookies[2];
|
|
|
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((time_t)2147483647, c.getExpiryTime());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("localhost.local"), c.getDomain());
|
|
|
- CPPUNIT_ASSERT(c.isSecureCookie());
|
|
|
-
|
|
|
- c = cookies[2];
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
|
|
|
- CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.getPath());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("localhost.local"), c.getDomain());
|
|
|
- CPPUNIT_ASSERT(!c.isSecureCookie());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
|
|
|
+ CPPUNIT_ASSERT(c.getHostOnly());
|
|
|
+ CPPUNIT_ASSERT(c.getSecure());
|
|
|
|
|
|
c = cookies[3];
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c.getName());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1000"), c.getValue());
|
|
|
- CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
|
|
|
+ CPPUNIT_ASSERT((time_t)INT32_MAX <= c.getExpiryTime());
|
|
|
+ CPPUNIT_ASSERT(c.getPersistent());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("overflow.local"), c.getDomain());
|
|
|
- CPPUNIT_ASSERT(!c.isSecureCookie());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("overflow"), c.getDomain());
|
|
|
+ CPPUNIT_ASSERT(!c.getSecure());
|
|
|
}
|
|
|
|
|
|
void CookieStorageTest::testLoad_sqlite3()
|
|
|
{
|
|
|
CookieStorage st;
|
|
|
#ifdef HAVE_SQLITE3
|
|
|
- st.load("cookies.sqlite");
|
|
|
- CPPUNIT_ASSERT_EQUAL((size_t)3, st.size());
|
|
|
+ st.load("cookies.sqlite", 1000);
|
|
|
+ CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
|
|
|
std::vector<Cookie> cookies;
|
|
|
dumpCookie(cookies, st);
|
|
|
Cookie c = cookies[0];
|
|
|
- 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.com"), c.getDomain());
|
|
|
- CPPUNIT_ASSERT(!c.isSecureCookie());
|
|
|
- CPPUNIT_ASSERT(c.isSessionCookie());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
|
|
|
+ CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, c.getExpiryTime());
|
|
|
+ CPPUNIT_ASSERT(c.getPersistent());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
|
|
|
+ CPPUNIT_ASSERT(c.getHostOnly());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
|
|
|
+ CPPUNIT_ASSERT(c.getSecure());
|
|
|
|
|
|
c = cookies[1];
|
|
|
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((time_t)INT32_MAX <= c.getExpiryTime());
|
|
|
+ CPPUNIT_ASSERT(c.getPersistent());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("overflow.time_t.org"), c.getDomain());
|
|
|
+ CPPUNIT_ASSERT(!c.getHostOnly());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), c.getPath());
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string(".overflow.time_t.org"), c.getDomain());
|
|
|
- CPPUNIT_ASSERT(!c.isSecureCookie());
|
|
|
- CPPUNIT_ASSERT(!c.isSessionCookie());
|
|
|
-
|
|
|
- c = cookies[2];
|
|
|
- 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.local"), c.getDomain());
|
|
|
- CPPUNIT_ASSERT(c.isSecureCookie());
|
|
|
- CPPUNIT_ASSERT(!c.isSessionCookie());
|
|
|
+ CPPUNIT_ASSERT(!c.getSecure());
|
|
|
|
|
|
#else // !HAVE_SQLITE3
|
|
|
CPPUNIT_ASSERT(!st.load("cookies.sqlite"));
|
|
@@ -319,7 +341,7 @@ void CookieStorageTest::testLoad_sqlite3()
|
|
|
void CookieStorageTest::testLoad_fileNotfound()
|
|
|
{
|
|
|
CookieStorage st;
|
|
|
- CPPUNIT_ASSERT(!st.load("./aria2_CookieStorageTest_testLoad_fileNotfound"));
|
|
|
+ CPPUNIT_ASSERT(!st.load("./aria2_CookieStorageTest_testLoad_fileNotfound",0));
|
|
|
}
|
|
|
|
|
|
void CookieStorageTest::testSaveNsFormat()
|
|
@@ -328,19 +350,20 @@ void CookieStorageTest::testSaveNsFormat()
|
|
|
std::string filename = "./aria2_CookieStorageTest_testSaveNsFormat";
|
|
|
File(filename).remove();
|
|
|
CookieStorage st;
|
|
|
- st.store(Cookie("favorite","classic","/config",".domain.org",true));
|
|
|
- st.store(Cookie("uid","tujikawa","/",".domain.org",false));
|
|
|
+ time_t now = 1000;
|
|
|
+ st.store(Cookie(createCookie("favorite", "classic", "domain.org", false,
|
|
|
+ "/config",true)), now);
|
|
|
+ st.store(Cookie(createCookie("uid", "tujikawa", now, "domain.org", true,
|
|
|
+ "/",false)), now);
|
|
|
st.saveNsFormat(filename);
|
|
|
CookieStorage loadst;
|
|
|
- loadst.load(filename);
|
|
|
+ loadst.load(filename, now);
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, loadst.size());
|
|
|
|
|
|
std::vector<Cookie> cookies;
|
|
|
dumpCookie(cookies, loadst);
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("favorite"), cookies[0].getName());
|
|
|
- CPPUNIT_ASSERT_EQUAL((time_t)0, cookies[0].getExpiry());
|
|
|
- CPPUNIT_ASSERT(cookies[0].isSessionCookie());
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("uid"), cookies[1].getName());
|
|
|
}
|
|
|
|
|
@@ -359,8 +382,9 @@ void CookieStorageTest::testCookieIsFull()
|
|
|
{
|
|
|
CookieStorage st;
|
|
|
for(size_t i = 0; i < CookieStorage::MAX_COOKIE_PER_DOMAIN+1; ++i) {
|
|
|
- Cookie c("k"+util::itos(i), "v", "/", ".aria2.org", false);
|
|
|
- st.store(c);
|
|
|
+ Cookie c(createCookie("k"+util::itos(i), "v", "aria2.org", false,
|
|
|
+ "/", false));
|
|
|
+ st.store(c, 0);
|
|
|
}
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)CookieStorage::MAX_COOKIE_PER_DOMAIN, st.size());
|
|
|
}
|
|
@@ -371,8 +395,9 @@ void CookieStorageTest::testDomainIsFull()
|
|
|
// CookieStorage.cc
|
|
|
CookieStorage st;
|
|
|
for(size_t i = 0; i < 2001; ++i) {
|
|
|
- Cookie c("k", "v", "/", "domain"+util::itos(i), false);
|
|
|
- st.store(c);
|
|
|
+ Cookie c(createCookie("k", "v", "domain"+util::itos(i), true,
|
|
|
+ "/", false));
|
|
|
+ st.store(c, 0);
|
|
|
}
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1801, st.size());
|
|
|
}
|