2007-03-27 16:16:44 +00:00
|
|
|
#include "NetrcAuthResolver.h"
|
|
|
|
#include "prefs.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Netrc.h"
|
|
|
|
#include "AuthConfig.h"
|
2007-03-27 16:16:44 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-03-27 16:16:44 +00:00
|
|
|
|
|
|
|
class NetrcAuthResolverTest : public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(NetrcAuthResolverTest);
|
|
|
|
CPPUNIT_TEST(testResolveAuthConfig_without_userDefined);
|
|
|
|
CPPUNIT_TEST(testResolveAuthConfig_with_userDefined);
|
2008-09-25 14:37:28 +00:00
|
|
|
CPPUNIT_TEST(testResolveAuthConfig_ignoreDefault);
|
2007-03-27 16:16:44 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Netrc> _netrc;
|
2007-03-27 16:16:44 +00:00
|
|
|
//SharedHandle<Option> _option;
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<NetrcAuthResolver> _resolver;
|
2007-03-27 16:16:44 +00:00
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
_netrc.reset(new Netrc());
|
|
|
|
_netrc->addAuthenticator
|
|
|
|
(SharedHandle<Authenticator>(new Authenticator("localhost", "name", "passwd", "account")));
|
|
|
|
_netrc->addAuthenticator
|
|
|
|
(SharedHandle<Authenticator>(new DefaultAuthenticator("default", "defaultpasswd", "defaultaccount")));
|
2007-03-27 16:16:44 +00:00
|
|
|
|
|
|
|
//_option = new Option();
|
2008-04-20 00:50:22 +00:00
|
|
|
_resolver.reset(new NetrcAuthResolver());
|
2007-03-27 16:16:44 +00:00
|
|
|
_resolver->setNetrc(_netrc);
|
2008-04-20 00:50:22 +00:00
|
|
|
_resolver->setDefaultAuthConfig
|
|
|
|
(SharedHandle<AuthConfig>(new AuthConfig("foo", "bar")));
|
2007-03-27 16:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testResolveAuthConfig_without_userDefined();
|
|
|
|
void testResolveAuthConfig_with_userDefined();
|
2008-09-25 14:37:28 +00:00
|
|
|
void testResolveAuthConfig_ignoreDefault();
|
2007-03-27 16:16:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( NetrcAuthResolverTest );
|
|
|
|
|
|
|
|
void NetrcAuthResolverTest::testResolveAuthConfig_without_userDefined()
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<AuthConfig> authConfig = _resolver->resolveAuthConfig("localhost");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("name:passwd"), authConfig->getAuthText());
|
2007-03-27 16:16:44 +00:00
|
|
|
|
|
|
|
authConfig = _resolver->resolveAuthConfig("mymachine");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("default:defaultpasswd"), authConfig->getAuthText());
|
2007-03-27 16:16:44 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
_resolver->setNetrc(SharedHandle<Netrc>());
|
2007-03-27 16:16:44 +00:00
|
|
|
authConfig = _resolver->resolveAuthConfig("localhost");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), authConfig->getAuthText());
|
2007-03-27 16:16:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetrcAuthResolverTest::testResolveAuthConfig_with_userDefined()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
_resolver->setUserDefinedAuthConfig
|
|
|
|
(SharedHandle<AuthConfig>(new AuthConfig("myname", "mypasswd")));
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<AuthConfig> authConfig = _resolver->resolveAuthConfig("localhost");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypasswd"), authConfig->getAuthText());
|
2007-03-27 16:16:44 +00:00
|
|
|
|
|
|
|
authConfig = _resolver->resolveAuthConfig("mymachine");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypasswd"), authConfig->getAuthText());
|
2007-03-27 16:16:44 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
_resolver->setNetrc(SharedHandle<Netrc>());
|
2007-03-27 16:16:44 +00:00
|
|
|
authConfig = _resolver->resolveAuthConfig("mymachine");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypasswd"), authConfig->getAuthText());
|
2007-03-27 16:16:44 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-09-25 14:37:28 +00:00
|
|
|
void NetrcAuthResolverTest::testResolveAuthConfig_ignoreDefault()
|
|
|
|
{
|
|
|
|
_resolver->ignoreDefault();
|
|
|
|
SharedHandle<AuthConfig> authConfig = _resolver->resolveAuthConfig("mirror");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), authConfig->getAuthText());
|
|
|
|
|
|
|
|
_resolver->useDefault();
|
|
|
|
SharedHandle<AuthConfig> defAuthConfig =
|
|
|
|
_resolver->resolveAuthConfig("mirror");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("default:defaultpasswd"),
|
|
|
|
defAuthConfig->getAuthText());
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|