Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 8502024: Allow chrome to handle 407 auth challenges to CONNECT requests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync again Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 1674 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
1675 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1675 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1676 session_deps.net_log = log.bound().net_log(); 1676 session_deps.net_log = log.bound().net_log();
1677 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1677 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1678 1678
1679 // Since we have proxy, should try to establish tunnel. 1679 // Since we have proxy, should try to establish tunnel.
1680 MockWrite data_writes1[] = { 1680 MockWrite data_writes1[] = {
1681 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1681 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1682 "Host: www.google.com\r\n" 1682 "Host: www.google.com\r\n"
1683 "Proxy-Connection: keep-alive\r\n\r\n"), 1683 "Proxy-Connection: keep-alive\r\n\r\n"),
1684 };
1684 1685
1686 MockWrite data_writes2[] = {
1685 // After calling trans->RestartWithAuth(), this is the request we should 1687 // After calling trans->RestartWithAuth(), this is the request we should
1686 // be issuing -- the final header line contains the credentials. 1688 // be issuing -- the final header line contains the credentials.
1687 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1689 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1688 "Host: www.google.com\r\n" 1690 "Host: www.google.com\r\n"
1689 "Proxy-Connection: keep-alive\r\n" 1691 "Proxy-Connection: keep-alive\r\n"
1690 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), 1692 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
1691 1693
1692 MockWrite("GET / HTTP/1.1\r\n" 1694 MockWrite("GET / HTTP/1.1\r\n"
1693 "Host: www.google.com\r\n" 1695 "Host: www.google.com\r\n"
1694 "Connection: keep-alive\r\n\r\n"), 1696 "Connection: keep-alive\r\n\r\n"),
1695 }; 1697 };
1696 1698
1697 // The proxy responds to the connect with a 407, using a persistent 1699 // The proxy responds to the connect with a 407, using a persistent
1698 // connection. 1700 // connection.
1699 MockRead data_reads1[] = { 1701 MockRead data_reads1[] = {
1700 // No credentials. 1702 // No credentials.
1701 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 1703 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
1702 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 1704 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1703 MockRead("Proxy-Connection: close\r\n\r\n"), 1705 MockRead("Proxy-Connection: close\r\n\r\n"),
1706 };
1704 1707
1708 MockRead data_reads2[] = {
1705 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), 1709 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
1706 1710
1707 MockRead("HTTP/1.1 200 OK\r\n"), 1711 MockRead("HTTP/1.1 200 OK\r\n"),
1708 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 1712 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1709 MockRead("Content-Length: 5\r\n\r\n"), 1713 MockRead("Content-Length: 5\r\n\r\n"),
1710 MockRead(false, "hello"), 1714 MockRead(false, "hello"),
1711 }; 1715 };
1712 1716
1713 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), 1717 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1714 data_writes1, arraysize(data_writes1)); 1718 data_writes1, arraysize(data_writes1));
1719 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
1720 data_writes2, arraysize(data_writes2));
1715 session_deps.socket_factory.AddSocketDataProvider(&data1); 1721 session_deps.socket_factory.AddSocketDataProvider(&data1);
1722 session_deps.socket_factory.AddSocketDataProvider(&data2);
1716 SSLSocketDataProvider ssl(true, OK); 1723 SSLSocketDataProvider ssl(true, OK);
1717 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); 1724 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
1718 1725
1719 TestOldCompletionCallback callback1; 1726 TestOldCompletionCallback callback1;
1720 1727
1721 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 1728 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
1722 1729
1723 int rv = trans->Start(&request, &callback1, log.bound()); 1730 int rv = trans->Start(&request, &callback1, log.bound());
1724 EXPECT_EQ(ERR_IO_PENDING, rv); 1731 EXPECT_EQ(ERR_IO_PENDING, rv);
1725 1732
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 1925 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1919 1926
1920 std::string response_data; 1927 std::string response_data;
1921 rv = ReadTransaction(trans.get(), &response_data); 1928 rv = ReadTransaction(trans.get(), &response_data);
1922 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 1929 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
1923 1930
1924 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 1931 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
1925 session->CloseAllConnections(); 1932 session->CloseAllConnections();
1926 } 1933 }
1927 1934
1935 // Test the request-challenge-retry sequence for basic auth, over a connection
1936 // that requires a restart when setting up an SSL tunnel.
1937 TEST_F(HttpNetworkTransactionTest, BasicAuthHttpsProxyNoKeepAlive) {
1938 HttpRequestInfo request;
1939 request.method = "GET";
1940 request.url = GURL("https://www.google.com/");
1941 // when the no authentication data flag is set.
1942 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1943
1944 // Configure against https proxy server "myproxy:70".
1945 SessionDependencies session_deps(
1946 ProxyService::CreateFixed("https://myproxy:70"));
1947 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1948 session_deps.net_log = log.bound().net_log();
1949 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1950
1951 // Since we have proxy, should try to establish tunnel.
1952 MockWrite data_writes1[] = {
1953 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1954 "Host: www.google.com\r\n"
1955 "Proxy-Connection: keep-alive\r\n\r\n"),
1956 };
1957
1958 MockWrite data_writes2[] = {
1959 // After calling trans->RestartWithAuth(), this is the request we should
1960 // be issuing -- the final header line contains the credentials.
1961 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1962 "Host: www.google.com\r\n"
1963 "Proxy-Connection: keep-alive\r\n"
1964 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
1965
1966 MockWrite("GET / HTTP/1.1\r\n"
1967 "Host: www.google.com\r\n"
1968 "Connection: keep-alive\r\n\r\n"),
1969 };
1970
1971 // The proxy responds to the connect with a 407, using a persistent
1972 // connection.
1973 MockRead data_reads1[] = {
1974 // No credentials.
1975 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
1976 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1977 MockRead("Proxy-Connection: close\r\n\r\n"),
1978 };
1979
1980 MockRead data_reads2[] = {
1981 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
1982
1983 MockRead("HTTP/1.1 200 OK\r\n"),
1984 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1985 MockRead("Content-Length: 5\r\n\r\n"),
1986 MockRead(false, "hello"),
1987 };
1988
1989 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1990 data_writes1, arraysize(data_writes1));
1991 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
1992 data_writes2, arraysize(data_writes2));
1993 session_deps.socket_factory.AddSocketDataProvider(&data1);
1994 session_deps.socket_factory.AddSocketDataProvider(&data2);
1995 SSLSocketDataProvider proxy(true, OK);
1996 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy);
1997 SSLSocketDataProvider proxy2(true, OK);
1998 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy2);
1999 SSLSocketDataProvider server(true, OK);
2000 session_deps.socket_factory.AddSSLSocketDataProvider(&server);
2001
2002 TestOldCompletionCallback callback1;
2003
2004 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2005
2006 int rv = trans->Start(&request, &callback1, log.bound());
2007 EXPECT_EQ(ERR_IO_PENDING, rv);
2008
2009 rv = callback1.WaitForResult();
2010 EXPECT_EQ(OK, rv);
2011 net::CapturingNetLog::EntryList entries;
2012 log.GetEntries(&entries);
2013 size_t pos = ExpectLogContainsSomewhere(
2014 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2015 NetLog::PHASE_NONE);
2016 ExpectLogContainsSomewhere(
2017 entries, pos,
2018 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2019 NetLog::PHASE_NONE);
2020
2021 const HttpResponseInfo* response = trans->GetResponseInfo();
2022 ASSERT_TRUE(response != NULL);
2023 ASSERT_FALSE(response->headers == NULL);
2024 EXPECT_EQ(407, response->headers->response_code());
2025 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2026 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2027
2028 TestOldCompletionCallback callback2;
2029
2030 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
2031 EXPECT_EQ(ERR_IO_PENDING, rv);
2032
2033 rv = callback2.WaitForResult();
2034 EXPECT_EQ(OK, rv);
2035
2036 response = trans->GetResponseInfo();
2037 ASSERT_TRUE(response != NULL);
2038
2039 EXPECT_TRUE(response->headers->IsKeepAlive());
2040 EXPECT_EQ(200, response->headers->response_code());
2041 EXPECT_EQ(5, response->headers->GetContentLength());
2042 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2043
2044 // The password prompt info should not be set.
2045 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2046
2047 trans.reset();
2048 session->CloseAllConnections();
2049 }
2050
2051 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
2052 // proxy connection, when setting up an SSL tunnel.
2053 TEST_F(HttpNetworkTransactionTest, BasicAuthHttpsProxyKeepAlive) {
2054 HttpRequestInfo request;
2055 request.method = "GET";
2056 request.url = GURL("https://www.google.com/");
2057 // Ensure that proxy authentication is attempted even
2058 // when the no authentication data flag is set.
2059 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2060
2061 // Configure against https proxy server "myproxy:70".
2062 SessionDependencies session_deps(
2063 ProxyService::CreateFixed("https://myproxy:70"));
2064 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2065 session_deps.net_log = log.bound().net_log();
2066 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2067
2068 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2069
2070 // Since we have proxy, should try to establish tunnel.
2071 MockWrite data_writes1[] = {
2072 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2073 "Host: www.google.com\r\n"
2074 "Proxy-Connection: keep-alive\r\n\r\n"),
2075
2076 // After calling trans->RestartWithAuth(), this is the request we should
2077 // be issuing -- the final header line contains the credentials.
2078 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2079 "Host: www.google.com\r\n"
2080 "Proxy-Connection: keep-alive\r\n"
2081 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
2082 };
2083
2084 // The proxy responds to the connect with a 407, using a persistent
2085 // connection.
2086 MockRead data_reads1[] = {
2087 // No credentials.
2088 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2089 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2090 MockRead("Content-Length: 10\r\n\r\n"),
2091 MockRead("0123456789"),
2092
2093 // Wrong credentials (wrong password).
2094 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2095 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2096 MockRead("Content-Length: 10\r\n\r\n"),
2097 // No response body because the test stops reading here.
2098 MockRead(false, ERR_UNEXPECTED), // Should not be reached.
2099 };
2100
2101 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2102 data_writes1, arraysize(data_writes1));
2103 session_deps.socket_factory.AddSocketDataProvider(&data1);
2104 SSLSocketDataProvider ssl(true, OK);
2105 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
2106
2107 TestOldCompletionCallback callback1;
2108
2109 int rv = trans->Start(&request, &callback1, log.bound());
2110 EXPECT_EQ(ERR_IO_PENDING, rv);
2111
2112 rv = callback1.WaitForResult();
2113 EXPECT_EQ(OK, rv);
2114 net::CapturingNetLog::EntryList entries;
2115 log.GetEntries(&entries);
2116 size_t pos = ExpectLogContainsSomewhere(
2117 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2118 NetLog::PHASE_NONE);
2119 ExpectLogContainsSomewhere(
2120 entries, pos,
2121 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2122 NetLog::PHASE_NONE);
2123
2124 const HttpResponseInfo* response = trans->GetResponseInfo();
2125 ASSERT_TRUE(response != NULL);
2126 ASSERT_FALSE(response->headers == NULL);
2127 EXPECT_TRUE(response->headers->IsKeepAlive());
2128 EXPECT_EQ(407, response->headers->response_code());
2129 EXPECT_EQ(10, response->headers->GetContentLength());
2130 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2131 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2132
2133 TestOldCompletionCallback callback2;
2134
2135 // Wrong password (should be "bar").
2136 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), &callback2);
2137 EXPECT_EQ(ERR_IO_PENDING, rv);
2138
2139 rv = callback2.WaitForResult();
2140 EXPECT_EQ(OK, rv);
2141
2142 response = trans->GetResponseInfo();
2143 ASSERT_TRUE(response != NULL);
2144 ASSERT_FALSE(response->headers == NULL);
2145 EXPECT_TRUE(response->headers->IsKeepAlive());
2146 EXPECT_EQ(407, response->headers->response_code());
2147 EXPECT_EQ(10, response->headers->GetContentLength());
2148 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2149 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2150
2151 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
2152 // out of scope.
2153 session->CloseAllConnections();
2154 }
2155
2156 // Test the request-challenge-retry sequence for basic auth, through
2157 // a SPDY proxy over a single SPDY session.
2158 TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) {
2159 HttpRequestInfo request;
2160 request.method = "GET";
2161 request.url = GURL("https://www.google.com/");
2162 // when the no authentication data flag is set.
2163 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2164
2165 // Configure against https proxy server "myproxy:70".
2166 SessionDependencies session_deps(
2167 ProxyService::CreateFixed("https://myproxy:70"));
2168 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2169 session_deps.net_log = log.bound().net_log();
2170 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2171
2172 // Since we have proxy, should try to establish tunnel.
2173 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyConnect(NULL, 0, 1));
2174 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL));
2175
2176 // After calling trans->RestartWithAuth(), this is the request we should
2177 // be issuing -- the final header line contains the credentials.
2178 const char* const kAuthCredentials[] = {
2179 "proxy-authorization", "Basic Zm9vOmJhcg==",
2180 };
2181 scoped_ptr<spdy::SpdyFrame> connect2(
2182 ConstructSpdyConnect(kAuthCredentials, arraysize(kAuthCredentials)/2, 3));
2183 // fetch https://www.google.com/ via HTTP
2184 const char get[] = "GET / HTTP/1.1\r\n"
2185 "Host: www.google.com\r\n"
2186 "Connection: keep-alive\r\n\r\n";
2187 scoped_ptr<spdy::SpdyFrame> wrapped_get(
2188 ConstructSpdyBodyFrame(3, get, strlen(get), false));
2189
2190 MockWrite spdy_writes[] = {
2191 CreateMockWrite(*req, 0, true),
2192 CreateMockWrite(*rst, 2, true),
2193 CreateMockWrite(*connect2, 3),
2194 CreateMockWrite(*wrapped_get, 5)
2195 };
2196
2197 // The proxy responds to the connect with a 407, using a persistent
2198 // connection.
2199 const char* const kAuthChallenge[] = {
2200 "status", "407 Proxy Authentication Required",
2201 "version", "HTTP/1.1",
2202 "proxy-authenticate", "Basic realm=\"MyRealm1\"",
2203 };
2204
2205 scoped_ptr<spdy::SpdyFrame> conn_auth_resp(
2206 ConstructSpdyControlFrame(NULL,
2207 0,
2208 false,
2209 1,
2210 LOWEST,
2211 spdy::SYN_REPLY,
2212 spdy::CONTROL_FLAG_NONE,
2213 kAuthChallenge,
2214 arraysize(kAuthChallenge)));
2215
2216 scoped_ptr<spdy::SpdyFrame> conn_resp(ConstructSpdyGetSynReply(NULL, 0, 3));
2217 const char resp[] = "HTTP/1.1 200 OK\r\n"
2218 "Content-Length: 5\r\n\r\n";
2219
2220 scoped_ptr<spdy::SpdyFrame> wrapped_get_resp(
2221 ConstructSpdyBodyFrame(3, resp, strlen(resp), false));
2222 scoped_ptr<spdy::SpdyFrame> wrapped_body(
2223 ConstructSpdyBodyFrame(3, "hello", 10, false));
2224 MockRead spdy_reads[] = {
2225 CreateMockRead(*conn_auth_resp, 1, true),
2226 CreateMockRead(*conn_resp, 4, true),
2227 CreateMockRead(*wrapped_get_resp, 5, true),
2228 CreateMockRead(*wrapped_body, 6, true),
2229 MockRead(false, ERR_IO_PENDING),
2230 };
2231
2232 scoped_refptr<OrderedSocketData> spdy_data(
2233 new OrderedSocketData(
2234 spdy_reads, arraysize(spdy_reads),
2235 spdy_writes, arraysize(spdy_writes)));
2236 session_deps.socket_factory.AddSocketDataProvider(spdy_data);
2237 // Negotiate SPDY to the proxy
2238 SSLSocketDataProvider proxy(true, OK);
2239 proxy.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
2240 proxy.next_proto = "spdy/2";
2241 proxy.was_npn_negotiated = true;
2242 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy);
2243 // Vanilla SSL to the server
2244 SSLSocketDataProvider server(true, OK);
2245 session_deps.socket_factory.AddSSLSocketDataProvider(&server);
2246
2247 TestOldCompletionCallback callback1;
2248
2249 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2250
2251 int rv = trans->Start(&request, &callback1, log.bound());
2252 EXPECT_EQ(ERR_IO_PENDING, rv);
2253
2254 rv = callback1.WaitForResult();
2255 EXPECT_EQ(OK, rv);
2256 net::CapturingNetLog::EntryList entries;
2257 log.GetEntries(&entries);
2258 size_t pos = ExpectLogContainsSomewhere(
2259 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2260 NetLog::PHASE_NONE);
2261 ExpectLogContainsSomewhere(
2262 entries, pos,
2263 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2264 NetLog::PHASE_NONE);
2265
2266 const HttpResponseInfo* response = trans->GetResponseInfo();
2267 ASSERT_TRUE(response != NULL);
2268 ASSERT_FALSE(response->headers == NULL);
2269 EXPECT_EQ(407, response->headers->response_code());
2270 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2271 EXPECT_TRUE(response->auth_challenge.get() != NULL);
2272 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2273
2274 TestOldCompletionCallback callback2;
2275
2276 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
2277 EXPECT_EQ(ERR_IO_PENDING, rv);
2278
2279 rv = callback2.WaitForResult();
2280 EXPECT_EQ(OK, rv);
2281
2282 response = trans->GetResponseInfo();
2283 ASSERT_TRUE(response != NULL);
2284
2285 EXPECT_TRUE(response->headers->IsKeepAlive());
2286 EXPECT_EQ(200, response->headers->response_code());
2287 EXPECT_EQ(5, response->headers->GetContentLength());
2288 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2289
2290 // The password prompt info should not be set.
2291 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2292
2293 trans.reset();
2294 session->CloseAllConnections();
2295 }
2296
1928 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 2297 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
1929 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 2298 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
1930 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 2299 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
1931 HttpRequestInfo request; 2300 HttpRequestInfo request;
1932 request.method = "GET"; 2301 request.method = "GET";
1933 request.url = GURL("http://www.google.com/"); 2302 request.url = GURL("http://www.google.com/");
1934 request.load_flags = 0; 2303 request.load_flags = 0;
1935 2304
1936 // We are using a DIRECT connection (i.e. no proxy) for this session. 2305 // We are using a DIRECT connection (i.e. no proxy) for this session.
1937 SessionDependencies session_deps; 2306 SessionDependencies session_deps;
(...skipping 5370 matching lines...) Expand 10 before | Expand all | Expand 10 after
7308 } 7677 }
7309 7678
7310 // GenerateAuthToken is a mighty big test. 7679 // GenerateAuthToken is a mighty big test.
7311 // It tests all permutation of GenerateAuthToken behavior: 7680 // It tests all permutation of GenerateAuthToken behavior:
7312 // - Synchronous and Asynchronous completion. 7681 // - Synchronous and Asynchronous completion.
7313 // - OK or error on completion. 7682 // - OK or error on completion.
7314 // - Direct connection, non-authenticating proxy, and authenticating proxy. 7683 // - Direct connection, non-authenticating proxy, and authenticating proxy.
7315 // - HTTP or HTTPS backend (to include proxy tunneling). 7684 // - HTTP or HTTPS backend (to include proxy tunneling).
7316 // - Non-authenticating and authenticating backend. 7685 // - Non-authenticating and authenticating backend.
7317 // 7686 //
7318 // In all, there are 44 reasonable permuations (for example, if there are 7687 // In all, there are 44 reasonable permutations (for example, if there are
7319 // problems generating an auth token for an authenticating proxy, we don't 7688 // problems generating an auth token for an authenticating proxy, we don't
7320 // need to test all permutations of the backend server). 7689 // need to test all permutations of the backend server).
7321 // 7690 //
7322 // The test proceeds by going over each of the configuration cases, and 7691 // The test proceeds by going over each of the configuration cases, and
7323 // potentially running up to three rounds in each of the tests. The TestConfig 7692 // potentially running up to three rounds in each of the tests. The TestConfig
7324 // specifies both the configuration for the test as well as the expectations 7693 // specifies both the configuration for the test as well as the expectations
7325 // for the results. 7694 // for the results.
7326 TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { 7695 TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) {
7327 static const char kServer[] = "http://www.example.com"; 7696 static const char kServer[] = "http://www.example.com";
7328 static const char kSecureServer[] = "https://www.example.com"; 7697 static const char kSecureServer[] = "https://www.example.com";
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
8125 TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { 8494 TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) {
8126 // This test ensures that the URL passed into the proxy is upgraded 8495 // This test ensures that the URL passed into the proxy is upgraded
8127 // to https when doing an Alternate Protocol upgrade. 8496 // to https when doing an Alternate Protocol upgrade.
8128 HttpStreamFactory::set_use_alternate_protocols(true); 8497 HttpStreamFactory::set_use_alternate_protocols(true);
8129 HttpStreamFactory::set_next_protos( 8498 HttpStreamFactory::set_next_protos(
8130 MakeNextProtos("http/1.1", "http1.1", "spdy/2", "spdy", NULL)); 8499 MakeNextProtos("http/1.1", "http1.1", "spdy/2", "spdy", NULL));
8131 8500
8132 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 8501 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
8133 HttpAuthHandlerMock::Factory* auth_factory = 8502 HttpAuthHandlerMock::Factory* auth_factory =
8134 new HttpAuthHandlerMock::Factory(); 8503 new HttpAuthHandlerMock::Factory();
8135 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); 8504 HttpAuthHandlerMock* auth_handler1 = new HttpAuthHandlerMock();
8136 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); 8505 auth_factory->AddMockHandler(auth_handler1, HttpAuth::AUTH_PROXY);
8506 HttpAuthHandlerMock* auth_handler2 = new HttpAuthHandlerMock();
8507 auth_factory->AddMockHandler(auth_handler2, HttpAuth::AUTH_PROXY);
8137 auth_factory->set_do_init_from_challenge(true); 8508 auth_factory->set_do_init_from_challenge(true);
8138 session_deps.http_auth_handler_factory.reset(auth_factory); 8509 session_deps.http_auth_handler_factory.reset(auth_factory);
8139 8510
8140 HttpRequestInfo request; 8511 HttpRequestInfo request;
8141 request.method = "GET"; 8512 request.method = "GET";
8142 request.url = GURL("http://www.google.com"); 8513 request.url = GURL("http://www.google.com");
8143 request.load_flags = 0; 8514 request.load_flags = 0;
8144 8515
8145 // First round goes unauthenticated through the proxy. 8516 // First round goes unauthenticated through the proxy.
8146 MockWrite data_writes_1[] = { 8517 MockWrite data_writes_1[] = {
(...skipping 11 matching lines...) Expand all
8158 }; 8529 };
8159 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), 8530 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1),
8160 data_writes_1, arraysize(data_writes_1)); 8531 data_writes_1, arraysize(data_writes_1));
8161 8532
8162 // Second round tries to tunnel to www.google.com due to the 8533 // Second round tries to tunnel to www.google.com due to the
8163 // Alternate-Protocol announcement in the first round. It fails due 8534 // Alternate-Protocol announcement in the first round. It fails due
8164 // to a proxy authentication challenge. 8535 // to a proxy authentication challenge.
8165 // After the failure, a tunnel is established to www.google.com using 8536 // After the failure, a tunnel is established to www.google.com using
8166 // Proxy-Authorization headers. There is then a SPDY request round. 8537 // Proxy-Authorization headers. There is then a SPDY request round.
8167 // 8538 //
8168 // NOTE: Despite the "Proxy-Connection: Close", these are done on the
8169 // same MockTCPClientSocket since the underlying HttpNetworkClientSocket
8170 // does a Disconnect and Connect on the same socket, rather than trying
8171 // to obtain a new one.
8172 //
8173 // NOTE: Originally, the proxy response to the second CONNECT request 8539 // NOTE: Originally, the proxy response to the second CONNECT request
8174 // simply returned another 407 so the unit test could skip the SSL connection 8540 // simply returned another 407 so the unit test could skip the SSL connection
8175 // establishment and SPDY framing issues. Alas, the 8541 // establishment and SPDY framing issues. Alas, the
8176 // retry-http-when-alternate-protocol fails logic kicks in, which was more 8542 // retry-http-when-alternate-protocol fails logic kicks in, which was more
8177 // complicated to set up expectations for than the SPDY session. 8543 // complicated to set up expectations for than the SPDY session.
8178 8544
8179 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 8545 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
8180 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 8546 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
8181 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); 8547 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true));
8182 8548
8183 MockWrite data_writes_2[] = { 8549 MockWrite data_writes_2[] = {
8184 // First connection attempt without Proxy-Authorization. 8550 // First connection attempt without Proxy-Authorization.
8185 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 8551 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
8186 "Host: www.google.com\r\n" 8552 "Host: www.google.com\r\n"
8187 "Proxy-Connection: keep-alive\r\n" 8553 "Proxy-Connection: keep-alive\r\n"
8188 "\r\n"), 8554 "\r\n"),
8555 };
8189 8556
8557 MockWrite data_writes_3[] = {
8558 // Non-alternate protocol job that will run in parallel
8559 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
8560 "Host: www.google.com\r\n"
8561 "Proxy-Connection: keep-alive\r\n"
8562 "\r\n"),
8563 };
8564
8565 MockWrite data_writes_4[] = {
8190 // Second connection attempt with Proxy-Authorization. 8566 // Second connection attempt with Proxy-Authorization.
8191 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 8567 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
8192 "Host: www.google.com\r\n" 8568 "Host: www.google.com\r\n"
8193 "Proxy-Connection: keep-alive\r\n" 8569 "Proxy-Connection: keep-alive\r\n"
8194 "Proxy-Authorization: auth_token\r\n" 8570 "Proxy-Authorization: auth_token\r\n"
8195 "\r\n"), 8571 "\r\n"),
8196 8572
8197 // SPDY request 8573 // SPDY request
8198 CreateMockWrite(*req), 8574 CreateMockWrite(*req),
8199 }; 8575 };
8200 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" 8576 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n"
8201 "Proxy-Authenticate: Mock\r\n" 8577 "Proxy-Authenticate: Mock\r\n"
8202 "Proxy-Connection: close\r\n" 8578 "Proxy-Connection: close\r\n"
8579 "Content-Length: 0\r\n"
8203 "\r\n"); 8580 "\r\n");
8204 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; 8581 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
8205 MockRead data_reads_2[] = { 8582 MockRead data_reads_2[] = {
8206 // First connection attempt fails 8583 // First connection attempt fails
8207 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), 8584 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1),
8208 MockRead(true, kRejectConnectResponse, 8585 MockRead(true, kRejectConnectResponse,
8209 arraysize(kRejectConnectResponse) - 1, 1), 8586 arraysize(kRejectConnectResponse) - 1, 1),
8587 };
8210 8588
8589 // Hang forever so we can ensure the alt job wins
8590 MockRead data_reads_3[] = {
8591 MockRead(false, ERR_IO_PENDING),
8592 };
8593
8594 MockRead data_reads_4[] = {
8211 // Second connection attempt passes 8595 // Second connection attempt passes
8212 MockRead(true, kAcceptConnectResponse, 8596 MockRead(true, kAcceptConnectResponse,
8213 arraysize(kAcceptConnectResponse) -1, 4), 8597 arraysize(kAcceptConnectResponse) -1, 1),
8214 8598
8215 // SPDY response 8599 // SPDY response
8216 CreateMockRead(*resp.get(), 6), 8600 CreateMockRead(*resp.get(), 3),
8217 CreateMockRead(*data.get(), 6), 8601 CreateMockRead(*data.get(), 3),
8218 MockRead(true, 0, 0, 6), 8602 MockRead(true, 0, 0, 4),
8219 }; 8603 };
8220 scoped_refptr<OrderedSocketData> data_2( 8604 scoped_refptr<OrderedSocketData> data_2(
8221 new OrderedSocketData(data_reads_2, arraysize(data_reads_2), 8605 new OrderedSocketData(data_reads_2, arraysize(data_reads_2),
8222 data_writes_2, arraysize(data_writes_2))); 8606 data_writes_2, arraysize(data_writes_2)));
8607 scoped_refptr<OrderedSocketData> data_3(
8608 new OrderedSocketData(data_reads_3, arraysize(data_reads_3),
8609 data_writes_3, arraysize(data_writes_3)));
8610 // Hang forever so we can ensure the alt job wins
8611 MockConnect conn_3(false, ERR_IO_PENDING);
8612 data_3->set_connect_data(conn_3);
8613 scoped_refptr<OrderedSocketData> data_4(
8614 new OrderedSocketData(data_reads_4, arraysize(data_reads_4),
8615 data_writes_4, arraysize(data_writes_4)));
8223 8616
8224 SSLSocketDataProvider ssl(true, OK); 8617 SSLSocketDataProvider ssl(true, OK);
8225 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; 8618 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
8226 ssl.next_proto = "spdy/2"; 8619 ssl.next_proto = "spdy/2";
8227 ssl.was_npn_negotiated = true; 8620 ssl.was_npn_negotiated = true;
8228 8621
8229 MockConnect never_finishing_connect(false, ERR_IO_PENDING); 8622 MockConnect never_finishing_connect(false, ERR_IO_PENDING);
8230 StaticSocketDataProvider hanging_non_alternate_protocol_socket( 8623 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
8231 NULL, 0, NULL, 0); 8624 NULL, 0, NULL, 0);
8232 hanging_non_alternate_protocol_socket.set_connect_data( 8625 hanging_non_alternate_protocol_socket.set_connect_data(
8233 never_finishing_connect); 8626 never_finishing_connect);
8234 8627
8235 session_deps.socket_factory.AddSocketDataProvider(&data_1); 8628 session_deps.socket_factory.AddSocketDataProvider(&data_1);
8236 session_deps.socket_factory.AddSocketDataProvider(data_2.get()); 8629 session_deps.socket_factory.AddSocketDataProvider(data_2.get());
8630 session_deps.socket_factory.AddSocketDataProvider(data_3.get());
8631 session_deps.socket_factory.AddSocketDataProvider(data_4.get());
8632 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
8237 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); 8633 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
8238 session_deps.socket_factory.AddSocketDataProvider( 8634 session_deps.socket_factory.AddSocketDataProvider(
8239 &hanging_non_alternate_protocol_socket); 8635 &hanging_non_alternate_protocol_socket);
8240 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 8636 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
8241 8637
8242 // First round should work and provide the Alternate-Protocol state. 8638 // First round should work and provide the Alternate-Protocol state.
8243 TestOldCompletionCallback callback_1; 8639 TestOldCompletionCallback callback_1;
8244 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session)); 8640 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session));
8245 int rv = trans_1->Start(&request, &callback_1, BoundNetLog()); 8641 int rv = trans_1->Start(&request, &callback_1, BoundNetLog());
8246 EXPECT_EQ(ERR_IO_PENDING, rv); 8642 EXPECT_EQ(ERR_IO_PENDING, rv);
(...skipping 10 matching lines...) Expand all
8257 ASSERT_FALSE(response->auth_challenge.get() == NULL); 8653 ASSERT_FALSE(response->auth_challenge.get() == NULL);
8258 8654
8259 // Restart with auth. Tunnel should work and response received. 8655 // Restart with auth. Tunnel should work and response received.
8260 TestOldCompletionCallback callback_3; 8656 TestOldCompletionCallback callback_3;
8261 rv = trans_2->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback_3); 8657 rv = trans_2->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback_3);
8262 EXPECT_EQ(ERR_IO_PENDING, rv); 8658 EXPECT_EQ(ERR_IO_PENDING, rv);
8263 EXPECT_EQ(OK, callback_3.WaitForResult()); 8659 EXPECT_EQ(OK, callback_3.WaitForResult());
8264 8660
8265 // After all that work, these two lines (or actually, just the scheme) are 8661 // After all that work, these two lines (or actually, just the scheme) are
8266 // what this test is all about. Make sure it happens correctly. 8662 // what this test is all about. Make sure it happens correctly.
8267 const GURL& request_url = auth_handler->request_url(); 8663 const GURL& request_url = auth_handler2->request_url();
8268 EXPECT_EQ("https", request_url.scheme()); 8664 EXPECT_EQ("https", request_url.scheme());
8269 EXPECT_EQ("www.google.com", request_url.host()); 8665 EXPECT_EQ("www.google.com", request_url.host());
8270 8666
8271 HttpStreamFactory::set_next_protos(std::vector<std::string>()); 8667 HttpStreamFactory::set_next_protos(std::vector<std::string>());
8272 HttpStreamFactory::set_use_alternate_protocols(false); 8668 HttpStreamFactory::set_use_alternate_protocols(false);
8273 } 8669 }
8274 8670
8275 // Test that if we cancel the transaction as the connection is completing, that 8671 // Test that if we cancel the transaction as the connection is completing, that
8276 // everything tears down correctly. 8672 // everything tears down correctly.
8277 TEST_F(HttpNetworkTransactionTest, SimpleCancel) { 8673 TEST_F(HttpNetworkTransactionTest, SimpleCancel) {
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
9222 StaticSocketDataProvider* data[] = { &data1, &data2 }; 9618 StaticSocketDataProvider* data[] = { &data1, &data2 };
9223 9619
9224 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); 9620 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
9225 9621
9226 EXPECT_EQ(OK, out.rv); 9622 EXPECT_EQ(OK, out.rv);
9227 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 9623 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
9228 EXPECT_EQ("hello world", out.response_data); 9624 EXPECT_EQ("hello world", out.response_data);
9229 } 9625 }
9230 9626
9231 } // namespace net 9627 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket.h » ('j') | net/spdy/spdy_proxy_client_socket.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698