2006-02-17 13:35:04 +00:00
|
|
|
#include "Request.h"
|
2007-03-18 15:42:34 +00:00
|
|
|
#include "Netrc.h"
|
2007-03-21 10:19:23 +00:00
|
|
|
#include "DefaultAuthResolver.h"
|
|
|
|
#include "NetrcAuthResolver.h"
|
2006-02-17 13:35:04 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
class RequestTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(RequestTest);
|
|
|
|
CPPUNIT_TEST(testSetUrl1);
|
|
|
|
CPPUNIT_TEST(testSetUrl2);
|
|
|
|
CPPUNIT_TEST(testSetUrl3);
|
|
|
|
CPPUNIT_TEST(testSetUrl4);
|
|
|
|
CPPUNIT_TEST(testSetUrl5);
|
|
|
|
CPPUNIT_TEST(testSetUrl6);
|
|
|
|
CPPUNIT_TEST(testSetUrl7);
|
|
|
|
CPPUNIT_TEST(testSetUrl8);
|
|
|
|
CPPUNIT_TEST(testSetUrl9);
|
|
|
|
CPPUNIT_TEST(testSetUrl10);
|
2006-06-18 09:23:25 +00:00
|
|
|
CPPUNIT_TEST(testSetUrl11);
|
|
|
|
CPPUNIT_TEST(testSetUrl12);
|
|
|
|
CPPUNIT_TEST(testSetUrl13);
|
|
|
|
CPPUNIT_TEST(testSetUrl14);
|
2007-10-14 16:29:05 +00:00
|
|
|
CPPUNIT_TEST(testSetUrl15);
|
|
|
|
CPPUNIT_TEST(testSetUrl16);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_TEST(testRedirectUrl);
|
2006-02-18 03:59:26 +00:00
|
|
|
CPPUNIT_TEST(testRedirectUrl2);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_TEST(testResetUrl);
|
|
|
|
CPPUNIT_TEST(testSafeChar);
|
2006-07-20 15:48:12 +00:00
|
|
|
CPPUNIT_TEST(testInnerLink);
|
|
|
|
CPPUNIT_TEST(testMetalink);
|
2007-03-21 10:19:23 +00:00
|
|
|
CPPUNIT_TEST(testResolveHttpAuthConfig);
|
|
|
|
CPPUNIT_TEST(testResolveHttpAuthConfig_noCandidate);
|
|
|
|
CPPUNIT_TEST(testResolveHttpProxyAuthConfig);
|
|
|
|
CPPUNIT_TEST(testResolveFtpAuthConfig);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void testSetUrl1();
|
|
|
|
void testSetUrl2();
|
|
|
|
void testSetUrl3();
|
|
|
|
void testSetUrl4();
|
|
|
|
void testSetUrl5();
|
|
|
|
void testSetUrl6();
|
|
|
|
void testSetUrl7();
|
|
|
|
void testSetUrl8();
|
|
|
|
void testSetUrl9();
|
|
|
|
void testSetUrl10();
|
2006-06-18 09:23:25 +00:00
|
|
|
void testSetUrl11();
|
|
|
|
void testSetUrl12();
|
|
|
|
void testSetUrl13();
|
|
|
|
void testSetUrl14();
|
2007-10-14 16:29:05 +00:00
|
|
|
void testSetUrl15();
|
|
|
|
void testSetUrl16();
|
2006-02-17 13:35:04 +00:00
|
|
|
void testRedirectUrl();
|
2006-02-18 03:59:26 +00:00
|
|
|
void testRedirectUrl2();
|
2006-02-17 13:35:04 +00:00
|
|
|
void testResetUrl();
|
|
|
|
void testSafeChar();
|
2006-07-20 15:48:12 +00:00
|
|
|
void testInnerLink();
|
|
|
|
void testMetalink();
|
2007-03-21 10:19:23 +00:00
|
|
|
void testResolveHttpAuthConfig();
|
|
|
|
void testResolveHttpAuthConfig_noCandidate();
|
|
|
|
void testResolveHttpProxyAuthConfig();
|
|
|
|
void testResolveFtpAuthConfig();
|
2006-02-17 13:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RequestTest );
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl1() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com/"), req.getUrl());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com/"), req.getCurrentUrl());
|
2006-02-18 03:59:26 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getPreviousUrl());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl2() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com:8080/index.html");
|
2006-02-18 03:59:26 +00:00
|
|
|
req.setReferer("http://aria.rednoah.com:8080");
|
2006-02-17 13:35:04 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
2006-02-18 03:59:26 +00:00
|
|
|
|
|
|
|
// referer is unchaged
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com:8080"), req.getReferer());
|
|
|
|
// previousUrl must equal to referer;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(req.getReferer(), req.getPreviousUrl());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)8080, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("index.html"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl3() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/aria2/index.html");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/aria2"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("index.html"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl4() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/aria2/aria3/index.html");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/aria2/aria3"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("index.html"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl5() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/aria2/aria3/");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/aria2/aria3"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl6() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/aria2/aria3");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/aria2"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria3"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl7() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl8() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http:/aria.rednoah.com");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl9() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("h");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl10() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!v);
|
|
|
|
}
|
|
|
|
|
2006-06-18 09:23:25 +00:00
|
|
|
void RequestTest::testSetUrl11() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://host?query/");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("?query/"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl12() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://host?query");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("?query"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl13() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://host/?query");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("?query"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl14() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://host:8080/abc?query");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)8080, req.getPort());
|
2006-06-18 09:23:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("abc?query"), req.getFile());
|
|
|
|
}
|
|
|
|
|
2007-10-14 16:29:05 +00:00
|
|
|
void RequestTest::testSetUrl15()
|
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
// 2 slashes after host name and dir
|
|
|
|
bool v = req.setUrl("http://host//dir1/dir2//file");
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/dir1/dir2"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("file"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSetUrl16()
|
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
// 2 slashes before file
|
|
|
|
bool v = req.setUrl("http://host//file");
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("file"), req.getFile());
|
|
|
|
}
|
|
|
|
|
2006-02-17 13:35:04 +00:00
|
|
|
void RequestTest::testRedirectUrl() {
|
|
|
|
Request req;
|
2007-10-17 16:26:51 +00:00
|
|
|
req.setKeepAlive(true);
|
2006-02-17 13:35:04 +00:00
|
|
|
bool v = req.setUrl("http://aria.rednoah.com:8080/aria2/index.html");
|
|
|
|
|
|
|
|
bool v2 = req.redirectUrl("http://aria.rednoah.co.jp/");
|
|
|
|
CPPUNIT_ASSERT(v2);
|
2007-10-17 16:26:51 +00:00
|
|
|
// keep-alive set to be false after redirection
|
|
|
|
CPPUNIT_ASSERT(!req.isKeepAlive());
|
2006-02-17 13:35:04 +00:00
|
|
|
// url must be the same
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com:8080/aria2/index.html"),
|
|
|
|
req.getUrl());
|
|
|
|
// currentUrl must be updated
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.co.jp/"), req.getCurrentUrl());
|
2007-10-11 17:04:53 +00:00
|
|
|
// previousUrl must be "" when redirection
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getPreviousUrl());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.co.jp"), req.getHost());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getFile());
|
|
|
|
}
|
|
|
|
|
2006-02-18 03:59:26 +00:00
|
|
|
void RequestTest::testRedirectUrl2() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/download.html");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getPreviousUrl());
|
|
|
|
req.setReferer("http://aria.rednoah.com/");
|
|
|
|
// previousUrl is updated when referer is specified
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com/"), req.getPreviousUrl());
|
|
|
|
bool v2 = req.redirectUrl("http://aria.rednoah.com/403.html");
|
|
|
|
|
2007-10-11 17:04:53 +00:00
|
|
|
// previousUrl must be "" when redirection
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getPreviousUrl());
|
2006-02-18 03:59:26 +00:00
|
|
|
// referer is unchagned
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com/"), req.getReferer());
|
|
|
|
|
|
|
|
bool v3 = req.redirectUrl("http://aria.rednoah.com/error.html");
|
|
|
|
|
2007-10-11 17:04:53 +00:00
|
|
|
// previousUrl must be "" when redirection
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), req.getPreviousUrl());
|
2006-02-18 03:59:26 +00:00
|
|
|
}
|
|
|
|
|
2006-02-17 13:35:04 +00:00
|
|
|
void RequestTest::testResetUrl() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com:8080/aria2/index.html");
|
2006-02-18 03:59:26 +00:00
|
|
|
req.setReferer("http://aria.rednoah.com:8080/");
|
2006-02-17 13:35:04 +00:00
|
|
|
bool v2 = req.redirectUrl("ftp://aria.rednoah.co.jp/");
|
|
|
|
|
|
|
|
bool v3 = req.resetUrl();
|
|
|
|
CPPUNIT_ASSERT(v3);
|
|
|
|
// currentUrl must equal to url
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com:8080/aria2/index.html"), req.getUrl());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(req.getUrl(), req.getCurrentUrl());
|
2006-02-18 03:59:26 +00:00
|
|
|
// previousUrl must equal to referer
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com:8080/"), req.getPreviousUrl());
|
|
|
|
// referer is unchanged
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria.rednoah.com:8080/"), req.getReferer());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)8080, req.getPort());
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/aria2"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("index.html"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testSafeChar() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/|<>");
|
|
|
|
CPPUNIT_ASSERT(!v);
|
|
|
|
}
|
2006-07-20 15:48:12 +00:00
|
|
|
|
|
|
|
void RequestTest::testInnerLink() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/index.html#download");
|
|
|
|
CPPUNIT_ASSERT(v);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("index.html"), req.getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTest::testMetalink() {
|
|
|
|
Request req;
|
|
|
|
bool v = req.setUrl("http://aria.rednoah.com/download/aria.tar.bz2#!metalink3!http://aria2.sourceforge.net/download/aria.metalink");
|
|
|
|
CPPUNIT_ASSERT(v);
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
#ifdef ENABLE_METALINK
|
2006-07-20 15:48:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2.sourceforge.net"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/download"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.metalink"), req.getFile());
|
|
|
|
|
|
|
|
bool v2 = req.setUrl("http://aria.rednoah.com/download/aria.tar.bz2#!metalink3!");
|
|
|
|
CPPUNIT_ASSERT(!v2);
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
#else
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.rednoah.com"), req.getHost());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/download"), req.getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria.tar.bz2"), req.getFile());
|
|
|
|
#endif // ENABLE_METALINK
|
2006-07-20 15:48:12 +00:00
|
|
|
}
|
2007-03-18 15:42:34 +00:00
|
|
|
|
2007-03-21 10:19:23 +00:00
|
|
|
void RequestTest::testResolveHttpAuthConfig()
|
2007-03-18 15:42:34 +00:00
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
2007-03-21 10:19:23 +00:00
|
|
|
// with DefaultAuthResolver
|
|
|
|
DefaultAuthResolverHandle defaultAuthResolver = new DefaultAuthResolver();
|
|
|
|
req.setHttpAuthResolver(defaultAuthResolver);
|
|
|
|
CPPUNIT_ASSERT(!req.resolveHttpAuthConfig().isNull());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(":"),
|
|
|
|
req.resolveHttpAuthConfig()->getAuthText());
|
2007-03-18 15:42:34 +00:00
|
|
|
|
|
|
|
// with Netrc
|
|
|
|
NetrcHandle netrc = new Netrc();
|
|
|
|
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
|
2007-03-21 10:19:23 +00:00
|
|
|
NetrcAuthResolverHandle netrcAuthResolver = new NetrcAuthResolver();
|
|
|
|
netrcAuthResolver->setNetrc(netrc);
|
|
|
|
req.setHttpAuthResolver(netrcAuthResolver);
|
|
|
|
AuthConfigHandle authConfig1 = req.resolveHttpAuthConfig();
|
|
|
|
CPPUNIT_ASSERT(!authConfig1.isNull());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("default:defaultpassword"),
|
|
|
|
authConfig1->getAuthText());
|
2007-03-18 15:42:34 +00:00
|
|
|
|
|
|
|
// with Netrc + user defined
|
2007-03-21 10:19:23 +00:00
|
|
|
AuthConfigHandle authConfig =
|
|
|
|
new AuthConfig("userDefinedUser", "userDefinedPassword");
|
|
|
|
netrcAuthResolver->setUserDefinedAuthConfig(authConfig);
|
|
|
|
AuthConfigHandle authConfig2 = req.resolveHttpAuthConfig();
|
|
|
|
CPPUNIT_ASSERT(!authConfig2.isNull());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser:userDefinedPassword"),
|
|
|
|
authConfig2->getAuthText());
|
2007-03-18 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 10:19:23 +00:00
|
|
|
void RequestTest::testResolveHttpAuthConfig_noCandidate()
|
2007-03-18 15:42:34 +00:00
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
|
|
|
|
2007-03-21 10:19:23 +00:00
|
|
|
DefaultAuthResolverHandle defaultAuthResolver = new DefaultAuthResolver();
|
|
|
|
req.setHttpAuthResolver(defaultAuthResolver);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(":"),
|
|
|
|
req.resolveHttpAuthConfig()->getAuthText());
|
2007-03-18 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 10:19:23 +00:00
|
|
|
void RequestTest::testResolveHttpProxyAuthConfig()
|
2007-03-18 15:42:34 +00:00
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
|
|
|
// with Netrc
|
|
|
|
NetrcHandle netrc = new Netrc();
|
|
|
|
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
|
2007-03-21 10:19:23 +00:00
|
|
|
NetrcAuthResolverHandle netrcAuthResolver = new NetrcAuthResolver();
|
|
|
|
netrcAuthResolver->setNetrc(netrc);
|
|
|
|
req.setHttpProxyAuthResolver(netrcAuthResolver);
|
|
|
|
AuthConfigHandle authConfig1 = req.resolveHttpProxyAuthConfig();
|
|
|
|
CPPUNIT_ASSERT(!authConfig1.isNull());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("default:defaultpassword"),
|
|
|
|
authConfig1->getAuthText());
|
2007-03-18 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 10:19:23 +00:00
|
|
|
void RequestTest::testResolveFtpAuthConfig()
|
2007-03-18 15:42:34 +00:00
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
|
|
|
// with Netrc
|
|
|
|
NetrcHandle netrc = new Netrc();
|
|
|
|
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
|
2007-03-21 10:19:23 +00:00
|
|
|
NetrcAuthResolverHandle netrcAuthResolver = new NetrcAuthResolver();
|
|
|
|
netrcAuthResolver->setNetrc(netrc);
|
|
|
|
req.setFtpAuthResolver(netrcAuthResolver);
|
|
|
|
AuthConfigHandle authConfig1 = req.resolveFtpAuthConfig();
|
|
|
|
CPPUNIT_ASSERT(!authConfig1.isNull());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("default:defaultpassword"),
|
|
|
|
authConfig1->getAuthText());
|
2007-03-18 15:42:34 +00:00
|
|
|
}
|