mirror of https://github.com/aria2/aria2
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.ccpull/1/head
parent
894641dfdb
commit
682bafae0a
16
ChangeLog
16
ChangeLog
|
@ -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>
|
||||
|
||||
Don't call prepareForRetry(1) if all segments are ignored in
|
||||
|
|
|
@ -51,18 +51,18 @@ const std::string AuthConfigFactory::ANONYMOUS("anonymous");
|
|||
|
||||
const std::string AuthConfigFactory::ARIA2USER_AT("ARIA2USER@");
|
||||
|
||||
AuthConfigFactory::AuthConfigFactory(const Option* option):
|
||||
_option(option) {}
|
||||
AuthConfigFactory::AuthConfigFactory() {}
|
||||
|
||||
AuthConfigFactory::~AuthConfigFactory() {}
|
||||
|
||||
AuthConfigHandle
|
||||
AuthConfigFactory::createAuthConfig(const RequestHandle& request)
|
||||
AuthConfigFactory::createAuthConfig
|
||||
(const SharedHandle<Request>& request, const Option* op)
|
||||
{
|
||||
if(request->getProtocol() == Request::PROTO_HTTP ||
|
||||
request->getProtocol() == Request::PROTO_HTTPS) {
|
||||
|
||||
if(_option->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) {
|
||||
if(op->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) {
|
||||
if(!request->getUsername().empty()) {
|
||||
// TODO setting "/" as path. Should we use request->getDir() instead?
|
||||
updateBasicCred(BasicCred(request->getUsername(), request->getPassword(),
|
||||
|
@ -80,14 +80,16 @@ AuthConfigFactory::createAuthConfig(const RequestHandle& request)
|
|||
if(!request->getUsername().empty()) {
|
||||
return createAuthConfig(request->getUsername(), request->getPassword());
|
||||
} else {
|
||||
return createHttpAuthResolver()->resolveAuthConfig(request->getHost());
|
||||
return
|
||||
createHttpAuthResolver(op)->resolveAuthConfig(request->getHost());
|
||||
}
|
||||
}
|
||||
} else if(request->getProtocol() == Request::PROTO_FTP) {
|
||||
if(!request->getUsername().empty()) {
|
||||
return createAuthConfig(request->getUsername(), request->getPassword());
|
||||
} else {
|
||||
return createFtpAuthResolver()->resolveAuthConfig(request->getHost());
|
||||
return
|
||||
createFtpAuthResolver(op)->resolveAuthConfig(request->getHost());
|
||||
}
|
||||
} else {
|
||||
return SharedHandle<AuthConfig>();
|
||||
|
@ -104,10 +106,11 @@ AuthConfigFactory::createAuthConfig(const std::string& user, const std::string&
|
|||
return ac;
|
||||
}
|
||||
|
||||
AuthResolverHandle AuthConfigFactory::createHttpAuthResolver() const
|
||||
AuthResolverHandle AuthConfigFactory::createHttpAuthResolver
|
||||
(const Option* op) const
|
||||
{
|
||||
AbstractAuthResolverHandle resolver;
|
||||
if(_option->getAsBool(PREF_NO_NETRC)) {
|
||||
if(op->getAsBool(PREF_NO_NETRC)) {
|
||||
resolver.reset(new DefaultAuthResolver());
|
||||
} else {
|
||||
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
|
||||
|
@ -115,21 +118,24 @@ AuthResolverHandle AuthConfigFactory::createHttpAuthResolver() const
|
|||
authResolver->ignoreDefault();
|
||||
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;
|
||||
}
|
||||
|
||||
AuthResolverHandle AuthConfigFactory::createFtpAuthResolver() const
|
||||
AuthResolverHandle AuthConfigFactory::createFtpAuthResolver
|
||||
(const Option* op) const
|
||||
{
|
||||
AbstractAuthResolverHandle resolver;
|
||||
if(_option->getAsBool(PREF_NO_NETRC)) {
|
||||
if(op->getAsBool(PREF_NO_NETRC)) {
|
||||
resolver.reset(new DefaultAuthResolver());
|
||||
} else {
|
||||
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
|
||||
authResolver->setNetrc(_netrc);
|
||||
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
|
||||
(new AuthConfig(AuthConfigFactory::ANONYMOUS,
|
||||
AuthConfigFactory::ARIA2USER_AT));
|
||||
|
@ -155,14 +161,14 @@ void AuthConfigFactory::updateBasicCred(const BasicCred& basicCred)
|
|||
}
|
||||
|
||||
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 =
|
||||
findBasicCred(host, path);
|
||||
if(i == _basicCreds.end()) {
|
||||
SharedHandle<AuthConfig> authConfig =
|
||||
createHttpAuthResolver()->resolveAuthConfig(host);
|
||||
createHttpAuthResolver(op)->resolveAuthConfig(host);
|
||||
if(authConfig.isNull()) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
@ -53,16 +53,14 @@ class AuthResolver;
|
|||
|
||||
class AuthConfigFactory {
|
||||
private:
|
||||
const Option* _option;
|
||||
|
||||
SharedHandle<Netrc> _netrc;
|
||||
|
||||
SharedHandle<AuthConfig> createAuthConfig(const std::string& user,
|
||||
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:
|
||||
class BasicCred {
|
||||
public:
|
||||
|
@ -88,19 +86,27 @@ private:
|
|||
std::deque<BasicCred> _basicCreds;
|
||||
public:
|
||||
|
||||
AuthConfigFactory(const Option* option);
|
||||
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
|
||||
(const SharedHandle<Request>& request);
|
||||
(const SharedHandle<Request>& request, const Option* op);
|
||||
|
||||
void setNetrc(const SharedHandle<Netrc>& netrc);
|
||||
|
||||
// Find a BasicCred using findBasicCred() and activate it then
|
||||
// return true. If matching BasicCred is not found, then return
|
||||
// false.
|
||||
bool activateBasicCred(const std::string& host, const std::string& path);
|
||||
// return true. If matching BasicCred is not found, AuthConfig
|
||||
// object is created using createHttpAuthResolver and op. If it is
|
||||
// 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
|
||||
// pointing to it. If not found, then return _basicCreds.end().
|
||||
|
|
|
@ -79,7 +79,8 @@ FtpNegotiationCommand::FtpNegotiationCommand
|
|||
const std::string& baseWorkingDir):
|
||||
AbstractCommand(cuid, req, fileEntry, requestGroup, e, s), sequence(seq),
|
||||
ftp(new FtpConnection(cuid, socket, req,
|
||||
e->getAuthConfigFactory()->createAuthConfig(req),
|
||||
e->getAuthConfigFactory()->createAuthConfig
|
||||
(req, requestGroup->getOption().get()),
|
||||
getOption().get()))
|
||||
{
|
||||
ftp->setBaseWorkingDir(baseWorkingDir);
|
||||
|
|
|
@ -128,7 +128,7 @@ std::string HttpRequest::getHostText(const std::string& host, uint16_t port) con
|
|||
|
||||
std::string HttpRequest::createRequest()
|
||||
{
|
||||
_authConfig = _authConfigFactory->createAuthConfig(request);
|
||||
_authConfig = _authConfigFactory->createAuthConfig(request, _option);
|
||||
std::string requestLine = request->getMethod();
|
||||
requestLine += " ";
|
||||
if(!_proxyRequest.isNull()) {
|
||||
|
@ -293,9 +293,10 @@ void HttpRequest::setCookieStorage
|
|||
}
|
||||
|
||||
void HttpRequest::setAuthConfigFactory
|
||||
(const SharedHandle<AuthConfigFactory>& factory)
|
||||
(const SharedHandle<AuthConfigFactory>& factory, const Option* option)
|
||||
{
|
||||
_authConfigFactory = factory;
|
||||
_option = option;
|
||||
}
|
||||
|
||||
void HttpRequest::setProxyRequest(const SharedHandle<Request>& proxyRequest)
|
||||
|
|
|
@ -77,6 +77,8 @@ private:
|
|||
|
||||
SharedHandle<AuthConfigFactory> _authConfigFactory;
|
||||
|
||||
const Option* _option;
|
||||
|
||||
SharedHandle<AuthConfig> _authConfig;
|
||||
|
||||
SharedHandle<Request> _proxyRequest;
|
||||
|
@ -206,7 +208,8 @@ public:
|
|||
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
|
||||
|
|
|
@ -92,7 +92,7 @@ createHttpRequest(const SharedHandle<Request>& req,
|
|||
httpRequest->setSegment(segment);
|
||||
httpRequest->addHeader(option->get(PREF_HEADER));
|
||||
httpRequest->setCookieStorage(cookieStorage);
|
||||
httpRequest->setAuthConfigFactory(authConfigFactory);
|
||||
httpRequest->setAuthConfigFactory(authConfigFactory, option.get());
|
||||
httpRequest->setProxyRequest(proxyRequest);
|
||||
httpRequest->addAcceptType(rg->getAcceptTypes().begin(),
|
||||
rg->getAcceptTypes().end());
|
||||
|
|
|
@ -164,7 +164,7 @@ bool HttpSkipResponseCommand::processResponse()
|
|||
if(getOption()->getAsBool(PREF_HTTP_AUTH_CHALLENGE) &&
|
||||
!_httpResponse->getHttpRequest()->authenticationUsed() &&
|
||||
e->getAuthConfigFactory()->activateBasicCred
|
||||
(req->getHost(), req->getDir())) {
|
||||
(req->getHost(), req->getDir(), getOption().get())) {
|
||||
return prepareForRetry(0);
|
||||
} else {
|
||||
throw DL_ABORT_EX(EX_AUTH_FAILED);
|
||||
|
|
|
@ -117,8 +117,7 @@ downloadresultcode::RESULT MultiUrlRequestInfo::execute()
|
|||
}
|
||||
}
|
||||
|
||||
SharedHandle<AuthConfigFactory> authConfigFactory
|
||||
(new AuthConfigFactory(_option.get()));
|
||||
SharedHandle<AuthConfigFactory> authConfigFactory(new AuthConfigFactory());
|
||||
File netrccf(_option->get(PREF_NETRC_PATH));
|
||||
if(!_option->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) {
|
||||
mode_t mode = netrccf.mode();
|
||||
|
|
|
@ -38,10 +38,10 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
|
|||
option.put(PREF_NO_NETRC, V_FALSE);
|
||||
option.put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE);
|
||||
|
||||
AuthConfigFactory factory(&option);
|
||||
AuthConfigFactory factory;
|
||||
|
||||
// without auth info
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull());
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
|
||||
|
||||
// with Netrc
|
||||
SharedHandle<Netrc> netrc(new Netrc());
|
||||
|
@ -55,35 +55,35 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
|
|||
factory.setNetrc(netrc);
|
||||
|
||||
// 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"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// See default token in netrc is ignored.
|
||||
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
|
||||
option.put(PREF_HTTP_USER, "userDefinedUser");
|
||||
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"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// username and password in URI
|
||||
req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
}
|
||||
|
||||
void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
|
||||
|
@ -94,10 +94,10 @@ void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
|
|||
Option option;
|
||||
option.put(PREF_NO_NETRC, V_FALSE);
|
||||
|
||||
AuthConfigFactory factory(&option);
|
||||
AuthConfigFactory factory;
|
||||
|
||||
// without auth info
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull());
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
|
||||
|
||||
// with Netrc
|
||||
SharedHandle<Netrc> netrc(new Netrc());
|
||||
|
@ -112,24 +112,24 @@ void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
|
|||
|
||||
// not activated
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhostuser:localhostpass"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// See default token in netrc is ignored.
|
||||
req->setUrl("http://mirror/");
|
||||
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull());
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
|
||||
|
||||
// with Netrc + user defined
|
||||
option.put(PREF_HTTP_USER, "userDefinedUser");
|
||||
option.put(PREF_HTTP_PASSWD, "userDefinedPassword");
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// username and password in URI
|
||||
req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
}
|
||||
|
||||
void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
|
||||
|
@ -140,11 +140,11 @@ void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
|
|||
Option option;
|
||||
option.put(PREF_NO_NETRC, V_FALSE);
|
||||
|
||||
AuthConfigFactory factory(&option);
|
||||
AuthConfigFactory factory;
|
||||
|
||||
// without auth info
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("anonymous:ARIA2USER@"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// with Netrc
|
||||
SharedHandle<Netrc> netrc(new Netrc());
|
||||
|
@ -152,24 +152,24 @@ void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
|
|||
(SharedHandle<Authenticator>(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount")));
|
||||
factory.setNetrc(netrc);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("default:defaultpassword"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// disable Netrc
|
||||
option.put(PREF_NO_NETRC, V_TRUE);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("anonymous:ARIA2USER@"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// with Netrc + user defined
|
||||
option.put(PREF_NO_NETRC, V_FALSE);
|
||||
option.put(PREF_FTP_USER, "userDefinedUser");
|
||||
option.put(PREF_FTP_PASSWD, "userDefinedPassword");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
// username and password in URI
|
||||
req->setUrl("ftp://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
}
|
||||
|
||||
void AuthConfigFactoryTest::testUpdateBasicCred()
|
||||
|
@ -178,7 +178,7 @@ void AuthConfigFactoryTest::testUpdateBasicCred()
|
|||
option.put(PREF_NO_NETRC, V_FALSE);
|
||||
option.put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE);
|
||||
|
||||
AuthConfigFactory factory(&option);
|
||||
AuthConfigFactory factory;
|
||||
|
||||
factory.updateBasicCred
|
||||
(AuthConfigFactory::BasicCred("myname", "mypass", "localhost", "/", true));
|
||||
|
@ -193,25 +193,25 @@ void AuthConfigFactoryTest::testUpdateBasicCred()
|
|||
req->setUrl("http://localhost/download/v2.6/Changelog");
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("price:j38jdc"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
req->setUrl("http://localhost/documents/reference.html");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("alice:ium8"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
req->setUrl("http://localhost/documents2/manual.html");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
req->setUrl("http://localhost/doc/readme.txt");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"),
|
||||
factory.createAuthConfig(req)->getAuthText());
|
||||
factory.createAuthConfig(req, &option)->getAuthText());
|
||||
|
||||
req->setUrl("http://local/");
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull());
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
|
||||
|
||||
req->setUrl("http://mirror/");
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req).isNull());
|
||||
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
void setUp()
|
||||
{
|
||||
_option.reset(new Option());
|
||||
_authConfigFactory.reset(new AuthConfigFactory(_option.get()));
|
||||
_authConfigFactory.reset(new AuthConfigFactory());
|
||||
|
||||
//_ftpServerSocket.reset(new SocketCore());
|
||||
SharedHandle<SocketCore> listenSocket(new SocketCore());
|
||||
|
@ -64,7 +64,8 @@ public:
|
|||
|
||||
_serverSocket.reset(listenSocket->acceptConnection());
|
||||
_ftp.reset(new FtpConnection(1, _clientSocket, req,
|
||||
_authConfigFactory->createAuthConfig(req),
|
||||
_authConfigFactory->createAuthConfig
|
||||
(req, _option.get()),
|
||||
_option.get()));
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
{
|
||||
_option.reset(new Option());
|
||||
_option->put(PREF_HTTP_AUTH_CHALLENGE, V_TRUE);
|
||||
_authConfigFactory.reset(new AuthConfigFactory(_option.get()));
|
||||
_authConfigFactory.reset(new AuthConfigFactory());
|
||||
}
|
||||
|
||||
void testGetStartByte();
|
||||
|
@ -135,7 +135,7 @@ void HttpRequestTest::testCreateRequest()
|
|||
httpRequest.setRequest(request);
|
||||
httpRequest.setSegment(segment);
|
||||
httpRequest.setFileEntry(fileEntry);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
|
||||
|
||||
// remove "Connection: close" and add end byte range
|
||||
request->setPipeliningHint(true);
|
||||
|
@ -236,7 +236,8 @@ void HttpRequestTest::testCreateRequest()
|
|||
_option->put(PREF_HTTP_USER, "aria2user");
|
||||
_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"
|
||||
"User-Agent: aria2\r\n"
|
||||
|
@ -327,7 +328,7 @@ void HttpRequestTest::testCreateRequest_ftp()
|
|||
httpRequest.setRequest(request);
|
||||
httpRequest.setSegment(segment);
|
||||
httpRequest.setFileEntry(fileEntry);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
|
||||
httpRequest.setProxyRequest(proxyRequest);
|
||||
|
||||
std::string expectedText =
|
||||
|
@ -393,7 +394,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
|
|||
httpRequest.setSegment(segment);
|
||||
httpRequest.setFileEntry(fileEntry);
|
||||
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"
|
||||
"User-Agent: aria2\r\n"
|
||||
|
@ -459,7 +460,7 @@ void HttpRequestTest::testCreateRequest_query()
|
|||
HttpRequest httpRequest;
|
||||
httpRequest.disableContentEncoding();
|
||||
httpRequest.setRequest(request);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
|
||||
|
||||
std::string expectedText =
|
||||
"GET /wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138 HTTP/1.1\r\n"
|
||||
|
@ -482,7 +483,7 @@ void HttpRequestTest::testCreateRequest_head()
|
|||
|
||||
HttpRequest httpRequest;
|
||||
httpRequest.setRequest(request);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
|
||||
|
||||
std::stringstream result(httpRequest.createRequest());
|
||||
std::string line;
|
||||
|
@ -623,7 +624,7 @@ void HttpRequestTest::testUserAgent()
|
|||
httpRequest.setRequest(request);
|
||||
//httpRequest.setSegment(segment);
|
||||
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"
|
||||
"User-Agent: aria2 (Linux)\r\n"
|
||||
|
@ -658,7 +659,7 @@ void HttpRequestTest::testAddHeader()
|
|||
HttpRequest httpRequest;
|
||||
httpRequest.disableContentEncoding();
|
||||
httpRequest.setRequest(request);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
|
||||
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"
|
||||
|
@ -686,7 +687,7 @@ void HttpRequestTest::testAddAcceptType()
|
|||
HttpRequest httpRequest;
|
||||
httpRequest.disableContentEncoding();
|
||||
httpRequest.setRequest(request);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
|
||||
httpRequest.addAcceptType(&acceptTypes[0],
|
||||
&acceptTypes[arrayLength(acceptTypes)]);
|
||||
|
||||
|
@ -710,7 +711,7 @@ void HttpRequestTest::testEnableAcceptEncoding()
|
|||
|
||||
HttpRequest httpRequest;
|
||||
httpRequest.setRequest(request);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory);
|
||||
httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get());
|
||||
|
||||
std::string acceptEncodings;
|
||||
#ifdef HAVE_LIBZ
|
||||
|
|
Loading…
Reference in New Issue