2008-08-17 10:44:12 +00:00
|
|
|
#include "Sqlite3MozCookieParser.h"
|
2008-10-04 03:02:35 +00:00
|
|
|
|
2008-08-17 10:44:12 +00:00
|
|
|
#include <iostream>
|
2008-10-04 03:02:35 +00:00
|
|
|
|
2008-08-17 10:44:12 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-10-04 03:02:35 +00:00
|
|
|
#include "RecoverableException.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-10-04 03:02:35 +00:00
|
|
|
|
2008-08-17 10:44:12 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class Sqlite3MozCookieParserTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(Sqlite3MozCookieParserTest);
|
|
|
|
CPPUNIT_TEST(testParse);
|
|
|
|
CPPUNIT_TEST(testParse_fileNotFound);
|
|
|
|
CPPUNIT_TEST(testParse_badfile);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testParse();
|
|
|
|
void testParse_fileNotFound();
|
|
|
|
void testParse_badfile();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(Sqlite3MozCookieParserTest);
|
|
|
|
|
|
|
|
void Sqlite3MozCookieParserTest::testParse()
|
|
|
|
{
|
|
|
|
Sqlite3MozCookieParser parser;
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<Cookie> cookies = parser.parse("cookies.sqlite");
|
2008-08-17 10:44:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, cookies.size());
|
|
|
|
|
|
|
|
const Cookie& localhost = cookies[0];
|
2010-01-29 12:04:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost.local"), localhost.getDomain());
|
2008-09-01 15:00:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), localhost.getPath());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), localhost.getName());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), localhost.getValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, localhost.getExpiry());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, localhost.isSecureCookie());
|
2008-08-17 10:44:12 +00:00
|
|
|
|
|
|
|
const Cookie& nullValue = cookies[1];
|
2010-01-29 12:04:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(".null_value.com"), nullValue.getDomain());
|
2008-09-01 15:00:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), nullValue.getPath());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("uid"), nullValue.getName());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), nullValue.getValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)0, nullValue.getExpiry());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, nullValue.isSecureCookie());
|
2008-08-17 10:44:12 +00:00
|
|
|
|
|
|
|
// See row id=3 has no name, so it is skipped.
|
|
|
|
|
|
|
|
const Cookie& overflowTime = cookies[2];
|
2010-01-29 12:04:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(".overflow.time_t.org"),
|
2010-01-05 16:01:46 +00:00
|
|
|
overflowTime.getDomain());
|
2008-09-01 15:00:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), overflowTime.getPath());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo"), overflowTime.getName());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("bar"), overflowTime.getValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, overflowTime.getExpiry());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, overflowTime.isSecureCookie());
|
2008-08-17 10:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sqlite3MozCookieParserTest::testParse_fileNotFound()
|
|
|
|
{
|
|
|
|
Sqlite3MozCookieParser parser;
|
|
|
|
try {
|
|
|
|
parser.parse("fileNotFound");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(RecoverableException& e) {
|
|
|
|
// SUCCESS
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(e.what(),
|
2010-01-05 16:01:46 +00:00
|
|
|
"Failed to open SQLite3 database:"));
|
2008-08-17 10:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sqlite3MozCookieParserTest::testParse_badfile()
|
|
|
|
{
|
|
|
|
Sqlite3MozCookieParser parser;
|
|
|
|
try {
|
|
|
|
parser.parse("badcookies.sqlite");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(RecoverableException& e) {
|
|
|
|
// SUCCESS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|