aria2/test/NetrcAuthResolverTest.cc
Tatsuhiro Tsujikawa 6e6ba30c60 2007-03-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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.
2007-03-27 16:16:44 +00:00

64 lines
2.1 KiB
C++

#include "NetrcAuthResolver.h"
#include "prefs.h"
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class NetrcAuthResolverTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(NetrcAuthResolverTest);
CPPUNIT_TEST(testResolveAuthConfig_without_userDefined);
CPPUNIT_TEST(testResolveAuthConfig_with_userDefined);
CPPUNIT_TEST_SUITE_END();
private:
NetrcHandle _netrc;
//SharedHandle<Option> _option;
NetrcAuthResolverHandle _resolver;
public:
void setUp()
{
_netrc = new Netrc();
_netrc->addAuthenticator(new Authenticator("localhost", "name", "passwd", "account"));
_netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpasswd", "defaultaccount"));
//_option = new Option();
_resolver = new NetrcAuthResolver();
_resolver->setNetrc(_netrc);
_resolver->setDefaultAuthConfig(new AuthConfig("foo", "bar"));
}
void testResolveAuthConfig_without_userDefined();
void testResolveAuthConfig_with_userDefined();
};
CPPUNIT_TEST_SUITE_REGISTRATION( NetrcAuthResolverTest );
void NetrcAuthResolverTest::testResolveAuthConfig_without_userDefined()
{
AuthConfigHandle authConfig = _resolver->resolveAuthConfig("localhost");
CPPUNIT_ASSERT_EQUAL(string("name:passwd"), authConfig->getAuthText());
authConfig = _resolver->resolveAuthConfig("mymachine");
CPPUNIT_ASSERT_EQUAL(string("default:defaultpasswd"), authConfig->getAuthText());
_resolver->setNetrc(0);
authConfig = _resolver->resolveAuthConfig("localhost");
CPPUNIT_ASSERT_EQUAL(string("foo:bar"), authConfig->getAuthText());
}
void NetrcAuthResolverTest::testResolveAuthConfig_with_userDefined()
{
_resolver->setUserDefinedAuthConfig(new AuthConfig("myname", "mypasswd"));
AuthConfigHandle authConfig = _resolver->resolveAuthConfig("localhost");
CPPUNIT_ASSERT_EQUAL(string("myname:mypasswd"), authConfig->getAuthText());
authConfig = _resolver->resolveAuthConfig("mymachine");
CPPUNIT_ASSERT_EQUAL(string("myname:mypasswd"), authConfig->getAuthText());
_resolver->setNetrc(0);
authConfig = _resolver->resolveAuthConfig("mymachine");
CPPUNIT_ASSERT_EQUAL(string("myname:mypasswd"), authConfig->getAuthText());
}