Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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_refptr<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); | |
| 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 Loading... | |
| 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, NTLMAuthFull) { | |
|
cbentzel
2012/01/20 02:09:46
Should the name/description of this test include a
Ryan Hamilton
2012/01/20 04:20:04
Done.
| |
| 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 4313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7391 } | 7921 } |
| 7392 | 7922 |
| 7393 // GenerateAuthToken is a mighty big test. | 7923 // GenerateAuthToken is a mighty big test. |
| 7394 // It tests all permutation of GenerateAuthToken behavior: | 7924 // It tests all permutation of GenerateAuthToken behavior: |
| 7395 // - Synchronous and Asynchronous completion. | 7925 // - Synchronous and Asynchronous completion. |
| 7396 // - OK or error on completion. | 7926 // - OK or error on completion. |
| 7397 // - Direct connection, non-authenticating proxy, and authenticating proxy. | 7927 // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 7398 // - HTTP or HTTPS backend (to include proxy tunneling). | 7928 // - HTTP or HTTPS backend (to include proxy tunneling). |
| 7399 // - Non-authenticating and authenticating backend. | 7929 // - Non-authenticating and authenticating backend. |
| 7400 // | 7930 // |
| 7401 // In all, there are 44 reasonable permuations (for example, if there are | 7931 // In all, there are 44 reasonable permutations (for example, if there are |
| 7402 // problems generating an auth token for an authenticating proxy, we don't | 7932 // problems generating an auth token for an authenticating proxy, we don't |
| 7403 // need to test all permutations of the backend server). | 7933 // need to test all permutations of the backend server). |
| 7404 // | 7934 // |
| 7405 // The test proceeds by going over each of the configuration cases, and | 7935 // The test proceeds by going over each of the configuration cases, and |
| 7406 // potentially running up to three rounds in each of the tests. The TestConfig | 7936 // potentially running up to three rounds in each of the tests. The TestConfig |
| 7407 // specifies both the configuration for the test as well as the expectations | 7937 // specifies both the configuration for the test as well as the expectations |
| 7408 // for the results. | 7938 // for the results. |
| 7409 TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { | 7939 TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
| 7410 static const char kServer[] = "http://www.example.com"; | 7940 static const char kServer[] = "http://www.example.com"; |
| 7411 static const char kSecureServer[] = "https://www.example.com"; | 7941 static const char kSecureServer[] = "https://www.example.com"; |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8249 }; | 8779 }; |
| 8250 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), | 8780 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 8251 data_writes_1, arraysize(data_writes_1)); | 8781 data_writes_1, arraysize(data_writes_1)); |
| 8252 | 8782 |
| 8253 // Second round tries to tunnel to www.google.com due to the | 8783 // Second round tries to tunnel to www.google.com due to the |
| 8254 // Alternate-Protocol announcement in the first round. It fails due | 8784 // Alternate-Protocol announcement in the first round. It fails due |
| 8255 // to a proxy authentication challenge. | 8785 // to a proxy authentication challenge. |
| 8256 // After the failure, a tunnel is established to www.google.com using | 8786 // After the failure, a tunnel is established to www.google.com using |
| 8257 // Proxy-Authorization headers. There is then a SPDY request round. | 8787 // Proxy-Authorization headers. There is then a SPDY request round. |
| 8258 // | 8788 // |
| 8259 // NOTE: Despite the "Proxy-Connection: Close", these are done on the | |
| 8260 // same MockTCPClientSocket since the underlying HttpNetworkClientSocket | |
| 8261 // does a Disconnect and Connect on the same socket, rather than trying | |
| 8262 // to obtain a new one. | |
| 8263 // | |
| 8264 // NOTE: Originally, the proxy response to the second CONNECT request | 8789 // NOTE: Originally, the proxy response to the second CONNECT request |
| 8265 // simply returned another 407 so the unit test could skip the SSL connection | 8790 // simply returned another 407 so the unit test could skip the SSL connection |
| 8266 // establishment and SPDY framing issues. Alas, the | 8791 // establishment and SPDY framing issues. Alas, the |
| 8267 // retry-http-when-alternate-protocol fails logic kicks in, which was more | 8792 // retry-http-when-alternate-protocol fails logic kicks in, which was more |
| 8268 // complicated to set up expectations for than the SPDY session. | 8793 // complicated to set up expectations for than the SPDY session. |
| 8269 | 8794 |
| 8270 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 8795 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 8271 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 8796 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8272 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | 8797 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); |
| 8273 | 8798 |
| 8274 MockWrite data_writes_2[] = { | 8799 MockWrite data_writes_2[] = { |
| 8275 // First connection attempt without Proxy-Authorization. | 8800 // First connection attempt without Proxy-Authorization. |
| 8276 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | 8801 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 8277 "Host: www.google.com\r\n" | 8802 "Host: www.google.com\r\n" |
| 8278 "Proxy-Connection: keep-alive\r\n" | 8803 "Proxy-Connection: keep-alive\r\n" |
| 8279 "\r\n"), | 8804 "\r\n"), |
| 8805 }; | |
| 8280 | 8806 |
| 8807 MockWrite data_writes_3[] = { | |
| 8808 // Non-alternate protocol job that will run in parallel | |
| 8809 MockWrite("GET https://www.google.com/ HTTP/1.1\r\n" | |
| 8810 "Host: www.google.com\r\n" | |
| 8811 "Proxy-Connection: keep-alive\r\n" | |
| 8812 "\r\n"), | |
| 8813 }; | |
| 8814 | |
| 8815 MockWrite data_writes_4[] = { | |
| 8281 // Second connection attempt with Proxy-Authorization. | 8816 // Second connection attempt with Proxy-Authorization. |
| 8282 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | 8817 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 8283 "Host: www.google.com\r\n" | 8818 "Host: www.google.com\r\n" |
| 8284 "Proxy-Connection: keep-alive\r\n" | 8819 "Proxy-Connection: keep-alive\r\n" |
| 8285 "Proxy-Authorization: auth_token\r\n" | 8820 "Proxy-Authorization: auth_token\r\n" |
| 8286 "\r\n"), | 8821 "\r\n"), |
| 8287 | 8822 |
| 8288 // SPDY request | 8823 // SPDY request |
| 8289 CreateMockWrite(*req), | 8824 CreateMockWrite(*req), |
| 8290 }; | 8825 }; |
| 8291 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" | 8826 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 8292 "Proxy-Authenticate: Mock\r\n" | 8827 "Proxy-Authenticate: Mock\r\n" |
| 8293 "Proxy-Connection: close\r\n" | 8828 "Proxy-Connection: close\r\n" |
| 8829 "Content-Length: 0\r\n" | |
| 8294 "\r\n"); | 8830 "\r\n"); |
| 8295 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; | 8831 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 8296 MockRead data_reads_2[] = { | 8832 MockRead data_reads_2[] = { |
| 8297 // First connection attempt fails | 8833 // First connection attempt fails |
| 8298 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), | 8834 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 8299 MockRead(true, kRejectConnectResponse, | 8835 MockRead(true, kRejectConnectResponse, |
| 8300 arraysize(kRejectConnectResponse) - 1, 1), | 8836 arraysize(kRejectConnectResponse) - 1, 1), |
| 8837 }; | |
| 8301 | 8838 |
| 8839 // Hang forever so we can ensure the alt job wins | |
| 8840 MockRead data_reads_3[] = { | |
| 8841 MockRead(false, ERR_IO_PENDING), | |
| 8842 }; | |
| 8843 | |
| 8844 MockRead data_reads_4[] = { | |
| 8302 // Second connection attempt passes | 8845 // Second connection attempt passes |
| 8303 MockRead(true, kAcceptConnectResponse, | 8846 MockRead(true, kAcceptConnectResponse, |
| 8304 arraysize(kAcceptConnectResponse) -1, 4), | 8847 arraysize(kAcceptConnectResponse) -1, 1), |
| 8305 | 8848 |
| 8306 // SPDY response | 8849 // SPDY response |
| 8307 CreateMockRead(*resp.get(), 6), | 8850 CreateMockRead(*resp.get(), 3), |
| 8308 CreateMockRead(*data.get(), 6), | 8851 CreateMockRead(*data.get(), 3), |
| 8309 MockRead(true, 0, 0, 6), | 8852 MockRead(true, 0, 0, 4), |
| 8310 }; | 8853 }; |
| 8311 scoped_refptr<OrderedSocketData> data_2( | 8854 scoped_refptr<OrderedSocketData> data_2( |
| 8312 new OrderedSocketData(data_reads_2, arraysize(data_reads_2), | 8855 new OrderedSocketData(data_reads_2, arraysize(data_reads_2), |
| 8313 data_writes_2, arraysize(data_writes_2))); | 8856 data_writes_2, arraysize(data_writes_2))); |
| 8857 scoped_refptr<OrderedSocketData> data_3( | |
| 8858 new OrderedSocketData(data_reads_3, arraysize(data_reads_3), | |
| 8859 data_writes_3, arraysize(data_writes_3))); | |
| 8860 // Hang forever so we can ensure the alt job wins | |
| 8861 MockConnect conn_3(false, ERR_IO_PENDING); | |
| 8862 data_3->set_connect_data(conn_3); | |
| 8863 scoped_refptr<OrderedSocketData> data_4( | |
| 8864 new OrderedSocketData(data_reads_4, arraysize(data_reads_4), | |
| 8865 data_writes_4, arraysize(data_writes_4))); | |
| 8314 | 8866 |
| 8315 SSLSocketDataProvider ssl(true, OK); | 8867 SSLSocketDataProvider ssl(true, OK); |
| 8316 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | 8868 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 8317 ssl.next_proto = "spdy/2"; | 8869 ssl.next_proto = "spdy/2"; |
| 8318 ssl.was_npn_negotiated = true; | 8870 ssl.was_npn_negotiated = true; |
| 8319 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2; | 8871 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2; |
| 8320 | 8872 |
| 8321 MockConnect never_finishing_connect(false, ERR_IO_PENDING); | 8873 MockConnect never_finishing_connect(false, ERR_IO_PENDING); |
| 8322 StaticSocketDataProvider hanging_non_alternate_protocol_socket( | 8874 StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8323 NULL, 0, NULL, 0); | 8875 NULL, 0, NULL, 0); |
| 8324 hanging_non_alternate_protocol_socket.set_connect_data( | 8876 hanging_non_alternate_protocol_socket.set_connect_data( |
| 8325 never_finishing_connect); | 8877 never_finishing_connect); |
| 8326 | 8878 |
| 8327 session_deps.socket_factory.AddSocketDataProvider(&data_1); | 8879 session_deps.socket_factory.AddSocketDataProvider(&data_1); |
| 8328 session_deps.socket_factory.AddSocketDataProvider(data_2.get()); | 8880 session_deps.socket_factory.AddSocketDataProvider(data_2.get()); |
| 8881 session_deps.socket_factory.AddSocketDataProvider(data_3.get()); | |
| 8882 session_deps.socket_factory.AddSocketDataProvider(data_4.get()); | |
| 8883 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); | |
| 8329 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); | 8884 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
| 8330 session_deps.socket_factory.AddSocketDataProvider( | 8885 session_deps.socket_factory.AddSocketDataProvider( |
| 8331 &hanging_non_alternate_protocol_socket); | 8886 &hanging_non_alternate_protocol_socket); |
| 8332 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 8887 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 8333 | 8888 |
| 8334 // First round should work and provide the Alternate-Protocol state. | 8889 // First round should work and provide the Alternate-Protocol state. |
| 8335 TestCompletionCallback callback_1; | 8890 TestCompletionCallback callback_1; |
| 8336 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session)); | 8891 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session)); |
| 8337 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); | 8892 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
| 8338 EXPECT_EQ(ERR_IO_PENDING, rv); | 8893 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9499 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); | 10054 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); |
| 9500 | 10055 |
| 9501 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 10056 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
| 9502 ClientSocketPoolManager::set_max_sockets_per_pool(old_max_sockets_per_pool); | 10057 ClientSocketPoolManager::set_max_sockets_per_pool(old_max_sockets_per_pool); |
| 9503 ClientSocketPoolManager::set_max_sockets_per_proxy_server( | 10058 ClientSocketPoolManager::set_max_sockets_per_proxy_server( |
| 9504 old_max_sockets_per_proxy_server); | 10059 old_max_sockets_per_proxy_server); |
| 9505 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets_per_group); | 10060 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets_per_group); |
| 9506 } | 10061 } |
| 9507 | 10062 |
| 9508 } // namespace net | 10063 } // namespace net |
| OLD | NEW |