|
@@ -1,9 +1,12 @@
|
|
|
#include "Cookie.h"
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+#include <cppunit/extensions/HelperMacros.h>
|
|
|
+
|
|
|
#include "Exception.h"
|
|
|
#include "Util.h"
|
|
|
#include "TimeA2.h"
|
|
|
-#include <iostream>
|
|
|
-#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
@@ -14,6 +17,7 @@ class CookieTest:public CppUnit::TestFixture {
|
|
|
CPPUNIT_TEST(testOperatorEqual);
|
|
|
CPPUNIT_TEST(testMatch);
|
|
|
CPPUNIT_TEST(testIsExpired);
|
|
|
+ CPPUNIT_TEST(testNormalizeDomain);
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
public:
|
|
|
void setUp() {}
|
|
@@ -24,6 +28,7 @@ public:
|
|
|
void testOperatorEqual();
|
|
|
void testMatch();
|
|
|
void testIsExpired();
|
|
|
+ void testNormalizeDomain();
|
|
|
};
|
|
|
|
|
|
|
|
@@ -36,10 +41,10 @@ void CookieTest::testValidate()
|
|
|
CPPUNIT_ASSERT(defaultDomainPath.validate("localhost", "/"));
|
|
|
}
|
|
|
{
|
|
|
- Cookie domainStartsWithDot("k", "v", "/", "aria2.org", false);
|
|
|
- CPPUNIT_ASSERT(!domainStartsWithDot.validate("www.aria2.org", "/"));
|
|
|
- Cookie success("k", "v", "/", ".aria2.org", false);
|
|
|
- CPPUNIT_ASSERT(success.validate("www.aria2.org", "/"));
|
|
|
+ Cookie domainStartsWithoutDot("k", "v", "/", "aria2.org", false);
|
|
|
+ CPPUNIT_ASSERT(domainStartsWithoutDot.validate("www.aria2.org", "/"));
|
|
|
+ Cookie domainStartsWithDot("k", "v", "/", ".aria2.org", false);
|
|
|
+ CPPUNIT_ASSERT(domainStartsWithDot.validate("www.aria2.org", "/"));
|
|
|
}
|
|
|
{
|
|
|
Cookie domainWithoutEmbeddedDot("k", "v", "/", ".org", false);
|
|
@@ -105,12 +110,22 @@ void CookieTest::testOperatorEqual()
|
|
|
CPPUNIT_ASSERT(!(a == wrongDomain));
|
|
|
CPPUNIT_ASSERT(!(a == wrongName));
|
|
|
CPPUNIT_ASSERT(!(a == caseSensitiveName));
|
|
|
+ // normalize
|
|
|
+ Cookie n1("k", "v", "/", "localhost", false);
|
|
|
+ Cookie n2("k", "v", "/", ".localhost", false);
|
|
|
+ Cookie n3("k", "v", "/", "localhost.local", false);
|
|
|
+ Cookie n4("k", "v", "/", ".localhost.local", false);
|
|
|
+ CPPUNIT_ASSERT(n1 == n2);
|
|
|
+ CPPUNIT_ASSERT(n1 == n3);
|
|
|
+ CPPUNIT_ASSERT(n1 == n4);
|
|
|
}
|
|
|
|
|
|
void CookieTest::testMatch()
|
|
|
{
|
|
|
Cookie c("k", "v", "/downloads", ".aria2.org", false);
|
|
|
Cookie c2("k", "v", "/downloads/", ".aria2.org", false);
|
|
|
+ Cookie c3("k", "v", "/downloads/", "aria2.org", false);
|
|
|
+ Cookie c4("k", "v", "/downloads/", "localhost", false);
|
|
|
CPPUNIT_ASSERT(c.match("www.aria2.org", "/downloads", 0, false));
|
|
|
CPPUNIT_ASSERT(c.match("www.aria2.org", "/downloads/", 0, false));
|
|
|
CPPUNIT_ASSERT(c2.match("www.aria2.org", "/downloads", 0, false));
|
|
@@ -121,12 +136,14 @@ void CookieTest::testMatch()
|
|
|
CPPUNIT_ASSERT(c.match("www.aria2.org", "/downloads/latest", 0, false));
|
|
|
CPPUNIT_ASSERT(!c.match("www.aria2.org", "/downloadss/latest", 0, false));
|
|
|
CPPUNIT_ASSERT(!c.match("www.aria2.org", "/DOWNLOADS", 0, false));
|
|
|
+ CPPUNIT_ASSERT(c3.match("www.aria2.org", "/downloads", 0, false));
|
|
|
+ CPPUNIT_ASSERT(c4.match("localhost", "/downloads", 0, false));
|
|
|
|
|
|
Cookie secureCookie("k", "v", "/", "secure.aria2.org", true);
|
|
|
CPPUNIT_ASSERT(secureCookie.match("secure.aria2.org", "/", 0, true));
|
|
|
CPPUNIT_ASSERT(!secureCookie.match("secure.aria2.org", "/", 0, false));
|
|
|
CPPUNIT_ASSERT(!secureCookie.match("ssecure.aria2.org", "/", 0, true));
|
|
|
- CPPUNIT_ASSERT(!secureCookie.match("www.secure.aria2.org", "/", 0, true));
|
|
|
+ CPPUNIT_ASSERT(secureCookie.match("www.secure.aria2.org", "/", 0, true));
|
|
|
|
|
|
Cookie expireTest("k", "v", 1000, "/", ".aria2.org", false);
|
|
|
CPPUNIT_ASSERT(expireTest.match("www.aria2.org", "/", 999, false));
|
|
@@ -147,7 +164,16 @@ void CookieTest::testIsExpired()
|
|
|
Cookie sessionCookie("k", "v", "/", "localhost", false);
|
|
|
CPPUNIT_ASSERT(!sessionCookie.isExpired());
|
|
|
Cookie sessionCookie2("k", "v", 0, "/", "localhost", false);
|
|
|
- CPPUNIT_ASSERT(!sessionCookie2.isExpired());
|
|
|
+ CPPUNIT_ASSERT(!sessionCookie2.isExpired());
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void CookieTest::testNormalizeDomain()
|
|
|
+{
|
|
|
+ Cookie dot("k", "v", "/", ".", false);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("..local"), dot.getDomain());
|
|
|
+ Cookie ip("k", "v", "/", "192.168.1.1", false);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("192.168.1.1"), ip.getDomain());
|
|
|
}
|
|
|
|
|
|
} // namespace aria2
|