2007-06-10 07:55:43 +00:00
|
|
|
#include "CookieParser.h"
|
2010-01-29 12:12:21 +00:00
|
|
|
|
2007-06-10 07:55:43 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
class CookieParserTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(CookieParserTest);
|
|
|
|
CPPUNIT_TEST(testParse);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void testParse();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( CookieParserTest );
|
|
|
|
|
|
|
|
void CookieParserTest::testParse()
|
|
|
|
{
|
2008-09-07 04:36:41 +00:00
|
|
|
std::string str = "JSESSIONID=123456789; expires=Sun, 10-Jun-2007 11:00:00 GMT; path=/; domain=localhost; secure";
|
2010-01-29 12:12:21 +00:00
|
|
|
Cookie c = CookieParser().parse(str, "", "");
|
2007-06-10 07:55:43 +00:00
|
|
|
CPPUNIT_ASSERT(c.good());
|
2008-09-01 15:00:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.getExpiry());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
|
2008-12-15 15:48:48 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(".localhost.local"), c.getDomain());
|
2008-09-01 15:00:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, c.isSecureCookie());
|
2008-10-26 14:22:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, c.isSessionCookie());
|
2007-06-10 07:55:43 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string str2 = "JSESSIONID=123456789";
|
2008-01-11 15:20:35 +00:00
|
|
|
c = CookieParser().parse(str2, "default.domain", "/default/path");
|
2007-06-10 07:55:43 +00:00
|
|
|
CPPUNIT_ASSERT(c.good());
|
2008-09-01 15:00:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)0, c.getExpiry());
|
2010-01-28 14:01:50 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("default.domain"), c.getDomain());
|
2008-09-01 15:00:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/default/path"), c.getPath());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, c.isSecureCookie());
|
2008-10-26 14:22:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, c.isSessionCookie());
|
2007-06-10 07:55:43 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string str3 = "";
|
2010-01-29 12:12:21 +00:00
|
|
|
c = CookieParser().parse(str3, "", "");
|
2007-06-10 07:55:43 +00:00
|
|
|
CPPUNIT_ASSERT(!c.good());
|
2008-08-17 14:09:03 +00:00
|
|
|
|
2008-11-22 20:28:50 +00:00
|
|
|
#ifndef __MINGW32__
|
2008-11-10 16:18:39 +00:00
|
|
|
std::string str4 = "UID=300; expires=Wed, 01-Jan-1960 00:00:00 GMT";
|
2008-11-22 20:28:50 +00:00
|
|
|
time_t expire_time = (time_t) -315619200;
|
|
|
|
#else
|
|
|
|
std::string str4 = "UID=300; expires=Wed, 01-Jan-1970 00:00:01 GMT";
|
|
|
|
time_t expire_time = (time_t) 1;
|
|
|
|
#endif
|
2008-08-17 14:09:03 +00:00
|
|
|
c = CookieParser().parse(str4, "localhost", "/");
|
|
|
|
CPPUNIT_ASSERT(c.good());
|
2008-11-05 10:30:43 +00:00
|
|
|
CPPUNIT_ASSERT(!c.isSessionCookie());
|
2008-11-22 20:28:50 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(expire_time, c.getExpiry());
|
2008-09-07 04:36:41 +00:00
|
|
|
|
|
|
|
std::string str5 = "k=v; expires=Sun, 10-Jun-07 11:00:00 GMT";
|
2010-01-29 12:12:21 +00:00
|
|
|
c = CookieParser().parse(str5, "", "");
|
2008-09-07 04:36:41 +00:00
|
|
|
CPPUNIT_ASSERT(c.good());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k"), c.getName());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("v"), c.getValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.getExpiry());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), c.getDomain());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), c.getPath());
|
|
|
|
CPPUNIT_ASSERT(!c.isSecureCookie());
|
2008-10-26 14:22:58 +00:00
|
|
|
CPPUNIT_ASSERT(!c.isSessionCookie());
|
2007-06-10 07:55:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|