diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-10-30 12:48:01 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-10-30 12:48:01 +0000 |
| commit | 6b7df851d3d4f237c17528310e46bd2ffb91ba8f (patch) | |
| tree | 600c87920f37dd1790df66c59ff3c11119d9405f /test/HttpRequestTest.cc | |
| parent | f3f8cc593c39e0b63958faf2c1271998c27f68f9 (diff) | |
2007-10-30 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added ftp://USER:PASSWD@Servername automatic parsing.
* src/Request.{h, cc}: Removed AuthResolvers. Added _username
and
_password. Recognize username and password in URI.
* src/main.cc: Use AuthConfigFactory instead of RequestFactory.
* src/RequestGroup.cc: Use AuthConfigFactory instead of
RequestFactory.
* src/RequestFactory.{h, cc}: Removed.
* src/AuthConfigFactory.{h, cc}: New class.
* src/FtpConnection.cc: Use AuthConfigFactory.
* src/HttpRequest.cc: Use AuthConfigFactory.
* test/HttpRequestTest.cc: Updated.
* test/RequestTest.cc: Updated.
* test/AuthConfigFactoryTest.cc: New class.
* test/RequestFactoryTest.cc: Removed.
Diffstat (limited to 'test/HttpRequestTest.cc')
| -rw-r--r-- | test/HttpRequestTest.cc | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/test/HttpRequestTest.cc b/test/HttpRequestTest.cc index 836b7dd9..df79b514 100644 --- a/test/HttpRequestTest.cc +++ b/test/HttpRequestTest.cc @@ -1,6 +1,6 @@ #include "HttpRequest.h" #include "prefs.h" -#include "RequestFactory.h" +#include "AuthConfigFactory.h" #include "PiecedSegment.h" #include "Piece.h" #include <cppunit/extensions/HelperMacros.h> @@ -84,31 +84,30 @@ void HttpRequestTest::testGetEndByte() void HttpRequestTest::testCreateRequest() { - SharedHandle<Option> option = new Option(); - option->put(PREF_HTTP_AUTH_ENABLED, V_FALSE); - option->put(PREF_HTTP_PROXY_ENABLED, V_FALSE); - option->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL); - option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE); - option->put(PREF_HTTP_USER, "aria2user"); - option->put(PREF_HTTP_PASSWD, "aria2passwd"); - option->put(PREF_HTTP_PROXY_USER, "aria2proxyuser"); - option->put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd"); - RequestFactory requestFactory; - requestFactory.setOption(option.get()); - - RequestHandle request = requestFactory.createRequest(); + Option option; + option.put(PREF_HTTP_AUTH_ENABLED, V_FALSE); + option.put(PREF_HTTP_PROXY_ENABLED, V_FALSE); + option.put(PREF_HTTP_PROXY_METHOD, V_TUNNEL); + option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE); + option.put(PREF_HTTP_USER, "aria2user"); + option.put(PREF_HTTP_PASSWD, "aria2passwd"); + option.put(PREF_HTTP_PROXY_USER, "aria2proxyuser"); + option.put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd"); + + AuthConfigFactoryHandle authConfigFactory = new AuthConfigFactory(&option); + AuthConfigFactorySingleton::instance(authConfigFactory); + RequestHandle request = new Request(); request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); SegmentHandle segment = new PiecedSegment(1024, new Piece(0, 1024)); HttpRequest httpRequest; - httpRequest.setRequest(request); httpRequest.setSegment(segment); request->setKeepAlive(true); - + string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" "Accept: */*\r\n" @@ -158,7 +157,7 @@ void HttpRequestTest::testCreateRequest() "Cache-Control: no-cache\r\n" "Range: bytes=1048576-2097151\r\n" "\r\n"; - + CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); request->setKeepAlive(false); @@ -183,9 +182,9 @@ void HttpRequestTest::testCreateRequest() httpRequest.setSegment(segment); // enable http auth - option->put(PREF_HTTP_AUTH_ENABLED, V_TRUE); - - httpRequest.configure(option.get()); + option.put(PREF_HTTP_AUTH_ENABLED, V_TRUE); + + httpRequest.configure(&option); expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" @@ -200,9 +199,9 @@ void HttpRequestTest::testCreateRequest() CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); // enable http proxy auth - option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE); + option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE); - httpRequest.configure(option.get()); + httpRequest.configure(&option); expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" @@ -216,9 +215,9 @@ void HttpRequestTest::testCreateRequest() CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); - option->put(PREF_HTTP_PROXY_ENABLED, V_TRUE); + option.put(PREF_HTTP_PROXY_ENABLED, V_TRUE); - httpRequest.configure(option.get()); + httpRequest.configure(&option); expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" @@ -232,9 +231,9 @@ void HttpRequestTest::testCreateRequest() CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); - option->put(PREF_HTTP_PROXY_METHOD, V_GET); + option.put(PREF_HTTP_PROXY_METHOD, V_GET); - httpRequest.configure(option.get()); + httpRequest.configure(&option); expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" @@ -268,9 +267,9 @@ void HttpRequestTest::testCreateRequest() request->setKeepAlive(false); - option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE); + option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE); - httpRequest.configure(option.get()); + httpRequest.configure(&option); expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" @@ -288,20 +287,20 @@ void HttpRequestTest::testCreateRequest() void HttpRequestTest::testCreateRequest_ftp() { - SharedHandle<Option> option = new Option(); - option->put(PREF_HTTP_AUTH_ENABLED, V_FALSE); - option->put(PREF_HTTP_PROXY_ENABLED, V_FALSE); - option->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL); - option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE); - option->put(PREF_HTTP_USER, "aria2user"); - option->put(PREF_HTTP_PASSWD, "aria2passwd"); - option->put(PREF_HTTP_PROXY_USER, "aria2proxyuser"); - option->put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd"); - - RequestFactory requestFactory; - requestFactory.setOption(option.get()); - - RequestHandle request = requestFactory.createRequest(); + Option option; + option.put(PREF_HTTP_AUTH_ENABLED, V_FALSE); + option.put(PREF_HTTP_PROXY_ENABLED, V_FALSE); + option.put(PREF_HTTP_PROXY_METHOD, V_TUNNEL); + option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE); + option.put(PREF_HTTP_USER, "aria2user"); + option.put(PREF_HTTP_PASSWD, "aria2passwd"); + option.put(PREF_HTTP_PROXY_USER, "aria2proxyuser"); + option.put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd"); + + AuthConfigFactoryHandle authConfigFactory = new AuthConfigFactory(&option); + AuthConfigFactorySingleton::instance(authConfigFactory); + + RequestHandle request = new Request(); request->setUrl("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2"); HttpRequest httpRequest; @@ -309,7 +308,7 @@ void HttpRequestTest::testCreateRequest_ftp() httpRequest.setRequest(request); httpRequest.setSegment(segment); - httpRequest.configure(option.get()); + httpRequest.configure(&option); string expectedText = "GET ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" @@ -323,11 +322,11 @@ void HttpRequestTest::testCreateRequest_ftp() CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); // How to enable HTTP proxy authorization in FTP download via HTTP proxy - option->put(PREF_HTTP_PROXY_ENABLED, V_TRUE); - option->put(PREF_HTTP_PROXY_METHOD, V_GET); - option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE); + option.put(PREF_HTTP_PROXY_ENABLED, V_TRUE); + option.put(PREF_HTTP_PROXY_METHOD, V_GET); + option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE); - httpRequest.configure(option.get()); + httpRequest.configure(&option); expectedText = "GET ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" "User-Agent: aria2\r\n" @@ -505,17 +504,17 @@ void HttpRequestTest::testIsRangeSatisfied() void HttpRequestTest::testUserAgent() { - SharedHandle<Option> option = new Option(); - RequestFactory requestFactory; - requestFactory.setOption(option.get()); + Option option; - RequestHandle request = requestFactory.createRequest(); + AuthConfigFactoryHandle authConfigFactory = new AuthConfigFactory(&option); + AuthConfigFactorySingleton::instance(authConfigFactory); + + RequestHandle request = new Request(); request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); SegmentHandle segment = new PiecedSegment(1024, new Piece(0, 1024)); HttpRequest httpRequest; - httpRequest.setRequest(request); httpRequest.setSegment(segment); httpRequest.setUserAgent("aria2 (Linux)"); |
