2008-09-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Use CookieStorage class instead of CookieBox class.
	Now CookieStorage accepts cookies from numeric host such as 
192.168.1.1.
	* src/AbstractProxyRequestCommand.cc
	* src/CookieStorage.cc
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
	* src/HttpConnection.cc
	* src/HttpConnection.h
	* src/HttpRequest.cc
	* src/HttpRequest.h
	* src/HttpRequestCommand.cc
	* src/HttpResponse.cc
	* src/HttpResponseCommand.cc
	* src/HttpSkipResponseCommand.cc
	* src/Makefile.am
	* src/MultiUrlRequestInfo.cc
	* src/Request.cc
	* src/Request.h
	* src/main.cc
	* test/AllTest.cc
	* test/CookieStorageTest.cc
	* test/CookieTest.cc
	* test/HttpRequestTest.cc
	* test/HttpResponseTest.cc
	* test/Makefile.am
	* test/NsCookieParserTest.cc
	* test/Sqlite3MozCookieParserTest.cc
	* test/nscookietest.txt
This commit is contained in:
Tatsuhiro Tsujikawa 2008-09-01 13:46:03 +00:00
parent f670cdbba9
commit 398d53f5f5
29 changed files with 258 additions and 136 deletions

View File

@ -1,3 +1,33 @@
2008-09-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Use CookieStorage class instead of CookieBox class.
* src/AbstractProxyRequestCommand.cc
* src/CookieStorage.cc
* src/DownloadEngine.cc
* src/DownloadEngine.h
* src/HttpConnection.cc
* src/HttpConnection.h
* src/HttpRequest.cc
* src/HttpRequest.h
* src/HttpRequestCommand.cc
* src/HttpResponse.cc
* src/HttpResponseCommand.cc
* src/HttpSkipResponseCommand.cc
* src/Makefile.am
* src/MultiUrlRequestInfo.cc
* src/Request.cc
* src/Request.h
* src/main.cc
* test/AllTest.cc
* test/CookieStorageTest.cc
* test/CookieTest.cc
* test/HttpRequestTest.cc
* test/HttpResponseTest.cc
* test/Makefile.am
* test/NsCookieParserTest.cc
* test/Sqlite3MozCookieParserTest.cc
* test/nscookietest.txt
2008-08-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Updated

View File

@ -42,6 +42,7 @@
#include "Option.h"
#include "prefs.h"
#include "Socket.h"
#include "CookieStorage.h"
namespace aria2 {

View File

@ -86,9 +86,6 @@ bool CookieStorage::parseAndStore(const std::string& setCookieString,
const std::string& requestHost,
const std::string& requestPath)
{
if(Util::isNumbersAndDotsNotation(requestHost)) {
return false;
}
Cookie cookie = _parser.parse(setCookieString, requestHost, requestPath);
if(cookie.validate(requestHost, requestPath)) {
return store(cookie);

View File

@ -52,6 +52,7 @@
#include "a2functional.h"
#include "DlAbortEx.h"
#include "ServerStatMan.h"
#include "CookieStorage.h"
#include <signal.h>
#include <cstring>
#include <algorithm>
@ -393,7 +394,8 @@ void AsyncNameResolverEntry::process(fd_set* rfdsPtr, fd_set* wfdsPtr)
DownloadEngine::DownloadEngine():logger(LogFactory::getInstance()),
_haltRequested(false),
_noWait(false)
_noWait(false),
_cookieStorage(new CookieStorage())
{
#ifdef HAVE_EPOLL
@ -881,6 +883,11 @@ void DownloadEngine::addRoutineCommand(Command* command)
_routineCommands.push_back(command);
}
SharedHandle<CookieStorage> DownloadEngine::getCookieStorage() const
{
return _cookieStorage;
}
void DownloadEngine::poolSocket(const std::string& ipaddr, uint16_t port,
const SharedHandle<SocketCore>& sock,
time_t timeout)

View File

@ -59,6 +59,7 @@ class FileAllocationMan;
class StatCalc;
class CheckIntegrityMan;
class SocketCore;
class CookieStorage;
class CommandEvent
{
@ -277,6 +278,12 @@ private:
// key = IP address:port, value = SocketPoolEntry
std::multimap<std::string, SocketPoolEntry> _socketPool;
bool _noWait;
std::deque<Command*> _routineCommands;
SharedHandle<CookieStorage> _cookieStorage;
void shortSleep() const;
/**
@ -287,12 +294,6 @@ private:
void onEndOfRun();
void afterEachIteration();
private:
bool _noWait;
std::deque<Command*> _routineCommands;
public:
std::deque<Command*> commands;
SharedHandle<RequestGroupMan> _requestGroupMan;
@ -371,6 +372,8 @@ public:
SharedHandle<SocketCore>
popPooledSocket(const std::deque<std::string>& ipaddrs, uint16_t port);
SharedHandle<CookieStorage> getCookieStorage() const;
};
typedef SharedHandle<DownloadEngine> DownloadEngineHandle;

View File

@ -48,6 +48,7 @@
#include "Logger.h"
#include "Socket.h"
#include "Option.h"
#include "CookieStorage.h"
#include <sstream>
namespace aria2 {
@ -169,4 +170,13 @@ bool HttpConnection::isIssued(const SegmentHandle& segment) const
return false;
}
SharedHandle<HttpRequest> HttpConnection::getFirstHttpRequest() const
{
if(outstandingHttpRequests.empty()) {
return SharedHandle<HttpRequest>();
} else {
return outstandingHttpRequests.front()->getHttpRequest();
}
}
} // namespace aria2

View File

@ -109,14 +109,7 @@ public:
*/
SharedHandle<HttpResponse> receiveResponse();
SharedHandle<HttpRequest> getFirstHttpRequest() const
{
if(outstandingHttpRequests.size() > 0) {
return outstandingHttpRequests.front()->getHttpRequest();
} else {
return SharedHandle<HttpRequest>();
}
}
SharedHandle<HttpRequest> getFirstHttpRequest() const;
bool isIssued(const SharedHandle<Segment>& segment) const;
};

View File

@ -36,8 +36,7 @@
#include "Request.h"
#include "Segment.h"
#include "Range.h"
#include "Cookie.h"
#include "CookieBox.h"
#include "CookieStorage.h"
#include "Option.h"
#include "Util.h"
#include "Base64.h"
@ -45,6 +44,7 @@
#include "AuthConfigFactory.h"
#include "AuthConfig.h"
#include "a2functional.h"
#include "TimeA2.h"
#include <numeric>
namespace aria2 {
@ -200,17 +200,21 @@ std::string HttpRequest::createRequest() const
if(getPreviousURI().size()) {
requestLine += "Referer: "+getPreviousURI()+"\r\n";
}
std::string cookiesValue;
Cookies cookies = request->cookieBox->criteriaFind(getHost(),
getDir(),
time(0),
getProtocol() == Request::PROTO_HTTPS ?
true : false);
for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
cookiesValue += (*itr).toString()+";";
}
if(cookiesValue.size()) {
requestLine += std::string("Cookie: ")+cookiesValue+"\r\n";
if(!_cookieStorage.isNull()) {
std::string cookiesValue;
std::deque<Cookie> cookies =
_cookieStorage->criteriaFind(getHost(),
getDir(),
Time().getTime(),
getProtocol() == Request::PROTO_HTTPS ?
true : false);
for(std::deque<Cookie>::const_iterator itr = cookies.begin();
itr != cookies.end(); ++itr) {
cookiesValue += (*itr).toString()+";";
}
if(!cookiesValue.empty()) {
requestLine += std::string("Cookie: ")+cookiesValue+"\r\n";
}
}
// append additional headers given by user.
for(std::deque<std::string>::const_iterator i = _headers.begin();
@ -322,4 +326,15 @@ const std::string& HttpRequest::getQuery() const
return request->getQuery();
}
void HttpRequest::setCookieStorage
(const SharedHandle<CookieStorage>& cookieStorage)
{
_cookieStorage = cookieStorage;
}
SharedHandle<CookieStorage> HttpRequest::getCookieStorage() const
{
return _cookieStorage;
}
} // namespace aria2

View File

@ -46,6 +46,7 @@ class Request;
class Segment;
class Range;
class Option;
class CookieStorage;
class HttpRequest {
private:
@ -72,10 +73,11 @@ private:
std::deque<std::string> _acceptTypes;
SharedHandle<CookieStorage> _cookieStorage;
std::string getHostText(const std::string& host, uint16_t port) const;
std::string getProxyAuthString() const;
public:
HttpRequest();
@ -187,6 +189,10 @@ public:
{
_acceptTypes.insert(_acceptTypes.end(), first, last);
}
void setCookieStorage(const SharedHandle<CookieStorage>& cookieStorage);
SharedHandle<CookieStorage> getCookieStorage() const;
};
typedef SharedHandle<HttpRequest> HttpRequestHandle;

View File

@ -46,6 +46,7 @@
#include "prefs.h"
#include "a2functional.h"
#include "Util.h"
#include "CookieStorage.h"
#include <algorithm>
namespace aria2 {
@ -71,7 +72,8 @@ createHttpRequest(const SharedHandle<Request>& req,
const SharedHandle<Segment>& segment,
uint64_t totalLength,
const Option* option,
const RequestGroup* rg)
const RequestGroup* rg,
const SharedHandle<CookieStorage>& cookieStorage)
{
HttpRequestHandle httpRequest(new HttpRequest());
httpRequest->setUserAgent(option->get(PREF_USER_AGENT));
@ -79,6 +81,7 @@ createHttpRequest(const SharedHandle<Request>& req,
httpRequest->setSegment(segment);
httpRequest->setEntityLength(totalLength);
httpRequest->addHeader(option->get(PREF_HEADER));
httpRequest->setCookieStorage(cookieStorage);
if(!rg->getAcceptFeatures().empty()) {
const std::deque<std::string>& acceptFeatures = rg->getAcceptFeatures();
std::string acceptFeaturesHeader = "Accept-Features: ";
@ -103,7 +106,8 @@ bool HttpRequestCommand::executeInternal() {
HttpRequestHandle httpRequest
(createHttpRequest(req, SharedHandle<Segment>(),
_requestGroup->getTotalLength(), e->option,
_requestGroup));
_requestGroup,
e->getCookieStorage()));
_httpConnection->sendRequest(httpRequest);
} else {
for(Segments::iterator itr = _segments.begin(); itr != _segments.end(); ++itr) {
@ -112,7 +116,8 @@ bool HttpRequestCommand::executeInternal() {
HttpRequestHandle httpRequest
(createHttpRequest(req, segment,
_requestGroup->getTotalLength(), e->option,
_requestGroup));
_requestGroup,
e->getCookieStorage()));
_httpConnection->sendRequest(httpRequest);
}
}

View File

@ -35,7 +35,6 @@
#include "HttpResponse.h"
#include "Request.h"
#include "Segment.h"
#include "CookieBox.h"
#include "HttpRequest.h"
#include "HttpHeader.h"
#include "Range.h"
@ -52,6 +51,7 @@
#ifdef HAVE_LIBZ
# include "GZipDecoder.h"
#endif // HAVE_LIBZ
#include "CookieStorage.h"
#include <deque>
namespace aria2 {
@ -109,9 +109,10 @@ void HttpResponse::retrieveCookie()
{
std::deque<std::string> v = httpHeader->get(HttpHeader::SET_COOKIE);
for(std::deque<std::string>::const_iterator itr = v.begin(); itr != v.end();
itr++) {
httpRequest->getRequest()->cookieBox->add(*itr, httpRequest->getHost(),
httpRequest->getDir());
++itr) {
httpRequest->getCookieStorage()->parseAndStore(*itr,
httpRequest->getHost(),
httpRequest->getDir());
}
}

View File

@ -63,6 +63,7 @@
#include "HttpHeader.h"
#include "Decoder.h"
#include "LogFactory.h"
#include "CookieStorage.h"
namespace aria2 {

View File

@ -50,6 +50,7 @@
#include "HttpHeader.h"
#include "prefs.h"
#include "Option.h"
#include "CookieStorage.h"
namespace aria2 {

View File

@ -195,7 +195,8 @@ SRCS = Socket.h\
URISelector.h\
InOrderURISelector.cc InOrderURISelector.h\
ServerStatURISelector.cc ServerStatURISelector.h\
NsCookieParser.cc NsCookieParser.h
NsCookieParser.cc NsCookieParser.h\
CookieStorage.cc CookieStorage.h
if HAVE_LIBZ
SRCS += GZipDecoder.cc GZipDecoder.h

View File

@ -415,9 +415,10 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
ServerStatMan.h URISelector.h InOrderURISelector.cc \
InOrderURISelector.h ServerStatURISelector.cc \
ServerStatURISelector.h NsCookieParser.cc NsCookieParser.h \
GZipDecoder.cc GZipDecoder.h Sqlite3MozCookieParser.cc \
Sqlite3MozCookieParser.h AsyncNameResolver.cc \
AsyncNameResolver.h IteratableChunkChecksumValidator.cc \
CookieStorage.cc CookieStorage.h GZipDecoder.cc GZipDecoder.h \
Sqlite3MozCookieParser.cc Sqlite3MozCookieParser.h \
AsyncNameResolver.cc AsyncNameResolver.h \
IteratableChunkChecksumValidator.cc \
IteratableChunkChecksumValidator.h \
IteratableChecksumValidator.cc IteratableChecksumValidator.h \
CheckIntegrityCommand.cc CheckIntegrityCommand.h \
@ -809,12 +810,12 @@ am__objects_18 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
Signature.$(OBJEXT) ServerStat.$(OBJEXT) \
ServerStatMan.$(OBJEXT) InOrderURISelector.$(OBJEXT) \
ServerStatURISelector.$(OBJEXT) NsCookieParser.$(OBJEXT) \
$(am__objects_1) $(am__objects_2) $(am__objects_3) \
$(am__objects_4) $(am__objects_5) $(am__objects_6) \
$(am__objects_7) $(am__objects_8) $(am__objects_9) \
$(am__objects_10) $(am__objects_11) $(am__objects_12) \
$(am__objects_13) $(am__objects_14) $(am__objects_15) \
$(am__objects_16) $(am__objects_17)
CookieStorage.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
$(am__objects_3) $(am__objects_4) $(am__objects_5) \
$(am__objects_6) $(am__objects_7) $(am__objects_8) \
$(am__objects_9) $(am__objects_10) $(am__objects_11) \
$(am__objects_12) $(am__objects_13) $(am__objects_14) \
$(am__objects_15) $(am__objects_16) $(am__objects_17)
am_libaria2c_a_OBJECTS = $(am__objects_18)
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)"
@ -1139,12 +1140,13 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
ServerStatMan.h URISelector.h InOrderURISelector.cc \
InOrderURISelector.h ServerStatURISelector.cc \
ServerStatURISelector.h NsCookieParser.cc NsCookieParser.h \
$(am__append_1) $(am__append_2) $(am__append_3) \
$(am__append_4) $(am__append_5) $(am__append_6) \
$(am__append_7) $(am__append_8) $(am__append_9) \
$(am__append_10) $(am__append_11) $(am__append_12) \
$(am__append_13) $(am__append_14) $(am__append_15) \
$(am__append_16) $(am__append_17)
CookieStorage.cc CookieStorage.h $(am__append_1) \
$(am__append_2) $(am__append_3) $(am__append_4) \
$(am__append_5) $(am__append_6) $(am__append_7) \
$(am__append_8) $(am__append_9) $(am__append_10) \
$(am__append_11) $(am__append_12) $(am__append_13) \
$(am__append_14) $(am__append_15) $(am__append_16) \
$(am__append_17)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@ -1297,6 +1299,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBox.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBoxFactory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieParser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieStorage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CopyDiskAdaptor.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTAbstractMessage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTAbstractNodeLookupTask.Po@am__quote@

View File

@ -46,6 +46,8 @@
#include "Util.h"
#include "Option.h"
#include "StatCalc.h"
#include "CookieStorage.h"
#include "File.h"
#include <signal.h>
#include <ostream>
@ -100,6 +102,20 @@ int MultiUrlRequestInfo::execute()
DownloadEngineHandle e =
DownloadEngineFactory().newDownloadEngine(_option, _requestGroups);
try {
if(_option->defined(PREF_LOAD_COOKIES)) {
File cookieFile(_option->get(PREF_LOAD_COOKIES));
if(cookieFile.isFile()) {
e->getCookieStorage()->load(_option->get(PREF_LOAD_COOKIES));
} else {
_logger->error(MSG_LOADING_COOKIE_FAILED,
_option->get(PREF_LOAD_COOKIES).c_str());
}
}
} catch(RecoverableException& e) {
_logger->error(EX_EXCEPTION_CAUGHT, e);
}
std::string serverStatIf = _option->get(PREF_SERVER_STAT_IF);
if(!serverStatIf.empty()) {
e->_requestGroupMan->loadServerStat(serverStatIf);

View File

@ -35,8 +35,6 @@
#include "Request.h"
#include "Util.h"
#include "FeatureConfig.h"
#include "CookieBoxFactory.h"
#include "CookieBox.h"
#include "RecoverableException.h"
#include "StringFormat.h"
#include "A2STR.h"
@ -60,8 +58,7 @@ Request::Request():
_supportsPersistentConnection(true),
_keepAliveHint(false),
_pipeliningHint(false),
method(METHOD_GET),
cookieBox(CookieBoxFactorySingletonHolder::instance()->createNewInstance())
method(METHOD_GET)
{}
Request::~Request() {}

View File

@ -50,8 +50,6 @@
namespace aria2 {
class CookieBox;
class Request {
private:
std::string url;
@ -93,9 +91,6 @@ private:
bool isHexNumber(const char c) const;
void urlencode(std::string& result, const std::string& src) const;
public:
SharedHandle<CookieBox> cookieBox;
public:
Request();
virtual ~Request();

View File

@ -39,7 +39,6 @@
#include "Util.h"
#include "BitfieldManFactory.h"
#include "AuthConfigFactory.h"
#include "CookieBoxFactory.h"
#include "FeatureConfig.h"
#include "MultiUrlRequestInfo.h"
#include "SimpleRandomizer.h"
@ -380,20 +379,6 @@ int main(int argc, char* argv[])
}
}
CookieBoxFactoryHandle cookieBoxFactory(new CookieBoxFactory());
CookieBoxFactorySingletonHolder::instance(cookieBoxFactory);
if(op->defined(PREF_LOAD_COOKIES)) {
File cookieFile(op->get(PREF_LOAD_COOKIES));
if(cookieFile.isFile()) {
CookieBoxFactorySingletonHolder::instance()->loadDefaultCookie
(op->get(PREF_LOAD_COOKIES));
} else {
logger->error(MSG_LOADING_COOKIE_FAILED,
op->get(PREF_LOAD_COOKIES).c_str());
exit(EXIT_FAILURE);
}
}
AuthConfigFactorySingleton::instance(authConfigFactory);
CUIDCounterHandle cuidCounter(new CUIDCounter());
CUIDCounterSingletonHolder::instance(cuidCounter);

View File

@ -1,13 +1,9 @@
#include "Platform.h"
#include "CookieBoxFactory.h"
#include <iostream>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
using aria2::SharedHandle;
using aria2::SingletonHolder;
int main(int argc, char* argv[]) {
aria2::Platform platform;
@ -22,12 +18,6 @@ int main(int argc, char* argv[]) {
runner.addTest(suite);
runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), std::cerr));
// setup
SharedHandle<aria2::CookieBoxFactory> cookieBoxFactory
(new aria2::CookieBoxFactory());
SingletonHolder<SharedHandle<aria2::CookieBoxFactory> >::instance(cookieBoxFactory);
// Run the tests.
bool successfull = runner.run();

View File

@ -65,6 +65,11 @@ void CookieStorageTest::testStore()
CPPUNIT_ASSERT(!st.store(badCookie));
CPPUNIT_ASSERT_EQUAL((size_t)1, st.size());
CPPUNIT_ASSERT(std::find(st.begin(), st.end(), anotherCookie) != st.end());
Cookie fromNumericHost("k", "v", "/", "192.168.1.1", false);
CPPUNIT_ASSERT(st.store(fromNumericHost));
CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
CPPUNIT_ASSERT(std::find(st.begin(), st.end(), fromNumericHost) != st.end());
}
void CookieStorageTest::testParseAndStore()
@ -81,6 +86,11 @@ void CookieStorageTest::testParseAndStore()
CPPUNIT_ASSERT(!st.parseAndStore(localhostCookieStr,
"127.0.0.1", "/downloads"));
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", "/"));
}
void CookieStorageTest::testCriteriaFind()
@ -94,12 +104,15 @@ void CookieStorageTest::testCriteriaFind()
Cookie delta("delta", "DELTA", "/foo/bar", ".aria2.org", false);
Cookie echo("echo", "ECHO", "/", "www.aria2.org", false);
Cookie foxtrot("foxtrot", "FOXTROT", "/", ".sf.net", false);
Cookie golf("golf", "GOLF", "/", "192.168.1.1", 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));
std::deque<Cookie> aria2Slash = st.criteriaFind("www.aria2.org", "/",
0, false);
@ -130,6 +143,11 @@ void CookieStorageTest::testCriteriaFind()
std::deque<Cookie> dlAria2 = st.criteriaFind("dl.aria2.org", "/", 0, false);
CPPUNIT_ASSERT_EQUAL((size_t)1, dlAria2.size());
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), dlAria2[0].name);
std::deque<Cookie> numericHostCookies = st.criteriaFind("192.168.1.1", "/", 0,
false);
CPPUNIT_ASSERT_EQUAL((size_t)1, numericHostCookies.size());
CPPUNIT_ASSERT_EQUAL(std::string("golf"), numericHostCookies[0].name);
}
void CookieStorageTest::testLoad()

View File

@ -85,6 +85,11 @@ void CookieTest::testValidate()
Cookie nameEmpty("", "v", "/", "localhost", false);
CPPUNIT_ASSERT(!nameEmpty.validate("localhost", "/"));
}
{
Cookie fromNumericHost("k", "v", "/", "192.168.1.1", false);
CPPUNIT_ASSERT(fromNumericHost.validate("192.168.1.1", "/"));
CPPUNIT_ASSERT(!fromNumericHost.validate("www.aria2.org", "/"));
}
}
void CookieTest::testOperatorEqual()
@ -127,6 +132,10 @@ void CookieTest::testMatch()
CPPUNIT_ASSERT(expireTest.match("www.aria2.org", "/", 999, false));
CPPUNIT_ASSERT(!expireTest.match("www.aria2.org", "/", 1000, false));
CPPUNIT_ASSERT(!expireTest.match("www.aria2.org", "/", 1001, false));
Cookie fromNumericHost("k", "v", "/", "192.168.1.1", false);
CPPUNIT_ASSERT(fromNumericHost.match("192.168.1.1", "/", 0, false));
CPPUNIT_ASSERT(!fromNumericHost.match("www.aria2.org", "/", 0, false));
}
void CookieTest::testIsExpired()

View File

@ -5,9 +5,9 @@
#include "Piece.h"
#include "Range.h"
#include "Request.h"
#include "CookieBox.h"
#include "Option.h"
#include "array_fun.h"
#include "CookieStorage.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@ -396,19 +396,21 @@ void HttpRequestTest::testCreateRequest_with_cookie()
Cookie cookie1("name1", "value1", "/archives", "localhost", false);
Cookie cookie2("name2", "value2", "/archives/download", "localhost", false);
Cookie cookie3("name3", "value3", "/archives/download", "tt.localhost", false);
Cookie cookie4("name4", "value4", "/archives/download", "tt.localhost", true);
Cookie cookie3("name3", "value3", "/archives/download", ".aria2.org", false);
Cookie cookie4("name4", "value4", "/archives/", ".aria2.org", true);
request->cookieBox->add(cookie1);
request->cookieBox->add(cookie2);
request->cookieBox->add(cookie3);
request->cookieBox->add(cookie4);
SharedHandle<CookieStorage> st(new CookieStorage());
CPPUNIT_ASSERT(st->store(cookie1));
CPPUNIT_ASSERT(st->store(cookie2));
CPPUNIT_ASSERT(st->store(cookie3));
CPPUNIT_ASSERT(st->store(cookie4));
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
httpRequest.setCookieStorage(st);
std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
@ -431,35 +433,36 @@ void HttpRequestTest::testCreateRequest_with_cookie()
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Cookie: name1=value1;name2=value2;\r\n"
"Cookie: name2=value2;name1=value1;\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
request->setUrl("http://tt.localhost/archives/download/aria2-1.0.0.tar.bz2");
request->setUrl("http://www.aria2.org/archives/download/aria2-1.0.0.tar.bz2");
expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
"Accept: */*\r\n"
"Host: tt.localhost\r\n"
"Host: www.aria2.org\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Cookie: name1=value1;name2=value2;name3=value3;\r\n"
"Cookie: name3=value3;\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
request->setUrl("https://tt.localhost/archives/download/aria2-1.0.0.tar.bz2");
request->setUrl("https://www.aria2.org/archives/download/"
"aria2-1.0.0.tar.bz2");
expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
"Accept: */*\r\n"
"Host: tt.localhost\r\n"
"Host: www.aria2.org\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Cookie: name1=value1;name2=value2;name3=value3;name4=value4;\r\n"
"Cookie: name3=value3;name4=value4;\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());

View File

@ -9,6 +9,7 @@
#include "A2STR.h"
#include "Decoder.h"
#include "DlRetryEx.h"
#include "CookieStorage.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
@ -40,6 +41,7 @@ class HttpResponseTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testValidateResponse_chunked);
CPPUNIT_TEST(testHasRetryAfter);
CPPUNIT_TEST(testProcessRedirect);
CPPUNIT_TEST(testRetrieveCookie);
CPPUNIT_TEST_SUITE_END();
private:
@ -69,6 +71,7 @@ public:
void testValidateResponse_chunked();
void testHasRetryAfter();
void testProcessRedirect();
void testRetrieveCookie();
};
@ -454,4 +457,33 @@ void HttpResponseTest::testProcessRedirect()
}
}
void HttpResponseTest::testRetrieveCookie()
{
HttpResponse httpResponse;
SharedHandle<HttpHeader> httpHeader(new HttpHeader());
httpResponse.setHttpHeader(httpHeader);
SharedHandle<HttpRequest> httpRequest(new HttpRequest());
SharedHandle<Request> request(new Request());
request->setUrl("http://www.aria2.org/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request);
SharedHandle<CookieStorage> st(new CookieStorage());
httpRequest->setCookieStorage(st);
httpResponse.setHttpRequest(httpRequest);
httpHeader->put("Set-Cookie", "k1=v1; expires=Sun, 2007-06-10 11:00:00 GMT;"
"path=/; domain=.aria2.org;");
httpHeader->put("Set-Cookie", "k2=v2; expires=Sun, 2038-01-01 00:00:00 GMT;"
"path=/; domain=.aria2.org;");
httpHeader->put("Set-Cookie", "k3=v3;");
httpResponse.retrieveCookie();
CPPUNIT_ASSERT_EQUAL((size_t)2, st->size());
std::deque<Cookie>::const_iterator citer = st->begin();
CPPUNIT_ASSERT_EQUAL(std::string("k2=v2"), (*(st->begin())).toString());
CPPUNIT_ASSERT_EQUAL(std::string("k3=v3"), (*(st->begin()+1)).toString());
}
} // namespace aria2

View File

@ -24,11 +24,9 @@ aria2c_SOURCES = AllTest.cc\
AlphaNumberDecoratorTest.cc\
UriListParserTest.cc\
HttpHeaderProcessorTest.cc\
CookieBoxTest.cc\
RequestTest.cc\
CookieParserTest.cc\
HttpRequestTest.cc\
CookieBoxFactoryTest.cc\
RequestGroupManTest.cc\
AuthConfigFactoryTest.cc\
NetrcAuthResolverTest.cc\

View File

@ -178,17 +178,17 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
SingleFileDownloadContextTest.cc RequestGroupTest.cc \
PStringBuildVisitorTest.cc ParameterizedStringParserTest.cc \
UtilTest.cc AlphaNumberDecoratorTest.cc UriListParserTest.cc \
HttpHeaderProcessorTest.cc CookieBoxTest.cc RequestTest.cc \
CookieParserTest.cc HttpRequestTest.cc CookieBoxFactoryTest.cc \
RequestGroupManTest.cc AuthConfigFactoryTest.cc \
NetrcAuthResolverTest.cc DefaultAuthResolverTest.cc \
OptionHandlerTest.cc SegmentManTest.cc BitfieldManTest.cc \
NetrcTest.cc SingletonHolderTest.cc HttpHeaderTest.cc \
HttpResponseTest.cc SharedHandleTest.cc FileTest.cc \
OptionTest.cc DefaultDiskWriterTest.cc FeatureConfigTest.cc \
SpeedCalcTest.cc MultiDiskAdaptorTest.cc \
MultiFileAllocationIteratorTest.cc FixedNumberRandomizer.h \
ProtocolDetectorTest.cc StringFormatTest.cc ExceptionTest.cc \
HttpHeaderProcessorTest.cc RequestTest.cc CookieParserTest.cc \
HttpRequestTest.cc RequestGroupManTest.cc \
AuthConfigFactoryTest.cc NetrcAuthResolverTest.cc \
DefaultAuthResolverTest.cc OptionHandlerTest.cc \
SegmentManTest.cc BitfieldManTest.cc NetrcTest.cc \
SingletonHolderTest.cc HttpHeaderTest.cc HttpResponseTest.cc \
SharedHandleTest.cc FileTest.cc OptionTest.cc \
DefaultDiskWriterTest.cc FeatureConfigTest.cc SpeedCalcTest.cc \
MultiDiskAdaptorTest.cc MultiFileAllocationIteratorTest.cc \
FixedNumberRandomizer.h ProtocolDetectorTest.cc \
StringFormatTest.cc ExceptionTest.cc \
DownloadHandlerFactoryTest.cc ChunkedDecoderTest.cc \
SignatureTest.cc ServerStatManTest.cc \
ServerStatURISelectorTest.cc InOrderURISelectorTest.cc \
@ -345,9 +345,8 @@ am_aria2c_OBJECTS = AllTest.$(OBJEXT) TestUtil.$(OBJEXT) \
RequestGroupTest.$(OBJEXT) PStringBuildVisitorTest.$(OBJEXT) \
ParameterizedStringParserTest.$(OBJEXT) UtilTest.$(OBJEXT) \
AlphaNumberDecoratorTest.$(OBJEXT) UriListParserTest.$(OBJEXT) \
HttpHeaderProcessorTest.$(OBJEXT) CookieBoxTest.$(OBJEXT) \
RequestTest.$(OBJEXT) CookieParserTest.$(OBJEXT) \
HttpRequestTest.$(OBJEXT) CookieBoxFactoryTest.$(OBJEXT) \
HttpHeaderProcessorTest.$(OBJEXT) RequestTest.$(OBJEXT) \
CookieParserTest.$(OBJEXT) HttpRequestTest.$(OBJEXT) \
RequestGroupManTest.$(OBJEXT) AuthConfigFactoryTest.$(OBJEXT) \
NetrcAuthResolverTest.$(OBJEXT) \
DefaultAuthResolverTest.$(OBJEXT) OptionHandlerTest.$(OBJEXT) \
@ -574,17 +573,17 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \
SingleFileDownloadContextTest.cc RequestGroupTest.cc \
PStringBuildVisitorTest.cc ParameterizedStringParserTest.cc \
UtilTest.cc AlphaNumberDecoratorTest.cc UriListParserTest.cc \
HttpHeaderProcessorTest.cc CookieBoxTest.cc RequestTest.cc \
CookieParserTest.cc HttpRequestTest.cc CookieBoxFactoryTest.cc \
RequestGroupManTest.cc AuthConfigFactoryTest.cc \
NetrcAuthResolverTest.cc DefaultAuthResolverTest.cc \
OptionHandlerTest.cc SegmentManTest.cc BitfieldManTest.cc \
NetrcTest.cc SingletonHolderTest.cc HttpHeaderTest.cc \
HttpResponseTest.cc SharedHandleTest.cc FileTest.cc \
OptionTest.cc DefaultDiskWriterTest.cc FeatureConfigTest.cc \
SpeedCalcTest.cc MultiDiskAdaptorTest.cc \
MultiFileAllocationIteratorTest.cc FixedNumberRandomizer.h \
ProtocolDetectorTest.cc StringFormatTest.cc ExceptionTest.cc \
HttpHeaderProcessorTest.cc RequestTest.cc CookieParserTest.cc \
HttpRequestTest.cc RequestGroupManTest.cc \
AuthConfigFactoryTest.cc NetrcAuthResolverTest.cc \
DefaultAuthResolverTest.cc OptionHandlerTest.cc \
SegmentManTest.cc BitfieldManTest.cc NetrcTest.cc \
SingletonHolderTest.cc HttpHeaderTest.cc HttpResponseTest.cc \
SharedHandleTest.cc FileTest.cc OptionTest.cc \
DefaultDiskWriterTest.cc FeatureConfigTest.cc SpeedCalcTest.cc \
MultiDiskAdaptorTest.cc MultiFileAllocationIteratorTest.cc \
FixedNumberRandomizer.h ProtocolDetectorTest.cc \
StringFormatTest.cc ExceptionTest.cc \
DownloadHandlerFactoryTest.cc ChunkedDecoderTest.cc \
SignatureTest.cc ServerStatManTest.cc \
ServerStatURISelectorTest.cc InOrderURISelectorTest.cc \
@ -710,8 +709,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtUnchokeMessageTest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ByteArrayDiskWriterTest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedDecoderTest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBoxFactoryTest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBoxTest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieParserTest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieStorageTest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieTest.Po@am__quote@

View File

@ -28,12 +28,12 @@ void NsCookieParserTest::testParse()
{
NsCookieParser parser;
std::deque<Cookie> cookies = parser.parse("nscookietest.txt");
CPPUNIT_ASSERT_EQUAL((size_t)4, cookies.size());
CPPUNIT_ASSERT_EQUAL((size_t)5, cookies.size());
Cookie c = cookies[0];
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
@ -42,7 +42,7 @@ void NsCookieParserTest::testParse()
CPPUNIT_ASSERT_EQUAL(std::string("me"), c.value);
CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
CPPUNIT_ASSERT_EQUAL(std::string("expired"), c.domain);
c = cookies[2];
CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.name);
@ -52,6 +52,13 @@ void NsCookieParserTest::testParse()
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
c = cookies[3];
CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c.name);
CPPUNIT_ASSERT_EQUAL(std::string("1000"), c.value);
CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
CPPUNIT_ASSERT_EQUAL(std::string("overflow"), c.domain);
c = cookies[4];
CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.name);
CPPUNIT_ASSERT_EQUAL(std::string(""), c.value);
CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);

View File

@ -37,7 +37,7 @@ void Sqlite3MozCookieParserTest::testParse()
CPPUNIT_ASSERT_EQUAL(std::string("/"), localhost.path);
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), localhost.name);
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), localhost.value);
CPPUNIT_ASSERT_EQUAL((time_t)1200000000, localhost.expires);
CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, localhost.expires);
CPPUNIT_ASSERT_EQUAL(true, localhost.secure);
const Cookie& nullValue = cookies[1];

View File

@ -4,5 +4,6 @@ localhost FALSE / TRUE 2147483647 JSESSIONID 123456789
expired FALSE / FALSE 1181473200 user me
localhost FALSE /cgi-bin FALSE 2147483647 passwd secret
badformat
overflow FALSE / FALSE 9223372036854775807 TAX 1000
localhost FALSE / FALSE 2147483648 novalue