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

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

Issue 9148011: Allow chrome to handle 407 auth challenges to CONNECT requests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months 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
« no previous file with comments | « net/base/net_error_list.h ('k') | net/http/http_proxy_client_socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { 414 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) {
415 if (!auth_challenge) 415 if (!auth_challenge)
416 return false; 416 return false;
417 EXPECT_FALSE(auth_challenge->is_proxy); 417 EXPECT_FALSE(auth_challenge->is_proxy);
418 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); 418 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString());
419 EXPECT_EQ(std::string(), auth_challenge->realm); 419 EXPECT_EQ(std::string(), auth_challenge->realm);
420 EXPECT_EQ("ntlm", auth_challenge->scheme); 420 EXPECT_EQ("ntlm", auth_challenge->scheme);
421 return true; 421 return true;
422 } 422 }
423 423
424 bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) {
425 if (!auth_challenge)
426 return false;
427 EXPECT_TRUE(auth_challenge->is_proxy);
428 EXPECT_EQ("proxy:70", auth_challenge->challenger.ToString());
429 EXPECT_EQ(std::string(), auth_challenge->realm);
430 EXPECT_EQ("ntlm", auth_challenge->scheme);
431 return true;
432 }
433
424 TEST_F(HttpNetworkTransactionTest, Basic) { 434 TEST_F(HttpNetworkTransactionTest, Basic) {
425 SessionDependencies session_deps; 435 SessionDependencies session_deps;
426 scoped_ptr<HttpTransaction> trans( 436 scoped_ptr<HttpTransaction> trans(
427 new HttpNetworkTransaction(CreateSession(&session_deps))); 437 new HttpNetworkTransaction(CreateSession(&session_deps)));
428 } 438 }
429 439
430 TEST_F(HttpNetworkTransactionTest, SimpleGET) { 440 TEST_F(HttpNetworkTransactionTest, SimpleGET) {
431 MockRead data_reads[] = { 441 MockRead data_reads[] = {
432 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 442 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
433 MockRead("hello world"), 443 MockRead("hello world"),
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1721 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1712 session_deps.net_log = log.bound().net_log(); 1722 session_deps.net_log = log.bound().net_log();
1713 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1723 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1714 1724
1715 // Since we have proxy, should try to establish tunnel. 1725 // Since we have proxy, should try to establish tunnel.
1716 MockWrite data_writes1[] = { 1726 MockWrite data_writes1[] = {
1717 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1727 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1718 "Host: www.google.com\r\n" 1728 "Host: www.google.com\r\n"
1719 "Proxy-Connection: keep-alive\r\n\r\n"), 1729 "Proxy-Connection: keep-alive\r\n\r\n"),
1720 1730
1731 };
1732
1733 MockWrite data_writes2[] = {
1721 // After calling trans->RestartWithAuth(), this is the request we should 1734 // After calling trans->RestartWithAuth(), this is the request we should
1722 // be issuing -- the final header line contains the credentials. 1735 // be issuing -- the final header line contains the credentials.
1723 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1736 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1724 "Host: www.google.com\r\n" 1737 "Host: www.google.com\r\n"
1725 "Proxy-Connection: keep-alive\r\n" 1738 "Proxy-Connection: keep-alive\r\n"
1726 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), 1739 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
1727 1740
1728 MockWrite("GET / HTTP/1.1\r\n" 1741 MockWrite("GET / HTTP/1.1\r\n"
1729 "Host: www.google.com\r\n" 1742 "Host: www.google.com\r\n"
1730 "Connection: keep-alive\r\n\r\n"), 1743 "Connection: keep-alive\r\n\r\n"),
1731 }; 1744 };
1732 1745
1733 // The proxy responds to the connect with a 407, using a persistent 1746 // The proxy responds to the connect with a 407, using a persistent
1734 // connection. 1747 // connection.
1735 MockRead data_reads1[] = { 1748 MockRead data_reads1[] = {
1736 // No credentials. 1749 // No credentials.
1737 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 1750 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
1738 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 1751 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1739 MockRead("Proxy-Connection: close\r\n\r\n"), 1752 MockRead("Proxy-Connection: close\r\n\r\n"),
1753 };
1740 1754
1755 MockRead data_reads2[] = {
1741 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), 1756 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
1742 1757
1743 MockRead("HTTP/1.1 200 OK\r\n"), 1758 MockRead("HTTP/1.1 200 OK\r\n"),
1744 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 1759 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1745 MockRead("Content-Length: 5\r\n\r\n"), 1760 MockRead("Content-Length: 5\r\n\r\n"),
1746 MockRead(false, "hello"), 1761 MockRead(false, "hello"),
1747 }; 1762 };
1748 1763
1749 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), 1764 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1750 data_writes1, arraysize(data_writes1)); 1765 data_writes1, arraysize(data_writes1));
1766 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
1767 data_writes2, arraysize(data_writes2));
1751 session_deps.socket_factory.AddSocketDataProvider(&data1); 1768 session_deps.socket_factory.AddSocketDataProvider(&data1);
1769 session_deps.socket_factory.AddSocketDataProvider(&data2);
1752 SSLSocketDataProvider ssl(true, OK); 1770 SSLSocketDataProvider ssl(true, OK);
1753 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); 1771 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
1754 1772
1755 TestCompletionCallback callback1; 1773 TestCompletionCallback callback1;
1756 1774
1757 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 1775 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
1758 1776
1759 int rv = trans->Start(&request, callback1.callback(), log.bound()); 1777 int rv = trans->Start(&request, callback1.callback(), log.bound());
1760 EXPECT_EQ(ERR_IO_PENDING, rv); 1778 EXPECT_EQ(ERR_IO_PENDING, rv);
1761 1779
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 1974 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1957 1975
1958 std::string response_data; 1976 std::string response_data;
1959 rv = ReadTransaction(trans.get(), &response_data); 1977 rv = ReadTransaction(trans.get(), &response_data);
1960 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 1978 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
1961 1979
1962 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 1980 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
1963 session->CloseAllConnections(); 1981 session->CloseAllConnections();
1964 } 1982 }
1965 1983
1984 // Test the request-challenge-retry sequence for basic auth, over a connection
1985 // that requires a restart when setting up an SSL tunnel.
1986 TEST_F(HttpNetworkTransactionTest, BasicAuthHttpsProxyNoKeepAlive) {
1987 HttpRequestInfo request;
1988 request.method = "GET";
1989 request.url = GURL("https://www.google.com/");
1990 // when the no authentication data flag is set.
1991 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1992
1993 // Configure against https proxy server "myproxy:70".
1994 SessionDependencies session_deps(
1995 ProxyService::CreateFixed("https://myproxy:70"));
1996 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1997 session_deps.net_log = log.bound().net_log();
1998 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1999
2000 // Since we have proxy, should try to establish tunnel.
2001 MockWrite data_writes1[] = {
2002 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2003 "Host: www.google.com\r\n"
2004 "Proxy-Connection: keep-alive\r\n\r\n"),
2005 };
2006
2007 MockWrite data_writes2[] = {
2008 // After calling trans->RestartWithAuth(), this is the request we should
2009 // be issuing -- the final header line contains the credentials.
2010 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2011 "Host: www.google.com\r\n"
2012 "Proxy-Connection: keep-alive\r\n"
2013 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2014
2015 MockWrite("GET / HTTP/1.1\r\n"
2016 "Host: www.google.com\r\n"
2017 "Connection: keep-alive\r\n\r\n"),
2018 };
2019
2020 // The proxy responds to the connect with a 407, using a persistent
2021 // connection.
2022 MockRead data_reads1[] = {
2023 // No credentials.
2024 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2025 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2026 MockRead("Proxy-Connection: close\r\n\r\n"),
2027 };
2028
2029 MockRead data_reads2[] = {
2030 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2031
2032 MockRead("HTTP/1.1 200 OK\r\n"),
2033 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2034 MockRead("Content-Length: 5\r\n\r\n"),
2035 MockRead(false, "hello"),
2036 };
2037
2038 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2039 data_writes1, arraysize(data_writes1));
2040 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2041 data_writes2, arraysize(data_writes2));
2042 session_deps.socket_factory.AddSocketDataProvider(&data1);
2043 session_deps.socket_factory.AddSocketDataProvider(&data2);
2044 SSLSocketDataProvider proxy(true, OK);
2045 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy);
2046 SSLSocketDataProvider proxy2(true, OK);
2047 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy2);
2048 SSLSocketDataProvider server(true, OK);
2049 session_deps.socket_factory.AddSSLSocketDataProvider(&server);
2050
2051 TestCompletionCallback callback1;
2052
2053 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2054
2055 int rv = trans->Start(&request, callback1.callback(), log.bound());
2056 EXPECT_EQ(ERR_IO_PENDING, rv);
2057
2058 rv = callback1.WaitForResult();
2059 EXPECT_EQ(OK, rv);
2060 net::CapturingNetLog::EntryList entries;
2061 log.GetEntries(&entries);
2062 size_t pos = ExpectLogContainsSomewhere(
2063 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2064 NetLog::PHASE_NONE);
2065 ExpectLogContainsSomewhere(
2066 entries, pos,
2067 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2068 NetLog::PHASE_NONE);
2069
2070 const HttpResponseInfo* response = trans->GetResponseInfo();
2071 ASSERT_TRUE(response != NULL);
2072 ASSERT_FALSE(response->headers == NULL);
2073 EXPECT_EQ(407, response->headers->response_code());
2074 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2075 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2076
2077 TestCompletionCallback callback2;
2078
2079 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar),
2080 callback2.callback());
2081 EXPECT_EQ(ERR_IO_PENDING, rv);
2082
2083 rv = callback2.WaitForResult();
2084 EXPECT_EQ(OK, rv);
2085
2086 response = trans->GetResponseInfo();
2087 ASSERT_TRUE(response != NULL);
2088
2089 EXPECT_TRUE(response->headers->IsKeepAlive());
2090 EXPECT_EQ(200, response->headers->response_code());
2091 EXPECT_EQ(5, response->headers->GetContentLength());
2092 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2093
2094 // The password prompt info should not be set.
2095 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2096
2097 trans.reset();
2098 session->CloseAllConnections();
2099 }
2100
2101 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
2102 // proxy connection, when setting up an SSL tunnel.
2103 TEST_F(HttpNetworkTransactionTest, BasicAuthHttpsProxyKeepAlive) {
2104 HttpRequestInfo request;
2105 request.method = "GET";
2106 request.url = GURL("https://www.google.com/");
2107 // Ensure that proxy authentication is attempted even
2108 // when the no authentication data flag is set.
2109 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2110
2111 // Configure against https proxy server "myproxy:70".
2112 SessionDependencies session_deps(
2113 ProxyService::CreateFixed("https://myproxy:70"));
2114 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2115 session_deps.net_log = log.bound().net_log();
2116 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2117
2118 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2119
2120 // Since we have proxy, should try to establish tunnel.
2121 MockWrite data_writes1[] = {
2122 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2123 "Host: www.google.com\r\n"
2124 "Proxy-Connection: keep-alive\r\n\r\n"),
2125
2126 // After calling trans->RestartWithAuth(), this is the request we should
2127 // be issuing -- the final header line contains the credentials.
2128 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2129 "Host: www.google.com\r\n"
2130 "Proxy-Connection: keep-alive\r\n"
2131 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
2132 };
2133
2134 // The proxy responds to the connect with a 407, using a persistent
2135 // connection.
2136 MockRead data_reads1[] = {
2137 // No credentials.
2138 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2139 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2140 MockRead("Content-Length: 10\r\n\r\n"),
2141 MockRead("0123456789"),
2142
2143 // Wrong credentials (wrong password).
2144 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2145 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2146 MockRead("Content-Length: 10\r\n\r\n"),
2147 // No response body because the test stops reading here.
2148 MockRead(false, ERR_UNEXPECTED), // Should not be reached.
2149 };
2150
2151 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2152 data_writes1, arraysize(data_writes1));
2153 session_deps.socket_factory.AddSocketDataProvider(&data1);
2154 SSLSocketDataProvider ssl(true, OK);
2155 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
2156
2157 TestCompletionCallback callback1;
2158
2159 int rv = trans->Start(&request, callback1.callback(), log.bound());
2160 EXPECT_EQ(ERR_IO_PENDING, rv);
2161
2162 rv = callback1.WaitForResult();
2163 EXPECT_EQ(OK, rv);
2164 net::CapturingNetLog::EntryList entries;
2165 log.GetEntries(&entries);
2166 size_t pos = ExpectLogContainsSomewhere(
2167 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2168 NetLog::PHASE_NONE);
2169 ExpectLogContainsSomewhere(
2170 entries, pos,
2171 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2172 NetLog::PHASE_NONE);
2173
2174 const HttpResponseInfo* response = trans->GetResponseInfo();
2175 ASSERT_TRUE(response != NULL);
2176 ASSERT_FALSE(response->headers == NULL);
2177 EXPECT_TRUE(response->headers->IsKeepAlive());
2178 EXPECT_EQ(407, response->headers->response_code());
2179 EXPECT_EQ(10, response->headers->GetContentLength());
2180 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2181 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2182
2183 TestCompletionCallback callback2;
2184
2185 // Wrong password (should be "bar").
2186 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz),
2187 callback2.callback());
2188 EXPECT_EQ(ERR_IO_PENDING, rv);
2189
2190 rv = callback2.WaitForResult();
2191 EXPECT_EQ(OK, rv);
2192
2193 response = trans->GetResponseInfo();
2194 ASSERT_TRUE(response != NULL);
2195 ASSERT_FALSE(response->headers == NULL);
2196 EXPECT_TRUE(response->headers->IsKeepAlive());
2197 EXPECT_EQ(407, response->headers->response_code());
2198 EXPECT_EQ(10, response->headers->GetContentLength());
2199 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2200 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2201
2202 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
2203 // out of scope.
2204 session->CloseAllConnections();
2205 }
2206
2207 // Test the request-challenge-retry sequence for basic auth, through
2208 // a SPDY proxy over a single SPDY session.
2209 TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) {
2210 HttpRequestInfo request;
2211 request.method = "GET";
2212 request.url = GURL("https://www.google.com/");
2213 // when the no authentication data flag is set.
2214 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2215
2216 // Configure against https proxy server "myproxy:70".
2217 SessionDependencies session_deps(
2218 ProxyService::CreateFixed("https://myproxy:70"));
2219 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2220 session_deps.net_log = log.bound().net_log();
2221 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2222
2223 // Since we have proxy, should try to establish tunnel.
2224 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyConnect(NULL, 0, 1));
2225 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL));
2226
2227 // After calling trans->RestartWithAuth(), this is the request we should
2228 // be issuing -- the final header line contains the credentials.
2229 const char* const kAuthCredentials[] = {
2230 "proxy-authorization", "Basic Zm9vOmJhcg==",
2231 };
2232 scoped_ptr<spdy::SpdyFrame> connect2(
2233 ConstructSpdyConnect(kAuthCredentials, arraysize(kAuthCredentials)/2, 3));
2234 // fetch https://www.google.com/ via HTTP
2235 const char get[] = "GET / HTTP/1.1\r\n"
2236 "Host: www.google.com\r\n"
2237 "Connection: keep-alive\r\n\r\n";
2238 scoped_ptr<spdy::SpdyFrame> wrapped_get(
2239 ConstructSpdyBodyFrame(3, get, strlen(get), false));
2240
2241 MockWrite spdy_writes[] = {
2242 CreateMockWrite(*req, 0, true),
2243 CreateMockWrite(*rst, 2, true),
2244 CreateMockWrite(*connect2, 3),
2245 CreateMockWrite(*wrapped_get, 5)
2246 };
2247
2248 // The proxy responds to the connect with a 407, using a persistent
2249 // connection.
2250 const char* const kAuthChallenge[] = {
2251 "status", "407 Proxy Authentication Required",
2252 "version", "HTTP/1.1",
2253 "proxy-authenticate", "Basic realm=\"MyRealm1\"",
2254 };
2255
2256 scoped_ptr<spdy::SpdyFrame> conn_auth_resp(
2257 ConstructSpdyControlFrame(NULL,
2258 0,
2259 false,
2260 1,
2261 LOWEST,
2262 spdy::SYN_REPLY,
2263 spdy::CONTROL_FLAG_NONE,
2264 kAuthChallenge,
2265 arraysize(kAuthChallenge)));
2266
2267 scoped_ptr<spdy::SpdyFrame> conn_resp(ConstructSpdyGetSynReply(NULL, 0, 3));
2268 const char resp[] = "HTTP/1.1 200 OK\r\n"
2269 "Content-Length: 5\r\n\r\n";
2270
2271 scoped_ptr<spdy::SpdyFrame> wrapped_get_resp(
2272 ConstructSpdyBodyFrame(3, resp, strlen(resp), false));
2273 scoped_ptr<spdy::SpdyFrame> wrapped_body(
2274 ConstructSpdyBodyFrame(3, "hello", 5, false));
2275 MockRead spdy_reads[] = {
2276 CreateMockRead(*conn_auth_resp, 1, true),
2277 CreateMockRead(*conn_resp, 4, true),
2278 CreateMockRead(*wrapped_get_resp, 5, true),
2279 CreateMockRead(*wrapped_body, 6, true),
2280 MockRead(false, ERR_IO_PENDING),
2281 };
2282
2283 scoped_ptr<OrderedSocketData> spdy_data(
2284 new OrderedSocketData(
2285 spdy_reads, arraysize(spdy_reads),
2286 spdy_writes, arraysize(spdy_writes)));
2287 session_deps.socket_factory.AddSocketDataProvider(spdy_data.get());
2288 // Negotiate SPDY to the proxy
2289 SSLSocketDataProvider proxy(true, OK);
2290 proxy.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
2291 proxy.next_proto = "spdy/2";
2292 proxy.was_npn_negotiated = true;
2293 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy);
2294 // Vanilla SSL to the server
2295 SSLSocketDataProvider server(true, OK);
2296 session_deps.socket_factory.AddSSLSocketDataProvider(&server);
2297
2298 TestCompletionCallback callback1;
2299
2300 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2301
2302 int rv = trans->Start(&request, callback1.callback(), log.bound());
2303 EXPECT_EQ(ERR_IO_PENDING, rv);
2304
2305 rv = callback1.WaitForResult();
2306 EXPECT_EQ(OK, rv);
2307 net::CapturingNetLog::EntryList entries;
2308 log.GetEntries(&entries);
2309 size_t pos = ExpectLogContainsSomewhere(
2310 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2311 NetLog::PHASE_NONE);
2312 ExpectLogContainsSomewhere(
2313 entries, pos,
2314 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2315 NetLog::PHASE_NONE);
2316
2317 const HttpResponseInfo* response = trans->GetResponseInfo();
2318 ASSERT_TRUE(response != NULL);
2319 ASSERT_FALSE(response->headers == NULL);
2320 EXPECT_EQ(407, response->headers->response_code());
2321 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2322 EXPECT_TRUE(response->auth_challenge.get() != NULL);
2323 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2324
2325 TestCompletionCallback callback2;
2326
2327 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar),
2328 callback2.callback());
2329 EXPECT_EQ(ERR_IO_PENDING, rv);
2330
2331 rv = callback2.WaitForResult();
2332 EXPECT_EQ(OK, rv);
2333
2334 response = trans->GetResponseInfo();
2335 ASSERT_TRUE(response != NULL);
2336
2337 EXPECT_TRUE(response->headers->IsKeepAlive());
2338 EXPECT_EQ(200, response->headers->response_code());
2339 EXPECT_EQ(5, response->headers->GetContentLength());
2340 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2341
2342 // The password prompt info should not be set.
2343 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2344
2345 trans.reset();
2346 session->CloseAllConnections();
2347 }
2348
2349
1966 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 2350 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
1967 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 2351 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
1968 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 2352 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
1969 HttpRequestInfo request; 2353 HttpRequestInfo request;
1970 request.method = "GET"; 2354 request.method = "GET";
1971 request.url = GURL("http://www.google.com/"); 2355 request.url = GURL("http://www.google.com/");
1972 request.load_flags = 0; 2356 request.load_flags = 0;
1973 2357
1974 // We are using a DIRECT connection (i.e. no proxy) for this session. 2358 // We are using a DIRECT connection (i.e. no proxy) for this session.
1975 SessionDependencies session_deps; 2359 SessionDependencies session_deps;
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
3058 3442
3059 rv = callback3.WaitForResult(); 3443 rv = callback3.WaitForResult();
3060 EXPECT_EQ(OK, rv); 3444 EXPECT_EQ(OK, rv);
3061 3445
3062 response = trans->GetResponseInfo(); 3446 response = trans->GetResponseInfo();
3063 ASSERT_TRUE(response != NULL); 3447 ASSERT_TRUE(response != NULL);
3064 EXPECT_TRUE(response->auth_challenge.get() == NULL); 3448 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3065 EXPECT_EQ(13, response->headers->GetContentLength()); 3449 EXPECT_EQ(13, response->headers->GetContentLength());
3066 } 3450 }
3067 3451
3452
3453 // Enter the correct password and authenticate successfully.
3454 TEST_F(HttpNetworkTransactionTest, NTLMProxyAuthWithConnectTunnel) {
3455 HttpRequestInfo request;
3456 request.method = "GET";
3457 request.url = GURL("https://www.google.com/");
3458 request.load_flags = 0;
3459
3460 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1,
3461 MockGetHostName);
3462 SessionDependencies session_deps(ProxyService::CreateFixed(
3463 "https://proxy:70"));
3464
3465 MockWrite data_writes1[] = {
3466 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
3467 "Host: www.google.com\r\n"
3468 "Proxy-Connection: keep-alive\r\n\r\n"),
3469 };
3470
3471 MockRead data_reads1[] = {
3472 MockRead("HTTP/1.1 407 Access Denied\r\n"),
3473 // Negotiate and NTLM are often requested together. However, we only want
3474 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip
3475 // the header that requests Negotiate for this test.
3476 MockRead("Proxy-Authenticate: NTLM\r\n"),
3477 MockRead("Connection: close\r\n"),
3478 MockRead("Content-Length: 42\r\n"),
3479 MockRead("Content-Type: text/html\r\n\r\n"),
3480 // Missing content -- won't matter, as connection will be reset.
3481 MockRead(false, ERR_UNEXPECTED),
3482 };
3483
3484 MockWrite data_writes2[] = {
3485 // After restarting with a null identity, this is the
3486 // request we should be issuing -- the final header line contains a Type
3487 // 1 message.
3488 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
3489 "Host: www.google.com\r\n"
3490 "Proxy-Connection: keep-alive\r\n"
3491 "Proxy-Authorization: NTLM "
3492 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
3493
3494 // After calling trans->RestartWithAuth(), we should send a Type 3 message
3495 // (the credentials for the origin server). The second request continues
3496 // on the same connection.
3497 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
3498 "Host: www.google.com\r\n"
3499 "Proxy-Connection: keep-alive\r\n"
3500 "Proxy-Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA"
3501 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA"
3502 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW"
3503 "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX"
3504 "ahlhx5I=\r\n\r\n"),
3505
3506 MockWrite("GET / HTTP/1.1\r\n"
3507 "Host: www.google.com\r\n"
3508 "Connection: keep-alive\r\n\r\n"),
3509 };
3510
3511 MockRead data_reads2[] = {
3512 // The origin server responds with a Type 2 message.
3513 MockRead("HTTP/1.1 407 Access Denied\r\n"),
3514 MockRead("Proxy-Authenticate: NTLM "
3515 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo"
3516 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
3517 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
3518 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
3519 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
3520 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
3521 "BtAAAAAAA=\r\n"),
3522 MockRead("Content-Length: 42\r\n"),
3523 MockRead("Content-Type: text/html\r\n\r\n"),
3524 MockRead("You are not authorized to view this page\r\n"),
3525
3526 // Connect succeeds
3527 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
3528
3529 // Lastly we get the desired content.
3530 MockRead("HTTP/1.1 200 OK\r\n"),
3531 MockRead("Content-Type: text/html; charset=utf-8\r\n"),
3532 MockRead("Content-Length: 13\r\n\r\n"),
3533 MockRead("Please Login\r\n"),
3534 MockRead(false, OK),
3535 };
3536
3537 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
3538 data_writes1, arraysize(data_writes1));
3539 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
3540 data_writes2, arraysize(data_writes2));
3541 SSLSocketDataProvider ssl(true, OK);
3542 SSLSocketDataProvider ssl2(true, OK);
3543 SSLSocketDataProvider ssl3(true, OK);
3544 SSLSocketDataProvider ssl_server(true, OK);
3545 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
3546 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2);
3547 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl3);
3548 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_server);
3549 session_deps.socket_factory.AddSocketDataProvider(&data1);
3550 session_deps.socket_factory.AddSocketDataProvider(&data2);
3551 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3552
3553 TestCompletionCallback callback1;
3554
3555 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3556
3557 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
3558 EXPECT_EQ(ERR_IO_PENDING, rv);
3559
3560 rv = callback1.WaitForResult();
3561 EXPECT_EQ(OK, rv);
3562
3563 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
3564
3565 const HttpResponseInfo* response = trans->GetResponseInfo();
3566 ASSERT_FALSE(response == NULL);
3567 EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get()));
3568
3569 TestCompletionCallback callback2;
3570
3571 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM),
3572 callback2.callback());
3573 EXPECT_EQ(ERR_IO_PENDING, rv);
3574
3575 rv = callback2.WaitForResult();
3576 EXPECT_EQ(OK, rv);
3577
3578 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
3579
3580 response = trans->GetResponseInfo();
3581 ASSERT_TRUE(response != NULL);
3582 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3583
3584 TestCompletionCallback callback3;
3585
3586 rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback());
3587 EXPECT_EQ(ERR_IO_PENDING, rv);
3588
3589 rv = callback3.WaitForResult();
3590 EXPECT_EQ(OK, rv);
3591
3592 response = trans->GetResponseInfo();
3593 ASSERT_TRUE(response != NULL);
3594 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3595 EXPECT_EQ(13, response->headers->GetContentLength());
3596 }
3597
3068 // Enter a wrong password, and then the correct one. 3598 // Enter a wrong password, and then the correct one.
3069 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { 3599 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) {
3070 HttpRequestInfo request; 3600 HttpRequestInfo request;
3071 request.method = "GET"; 3601 request.method = "GET";
3072 request.url = GURL("http://172.22.68.17/kids/login.aspx"); 3602 request.url = GURL("http://172.22.68.17/kids/login.aspx");
3073 request.load_flags = 0; 3603 request.load_flags = 0;
3074 3604
3075 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, 3605 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2,
3076 MockGetHostName); 3606 MockGetHostName);
3077 SessionDependencies session_deps; 3607 SessionDependencies session_deps;
(...skipping 4367 matching lines...) Expand 10 before | Expand all | Expand 10 after
7445 } 7975 }
7446 7976
7447 // GenerateAuthToken is a mighty big test. 7977 // GenerateAuthToken is a mighty big test.
7448 // It tests all permutation of GenerateAuthToken behavior: 7978 // It tests all permutation of GenerateAuthToken behavior:
7449 // - Synchronous and Asynchronous completion. 7979 // - Synchronous and Asynchronous completion.
7450 // - OK or error on completion. 7980 // - OK or error on completion.
7451 // - Direct connection, non-authenticating proxy, and authenticating proxy. 7981 // - Direct connection, non-authenticating proxy, and authenticating proxy.
7452 // - HTTP or HTTPS backend (to include proxy tunneling). 7982 // - HTTP or HTTPS backend (to include proxy tunneling).
7453 // - Non-authenticating and authenticating backend. 7983 // - Non-authenticating and authenticating backend.
7454 // 7984 //
7455 // In all, there are 44 reasonable permuations (for example, if there are 7985 // In all, there are 44 reasonable permutations (for example, if there are
7456 // problems generating an auth token for an authenticating proxy, we don't 7986 // problems generating an auth token for an authenticating proxy, we don't
7457 // need to test all permutations of the backend server). 7987 // need to test all permutations of the backend server).
7458 // 7988 //
7459 // The test proceeds by going over each of the configuration cases, and 7989 // The test proceeds by going over each of the configuration cases, and
7460 // potentially running up to three rounds in each of the tests. The TestConfig 7990 // potentially running up to three rounds in each of the tests. The TestConfig
7461 // specifies both the configuration for the test as well as the expectations 7991 // specifies both the configuration for the test as well as the expectations
7462 // for the results. 7992 // for the results.
7463 TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { 7993 TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) {
7464 static const char kServer[] = "http://www.example.com"; 7994 static const char kServer[] = "http://www.example.com";
7465 static const char kSecureServer[] = "https://www.example.com"; 7995 static const char kSecureServer[] = "https://www.example.com";
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
8303 }; 8833 };
8304 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), 8834 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1),
8305 data_writes_1, arraysize(data_writes_1)); 8835 data_writes_1, arraysize(data_writes_1));
8306 8836
8307 // Second round tries to tunnel to www.google.com due to the 8837 // Second round tries to tunnel to www.google.com due to the
8308 // Alternate-Protocol announcement in the first round. It fails due 8838 // Alternate-Protocol announcement in the first round. It fails due
8309 // to a proxy authentication challenge. 8839 // to a proxy authentication challenge.
8310 // After the failure, a tunnel is established to www.google.com using 8840 // After the failure, a tunnel is established to www.google.com using
8311 // Proxy-Authorization headers. There is then a SPDY request round. 8841 // Proxy-Authorization headers. There is then a SPDY request round.
8312 // 8842 //
8313 // NOTE: Despite the "Proxy-Connection: Close", these are done on the
8314 // same MockTCPClientSocket since the underlying HttpNetworkClientSocket
8315 // does a Disconnect and Connect on the same socket, rather than trying
8316 // to obtain a new one.
8317 //
8318 // NOTE: Originally, the proxy response to the second CONNECT request 8843 // NOTE: Originally, the proxy response to the second CONNECT request
8319 // simply returned another 407 so the unit test could skip the SSL connection 8844 // simply returned another 407 so the unit test could skip the SSL connection
8320 // establishment and SPDY framing issues. Alas, the 8845 // establishment and SPDY framing issues. Alas, the
8321 // retry-http-when-alternate-protocol fails logic kicks in, which was more 8846 // retry-http-when-alternate-protocol fails logic kicks in, which was more
8322 // complicated to set up expectations for than the SPDY session. 8847 // complicated to set up expectations for than the SPDY session.
8323 8848
8324 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 8849 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
8325 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 8850 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
8326 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); 8851 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true));
8327 8852
8328 MockWrite data_writes_2[] = { 8853 MockWrite data_writes_2[] = {
8329 // First connection attempt without Proxy-Authorization. 8854 // First connection attempt without Proxy-Authorization.
8330 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 8855 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
8331 "Host: www.google.com\r\n" 8856 "Host: www.google.com\r\n"
8332 "Proxy-Connection: keep-alive\r\n" 8857 "Proxy-Connection: keep-alive\r\n"
8333 "\r\n"), 8858 "\r\n"),
8859 };
8334 8860
8861 MockWrite data_writes_3[] = {
8862 // Non-alternate protocol job that will run in parallel
8863 MockWrite("GET https://www.google.com/ HTTP/1.1\r\n"
8864 "Host: www.google.com\r\n"
8865 "Proxy-Connection: keep-alive\r\n"
8866 "\r\n"),
8867 };
8868
8869 MockWrite data_writes_4[] = {
8335 // Second connection attempt with Proxy-Authorization. 8870 // Second connection attempt with Proxy-Authorization.
8336 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 8871 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
8337 "Host: www.google.com\r\n" 8872 "Host: www.google.com\r\n"
8338 "Proxy-Connection: keep-alive\r\n" 8873 "Proxy-Connection: keep-alive\r\n"
8339 "Proxy-Authorization: auth_token\r\n" 8874 "Proxy-Authorization: auth_token\r\n"
8340 "\r\n"), 8875 "\r\n"),
8341 8876
8342 // SPDY request 8877 // SPDY request
8343 CreateMockWrite(*req), 8878 CreateMockWrite(*req),
8344 }; 8879 };
8345 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" 8880 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n"
8346 "Proxy-Authenticate: Mock\r\n" 8881 "Proxy-Authenticate: Mock\r\n"
8347 "Proxy-Connection: close\r\n" 8882 "Proxy-Connection: close\r\n"
8883 "Content-Length: 0\r\n"
8348 "\r\n"); 8884 "\r\n");
8349 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; 8885 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
8350 MockRead data_reads_2[] = { 8886 MockRead data_reads_2[] = {
8351 // First connection attempt fails 8887 // First connection attempt fails
8352 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), 8888 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1),
8353 MockRead(true, kRejectConnectResponse, 8889 MockRead(true, kRejectConnectResponse,
8354 arraysize(kRejectConnectResponse) - 1, 1), 8890 arraysize(kRejectConnectResponse) - 1, 1),
8891 };
8355 8892
8893 // Hang forever so we can ensure the alt job wins
8894 MockRead data_reads_3[] = {
8895 MockRead(false, ERR_IO_PENDING),
8896 };
8897
8898 MockRead data_reads_4[] = {
8356 // Second connection attempt passes 8899 // Second connection attempt passes
8357 MockRead(true, kAcceptConnectResponse, 8900 MockRead(true, kAcceptConnectResponse,
8358 arraysize(kAcceptConnectResponse) -1, 4), 8901 arraysize(kAcceptConnectResponse) -1, 1),
8359 8902
8360 // SPDY response 8903 // SPDY response
8361 CreateMockRead(*resp.get(), 6), 8904 CreateMockRead(*resp.get(), 3),
8362 CreateMockRead(*data.get(), 6), 8905 CreateMockRead(*data.get(), 3),
8363 MockRead(true, 0, 0, 6), 8906 MockRead(true, 0, 0, 4),
8364 }; 8907 };
8365 scoped_ptr<OrderedSocketData> data_2( 8908 scoped_ptr<OrderedSocketData> data_2(
8366 new OrderedSocketData(data_reads_2, arraysize(data_reads_2), 8909 new OrderedSocketData(data_reads_2, arraysize(data_reads_2),
8367 data_writes_2, arraysize(data_writes_2))); 8910 data_writes_2, arraysize(data_writes_2)));
8911 scoped_ptr<OrderedSocketData> data_3(
8912 new OrderedSocketData(data_reads_3, arraysize(data_reads_3),
8913 data_writes_3, arraysize(data_writes_3)));
8914 // Hang forever so we can ensure the alt job wins
8915 MockConnect conn_3(false, ERR_IO_PENDING);
8916 data_3->set_connect_data(conn_3);
8917 scoped_ptr<OrderedSocketData> data_4(
8918 new OrderedSocketData(data_reads_4, arraysize(data_reads_4),
8919 data_writes_4, arraysize(data_writes_4)));
8368 8920
8369 SSLSocketDataProvider ssl(true, OK); 8921 SSLSocketDataProvider ssl(true, OK);
8370 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; 8922 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
8371 ssl.next_proto = "spdy/2"; 8923 ssl.next_proto = "spdy/2";
8372 ssl.was_npn_negotiated = true; 8924 ssl.was_npn_negotiated = true;
8373 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2; 8925 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2;
8374 8926
8375 MockConnect never_finishing_connect(false, ERR_IO_PENDING); 8927 MockConnect never_finishing_connect(false, ERR_IO_PENDING);
8376 StaticSocketDataProvider hanging_non_alternate_protocol_socket( 8928 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
8377 NULL, 0, NULL, 0); 8929 NULL, 0, NULL, 0);
8378 hanging_non_alternate_protocol_socket.set_connect_data( 8930 hanging_non_alternate_protocol_socket.set_connect_data(
8379 never_finishing_connect); 8931 never_finishing_connect);
8380 8932
8381 session_deps.socket_factory.AddSocketDataProvider(&data_1); 8933 session_deps.socket_factory.AddSocketDataProvider(&data_1);
8382 session_deps.socket_factory.AddSocketDataProvider(data_2.get()); 8934 session_deps.socket_factory.AddSocketDataProvider(data_2.get());
8935 session_deps.socket_factory.AddSocketDataProvider(data_3.get());
8936 session_deps.socket_factory.AddSocketDataProvider(data_4.get());
8937 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
8383 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); 8938 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
8384 session_deps.socket_factory.AddSocketDataProvider( 8939 session_deps.socket_factory.AddSocketDataProvider(
8385 &hanging_non_alternate_protocol_socket); 8940 &hanging_non_alternate_protocol_socket);
8386 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 8941 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
8387 8942
8388 // First round should work and provide the Alternate-Protocol state. 8943 // First round should work and provide the Alternate-Protocol state.
8389 TestCompletionCallback callback_1; 8944 TestCompletionCallback callback_1;
8390 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session)); 8945 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session));
8391 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); 8946 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog());
8392 EXPECT_EQ(ERR_IO_PENDING, rv); 8947 EXPECT_EQ(ERR_IO_PENDING, rv);
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
9373 StaticSocketDataProvider* data[] = { &data1, &data2 }; 9928 StaticSocketDataProvider* data[] = { &data1, &data2 };
9374 9929
9375 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); 9930 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
9376 9931
9377 EXPECT_EQ(OK, out.rv); 9932 EXPECT_EQ(OK, out.rv);
9378 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 9933 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
9379 EXPECT_EQ("hello world", out.response_data); 9934 EXPECT_EQ("hello world", out.response_data);
9380 } 9935 }
9381 9936
9382 } // namespace net 9937 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_error_list.h ('k') | net/http/http_proxy_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698