summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_unittest.cc
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 02:48:15 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 02:48:15 +0000
commitd1ec590811a1d4e593c1ba7ad52cee26cef16305 (patch)
treef79245a0252441ad145e3b41c991b3ebd7e28eb9 /net/url_request/url_request_unittest.cc
parent3431b8926e2332f47f5e5eb6f78f512ca6ba286c (diff)
downloadchromium_src-d1ec590811a1d4e593c1ba7ad52cee26cef16305.zip
chromium_src-d1ec590811a1d4e593c1ba7ad52cee26cef16305.tar.gz
chromium_src-d1ec590811a1d4e593c1ba7ad52cee26cef16305.tar.bz2
Sanitize proxy response codes to CONNECT requests. For
anything other than 200 (success) or 400-599 (error), we rewrite the response code as 500 (internal server error) to prevent any special handling of the proxy's response to CONNECT by mistake. Add a new error code ERR_UNEXPECTED_SERVER_AUTH for a 401 response to a CONNECT request. Fix nits reported by cpplint.py. R=darin,eroman BUG=7338 Review URL: http://codereview.chromium.org/21158 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request_unittest.cc')
-rw-r--r--net/url_request/url_request_unittest.cc75
1 files changed, 51 insertions, 24 deletions
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 5c9146f..0cadd0e 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -55,10 +55,10 @@ class URLRequestHttpCacheContext : public URLRequestContext {
class TestURLRequest : public URLRequest {
public:
- TestURLRequest(const GURL& url, Delegate* delegate)
- : URLRequest(url, delegate) {
- set_context(new URLRequestHttpCacheContext());
- }
+ TestURLRequest(const GURL& url, Delegate* delegate)
+ : URLRequest(url, delegate) {
+ set_context(new URLRequestHttpCacheContext());
+ }
};
StringPiece TestNetResourceProvider(int key) {
@@ -82,6 +82,34 @@ bool ContainsString(const std::string& haystack, const char* needle) {
class URLRequestTest : public PlatformTest {
};
+TEST_F(URLRequestTest, ProxyTunnelRedirectTest) {
+ // In this unit test, we're using the HTTPTestServer as a proxy server and
+ // issue a CONNECT request with the magic host name "www.redirect.com" to
+ // it. The HTTPTestServer will return a 302 response, which we should not
+ // follow.
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(L"", NULL);
+ ASSERT_TRUE(NULL != server.get());
+ TestDelegate d;
+ {
+ URLRequest r(GURL("https://www.redirect.com/"), &d);
+ std::string proxy("localhost:");
+ proxy.append(IntToString(kHTTPDefaultPort));
+ r.set_context(new TestURLRequestContext(proxy));
+
+ r.Start();
+ EXPECT_TRUE(r.is_pending());
+
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(1, d.response_started_count());
+ // We should have rewritten the 302 response code as 500.
+ EXPECT_EQ(500, r.GetResponseCode());
+ // We should not have followed the redirect.
+ EXPECT_EQ(0, d.received_redirect_count());
+ }
+}
+
TEST_F(URLRequestTest, GetTest_NoCache) {
scoped_refptr<HTTPTestServer> server =
HTTPTestServer::CreateServer(L"", NULL);
@@ -100,7 +128,7 @@ TEST_F(URLRequestTest, GetTest_NoCache) {
EXPECT_NE(0, d.bytes_received());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -122,15 +150,15 @@ TEST_F(URLRequestTest, GetTest) {
EXPECT_NE(0, d.bytes_received());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
class HTTPSRequestTest : public testing::Test {
protected:
- HTTPSRequestTest() : util_() {};
+ HTTPSRequestTest() : util_() {}
- SSLTestUtil util_;
+ SSLTestUtil util_;
};
#if defined(OS_MACOSX)
@@ -165,7 +193,7 @@ TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) {
EXPECT_NE(0, d.bytes_received());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -188,7 +216,7 @@ TEST_F(URLRequestTest, CancelTest) {
EXPECT_FALSE(d.received_data_before_response());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -217,7 +245,7 @@ TEST_F(URLRequestTest, CancelTest2) {
EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -245,7 +273,7 @@ TEST_F(URLRequestTest, CancelTest3) {
EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -320,7 +348,7 @@ TEST_F(URLRequestTest, PostTest) {
char *uploadBytes = new char[kMsgSize+1];
char *ptr = uploadBytes;
char marker = 'a';
- for(int idx=0; idx<kMsgSize/10; idx++) {
+ for (int idx = 0; idx < kMsgSize/10; idx++) {
memcpy(ptr, "----------", 10);
ptr += 10;
if (idx % 100 == 0) {
@@ -329,7 +357,6 @@ TEST_F(URLRequestTest, PostTest) {
if (++marker > 'z')
marker = 'a';
}
-
}
uploadBytes[kMsgSize] = '\0';
@@ -354,12 +381,12 @@ TEST_F(URLRequestTest, PostTest) {
EXPECT_FALSE(d.received_data_before_response());
EXPECT_EQ(uploadBytes, d.data_received());
- EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize),0);
+ EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0);
EXPECT_EQ(d.data_received().compare(uploadBytes), 0);
}
delete[] uploadBytes;
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -384,7 +411,7 @@ TEST_F(URLRequestTest, PostEmptyTest) {
EXPECT_TRUE(d.data_received().empty());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -435,7 +462,7 @@ TEST_F(URLRequestTest, PostFileTest) {
EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size));
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -454,7 +481,7 @@ TEST_F(URLRequestTest, AboutBlankTest) {
EXPECT_EQ(d.bytes_received(), 0);
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -481,7 +508,7 @@ TEST_F(URLRequestTest, FileTest) {
EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -497,7 +524,7 @@ TEST_F(URLRequestTest, InvalidUrlTest) {
EXPECT_TRUE(d.request_failed());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -515,7 +542,7 @@ TEST_F(URLRequestTest, DISABLED_DnsFailureTest) {
EXPECT_TRUE(d.request_failed());
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
@@ -666,7 +693,7 @@ TEST_F(URLRequestTest, ResolveShortcutTest) {
CoUninitialize();
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
}
#endif // defined(OS_WIN)
@@ -713,7 +740,7 @@ TEST_F(URLRequestTest, FileDirCancelTest) {
MessageLoop::current()->Run();
}
#ifndef NDEBUG
- DCHECK_EQ(url_request_metrics.object_count,0);
+ DCHECK_EQ(url_request_metrics.object_count, 0);
#endif
// Take out mock resource provider.