2007-03-19 Tatsuhiro Tsujikawa <tujikawa at valkyrie dot rednoah com>

To integrate Netrc into exsiting classes:
	* src/Request.h
	(_userDefinedAuthConfig): New variable.
	(findNetrcAuthenticator): New function.
	(segment): Removed.
	(setUserDefinedAuthConfig): New function.
	(resolveHttpAuthConfigItem): New function.
	(resolveFtpAuthConfigItem): New function.
	(resolveHttpProxyAuthConfigItem): New function.
	* src/HttpRequest.h
	(authConfig): Removed.
	(proxyAuthConfig): Removed.
	(setAuthConfig): Removed.
	(setProxyAuthConfig): Removed.
	* src/UrlRequest.h
	(getHeadResult): Added a parameter: authConfigHandle
	* src/common.h
	(SingletonHolder.h): New include.
	* src/main.cc
	(Netrc.h): New include.
	(main): Removed initial values of PREF_FTP_USER, 
PREF_FTP_PASSWD.
	Added initial value of PREF_NETRC_PATH.
	Added the initialization of netrc.
	* src/AuthConfig.h: New class.
	* src/prefs.h
	(PREF_NETRC_PATH): New definition.
	* src/HttpAuthConfig.h: Removed.
	* src/Netrc.cc
	(getRequiredNextToken): New function.
	(skipMacdef): New function.
	(parse): Rewritten.
	* src/Netrc.h
	(getRequiredNextToken): New function.
	(skipMacdef): New function.
	* src/Util.h, src/Util.cc
	(getHomeDir): New function.
	* src/TrackerWatcherComand.cc
	(createRequestCommand): Use AuthConfig.
	* src/FtpConnection.cc
	(sendUser): Use Request::resolveFtpAuthConfigItem().
	(sendPass): Use Request::resolveFtpAuthConfigItem().
	* src/Request.cc
	(findNetrcAuthenticator): New function.
	(resolveHttpAuthConfigItem): New function.
	(resolveFtpAuthConfigItem): New function.
	(resolveHttpProxyAuthConfigItem): New function.
	* src/UrlRequestInfo.cc: Use AuthConfig.
	* src/HttpRequest.cc
	(createRequest): Use authConfig.
	(getProxyAuthString): Use authConfig.
	(configure): Removed PREF_HTTP_USER, PREF_HTTP_PASSWD,
	PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_PASSWD.
This commit is contained in:
Tatsuhiro Tsujikawa 2007-03-18 15:42:34 +00:00
parent 58d4dde223
commit 7ff627079f
29 changed files with 685 additions and 100 deletions

View file

@ -1,5 +1,5 @@
#include "Request.h"
#include "Netrc.h"
#include <cppunit/extensions/HelperMacros.h>
class RequestTest:public CppUnit::TestFixture {
@ -25,6 +25,12 @@ class RequestTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testSafeChar);
CPPUNIT_TEST(testInnerLink);
CPPUNIT_TEST(testMetalink);
CPPUNIT_TEST(testResolveHttpAuthConfigItem);
CPPUNIT_TEST(testResolveHttpAuthConfigItem_noCandidate);
CPPUNIT_TEST(testResolveHttpProxyAuthConfigItem);
CPPUNIT_TEST(testResolveHttpProxyAuthConfigItem_noCandidate);
CPPUNIT_TEST(testResolveFtpAuthConfigItem);
CPPUNIT_TEST(testResolveFtpAuthConfigItem_noCandidate);
CPPUNIT_TEST_SUITE_END();
public:
@ -48,6 +54,12 @@ public:
void testSafeChar();
void testInnerLink();
void testMetalink();
void testResolveHttpAuthConfigItem();
void testResolveHttpAuthConfigItem_noCandidate();
void testResolveHttpProxyAuthConfigItem();
void testResolveHttpProxyAuthConfigItem_noCandidate();
void testResolveFtpAuthConfigItem();
void testResolveFtpAuthConfigItem_noCandidate();
};
@ -293,3 +305,118 @@ void RequestTest::testMetalink() {
bool v2 = req.setUrl("http://aria.rednoah.com/download/aria.tar.bz2#!metalink3!");
CPPUNIT_ASSERT(!v2);
}
void RequestTest::testResolveHttpAuthConfigItem()
{
Request req;
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
// with no authConfig
CPPUNIT_ASSERT(req.resolveHttpAuthConfigItem().isNull());
// with Netrc
NetrcHandle netrc = new Netrc();
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
NetrcSingletonHolder::instance(netrc);
CPPUNIT_ASSERT(!req.resolveHttpAuthConfigItem().isNull());
AuthConfigItemHandle authConfig1 = req.resolveHttpAuthConfigItem();
CPPUNIT_ASSERT_EQUAL(string("default"), authConfig1->getUser());
CPPUNIT_ASSERT_EQUAL(string("defaultpassword"), authConfig1->getPassword());
// with Netrc + user defined
AuthConfigHandle authConfig = new AuthConfig();
authConfig->setHttpAuthConfigItem("userDefinedUser", "userDefinedPassword");
req.setUserDefinedAuthConfig(authConfig);
CPPUNIT_ASSERT(!req.resolveHttpAuthConfigItem().isNull());
AuthConfigItemHandle authConfig2 = req.resolveHttpAuthConfigItem();
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser"), authConfig2->getUser());
CPPUNIT_ASSERT_EQUAL(string("userDefinedPassword"), authConfig2->getPassword());
}
void RequestTest::testResolveHttpAuthConfigItem_noCandidate()
{
Request req;
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
NetrcHandle netrc = new Netrc();
netrc->addAuthenticator(new Authenticator("localhost2", "default", "defaultpassword", "defaultaccount"));
NetrcSingletonHolder::instance(netrc);
CPPUNIT_ASSERT(req.resolveHttpAuthConfigItem().isNull());
}
void RequestTest::testResolveHttpProxyAuthConfigItem()
{
Request req;
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
// with no authConfig
CPPUNIT_ASSERT(req.resolveHttpProxyAuthConfigItem().isNull());
// with Netrc
NetrcHandle netrc = new Netrc();
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
NetrcSingletonHolder::instance(netrc);
CPPUNIT_ASSERT(!req.resolveHttpProxyAuthConfigItem().isNull());
AuthConfigItemHandle authConfig1 = req.resolveHttpProxyAuthConfigItem();
CPPUNIT_ASSERT_EQUAL(string("default"), authConfig1->getUser());
CPPUNIT_ASSERT_EQUAL(string("defaultpassword"), authConfig1->getPassword());
// with Netrc + user defined
AuthConfigHandle authConfig = new AuthConfig();
authConfig->setHttpProxyAuthConfigItem("userDefinedUser", "userDefinedPassword");
req.setUserDefinedAuthConfig(authConfig);
CPPUNIT_ASSERT(!req.resolveHttpProxyAuthConfigItem().isNull());
AuthConfigItemHandle authConfig2 = req.resolveHttpProxyAuthConfigItem();
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser"), authConfig2->getUser());
CPPUNIT_ASSERT_EQUAL(string("userDefinedPassword"), authConfig2->getPassword());
}
void RequestTest::testResolveHttpProxyAuthConfigItem_noCandidate()
{
Request req;
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
NetrcHandle netrc = new Netrc();
netrc->addAuthenticator(new Authenticator("localhost2", "default", "defaultpassword", "defaultaccount"));
NetrcSingletonHolder::instance(netrc);
CPPUNIT_ASSERT(req.resolveHttpProxyAuthConfigItem().isNull());
}
void RequestTest::testResolveFtpAuthConfigItem()
{
Request req;
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
// with no authConfig
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
CPPUNIT_ASSERT_EQUAL(string("anonymous"), req.resolveFtpAuthConfigItem()->getUser());
CPPUNIT_ASSERT_EQUAL(string("ARIA2USER@"), req.resolveFtpAuthConfigItem()->getPassword());
// with Netrc
NetrcHandle netrc = new Netrc();
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
NetrcSingletonHolder::instance(netrc);
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
AuthConfigItemHandle authConfig1 = req.resolveFtpAuthConfigItem();
CPPUNIT_ASSERT_EQUAL(string("default"), authConfig1->getUser());
CPPUNIT_ASSERT_EQUAL(string("defaultpassword"), authConfig1->getPassword());
// with Netrc + user defined
AuthConfigHandle authConfig = new AuthConfig();
authConfig->setFtpAuthConfigItem("userDefinedUser", "userDefinedPassword");
req.setUserDefinedAuthConfig(authConfig);
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
AuthConfigItemHandle authConfig2 = req.resolveFtpAuthConfigItem();
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser"), authConfig2->getUser());
CPPUNIT_ASSERT_EQUAL(string("userDefinedPassword"), authConfig2->getPassword());
}
void RequestTest::testResolveFtpAuthConfigItem_noCandidate()
{
Request req;
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
NetrcHandle netrc = new Netrc();
netrc->addAuthenticator(new Authenticator("localhost2", "default", "defaultpassword", "defaultaccount"));
NetrcSingletonHolder::instance(netrc);
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
CPPUNIT_ASSERT_EQUAL(string("anonymous"), req.resolveFtpAuthConfigItem()->getUser());
CPPUNIT_ASSERT_EQUAL(string("ARIA2USER@"), req.resolveFtpAuthConfigItem()->getPassword());
}