mirror of
https://github.com/aria2/aria2.git
synced 2025-01-09 03:21:33 +00:00
6e6ba30c60
To add the command-line option which disables netrc support: * src/OptionHandlerFactory.cc (createOptionHandlers): Added PREF_NO_NETRC. * src/main.cc: Added -n option. * src/prefs.h (PREF_NO_NETRC): New definition. * src/RequestFactory.cc: Do not use netrc in ftp if PREF_NO_NETRC is V_TRUE. Note that netrc is not used in http, http proxy even if PREF_NO_NETRC is V_FALSE. This may get configurable in the future release. To clear peer's error status by time basis: * src/PeerAbstractCommand.cc (onAbort): Call Peer::startBadCondition(). * src/Peer.h, src/Peer.cc (error): Removed. (_badConditionStartTime): New variable. (_badConditionInterval): New variable. Initialized to 10 seconds. (startBadCondition): New function. (isGood): New function. * src/DefaultPeerStorage.cc (addPeer): Use Peer::isGood(). (FindFinePeer): Use Peer::isGood(). Always include port number in http request header: * src/HttpRequest.cc (getHostText): Always include port number in http request header.
129 lines
4.7 KiB
C++
129 lines
4.7 KiB
C++
#include "RequestFactory.h"
|
|
#include "prefs.h"
|
|
#include "NetrcAuthResolver.h"
|
|
#include "DefaultAuthResolver.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
using namespace std;
|
|
|
|
class RequestFactoryTest : public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(RequestFactoryTest);
|
|
CPPUNIT_TEST(testCreateHttpAuthResolver_netrc);
|
|
CPPUNIT_TEST(testCreateHttpAuthResolver_def);
|
|
CPPUNIT_TEST(testCreateFtpAuthResolver_netrc);
|
|
CPPUNIT_TEST(testCreateFtpAuthResolver_def);
|
|
CPPUNIT_TEST(testCreateHttpProxyAuthResolver_netrc);
|
|
CPPUNIT_TEST(testCreateHttpProxyAuthResolver_def);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
NetrcHandle _netrc;
|
|
SharedHandle<Option> _option;
|
|
RequestFactoryHandle _factory;
|
|
public:
|
|
void setUp()
|
|
{
|
|
_netrc = new Netrc();
|
|
_option = new Option();
|
|
_factory = new RequestFactory();
|
|
_factory->setNetrc(_netrc);
|
|
_factory->setOption(_option.get());
|
|
}
|
|
|
|
void testCreateHttpAuthResolver_netrc();
|
|
void testCreateHttpAuthResolver_def();
|
|
void testCreateFtpAuthResolver_netrc();
|
|
void testCreateFtpAuthResolver_def();
|
|
void testCreateHttpProxyAuthResolver_netrc();
|
|
void testCreateHttpProxyAuthResolver_def();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RequestFactoryTest );
|
|
|
|
void RequestFactoryTest::testCreateHttpAuthResolver_netrc()
|
|
{
|
|
_option->put(PREF_NO_NETRC, V_FALSE);
|
|
_option->put(PREF_HTTP_USER, "foo");
|
|
_option->put(PREF_HTTP_PASSWD, "bar");
|
|
DefaultAuthResolverHandle defResolver = _factory->createHttpAuthResolver();
|
|
CPPUNIT_ASSERT(!defResolver.isNull());
|
|
CPPUNIT_ASSERT(!defResolver->getUserDefinedAuthConfig().isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("foo:bar"),
|
|
defResolver->getUserDefinedAuthConfig()->getAuthText());
|
|
/*
|
|
NetrcAuthResolverHandle netrcResolver = _factory->createHttpAuthResolver();
|
|
CPPUNIT_ASSERT(!netrcResolver.isNull());
|
|
CPPUNIT_ASSERT(!netrcResolver->getNetrc().isNull());
|
|
CPPUNIT_ASSERT(netrcResolver->getUserDefinedAuthConfig().isNull());
|
|
*/
|
|
}
|
|
|
|
void RequestFactoryTest::testCreateHttpAuthResolver_def()
|
|
{
|
|
_option->put(PREF_NO_NETRC, V_TRUE);
|
|
_option->put(PREF_HTTP_USER, "foo");
|
|
_option->put(PREF_HTTP_PASSWD, "bar");
|
|
DefaultAuthResolverHandle defResolver = _factory->createHttpAuthResolver();
|
|
CPPUNIT_ASSERT(!defResolver.isNull());
|
|
CPPUNIT_ASSERT(!defResolver->getUserDefinedAuthConfig().isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("foo:bar"),
|
|
defResolver->getUserDefinedAuthConfig()->getAuthText());
|
|
}
|
|
|
|
void RequestFactoryTest::testCreateFtpAuthResolver_netrc()
|
|
{
|
|
_option->put(PREF_NO_NETRC, V_FALSE);
|
|
NetrcAuthResolverHandle netrcResolver = _factory->createFtpAuthResolver();
|
|
CPPUNIT_ASSERT(!netrcResolver.isNull());
|
|
CPPUNIT_ASSERT(!netrcResolver->getNetrc().isNull());
|
|
CPPUNIT_ASSERT(netrcResolver->getUserDefinedAuthConfig().isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("anonymous:ARIA2USER@"),
|
|
netrcResolver->getDefaultAuthConfig()->getAuthText());
|
|
}
|
|
|
|
void RequestFactoryTest::testCreateFtpAuthResolver_def()
|
|
{
|
|
_option->put(PREF_NO_NETRC, V_TRUE);
|
|
_option->put(PREF_FTP_USER, "foo");
|
|
_option->put(PREF_FTP_PASSWD, "bar");
|
|
DefaultAuthResolverHandle defResolver = _factory->createFtpAuthResolver();
|
|
CPPUNIT_ASSERT(!defResolver.isNull());
|
|
CPPUNIT_ASSERT(!defResolver->getUserDefinedAuthConfig().isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("foo:bar"),
|
|
defResolver->getUserDefinedAuthConfig()->getAuthText());
|
|
CPPUNIT_ASSERT_EQUAL(string("anonymous:ARIA2USER@"),
|
|
defResolver->getDefaultAuthConfig()->getAuthText());
|
|
}
|
|
|
|
void RequestFactoryTest::testCreateHttpProxyAuthResolver_netrc()
|
|
{
|
|
_option->put(PREF_NO_NETRC, V_FALSE);
|
|
_option->put(PREF_HTTP_PROXY_USER, "foo");
|
|
_option->put(PREF_HTTP_PROXY_PASSWD, "bar");
|
|
DefaultAuthResolverHandle defResolver = _factory->createHttpProxyAuthResolver();
|
|
CPPUNIT_ASSERT(!defResolver.isNull());
|
|
CPPUNIT_ASSERT(!defResolver->getUserDefinedAuthConfig().isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("foo:bar"),
|
|
defResolver->getUserDefinedAuthConfig()->getAuthText());
|
|
/*
|
|
NetrcAuthResolverHandle netrcResolver = _factory->createHttpProxyAuthResolver();
|
|
CPPUNIT_ASSERT(!netrcResolver.isNull());
|
|
CPPUNIT_ASSERT(!netrcResolver->getNetrc().isNull());
|
|
CPPUNIT_ASSERT(netrcResolver->getUserDefinedAuthConfig().isNull());
|
|
*/
|
|
}
|
|
|
|
void RequestFactoryTest::testCreateHttpProxyAuthResolver_def()
|
|
{
|
|
_option->put(PREF_NO_NETRC, V_TRUE);
|
|
_option->put(PREF_HTTP_PROXY_USER, "foo");
|
|
_option->put(PREF_HTTP_PROXY_PASSWD, "bar");
|
|
DefaultAuthResolverHandle defResolver = _factory->createHttpProxyAuthResolver();
|
|
CPPUNIT_ASSERT(!defResolver.isNull());
|
|
CPPUNIT_ASSERT(!defResolver->getUserDefinedAuthConfig().isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("foo:bar"),
|
|
defResolver->getUserDefinedAuthConfig()->getAuthText());
|
|
}
|
|
|