2009-07-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Use option of each download to create AuthConfig instead of global
	option.	
	* src/AuthConfigFactory.cc
	* src/AuthConfigFactory.h
	* src/FtpNegotiationCommand.cc
	* src/HttpRequest.cc
	* src/HttpRequest.h
	* src/HttpRequestCommand.cc
	* src/HttpSkipResponseCommand.cc
	* src/MultiUrlRequestInfo.cc
	* test/AuthConfigFactoryTest.cc
	* test/FtpConnectionTest.cc
	* test/HttpRequestTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-07-14 12:37:34 +00:00
parent 894641dfdb
commit 682bafae0a
12 changed files with 108 additions and 74 deletions

View File

@ -1,3 +1,19 @@
2009-07-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use option of each download to create AuthConfig instead of global
option.
* src/AuthConfigFactory.cc
* src/AuthConfigFactory.h
* src/FtpNegotiationCommand.cc
* src/HttpRequest.cc
* src/HttpRequest.h
* src/HttpRequestCommand.cc
* src/HttpSkipResponseCommand.cc
* src/MultiUrlRequestInfo.cc
* test/AuthConfigFactoryTest.cc
* test/FtpConnectionTest.cc
* test/HttpRequestTest.cc
2009-07-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-07-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Don't call prepareForRetry(1) if all segments are ignored in Don't call prepareForRetry(1) if all segments are ignored in

View File

@ -51,18 +51,18 @@ const std::string AuthConfigFactory::ANONYMOUS("anonymous");
const std::string AuthConfigFactory::ARIA2USER_AT("ARIA2USER@"); const std::string AuthConfigFactory::ARIA2USER_AT("ARIA2USER@");
AuthConfigFactory::AuthConfigFactory(const Option* option): AuthConfigFactory::AuthConfigFactory() {}
_option(option) {}
AuthConfigFactory::~AuthConfigFactory() {} AuthConfigFactory::~AuthConfigFactory() {}
AuthConfigHandle AuthConfigHandle
AuthConfigFactory::createAuthConfig(const RequestHandle& request) AuthConfigFactory::createAuthConfig
(const SharedHandle<Request>& request, const Option* op)
{ {
if(request->getProtocol() == Request::PROTO_HTTP || if(request->getProtocol() == Request::PROTO_HTTP ||
request->getProtocol() == Request::PROTO_HTTPS) { request->getProtocol() == Request::PROTO_HTTPS) {
if(_option->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) { if(op->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) {
if(!request->getUsername().empty()) { if(!request->getUsername().empty()) {
// TODO setting "/" as path. Should we use request->getDir() instead? // TODO setting "/" as path. Should we use request->getDir() instead?
updateBasicCred(BasicCred(request->getUsername(), request->getPassword(), updateBasicCred(BasicCred(request->getUsername(), request->getPassword(),
@ -80,14 +80,16 @@ AuthConfigFactory::createAuthConfig(const RequestHandle& request)
if(!request->getUsername().empty()) { if(!request->getUsername().empty()) {
return createAuthConfig(request->getUsername(), request->getPassword()); return createAuthConfig(request->getUsername(), request->getPassword());
} else { } else {
return createHttpAuthResolver()->resolveAuthConfig(request->getHost()); return
createHttpAuthResolver(op)->resolveAuthConfig(request->getHost());
} }
} }
} else if(request->getProtocol() == Request::PROTO_FTP) { } else if(request->getProtocol() == Request::PROTO_FTP) {
if(!request->getUsername().empty()) { if(!request->getUsername().empty()) {
return createAuthConfig(request->getUsername(), request->getPassword()); return createAuthConfig(request->getUsername(), request->getPassword());
} else { } else {
return createFtpAuthResolver()->resolveAuthConfig(request->getHost()); return
createFtpAuthResolver(op)->resolveAuthConfig(request->getHost());
} }
} else { } else {
return SharedHandle<AuthConfig>(); return SharedHandle<AuthConfig>();
@ -104,10 +106,11 @@ AuthConfigFactory::createAuthConfig(const std::string& user, const std::string&
return ac; return ac;
} }
AuthResolverHandle AuthConfigFactory::createHttpAuthResolver() const AuthResolverHandle AuthConfigFactory::createHttpAuthResolver
(const Option* op) const
{ {
AbstractAuthResolverHandle resolver; AbstractAuthResolverHandle resolver;
if(_option->getAsBool(PREF_NO_NETRC)) { if(op->getAsBool(PREF_NO_NETRC)) {
resolver.reset(new DefaultAuthResolver()); resolver.reset(new DefaultAuthResolver());
} else { } else {
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver()); NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
@ -115,21 +118,24 @@ AuthResolverHandle AuthConfigFactory::createHttpAuthResolver() const
authResolver->ignoreDefault(); authResolver->ignoreDefault();
resolver = authResolver; resolver = authResolver;
} }
resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_USER), _option->get(PREF_HTTP_PASSWD))); resolver->setUserDefinedAuthConfig
(createAuthConfig(op->get(PREF_HTTP_USER), op->get(PREF_HTTP_PASSWD)));
return resolver; return resolver;
} }
AuthResolverHandle AuthConfigFactory::createFtpAuthResolver() const AuthResolverHandle AuthConfigFactory::createFtpAuthResolver
(const Option* op) const
{ {
AbstractAuthResolverHandle resolver; AbstractAuthResolverHandle resolver;
if(_option->getAsBool(PREF_NO_NETRC)) { if(op->getAsBool(PREF_NO_NETRC)) {
resolver.reset(new DefaultAuthResolver()); resolver.reset(new DefaultAuthResolver());
} else { } else {
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver()); NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
authResolver->setNetrc(_netrc); authResolver->setNetrc(_netrc);
resolver = authResolver; resolver = authResolver;
} }
resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_FTP_USER), _option->get(PREF_FTP_PASSWD))); resolver->setUserDefinedAuthConfig
(createAuthConfig(op->get(PREF_FTP_USER), op->get(PREF_FTP_PASSWD)));
SharedHandle<AuthConfig> defaultAuthConfig SharedHandle<AuthConfig> defaultAuthConfig
(new AuthConfig(AuthConfigFactory::ANONYMOUS, (new AuthConfig(AuthConfigFactory::ANONYMOUS,
AuthConfigFactory::ARIA2USER_AT)); AuthConfigFactory::ARIA2USER_AT));
@ -155,14 +161,14 @@ void AuthConfigFactory::updateBasicCred(const BasicCred& basicCred)
} }
bool AuthConfigFactory::activateBasicCred bool AuthConfigFactory::activateBasicCred
(const std::string& host, const std::string& path) (const std::string& host, const std::string& path, const Option* op)
{ {
std::deque<BasicCred>::iterator i = std::deque<BasicCred>::iterator i =
findBasicCred(host, path); findBasicCred(host, path);
if(i == _basicCreds.end()) { if(i == _basicCreds.end()) {
SharedHandle<AuthConfig> authConfig = SharedHandle<AuthConfig> authConfig =
createHttpAuthResolver()->resolveAuthConfig(host); createHttpAuthResolver(op)->resolveAuthConfig(host);
if(authConfig.isNull()) { if(authConfig.isNull()) {
return false; return false;
} else { } else {

View File

@ -53,16 +53,14 @@ class AuthResolver;
class AuthConfigFactory { class AuthConfigFactory {
private: private:
const Option* _option;
SharedHandle<Netrc> _netrc; SharedHandle<Netrc> _netrc;
SharedHandle<AuthConfig> createAuthConfig(const std::string& user, SharedHandle<AuthConfig> createAuthConfig(const std::string& user,
const std::string& password) const; const std::string& password) const;
SharedHandle<AuthResolver> createHttpAuthResolver() const; SharedHandle<AuthResolver> createHttpAuthResolver(const Option* op) const;
SharedHandle<AuthResolver> createFtpAuthResolver() const; SharedHandle<AuthResolver> createFtpAuthResolver(const Option* op) const;
public: public:
class BasicCred { class BasicCred {
public: public:
@ -88,19 +86,27 @@ private:
std::deque<BasicCred> _basicCreds; std::deque<BasicCred> _basicCreds;
public: public:
AuthConfigFactory(const Option* option); AuthConfigFactory();
~AuthConfigFactory(); ~AuthConfigFactory();
// Creates AuthConfig object for request. Following option values
// are used in this method: PREF_HTTP_USER, PREF_HTTP_PASSWD,
// PREF_FTP_USER, PREF_FTP_PASSWD, PREF_NO_NETRC and
// PREF_HTTP_AUTH_CHALLENGE.
SharedHandle<AuthConfig> createAuthConfig SharedHandle<AuthConfig> createAuthConfig
(const SharedHandle<Request>& request); (const SharedHandle<Request>& request, const Option* op);
void setNetrc(const SharedHandle<Netrc>& netrc); void setNetrc(const SharedHandle<Netrc>& netrc);
// Find a BasicCred using findBasicCred() and activate it then // Find a BasicCred using findBasicCred() and activate it then
// return true. If matching BasicCred is not found, then return // return true. If matching BasicCred is not found, AuthConfig
// false. // object is created using createHttpAuthResolver and op. If it is
bool activateBasicCred(const std::string& host, const std::string& path); // null, then returns false. Otherwise new BasicCred is created
// using this AuthConfig object with given host and path "/" and
// returns true.
bool activateBasicCred
(const std::string& host, const std::string& path, const Option* op);
// Find a BasicCred using host and path and return the iterator // Find a BasicCred using host and path and return the iterator
// pointing to it. If not found, then return _basicCreds.end(). // pointing to it. If not found, then return _basicCreds.end().

View File

@ -79,7 +79,8 @@ FtpNegotiationCommand::FtpNegotiationCommand
const std::string& baseWorkingDir): const std::string& baseWorkingDir):
AbstractCommand(cuid, req, fileEntry, requestGroup, e, s), sequence(seq), AbstractCommand(cuid, req, fileEntry, requestGroup, e, s), sequence(seq),
ftp(new FtpConnection(cuid, socket, req, ftp(new FtpConnection(cuid, socket, req,
e->getAuthConfigFactory()->createAuthConfig(req), e->getAuthConfigFactory()->createAuthConfig
(req, requestGroup->getOption().get()),
getOption().get())) getOption().get()))
{ {
ftp->setBaseWorkingDir(baseWorkingDir); ftp->setBaseWorkingDir(baseWorkingDir);

View File

@ -128,7 +128,7 @@ std::string HttpRequest::getHostText(const std::string& host, uint16_t port) con
std::string HttpRequest::createRequest() std::string HttpRequest::createRequest()
{ {
_authConfig = _authConfigFactory->createAuthConfig(request); _authConfig = _authConfigFactory->createAuthConfig(request, _option);
std::string requestLine = request->getMethod(); std::string requestLine = request->getMethod();
requestLine += " "; requestLine += " ";
if(!_proxyRequest.isNull()) { if(!_proxyRequest.isNull()) {
@ -293,9 +293,10 @@ void HttpRequest::setCookieStorage
} }
void HttpRequest::setAuthConfigFactory void HttpRequest::setAuthConfigFactory
(const SharedHandle<AuthConfigFactory>& factory) (const SharedHandle<AuthConfigFactory>& factory, const Option* option)
{ {
_authConfigFactory = factory; _authConfigFactory = factory;
_option = option;
} }
void HttpRequest::setProxyRequest(const SharedHandle<Request>& proxyRequest) void HttpRequest::setProxyRequest(const SharedHandle<Request>& proxyRequest)

View File

@ -77,6 +77,8 @@ private:
SharedHandle<AuthConfigFactory> _authConfigFactory; SharedHandle<AuthConfigFactory> _authConfigFactory;
const Option* _option;
SharedHandle<AuthConfig> _authConfig; SharedHandle<AuthConfig> _authConfig;
SharedHandle<Request> _proxyRequest; SharedHandle<Request> _proxyRequest;
@ -206,7 +208,8 @@ public:
return _cookieStorage; return _cookieStorage;
} }
void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory); void setAuthConfigFactory
(const SharedHandle<AuthConfigFactory>& factory, const Option* option);
/* /*
* To use proxy, pass proxy string to Request::setUrl() and set it this * To use proxy, pass proxy string to Request::setUrl() and set it this

View File

@ -92,7 +92,7 @@ createHttpRequest(const SharedHandle<Request>& req,
httpRequest->setSegment(segment); httpRequest->setSegment(segment);
httpRequest->addHeader(option->get(PREF_HEADER)); httpRequest->addHeader(option->get(PREF_HEADER));
httpRequest->setCookieStorage(cookieStorage); httpRequest->setCookieStorage(cookieStorage);
httpRequest->setAuthConfigFactory(authConfigFactory); httpRequest->setAuthConfigFactory(authConfigFactory, option.get());
httpRequest->setProxyRequest(proxyRequest); httpRequest->setProxyRequest(proxyRequest);
httpRequest->addAcceptType(rg->getAcceptTypes().begin(), httpRequest->addAcceptType(rg->getAcceptTypes().begin(),
rg->getAcceptTypes().end()); rg->getAcceptTypes().end());

View File

@ -164,7 +164,7 @@ bool HttpSkipResponseCommand::processResponse()
if(getOption()->getAsBool(PREF_HTTP_AUTH_CHALLENGE) && if(getOption()->getAsBool(PREF_HTTP_AUTH_CHALLENGE) &&
!_httpResponse->getHttpRequest()->authenticationUsed() && !_httpResponse->getHttpRequest()->authenticationUsed() &&
e->getAuthConfigFactory()->activateBasicCred e->getAuthConfigFactory()->activateBasicCred
(req->getHost(), req->getDir())) { (req->getHost(), req->getDir(), getOption().get())) {
return prepareForRetry(0); return prepareForRetry(0);
} else { } else {
throw DL_ABORT_EX(EX_AUTH_FAILED); throw DL_ABORT_EX(EX_AUTH_FAILED);

View File

@ -117,8 +117,7 @@ downloadresultcode::RESULT MultiUrlRequestInfo::execute()
} }
} }
SharedHandle<AuthConfigFactory> authConfigFactory SharedHandle<AuthConfigFactory> authConfigFactory(new AuthConfigFactory());
(new AuthConfigFactory(_option.get()));
File netrccf(_option->get(PREF_NETRC_PATH)); File netrccf(_option->get(PREF_NETRC_PATH));
if(!_option->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) { if(!_option->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) {
mode_t mode = netrccf.mode(); mode_t mode = netrccf.mode();

View File

@ -38,10 +38,10 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
option.put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE); option.put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE);
AuthConfigFactory factory(&option); AuthConfigFactory factory;
// without auth info // without auth info
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
// with Netrc // with Netrc
SharedHandle<Netrc> netrc(new Netrc()); SharedHandle<Netrc> netrc(new Netrc());
@ -55,35 +55,35 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
factory.setNetrc(netrc); factory.setNetrc(netrc);
// not activated // not activated
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
CPPUNIT_ASSERT(factory.activateBasicCred("localhost", "/")); CPPUNIT_ASSERT(factory.activateBasicCred("localhost", "/", &option));
CPPUNIT_ASSERT_EQUAL(std::string("localhostuser:localhostpass"), CPPUNIT_ASSERT_EQUAL(std::string("localhostuser:localhostpass"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// See default token in netrc is ignored. // See default token in netrc is ignored.
req->setUrl("http://mirror/"); req->setUrl("http://mirror/");
CPPUNIT_ASSERT(!factory.activateBasicCred("mirror", "/")); CPPUNIT_ASSERT(!factory.activateBasicCred("mirror", "/", &option));
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
// with Netrc + user defined // with Netrc + user defined
option.put(PREF_HTTP_USER, "userDefinedUser"); option.put(PREF_HTTP_USER, "userDefinedUser");
option.put(PREF_HTTP_PASSWD, "userDefinedPassword"); option.put(PREF_HTTP_PASSWD, "userDefinedPassword");
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
CPPUNIT_ASSERT(factory.activateBasicCred("mirror", "/")); CPPUNIT_ASSERT(factory.activateBasicCred("mirror", "/", &option));
CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"), CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// username and password in URI // username and password in URI
req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2"); req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
} }
void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge() void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
@ -94,10 +94,10 @@ void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
Option option; Option option;
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
AuthConfigFactory factory(&option); AuthConfigFactory factory;
// without auth info // without auth info
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
// with Netrc // with Netrc
SharedHandle<Netrc> netrc(new Netrc()); SharedHandle<Netrc> netrc(new Netrc());
@ -112,24 +112,24 @@ void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
// not activated // not activated
CPPUNIT_ASSERT_EQUAL(std::string("localhostuser:localhostpass"), CPPUNIT_ASSERT_EQUAL(std::string("localhostuser:localhostpass"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// See default token in netrc is ignored. // See default token in netrc is ignored.
req->setUrl("http://mirror/"); req->setUrl("http://mirror/");
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
// with Netrc + user defined // with Netrc + user defined
option.put(PREF_HTTP_USER, "userDefinedUser"); option.put(PREF_HTTP_USER, "userDefinedUser");
option.put(PREF_HTTP_PASSWD, "userDefinedPassword"); option.put(PREF_HTTP_PASSWD, "userDefinedPassword");
CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"), CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// username and password in URI // username and password in URI
req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2"); req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
} }
void AuthConfigFactoryTest::testCreateAuthConfig_ftp() void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
@ -140,11 +140,11 @@ void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
Option option; Option option;
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
AuthConfigFactory factory(&option); AuthConfigFactory factory;
// without auth info // without auth info
CPPUNIT_ASSERT_EQUAL(std::string("anonymous:ARIA2USER@"), CPPUNIT_ASSERT_EQUAL(std::string("anonymous:ARIA2USER@"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// with Netrc // with Netrc
SharedHandle<Netrc> netrc(new Netrc()); SharedHandle<Netrc> netrc(new Netrc());
@ -152,24 +152,24 @@ void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
(SharedHandle<Authenticator>(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"))); (SharedHandle<Authenticator>(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount")));
factory.setNetrc(netrc); factory.setNetrc(netrc);
CPPUNIT_ASSERT_EQUAL(std::string("default:defaultpassword"), CPPUNIT_ASSERT_EQUAL(std::string("default:defaultpassword"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// disable Netrc // disable Netrc
option.put(PREF_NO_NETRC, V_TRUE); option.put(PREF_NO_NETRC, V_TRUE);
CPPUNIT_ASSERT_EQUAL(std::string("anonymous:ARIA2USER@"), CPPUNIT_ASSERT_EQUAL(std::string("anonymous:ARIA2USER@"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// with Netrc + user defined // with Netrc + user defined
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
option.put(PREF_FTP_USER, "userDefinedUser"); option.put(PREF_FTP_USER, "userDefinedUser");
option.put(PREF_FTP_PASSWD, "userDefinedPassword"); option.put(PREF_FTP_PASSWD, "userDefinedPassword");
CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"), CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// username and password in URI // username and password in URI
req->setUrl("ftp://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2"); req->setUrl("ftp://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
} }
void AuthConfigFactoryTest::testUpdateBasicCred() void AuthConfigFactoryTest::testUpdateBasicCred()
@ -178,7 +178,7 @@ void AuthConfigFactoryTest::testUpdateBasicCred()
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
option.put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE); option.put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE);
AuthConfigFactory factory(&option); AuthConfigFactory factory;
factory.updateBasicCred factory.updateBasicCred
(AuthConfigFactory::BasicCred("myname", "mypass", "localhost", "/", true)); (AuthConfigFactory::BasicCred("myname", "mypass", "localhost", "/", true));
@ -193,25 +193,25 @@ void AuthConfigFactoryTest::testUpdateBasicCred()
req->setUrl("http://localhost/download/v2.6/Changelog"); req->setUrl("http://localhost/download/v2.6/Changelog");
CPPUNIT_ASSERT_EQUAL(std::string("price:j38jdc"), CPPUNIT_ASSERT_EQUAL(std::string("price:j38jdc"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://localhost/documents/reference.html"); req->setUrl("http://localhost/documents/reference.html");
CPPUNIT_ASSERT_EQUAL(std::string("alice:ium8"), CPPUNIT_ASSERT_EQUAL(std::string("alice:ium8"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://localhost/documents2/manual.html"); req->setUrl("http://localhost/documents2/manual.html");
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"), CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://localhost/doc/readme.txt"); req->setUrl("http://localhost/doc/readme.txt");
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"), CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"),
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://local/"); req->setUrl("http://local/");
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
req->setUrl("http://mirror/"); req->setUrl("http://mirror/");
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
} }
} // namespace aria2 } // namespace aria2

View File

@ -43,7 +43,7 @@ public:
void setUp() void setUp()
{ {
_option.reset(new Option()); _option.reset(new Option());
_authConfigFactory.reset(new AuthConfigFactory(_option.get())); _authConfigFactory.reset(new AuthConfigFactory());
//_ftpServerSocket.reset(new SocketCore()); //_ftpServerSocket.reset(new SocketCore());
SharedHandle<SocketCore> listenSocket(new SocketCore()); SharedHandle<SocketCore> listenSocket(new SocketCore());
@ -64,7 +64,8 @@ public:
_serverSocket.reset(listenSocket->acceptConnection()); _serverSocket.reset(listenSocket->acceptConnection());
_ftp.reset(new FtpConnection(1, _clientSocket, req, _ftp.reset(new FtpConnection(1, _clientSocket, req,
_authConfigFactory->createAuthConfig(req), _authConfigFactory->createAuthConfig
(req, _option.get()),
_option.get())); _option.get()));
} }

View File

@ -43,7 +43,7 @@ public:
{ {
_option.reset(new Option()); _option.reset(new Option());
_option->put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE); _option->put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE);
_authConfigFactory.reset(new AuthConfigFactory(_option.get())); _authConfigFactory.reset(new AuthConfigFactory());
} }
void testGetStartByte(); void testGetStartByte();
@ -135,7 +135,7 @@ void HttpRequestTest::testCreateRequest()
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setSegment(segment); httpRequest.setSegment(segment);
httpRequest.setFileEntry(fileEntry); httpRequest.setFileEntry(fileEntry);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
// remove "Connection: close" and add end byte range // remove "Connection: close" and add end byte range
request->setPipeliningHint(true); request->setPipeliningHint(true);
@ -236,7 +236,8 @@ void HttpRequestTest::testCreateRequest()
_option->put(PREF_HTTP_USER, "aria2user"); _option->put(PREF_HTTP_USER, "aria2user");
_option->put(PREF_HTTP_PASSWD, "aria2passwd"); _option->put(PREF_HTTP_PASSWD, "aria2passwd");
CPPUNIT_ASSERT(_authConfigFactory->activateBasicCred("localhost", "/")); CPPUNIT_ASSERT(_authConfigFactory->activateBasicCred
("localhost", "/", _option.get()));
expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
@ -327,7 +328,7 @@ void HttpRequestTest::testCreateRequest_ftp()
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setSegment(segment); httpRequest.setSegment(segment);
httpRequest.setFileEntry(fileEntry); httpRequest.setFileEntry(fileEntry);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
httpRequest.setProxyRequest(proxyRequest); httpRequest.setProxyRequest(proxyRequest);
std::string expectedText = std::string expectedText =
@ -393,7 +394,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
httpRequest.setSegment(segment); httpRequest.setSegment(segment);
httpRequest.setFileEntry(fileEntry); httpRequest.setFileEntry(fileEntry);
httpRequest.setCookieStorage(st); httpRequest.setCookieStorage(st);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
@ -459,7 +460,7 @@ void HttpRequestTest::testCreateRequest_query()
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.disableContentEncoding(); httpRequest.disableContentEncoding();
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
std::string expectedText = std::string expectedText =
"GET /wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138 HTTP/1.1\r\n" "GET /wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138 HTTP/1.1\r\n"
@ -482,7 +483,7 @@ void HttpRequestTest::testCreateRequest_head()
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
std::stringstream result(httpRequest.createRequest()); std::stringstream result(httpRequest.createRequest());
std::string line; std::string line;
@ -623,7 +624,7 @@ void HttpRequestTest::testUserAgent()
httpRequest.setRequest(request); httpRequest.setRequest(request);
//httpRequest.setSegment(segment); //httpRequest.setSegment(segment);
httpRequest.setUserAgent("aria2 (Linux)"); httpRequest.setUserAgent("aria2 (Linux)");
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2 (Linux)\r\n" "User-Agent: aria2 (Linux)\r\n"
@ -658,7 +659,7 @@ void HttpRequestTest::testAddHeader()
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.disableContentEncoding(); httpRequest.disableContentEncoding();
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
httpRequest.addHeader("X-ARIA2: v0.13\nX-ARIA2-DISTRIBUTE: enabled\n"); httpRequest.addHeader("X-ARIA2: v0.13\nX-ARIA2-DISTRIBUTE: enabled\n");
std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
@ -686,7 +687,7 @@ void HttpRequestTest::testAddAcceptType()
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.disableContentEncoding(); httpRequest.disableContentEncoding();
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
httpRequest.addAcceptType(&acceptTypes[0], httpRequest.addAcceptType(&acceptTypes[0],
&acceptTypes[arrayLength(acceptTypes)]); &acceptTypes[arrayLength(acceptTypes)]);
@ -710,7 +711,7 @@ void HttpRequestTest::testEnableAcceptEncoding()
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
std::string acceptEncodings; std::string acceptEncodings;
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ