summaryrefslogtreecommitdiff
path: root/test/NetrcTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-03-18 15:42:34 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-03-18 15:42:34 +0000
commit7ff627079f6ed776dea1ce6fede1c1a07ef7f288 (patch)
tree8f7b7e5b763dc3841df03928fe2aa50abd35a810 /test/NetrcTest.cc
parent58d4dde223e815b75a3bf6bfbd4169818faca3bd (diff)
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.
Diffstat (limited to 'test/NetrcTest.cc')
-rw-r--r--test/NetrcTest.cc34
1 files changed, 24 insertions, 10 deletions
diff --git a/test/NetrcTest.cc b/test/NetrcTest.cc
index a02b7117..caa6dff7 100644
--- a/test/NetrcTest.cc
+++ b/test/NetrcTest.cc
@@ -7,10 +7,11 @@ using namespace std;
class NetrcTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(NetrcTest);
- CPPUNIT_TEST(testFindAuthenticatable);
+ CPPUNIT_TEST(testFindAuthenticator);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testParse_fileNotFound);
CPPUNIT_TEST(testParse_emptyfile);
+ CPPUNIT_TEST(testParse_malformedNetrc);
CPPUNIT_TEST_SUITE_END();
private:
@@ -18,29 +19,30 @@ public:
void setUp() {
}
- void testFindAuthenticatable();
+ void testFindAuthenticator();
void testParse();
void testParse_fileNotFound();
void testParse_emptyfile();
+ void testParse_malformedNetrc();
};
CPPUNIT_TEST_SUITE_REGISTRATION( NetrcTest );
-void NetrcTest::testFindAuthenticatable()
+void NetrcTest::testFindAuthenticator()
{
Netrc netrc;
- netrc.addAuthenticatable(new Authenticator("host1", "tujikawa", "tujikawapasswd", "tujikawaaccount"));
- netrc.addAuthenticatable(new Authenticator("host2", "aria2", "aria2password", "aria2account"));
- netrc.addAuthenticatable(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
+ netrc.addAuthenticator(new Authenticator("host1", "tujikawa", "tujikawapasswd", "tujikawaaccount"));
+ netrc.addAuthenticator(new Authenticator("host2", "aria2", "aria2password", "aria2account"));
+ netrc.addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
- AuthenticatorHandle aria2auth = netrc.findAuthenticatable("host2");
+ AuthenticatorHandle aria2auth = netrc.findAuthenticator("host2");
CPPUNIT_ASSERT(!aria2auth.isNull());
CPPUNIT_ASSERT_EQUAL(string("aria2"), aria2auth->getLogin());
CPPUNIT_ASSERT_EQUAL(string("aria2password"), aria2auth->getPassword());
CPPUNIT_ASSERT_EQUAL(string("aria2account"), aria2auth->getAccount());
- AuthenticatorHandle defaultauth = netrc.findAuthenticatable("host3");
+ AuthenticatorHandle defaultauth = netrc.findAuthenticator("host3");
CPPUNIT_ASSERT(!defaultauth.isNull());
CPPUNIT_ASSERT_EQUAL(string("default"), defaultauth->getLogin());
CPPUNIT_ASSERT_EQUAL(string("defaultpassword"), defaultauth->getPassword());
@@ -51,7 +53,7 @@ void NetrcTest::testParse()
{
Netrc netrc;
netrc.parse("sample.netrc");
- Authenticatables::const_iterator itr = netrc.getAuthenticatables().begin();
+ Authenticators::const_iterator itr = netrc.getAuthenticators().begin();
AuthenticatorHandle tujikawaauth = *itr;
CPPUNIT_ASSERT(!tujikawaauth.isNull());
@@ -91,5 +93,17 @@ void NetrcTest::testParse_emptyfile()
Netrc netrc;
netrc.parse("emptyfile");
- CPPUNIT_ASSERT_EQUAL((size_t)0, netrc.getAuthenticatables().size());
+ CPPUNIT_ASSERT_EQUAL((size_t)0, netrc.getAuthenticators().size());
+}
+
+void NetrcTest::testParse_malformedNetrc()
+{
+ Netrc netrc;
+ try {
+ netrc.parse("malformed.netrc");
+ CPPUNIT_FAIL("exception must be threw.");
+ } catch(Exception* e) {
+ cerr << e->getMsg() << endl;
+ delete e;
+ }
}