OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/http/http_network_transaction.h" | |
6 | |
7 #include <math.h> // ceil | |
8 #include <stdarg.h> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/compiler_specific.h" | |
14 #include "base/file_util.h" | |
15 #include "base/files/file_path.h" | |
16 #include "base/json/json_writer.h" | |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/strings/string_util.h" | |
19 #include "base/strings/utf_string_conversions.h" | |
20 #include "base/test/test_file_util.h" | |
21 #include "net/base/auth.h" | |
22 #include "net/base/capturing_net_log.h" | |
23 #include "net/base/completion_callback.h" | |
24 #include "net/base/load_timing_info.h" | |
25 #include "net/base/load_timing_info_test_util.h" | |
26 #include "net/base/net_log.h" | |
27 #include "net/base/net_log_unittest.h" | |
28 #include "net/base/request_priority.h" | |
29 #include "net/base/test_completion_callback.h" | |
30 #include "net/base/test_data_directory.h" | |
31 #include "net/base/upload_bytes_element_reader.h" | |
32 #include "net/base/upload_data_stream.h" | |
33 #include "net/base/upload_file_element_reader.h" | |
34 #include "net/cert/mock_cert_verifier.h" | |
35 #include "net/dns/host_cache.h" | |
36 #include "net/dns/mock_host_resolver.h" | |
37 #include "net/http/http_auth_handler_digest.h" | |
38 #include "net/http/http_auth_handler_mock.h" | |
39 #include "net/http/http_auth_handler_ntlm.h" | |
40 #include "net/http/http_basic_stream.h" | |
41 #include "net/http/http_network_session.h" | |
42 #include "net/http/http_network_session_peer.h" | |
43 #include "net/http/http_server_properties_impl.h" | |
44 #include "net/http/http_stream.h" | |
45 #include "net/http/http_stream_factory.h" | |
46 #include "net/http/http_transaction_unittest.h" | |
47 #include "net/proxy/proxy_config_service_fixed.h" | |
48 #include "net/proxy/proxy_resolver.h" | |
49 #include "net/proxy/proxy_service.h" | |
50 #include "net/socket/client_socket_factory.h" | |
51 #include "net/socket/client_socket_pool_manager.h" | |
52 #include "net/socket/mock_client_socket_pool_manager.h" | |
53 #include "net/socket/next_proto.h" | |
54 #include "net/socket/socket_test_util.h" | |
55 #include "net/socket/ssl_client_socket.h" | |
56 #include "net/spdy/spdy_framer.h" | |
57 #include "net/spdy/spdy_session.h" | |
58 #include "net/spdy/spdy_session_pool.h" | |
59 #include "net/spdy/spdy_test_util_spdy3.h" | |
60 #include "net/ssl/ssl_cert_request_info.h" | |
61 #include "net/ssl/ssl_config_service_defaults.h" | |
62 #include "net/ssl/ssl_info.h" | |
63 #include "net/test/cert_test_util.h" | |
64 #include "testing/gtest/include/gtest/gtest.h" | |
65 #include "testing/platform_test.h" | |
66 | |
67 using namespace net::test_spdy3; | |
68 | |
69 //----------------------------------------------------------------------------- | |
70 | |
71 namespace { | |
72 | |
73 const base::string16 kBar(ASCIIToUTF16("bar")); | |
74 const base::string16 kBar2(ASCIIToUTF16("bar2")); | |
75 const base::string16 kBar3(ASCIIToUTF16("bar3")); | |
76 const base::string16 kBaz(ASCIIToUTF16("baz")); | |
77 const base::string16 kFirst(ASCIIToUTF16("first")); | |
78 const base::string16 kFoo(ASCIIToUTF16("foo")); | |
79 const base::string16 kFoo2(ASCIIToUTF16("foo2")); | |
80 const base::string16 kFoo3(ASCIIToUTF16("foo3")); | |
81 const base::string16 kFou(ASCIIToUTF16("fou")); | |
82 const base::string16 kSecond(ASCIIToUTF16("second")); | |
83 const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); | |
84 const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); | |
85 | |
86 // MakeNextProtos is a utility function that returns a vector of std::strings | |
87 // from its arguments. Don't forget to terminate the argument list with a NULL. | |
88 std::vector<std::string> MakeNextProtos(const char* a, ...) { | |
89 std::vector<std::string> ret; | |
90 ret.push_back(a); | |
91 | |
92 va_list args; | |
93 va_start(args, a); | |
94 | |
95 for (;;) { | |
96 const char* value = va_arg(args, const char*); | |
97 if (value == NULL) | |
98 break; | |
99 ret.push_back(value); | |
100 } | |
101 va_end(args); | |
102 | |
103 return ret; | |
104 } | |
105 | |
106 // SpdyNextProtos returns a vector of NPN protocol strings for negotiating | |
107 // SPDY. | |
108 std::vector<std::string> SpdyNextProtos() { | |
109 return MakeNextProtos("http/1.1", "spdy/2", "spdy/3", "spdy/3.1", | |
110 "spdy/4a1", NULL); | |
111 } | |
112 | |
113 int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) { | |
114 return session->GetTransportSocketPool( | |
115 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); | |
116 } | |
117 | |
118 int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) { | |
119 return session->GetSSLSocketPool( | |
120 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); | |
121 } | |
122 | |
123 } // namespace | |
124 | |
125 namespace net { | |
126 | |
127 namespace { | |
128 | |
129 HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { | |
130 return SpdySessionDependencies::SpdyCreateSession(session_deps); | |
131 } | |
132 | |
133 // Takes in a Value created from a NetLogHttpResponseParameter, and returns | |
134 // a JSONified list of headers as a single string. Uses single quotes instead | |
135 // of double quotes for easier comparison. Returns false on failure. | |
136 bool GetHeaders(base::DictionaryValue* params, std::string* headers) { | |
137 if (!params) | |
138 return false; | |
139 base::ListValue* header_list; | |
140 if (!params->GetList("headers", &header_list)) | |
141 return false; | |
142 std::string double_quote_headers; | |
143 base::JSONWriter::Write(header_list, &double_quote_headers); | |
144 ReplaceChars(double_quote_headers, "\"", "'", headers); | |
145 return true; | |
146 } | |
147 | |
148 // Tests LoadTimingInfo in the case a socket is reused and no PAC script is | |
149 // used. | |
150 void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) { | |
151 EXPECT_TRUE(load_timing_info.socket_reused); | |
152 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
153 | |
154 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | |
155 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | |
156 | |
157 net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | |
158 EXPECT_FALSE(load_timing_info.send_start.is_null()); | |
159 | |
160 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | |
161 | |
162 // Set at a higher level. | |
163 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | |
164 EXPECT_TRUE(load_timing_info.request_start.is_null()); | |
165 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
166 } | |
167 | |
168 // Tests LoadTimingInfo in the case a new socket is used and no PAC script is | |
169 // used. | |
170 void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info, | |
171 int connect_timing_flags) { | |
172 EXPECT_FALSE(load_timing_info.socket_reused); | |
173 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
174 | |
175 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | |
176 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | |
177 | |
178 net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | |
179 connect_timing_flags); | |
180 EXPECT_LE(load_timing_info.connect_timing.connect_end, | |
181 load_timing_info.send_start); | |
182 | |
183 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | |
184 | |
185 // Set at a higher level. | |
186 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | |
187 EXPECT_TRUE(load_timing_info.request_start.is_null()); | |
188 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
189 } | |
190 | |
191 // Tests LoadTimingInfo in the case a socket is reused and a PAC script is | |
192 // used. | |
193 void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) { | |
194 EXPECT_TRUE(load_timing_info.socket_reused); | |
195 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
196 | |
197 net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | |
198 | |
199 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); | |
200 EXPECT_LE(load_timing_info.proxy_resolve_start, | |
201 load_timing_info.proxy_resolve_end); | |
202 EXPECT_LE(load_timing_info.proxy_resolve_end, | |
203 load_timing_info.send_start); | |
204 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | |
205 | |
206 // Set at a higher level. | |
207 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | |
208 EXPECT_TRUE(load_timing_info.request_start.is_null()); | |
209 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
210 } | |
211 | |
212 // Tests LoadTimingInfo in the case a new socket is used and a PAC script is | |
213 // used. | |
214 void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info, | |
215 int connect_timing_flags) { | |
216 EXPECT_FALSE(load_timing_info.socket_reused); | |
217 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
218 | |
219 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); | |
220 EXPECT_LE(load_timing_info.proxy_resolve_start, | |
221 load_timing_info.proxy_resolve_end); | |
222 EXPECT_LE(load_timing_info.proxy_resolve_end, | |
223 load_timing_info.connect_timing.connect_start); | |
224 net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | |
225 connect_timing_flags); | |
226 EXPECT_LE(load_timing_info.connect_timing.connect_end, | |
227 load_timing_info.send_start); | |
228 | |
229 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | |
230 | |
231 // Set at a higher level. | |
232 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | |
233 EXPECT_TRUE(load_timing_info.request_start.is_null()); | |
234 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
235 } | |
236 | |
237 } // namespace | |
238 | |
239 class HttpNetworkTransactionSpdy3Test : public PlatformTest { | |
240 public: | |
241 virtual ~HttpNetworkTransactionSpdy3Test() { | |
242 // Important to restore the per-pool limit first, since the pool limit must | |
243 // always be greater than group limit, and the tests reduce both limits. | |
244 ClientSocketPoolManager::set_max_sockets_per_pool( | |
245 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); | |
246 ClientSocketPoolManager::set_max_sockets_per_group( | |
247 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); | |
248 } | |
249 | |
250 protected: | |
251 HttpNetworkTransactionSpdy3Test() | |
252 : spdy_util_(kProtoSPDY3), | |
253 session_deps_(kProtoSPDY3), | |
254 old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( | |
255 HttpNetworkSession::NORMAL_SOCKET_POOL)), | |
256 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( | |
257 HttpNetworkSession::NORMAL_SOCKET_POOL)) { | |
258 } | |
259 | |
260 struct SimpleGetHelperResult { | |
261 int rv; | |
262 std::string status_line; | |
263 std::string response_data; | |
264 LoadTimingInfo load_timing_info; | |
265 }; | |
266 | |
267 virtual void SetUp() { | |
268 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | |
269 base::MessageLoop::current()->RunUntilIdle(); | |
270 } | |
271 | |
272 virtual void TearDown() { | |
273 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | |
274 base::MessageLoop::current()->RunUntilIdle(); | |
275 // Empty the current queue. | |
276 base::MessageLoop::current()->RunUntilIdle(); | |
277 PlatformTest::TearDown(); | |
278 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | |
279 base::MessageLoop::current()->RunUntilIdle(); | |
280 HttpStreamFactory::set_use_alternate_protocols(false); | |
281 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); | |
282 } | |
283 | |
284 // Either |write_failure| specifies a write failure or |read_failure| | |
285 // specifies a read failure when using a reused socket. In either case, the | |
286 // failure should cause the network transaction to resend the request, and the | |
287 // other argument should be NULL. | |
288 void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, | |
289 const MockRead* read_failure); | |
290 | |
291 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], | |
292 size_t data_count) { | |
293 SimpleGetHelperResult out; | |
294 | |
295 HttpRequestInfo request; | |
296 request.method = "GET"; | |
297 request.url = GURL("http://www.google.com/"); | |
298 request.load_flags = 0; | |
299 | |
300 CapturingBoundNetLog log; | |
301 session_deps_.net_log = log.bound().net_log(); | |
302 scoped_ptr<HttpNetworkTransaction> trans( | |
303 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
304 CreateSession(&session_deps_))); | |
305 | |
306 for (size_t i = 0; i < data_count; ++i) { | |
307 session_deps_.socket_factory->AddSocketDataProvider(data[i]); | |
308 } | |
309 | |
310 TestCompletionCallback callback; | |
311 | |
312 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); | |
313 int rv = trans->Start(&request, callback.callback(), log.bound()); | |
314 EXPECT_EQ(ERR_IO_PENDING, rv); | |
315 | |
316 out.rv = callback.WaitForResult(); | |
317 | |
318 // Even in the failure cases that use this function, connections are always | |
319 // successfully established before the error. | |
320 EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); | |
321 TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | |
322 | |
323 if (out.rv != OK) | |
324 return out; | |
325 | |
326 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
327 // Can't use ASSERT_* inside helper functions like this, so | |
328 // return an error. | |
329 if (response == NULL || response->headers.get() == NULL) { | |
330 out.rv = ERR_UNEXPECTED; | |
331 return out; | |
332 } | |
333 out.status_line = response->headers->GetStatusLine(); | |
334 | |
335 EXPECT_EQ("127.0.0.1", response->socket_address.host()); | |
336 EXPECT_EQ(80, response->socket_address.port()); | |
337 | |
338 rv = ReadTransaction(trans.get(), &out.response_data); | |
339 EXPECT_EQ(OK, rv); | |
340 | |
341 CapturingNetLog::CapturedEntryList entries; | |
342 log.GetEntries(&entries); | |
343 size_t pos = ExpectLogContainsSomewhere( | |
344 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | |
345 NetLog::PHASE_NONE); | |
346 ExpectLogContainsSomewhere( | |
347 entries, pos, | |
348 NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, | |
349 NetLog::PHASE_NONE); | |
350 | |
351 std::string line; | |
352 EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); | |
353 EXPECT_EQ("GET / HTTP/1.1\r\n", line); | |
354 | |
355 std::string headers; | |
356 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &headers)); | |
357 EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']", headers); | |
358 | |
359 return out; | |
360 } | |
361 | |
362 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], | |
363 size_t reads_count) { | |
364 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); | |
365 StaticSocketDataProvider* data[] = { &reads }; | |
366 return SimpleGetHelperForData(data, 1); | |
367 } | |
368 | |
369 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | |
370 int expected_status); | |
371 | |
372 void ConnectStatusHelper(const MockRead& status); | |
373 | |
374 void BypassHostCacheOnRefreshHelper(int load_flags); | |
375 | |
376 void CheckErrorIsPassedBack(int error, IoMode mode); | |
377 | |
378 SpdyTestUtil spdy_util_; | |
379 SpdySessionDependencies session_deps_; | |
380 | |
381 // Original socket limits. Some tests set these. Safest to always restore | |
382 // them once each test has been run. | |
383 int old_max_group_sockets_; | |
384 int old_max_pool_sockets_; | |
385 }; | |
386 | |
387 namespace { | |
388 | |
389 // Fill |str| with a long header list that consumes >= |size| bytes. | |
390 void FillLargeHeadersString(std::string* str, int size) { | |
391 const char* row = | |
392 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; | |
393 const int sizeof_row = strlen(row); | |
394 const int num_rows = static_cast<int>( | |
395 ceil(static_cast<float>(size) / sizeof_row)); | |
396 const int sizeof_data = num_rows * sizeof_row; | |
397 DCHECK(sizeof_data >= size); | |
398 str->reserve(sizeof_data); | |
399 | |
400 for (int i = 0; i < num_rows; ++i) | |
401 str->append(row, sizeof_row); | |
402 } | |
403 | |
404 // Alternative functions that eliminate randomness and dependency on the local | |
405 // host name so that the generated NTLM messages are reproducible. | |
406 void MockGenerateRandom1(uint8* output, size_t n) { | |
407 static const uint8 bytes[] = { | |
408 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 | |
409 }; | |
410 static size_t current_byte = 0; | |
411 for (size_t i = 0; i < n; ++i) { | |
412 output[i] = bytes[current_byte++]; | |
413 current_byte %= arraysize(bytes); | |
414 } | |
415 } | |
416 | |
417 void MockGenerateRandom2(uint8* output, size_t n) { | |
418 static const uint8 bytes[] = { | |
419 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, | |
420 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f | |
421 }; | |
422 static size_t current_byte = 0; | |
423 for (size_t i = 0; i < n; ++i) { | |
424 output[i] = bytes[current_byte++]; | |
425 current_byte %= arraysize(bytes); | |
426 } | |
427 } | |
428 | |
429 std::string MockGetHostName() { | |
430 return "WTC-WIN7"; | |
431 } | |
432 | |
433 template<typename ParentPool> | |
434 class CaptureGroupNameSocketPool : public ParentPool { | |
435 public: | |
436 CaptureGroupNameSocketPool(HostResolver* host_resolver, | |
437 CertVerifier* cert_verifier); | |
438 | |
439 const std::string last_group_name_received() const { | |
440 return last_group_name_; | |
441 } | |
442 | |
443 virtual int RequestSocket(const std::string& group_name, | |
444 const void* socket_params, | |
445 RequestPriority priority, | |
446 ClientSocketHandle* handle, | |
447 const CompletionCallback& callback, | |
448 const BoundNetLog& net_log) { | |
449 last_group_name_ = group_name; | |
450 return ERR_IO_PENDING; | |
451 } | |
452 virtual void CancelRequest(const std::string& group_name, | |
453 ClientSocketHandle* handle) {} | |
454 virtual void ReleaseSocket(const std::string& group_name, | |
455 StreamSocket* socket, | |
456 int id) {} | |
457 virtual void CloseIdleSockets() {} | |
458 virtual int IdleSocketCount() const { | |
459 return 0; | |
460 } | |
461 virtual int IdleSocketCountInGroup(const std::string& group_name) const { | |
462 return 0; | |
463 } | |
464 virtual LoadState GetLoadState(const std::string& group_name, | |
465 const ClientSocketHandle* handle) const { | |
466 return LOAD_STATE_IDLE; | |
467 } | |
468 virtual base::TimeDelta ConnectionTimeout() const { | |
469 return base::TimeDelta(); | |
470 } | |
471 | |
472 private: | |
473 std::string last_group_name_; | |
474 }; | |
475 | |
476 typedef CaptureGroupNameSocketPool<TransportClientSocketPool> | |
477 CaptureGroupNameTransportSocketPool; | |
478 typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> | |
479 CaptureGroupNameHttpProxySocketPool; | |
480 typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> | |
481 CaptureGroupNameSOCKSSocketPool; | |
482 typedef CaptureGroupNameSocketPool<SSLClientSocketPool> | |
483 CaptureGroupNameSSLSocketPool; | |
484 | |
485 template<typename ParentPool> | |
486 CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( | |
487 HostResolver* host_resolver, | |
488 CertVerifier* /* cert_verifier */) | |
489 : ParentPool(0, 0, NULL, host_resolver, NULL, NULL) {} | |
490 | |
491 template<> | |
492 CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( | |
493 HostResolver* host_resolver, | |
494 CertVerifier* /* cert_verifier */) | |
495 : HttpProxyClientSocketPool(0, 0, NULL, host_resolver, NULL, NULL, NULL) {} | |
496 | |
497 template <> | |
498 CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( | |
499 HostResolver* host_resolver, | |
500 CertVerifier* cert_verifier) | |
501 : SSLClientSocketPool(0, | |
502 0, | |
503 NULL, | |
504 host_resolver, | |
505 cert_verifier, | |
506 NULL, | |
507 NULL, | |
508 std::string(), | |
509 NULL, | |
510 NULL, | |
511 NULL, | |
512 NULL, | |
513 NULL, | |
514 NULL) {} | |
515 | |
516 //----------------------------------------------------------------------------- | |
517 | |
518 // This is the expected return from a current server advertising SPDY. | |
519 static const char kAlternateProtocolHttpHeader[] = | |
520 "Alternate-Protocol: 443:npn-spdy/3\r\n\r\n"; | |
521 | |
522 // Helper functions for validating that AuthChallengeInfo's are correctly | |
523 // configured for common cases. | |
524 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { | |
525 if (!auth_challenge) | |
526 return false; | |
527 EXPECT_FALSE(auth_challenge->is_proxy); | |
528 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); | |
529 EXPECT_EQ("MyRealm1", auth_challenge->realm); | |
530 EXPECT_EQ("basic", auth_challenge->scheme); | |
531 return true; | |
532 } | |
533 | |
534 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { | |
535 if (!auth_challenge) | |
536 return false; | |
537 EXPECT_TRUE(auth_challenge->is_proxy); | |
538 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); | |
539 EXPECT_EQ("MyRealm1", auth_challenge->realm); | |
540 EXPECT_EQ("basic", auth_challenge->scheme); | |
541 return true; | |
542 } | |
543 | |
544 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { | |
545 if (!auth_challenge) | |
546 return false; | |
547 EXPECT_FALSE(auth_challenge->is_proxy); | |
548 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); | |
549 EXPECT_EQ("digestive", auth_challenge->realm); | |
550 EXPECT_EQ("digest", auth_challenge->scheme); | |
551 return true; | |
552 } | |
553 | |
554 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { | |
555 if (!auth_challenge) | |
556 return false; | |
557 EXPECT_FALSE(auth_challenge->is_proxy); | |
558 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); | |
559 EXPECT_EQ(std::string(), auth_challenge->realm); | |
560 EXPECT_EQ("ntlm", auth_challenge->scheme); | |
561 return true; | |
562 } | |
563 | |
564 } // namespace | |
565 | |
566 TEST_F(HttpNetworkTransactionSpdy3Test, Basic) { | |
567 scoped_ptr<HttpTransaction> trans( | |
568 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
569 CreateSession(&session_deps_))); | |
570 } | |
571 | |
572 TEST_F(HttpNetworkTransactionSpdy3Test, SimpleGET) { | |
573 MockRead data_reads[] = { | |
574 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
575 MockRead("hello world"), | |
576 MockRead(SYNCHRONOUS, OK), | |
577 }; | |
578 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
579 arraysize(data_reads)); | |
580 EXPECT_EQ(OK, out.rv); | |
581 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | |
582 EXPECT_EQ("hello world", out.response_data); | |
583 } | |
584 | |
585 // Response with no status line. | |
586 TEST_F(HttpNetworkTransactionSpdy3Test, SimpleGETNoHeaders) { | |
587 MockRead data_reads[] = { | |
588 MockRead("hello world"), | |
589 MockRead(SYNCHRONOUS, OK), | |
590 }; | |
591 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
592 arraysize(data_reads)); | |
593 EXPECT_EQ(OK, out.rv); | |
594 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); | |
595 EXPECT_EQ("hello world", out.response_data); | |
596 } | |
597 | |
598 // Allow up to 4 bytes of junk to precede status line. | |
599 TEST_F(HttpNetworkTransactionSpdy3Test, StatusLineJunk3Bytes) { | |
600 MockRead data_reads[] = { | |
601 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), | |
602 MockRead(SYNCHRONOUS, OK), | |
603 }; | |
604 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
605 arraysize(data_reads)); | |
606 EXPECT_EQ(OK, out.rv); | |
607 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); | |
608 EXPECT_EQ("DATA", out.response_data); | |
609 } | |
610 | |
611 // Allow up to 4 bytes of junk to precede status line. | |
612 TEST_F(HttpNetworkTransactionSpdy3Test, StatusLineJunk4Bytes) { | |
613 MockRead data_reads[] = { | |
614 MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), | |
615 MockRead(SYNCHRONOUS, OK), | |
616 }; | |
617 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
618 arraysize(data_reads)); | |
619 EXPECT_EQ(OK, out.rv); | |
620 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); | |
621 EXPECT_EQ("DATA", out.response_data); | |
622 } | |
623 | |
624 // Beyond 4 bytes of slop and it should fail to find a status line. | |
625 TEST_F(HttpNetworkTransactionSpdy3Test, StatusLineJunk5Bytes) { | |
626 MockRead data_reads[] = { | |
627 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), | |
628 MockRead(SYNCHRONOUS, OK), | |
629 }; | |
630 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
631 arraysize(data_reads)); | |
632 EXPECT_EQ(OK, out.rv); | |
633 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); | |
634 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); | |
635 } | |
636 | |
637 // Same as StatusLineJunk4Bytes, except the read chunks are smaller. | |
638 TEST_F(HttpNetworkTransactionSpdy3Test, StatusLineJunk4Bytes_Slow) { | |
639 MockRead data_reads[] = { | |
640 MockRead("\n"), | |
641 MockRead("\n"), | |
642 MockRead("Q"), | |
643 MockRead("J"), | |
644 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), | |
645 MockRead(SYNCHRONOUS, OK), | |
646 }; | |
647 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
648 arraysize(data_reads)); | |
649 EXPECT_EQ(OK, out.rv); | |
650 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); | |
651 EXPECT_EQ("DATA", out.response_data); | |
652 } | |
653 | |
654 // Close the connection before enough bytes to have a status line. | |
655 TEST_F(HttpNetworkTransactionSpdy3Test, StatusLinePartial) { | |
656 MockRead data_reads[] = { | |
657 MockRead("HTT"), | |
658 MockRead(SYNCHRONOUS, OK), | |
659 }; | |
660 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
661 arraysize(data_reads)); | |
662 EXPECT_EQ(OK, out.rv); | |
663 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); | |
664 EXPECT_EQ("HTT", out.response_data); | |
665 } | |
666 | |
667 // Simulate a 204 response, lacking a Content-Length header, sent over a | |
668 // persistent connection. The response should still terminate since a 204 | |
669 // cannot have a response body. | |
670 TEST_F(HttpNetworkTransactionSpdy3Test, StopsReading204) { | |
671 MockRead data_reads[] = { | |
672 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), | |
673 MockRead("junk"), // Should not be read!! | |
674 MockRead(SYNCHRONOUS, OK), | |
675 }; | |
676 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
677 arraysize(data_reads)); | |
678 EXPECT_EQ(OK, out.rv); | |
679 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); | |
680 EXPECT_EQ("", out.response_data); | |
681 } | |
682 | |
683 // A simple request using chunked encoding with some extra data after. | |
684 // (Like might be seen in a pipelined response.) | |
685 TEST_F(HttpNetworkTransactionSpdy3Test, ChunkedEncoding) { | |
686 MockRead data_reads[] = { | |
687 MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), | |
688 MockRead("5\r\nHello\r\n"), | |
689 MockRead("1\r\n"), | |
690 MockRead(" \r\n"), | |
691 MockRead("5\r\nworld\r\n"), | |
692 MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), | |
693 MockRead(SYNCHRONOUS, OK), | |
694 }; | |
695 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
696 arraysize(data_reads)); | |
697 EXPECT_EQ(OK, out.rv); | |
698 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
699 EXPECT_EQ("Hello world", out.response_data); | |
700 } | |
701 | |
702 // Next tests deal with http://crbug.com/56344. | |
703 | |
704 TEST_F(HttpNetworkTransactionSpdy3Test, | |
705 MultipleContentLengthHeadersNoTransferEncoding) { | |
706 MockRead data_reads[] = { | |
707 MockRead("HTTP/1.1 200 OK\r\n"), | |
708 MockRead("Content-Length: 10\r\n"), | |
709 MockRead("Content-Length: 5\r\n\r\n"), | |
710 }; | |
711 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
712 arraysize(data_reads)); | |
713 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); | |
714 } | |
715 | |
716 TEST_F(HttpNetworkTransactionSpdy3Test, | |
717 DuplicateContentLengthHeadersNoTransferEncoding) { | |
718 MockRead data_reads[] = { | |
719 MockRead("HTTP/1.1 200 OK\r\n"), | |
720 MockRead("Content-Length: 5\r\n"), | |
721 MockRead("Content-Length: 5\r\n\r\n"), | |
722 MockRead("Hello"), | |
723 }; | |
724 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
725 arraysize(data_reads)); | |
726 EXPECT_EQ(OK, out.rv); | |
727 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
728 EXPECT_EQ("Hello", out.response_data); | |
729 } | |
730 | |
731 TEST_F(HttpNetworkTransactionSpdy3Test, | |
732 ComplexContentLengthHeadersNoTransferEncoding) { | |
733 // More than 2 dupes. | |
734 { | |
735 MockRead data_reads[] = { | |
736 MockRead("HTTP/1.1 200 OK\r\n"), | |
737 MockRead("Content-Length: 5\r\n"), | |
738 MockRead("Content-Length: 5\r\n"), | |
739 MockRead("Content-Length: 5\r\n\r\n"), | |
740 MockRead("Hello"), | |
741 }; | |
742 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
743 arraysize(data_reads)); | |
744 EXPECT_EQ(OK, out.rv); | |
745 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
746 EXPECT_EQ("Hello", out.response_data); | |
747 } | |
748 // HTTP/1.0 | |
749 { | |
750 MockRead data_reads[] = { | |
751 MockRead("HTTP/1.0 200 OK\r\n"), | |
752 MockRead("Content-Length: 5\r\n"), | |
753 MockRead("Content-Length: 5\r\n"), | |
754 MockRead("Content-Length: 5\r\n\r\n"), | |
755 MockRead("Hello"), | |
756 }; | |
757 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
758 arraysize(data_reads)); | |
759 EXPECT_EQ(OK, out.rv); | |
760 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | |
761 EXPECT_EQ("Hello", out.response_data); | |
762 } | |
763 // 2 dupes and one mismatched. | |
764 { | |
765 MockRead data_reads[] = { | |
766 MockRead("HTTP/1.1 200 OK\r\n"), | |
767 MockRead("Content-Length: 10\r\n"), | |
768 MockRead("Content-Length: 10\r\n"), | |
769 MockRead("Content-Length: 5\r\n\r\n"), | |
770 }; | |
771 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
772 arraysize(data_reads)); | |
773 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); | |
774 } | |
775 } | |
776 | |
777 TEST_F(HttpNetworkTransactionSpdy3Test, | |
778 MultipleContentLengthHeadersTransferEncoding) { | |
779 MockRead data_reads[] = { | |
780 MockRead("HTTP/1.1 200 OK\r\n"), | |
781 MockRead("Content-Length: 666\r\n"), | |
782 MockRead("Content-Length: 1337\r\n"), | |
783 MockRead("Transfer-Encoding: chunked\r\n\r\n"), | |
784 MockRead("5\r\nHello\r\n"), | |
785 MockRead("1\r\n"), | |
786 MockRead(" \r\n"), | |
787 MockRead("5\r\nworld\r\n"), | |
788 MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), | |
789 MockRead(SYNCHRONOUS, OK), | |
790 }; | |
791 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
792 arraysize(data_reads)); | |
793 EXPECT_EQ(OK, out.rv); | |
794 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
795 EXPECT_EQ("Hello world", out.response_data); | |
796 } | |
797 | |
798 // Next tests deal with http://crbug.com/98895. | |
799 | |
800 // Checks that a single Content-Disposition header results in no error. | |
801 TEST_F(HttpNetworkTransactionSpdy3Test, SingleContentDispositionHeader) { | |
802 MockRead data_reads[] = { | |
803 MockRead("HTTP/1.1 200 OK\r\n"), | |
804 MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), | |
805 MockRead("Content-Length: 5\r\n\r\n"), | |
806 MockRead("Hello"), | |
807 }; | |
808 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
809 arraysize(data_reads)); | |
810 EXPECT_EQ(OK, out.rv); | |
811 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
812 EXPECT_EQ("Hello", out.response_data); | |
813 } | |
814 | |
815 // Checks that two identical Content-Disposition headers result in no error. | |
816 TEST_F(HttpNetworkTransactionSpdy3Test, | |
817 TwoIdenticalContentDispositionHeaders) { | |
818 MockRead data_reads[] = { | |
819 MockRead("HTTP/1.1 200 OK\r\n"), | |
820 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), | |
821 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), | |
822 MockRead("Content-Length: 5\r\n\r\n"), | |
823 MockRead("Hello"), | |
824 }; | |
825 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
826 arraysize(data_reads)); | |
827 EXPECT_EQ(OK, out.rv); | |
828 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
829 EXPECT_EQ("Hello", out.response_data); | |
830 } | |
831 | |
832 // Checks that two distinct Content-Disposition headers result in an error. | |
833 TEST_F(HttpNetworkTransactionSpdy3Test, TwoDistinctContentDispositionHeaders) { | |
834 MockRead data_reads[] = { | |
835 MockRead("HTTP/1.1 200 OK\r\n"), | |
836 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), | |
837 MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), | |
838 MockRead("Content-Length: 5\r\n\r\n"), | |
839 MockRead("Hello"), | |
840 }; | |
841 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
842 arraysize(data_reads)); | |
843 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); | |
844 } | |
845 | |
846 // Checks that two identical Location headers result in no error. | |
847 // Also tests Location header behavior. | |
848 TEST_F(HttpNetworkTransactionSpdy3Test, TwoIdenticalLocationHeaders) { | |
849 MockRead data_reads[] = { | |
850 MockRead("HTTP/1.1 302 Redirect\r\n"), | |
851 MockRead("Location: http://good.com/\r\n"), | |
852 MockRead("Location: http://good.com/\r\n"), | |
853 MockRead("Content-Length: 0\r\n\r\n"), | |
854 MockRead(SYNCHRONOUS, OK), | |
855 }; | |
856 | |
857 HttpRequestInfo request; | |
858 request.method = "GET"; | |
859 request.url = GURL("http://redirect.com/"); | |
860 request.load_flags = 0; | |
861 | |
862 scoped_ptr<HttpTransaction> trans( | |
863 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
864 CreateSession(&session_deps_))); | |
865 | |
866 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
867 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
868 | |
869 TestCompletionCallback callback; | |
870 | |
871 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
872 EXPECT_EQ(ERR_IO_PENDING, rv); | |
873 | |
874 EXPECT_EQ(OK, callback.WaitForResult()); | |
875 | |
876 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
877 ASSERT_TRUE(response != NULL && response->headers.get() != NULL); | |
878 EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); | |
879 std::string url; | |
880 EXPECT_TRUE(response->headers->IsRedirect(&url)); | |
881 EXPECT_EQ("http://good.com/", url); | |
882 } | |
883 | |
884 // Checks that two distinct Location headers result in an error. | |
885 TEST_F(HttpNetworkTransactionSpdy3Test, TwoDistinctLocationHeaders) { | |
886 MockRead data_reads[] = { | |
887 MockRead("HTTP/1.1 302 Redirect\r\n"), | |
888 MockRead("Location: http://good.com/\r\n"), | |
889 MockRead("Location: http://evil.com/\r\n"), | |
890 MockRead("Content-Length: 0\r\n\r\n"), | |
891 MockRead(SYNCHRONOUS, OK), | |
892 }; | |
893 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
894 arraysize(data_reads)); | |
895 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); | |
896 } | |
897 | |
898 // Do a request using the HEAD method. Verify that we don't try to read the | |
899 // message body (since HEAD has none). | |
900 TEST_F(HttpNetworkTransactionSpdy3Test, Head) { | |
901 HttpRequestInfo request; | |
902 request.method = "HEAD"; | |
903 request.url = GURL("http://www.google.com/"); | |
904 request.load_flags = 0; | |
905 | |
906 scoped_ptr<HttpTransaction> trans( | |
907 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
908 CreateSession(&session_deps_))); | |
909 | |
910 MockWrite data_writes1[] = { | |
911 MockWrite("HEAD / HTTP/1.1\r\n" | |
912 "Host: www.google.com\r\n" | |
913 "Connection: keep-alive\r\n" | |
914 "Content-Length: 0\r\n\r\n"), | |
915 }; | |
916 MockRead data_reads1[] = { | |
917 MockRead("HTTP/1.1 404 Not Found\r\n"), | |
918 MockRead("Server: Blah\r\n"), | |
919 MockRead("Content-Length: 1234\r\n\r\n"), | |
920 | |
921 // No response body because the test stops reading here. | |
922 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
923 }; | |
924 | |
925 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
926 data_writes1, arraysize(data_writes1)); | |
927 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
928 | |
929 TestCompletionCallback callback1; | |
930 | |
931 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
932 EXPECT_EQ(ERR_IO_PENDING, rv); | |
933 | |
934 rv = callback1.WaitForResult(); | |
935 EXPECT_EQ(OK, rv); | |
936 | |
937 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
938 ASSERT_TRUE(response != NULL); | |
939 | |
940 // Check that the headers got parsed. | |
941 EXPECT_TRUE(response->headers.get() != NULL); | |
942 EXPECT_EQ(1234, response->headers->GetContentLength()); | |
943 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); | |
944 | |
945 std::string server_header; | |
946 void* iter = NULL; | |
947 bool has_server_header = response->headers->EnumerateHeader( | |
948 &iter, "Server", &server_header); | |
949 EXPECT_TRUE(has_server_header); | |
950 EXPECT_EQ("Blah", server_header); | |
951 | |
952 // Reading should give EOF right away, since there is no message body | |
953 // (despite non-zero content-length). | |
954 std::string response_data; | |
955 rv = ReadTransaction(trans.get(), &response_data); | |
956 EXPECT_EQ(OK, rv); | |
957 EXPECT_EQ("", response_data); | |
958 } | |
959 | |
960 TEST_F(HttpNetworkTransactionSpdy3Test, ReuseConnection) { | |
961 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
962 | |
963 MockRead data_reads[] = { | |
964 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
965 MockRead("hello"), | |
966 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
967 MockRead("world"), | |
968 MockRead(SYNCHRONOUS, OK), | |
969 }; | |
970 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
971 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
972 | |
973 const char* const kExpectedResponseData[] = { | |
974 "hello", "world" | |
975 }; | |
976 | |
977 for (int i = 0; i < 2; ++i) { | |
978 HttpRequestInfo request; | |
979 request.method = "GET"; | |
980 request.url = GURL("http://www.google.com/"); | |
981 request.load_flags = 0; | |
982 | |
983 scoped_ptr<HttpTransaction> trans( | |
984 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
985 | |
986 TestCompletionCallback callback; | |
987 | |
988 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
989 EXPECT_EQ(ERR_IO_PENDING, rv); | |
990 | |
991 rv = callback.WaitForResult(); | |
992 EXPECT_EQ(OK, rv); | |
993 | |
994 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
995 ASSERT_TRUE(response != NULL); | |
996 | |
997 EXPECT_TRUE(response->headers.get() != NULL); | |
998 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
999 | |
1000 std::string response_data; | |
1001 rv = ReadTransaction(trans.get(), &response_data); | |
1002 EXPECT_EQ(OK, rv); | |
1003 EXPECT_EQ(kExpectedResponseData[i], response_data); | |
1004 } | |
1005 } | |
1006 | |
1007 TEST_F(HttpNetworkTransactionSpdy3Test, Ignores100) { | |
1008 ScopedVector<UploadElementReader> element_readers; | |
1009 element_readers.push_back(new UploadBytesElementReader("foo", 3)); | |
1010 UploadDataStream upload_data_stream(&element_readers, 0); | |
1011 | |
1012 HttpRequestInfo request; | |
1013 request.method = "POST"; | |
1014 request.url = GURL("http://www.foo.com/"); | |
1015 request.upload_data_stream = &upload_data_stream; | |
1016 request.load_flags = 0; | |
1017 | |
1018 scoped_ptr<HttpTransaction> trans( | |
1019 new HttpNetworkTransaction( | |
1020 DEFAULT_PRIORITY, CreateSession(&session_deps_))); | |
1021 | |
1022 MockRead data_reads[] = { | |
1023 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), | |
1024 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
1025 MockRead("hello world"), | |
1026 MockRead(SYNCHRONOUS, OK), | |
1027 }; | |
1028 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1029 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1030 | |
1031 TestCompletionCallback callback; | |
1032 | |
1033 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1034 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1035 | |
1036 rv = callback.WaitForResult(); | |
1037 EXPECT_EQ(OK, rv); | |
1038 | |
1039 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1040 ASSERT_TRUE(response != NULL); | |
1041 | |
1042 EXPECT_TRUE(response->headers.get() != NULL); | |
1043 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); | |
1044 | |
1045 std::string response_data; | |
1046 rv = ReadTransaction(trans.get(), &response_data); | |
1047 EXPECT_EQ(OK, rv); | |
1048 EXPECT_EQ("hello world", response_data); | |
1049 } | |
1050 | |
1051 // This test is almost the same as Ignores100 above, but the response contains | |
1052 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is | |
1053 // HTTP/1.1 and the two status headers are read in one read. | |
1054 TEST_F(HttpNetworkTransactionSpdy3Test, Ignores1xx) { | |
1055 HttpRequestInfo request; | |
1056 request.method = "GET"; | |
1057 request.url = GURL("http://www.foo.com/"); | |
1058 request.load_flags = 0; | |
1059 | |
1060 scoped_ptr<HttpTransaction> trans( | |
1061 new HttpNetworkTransaction( | |
1062 DEFAULT_PRIORITY, CreateSession(&session_deps_))); | |
1063 | |
1064 MockRead data_reads[] = { | |
1065 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" | |
1066 "HTTP/1.1 200 OK\r\n\r\n"), | |
1067 MockRead("hello world"), | |
1068 MockRead(SYNCHRONOUS, OK), | |
1069 }; | |
1070 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1071 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1072 | |
1073 TestCompletionCallback callback; | |
1074 | |
1075 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1076 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1077 | |
1078 rv = callback.WaitForResult(); | |
1079 EXPECT_EQ(OK, rv); | |
1080 | |
1081 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1082 ASSERT_TRUE(response != NULL); | |
1083 | |
1084 EXPECT_TRUE(response->headers.get() != NULL); | |
1085 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
1086 | |
1087 std::string response_data; | |
1088 rv = ReadTransaction(trans.get(), &response_data); | |
1089 EXPECT_EQ(OK, rv); | |
1090 EXPECT_EQ("hello world", response_data); | |
1091 } | |
1092 | |
1093 TEST_F(HttpNetworkTransactionSpdy3Test, Incomplete100ThenEOF) { | |
1094 HttpRequestInfo request; | |
1095 request.method = "POST"; | |
1096 request.url = GURL("http://www.foo.com/"); | |
1097 request.load_flags = 0; | |
1098 | |
1099 scoped_ptr<HttpTransaction> trans( | |
1100 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
1101 CreateSession(&session_deps_))); | |
1102 | |
1103 MockRead data_reads[] = { | |
1104 MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), | |
1105 MockRead(ASYNC, 0), | |
1106 }; | |
1107 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1108 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1109 | |
1110 TestCompletionCallback callback; | |
1111 | |
1112 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1113 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1114 | |
1115 rv = callback.WaitForResult(); | |
1116 EXPECT_EQ(OK, rv); | |
1117 | |
1118 std::string response_data; | |
1119 rv = ReadTransaction(trans.get(), &response_data); | |
1120 EXPECT_EQ(OK, rv); | |
1121 EXPECT_EQ("", response_data); | |
1122 } | |
1123 | |
1124 TEST_F(HttpNetworkTransactionSpdy3Test, EmptyResponse) { | |
1125 HttpRequestInfo request; | |
1126 request.method = "POST"; | |
1127 request.url = GURL("http://www.foo.com/"); | |
1128 request.load_flags = 0; | |
1129 | |
1130 scoped_ptr<HttpTransaction> trans( | |
1131 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
1132 CreateSession(&session_deps_))); | |
1133 | |
1134 MockRead data_reads[] = { | |
1135 MockRead(ASYNC, 0), | |
1136 }; | |
1137 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1138 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1139 | |
1140 TestCompletionCallback callback; | |
1141 | |
1142 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1143 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1144 | |
1145 rv = callback.WaitForResult(); | |
1146 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); | |
1147 } | |
1148 | |
1149 void HttpNetworkTransactionSpdy3Test::KeepAliveConnectionResendRequestTest( | |
1150 const MockWrite* write_failure, | |
1151 const MockRead* read_failure) { | |
1152 HttpRequestInfo request; | |
1153 request.method = "GET"; | |
1154 request.url = GURL("http://www.foo.com/"); | |
1155 request.load_flags = 0; | |
1156 | |
1157 CapturingNetLog net_log; | |
1158 session_deps_.net_log = &net_log; | |
1159 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1160 | |
1161 // Written data for successfully sending both requests. | |
1162 MockWrite data1_writes[] = { | |
1163 MockWrite("GET / HTTP/1.1\r\n" | |
1164 "Host: www.foo.com\r\n" | |
1165 "Connection: keep-alive\r\n\r\n"), | |
1166 MockWrite("GET / HTTP/1.1\r\n" | |
1167 "Host: www.foo.com\r\n" | |
1168 "Connection: keep-alive\r\n\r\n") | |
1169 }; | |
1170 | |
1171 // Read results for the first request. | |
1172 MockRead data1_reads[] = { | |
1173 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
1174 MockRead("hello"), | |
1175 MockRead(ASYNC, OK), | |
1176 }; | |
1177 | |
1178 if (write_failure) { | |
1179 ASSERT_TRUE(!read_failure); | |
1180 data1_writes[1] = *write_failure; | |
1181 } else { | |
1182 ASSERT_TRUE(read_failure); | |
1183 data1_reads[2] = *read_failure; | |
1184 } | |
1185 | |
1186 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), | |
1187 data1_writes, arraysize(data1_writes)); | |
1188 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
1189 | |
1190 MockRead data2_reads[] = { | |
1191 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
1192 MockRead("world"), | |
1193 MockRead(ASYNC, OK), | |
1194 }; | |
1195 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); | |
1196 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1197 | |
1198 const char* kExpectedResponseData[] = { | |
1199 "hello", "world" | |
1200 }; | |
1201 | |
1202 uint32 first_socket_log_id = NetLog::Source::kInvalidId; | |
1203 for (int i = 0; i < 2; ++i) { | |
1204 TestCompletionCallback callback; | |
1205 | |
1206 scoped_ptr<HttpTransaction> trans( | |
1207 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1208 | |
1209 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1210 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1211 | |
1212 rv = callback.WaitForResult(); | |
1213 EXPECT_EQ(OK, rv); | |
1214 | |
1215 LoadTimingInfo load_timing_info; | |
1216 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
1217 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | |
1218 if (i == 0) { | |
1219 first_socket_log_id = load_timing_info.socket_log_id; | |
1220 } else { | |
1221 // The second request should be using a new socket. | |
1222 EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); | |
1223 } | |
1224 | |
1225 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1226 ASSERT_TRUE(response != NULL); | |
1227 | |
1228 EXPECT_TRUE(response->headers.get() != NULL); | |
1229 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
1230 | |
1231 std::string response_data; | |
1232 rv = ReadTransaction(trans.get(), &response_data); | |
1233 EXPECT_EQ(OK, rv); | |
1234 EXPECT_EQ(kExpectedResponseData[i], response_data); | |
1235 } | |
1236 } | |
1237 | |
1238 TEST_F(HttpNetworkTransactionSpdy3Test, | |
1239 KeepAliveConnectionNotConnectedOnWrite) { | |
1240 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); | |
1241 KeepAliveConnectionResendRequestTest(&write_failure, NULL); | |
1242 } | |
1243 | |
1244 TEST_F(HttpNetworkTransactionSpdy3Test, KeepAliveConnectionReset) { | |
1245 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); | |
1246 KeepAliveConnectionResendRequestTest(NULL, &read_failure); | |
1247 } | |
1248 | |
1249 TEST_F(HttpNetworkTransactionSpdy3Test, KeepAliveConnectionEOF) { | |
1250 MockRead read_failure(SYNCHRONOUS, OK); // EOF | |
1251 KeepAliveConnectionResendRequestTest(NULL, &read_failure); | |
1252 } | |
1253 | |
1254 TEST_F(HttpNetworkTransactionSpdy3Test, NonKeepAliveConnectionReset) { | |
1255 HttpRequestInfo request; | |
1256 request.method = "GET"; | |
1257 request.url = GURL("http://www.google.com/"); | |
1258 request.load_flags = 0; | |
1259 | |
1260 scoped_ptr<HttpTransaction> trans( | |
1261 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
1262 CreateSession(&session_deps_))); | |
1263 | |
1264 MockRead data_reads[] = { | |
1265 MockRead(ASYNC, ERR_CONNECTION_RESET), | |
1266 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used | |
1267 MockRead("hello world"), | |
1268 MockRead(SYNCHRONOUS, OK), | |
1269 }; | |
1270 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1271 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1272 | |
1273 TestCompletionCallback callback; | |
1274 | |
1275 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1276 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1277 | |
1278 rv = callback.WaitForResult(); | |
1279 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | |
1280 | |
1281 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1282 EXPECT_TRUE(response == NULL); | |
1283 } | |
1284 | |
1285 // What do various browsers do when the server closes a non-keepalive | |
1286 // connection without sending any response header or body? | |
1287 // | |
1288 // IE7: error page | |
1289 // Safari 3.1.2 (Windows): error page | |
1290 // Firefox 3.0.1: blank page | |
1291 // Opera 9.52: after five attempts, blank page | |
1292 // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) | |
1293 // Us: error page (EMPTY_RESPONSE) | |
1294 TEST_F(HttpNetworkTransactionSpdy3Test, NonKeepAliveConnectionEOF) { | |
1295 MockRead data_reads[] = { | |
1296 MockRead(SYNCHRONOUS, OK), // EOF | |
1297 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used | |
1298 MockRead("hello world"), | |
1299 MockRead(SYNCHRONOUS, OK), | |
1300 }; | |
1301 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
1302 arraysize(data_reads)); | |
1303 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); | |
1304 } | |
1305 | |
1306 // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression | |
1307 // tests. There was a bug causing HttpNetworkTransaction to hang in the | |
1308 // destructor in such situations. | |
1309 // See http://crbug.com/154712 and http://crbug.com/156609. | |
1310 TEST_F(HttpNetworkTransactionSpdy3Test, KeepAliveEarlyClose) { | |
1311 HttpRequestInfo request; | |
1312 request.method = "GET"; | |
1313 request.url = GURL("http://www.google.com/"); | |
1314 request.load_flags = 0; | |
1315 | |
1316 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1317 scoped_ptr<HttpTransaction> trans( | |
1318 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1319 | |
1320 MockRead data_reads[] = { | |
1321 MockRead("HTTP/1.0 200 OK\r\n"), | |
1322 MockRead("Connection: keep-alive\r\n"), | |
1323 MockRead("Content-Length: 100\r\n\r\n"), | |
1324 MockRead("hello"), | |
1325 MockRead(SYNCHRONOUS, 0), | |
1326 }; | |
1327 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1328 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1329 | |
1330 TestCompletionCallback callback; | |
1331 | |
1332 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1333 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1334 | |
1335 rv = callback.WaitForResult(); | |
1336 EXPECT_EQ(OK, rv); | |
1337 | |
1338 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); | |
1339 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
1340 if (rv == ERR_IO_PENDING) | |
1341 rv = callback.WaitForResult(); | |
1342 EXPECT_EQ(5, rv); | |
1343 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
1344 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); | |
1345 | |
1346 trans.reset(); | |
1347 base::MessageLoop::current()->RunUntilIdle(); | |
1348 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
1349 } | |
1350 | |
1351 TEST_F(HttpNetworkTransactionSpdy3Test, KeepAliveEarlyClose2) { | |
1352 HttpRequestInfo request; | |
1353 request.method = "GET"; | |
1354 request.url = GURL("http://www.google.com/"); | |
1355 request.load_flags = 0; | |
1356 | |
1357 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1358 scoped_ptr<HttpTransaction> trans( | |
1359 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1360 | |
1361 MockRead data_reads[] = { | |
1362 MockRead("HTTP/1.0 200 OK\r\n"), | |
1363 MockRead("Connection: keep-alive\r\n"), | |
1364 MockRead("Content-Length: 100\r\n\r\n"), | |
1365 MockRead(SYNCHRONOUS, 0), | |
1366 }; | |
1367 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1368 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1369 | |
1370 TestCompletionCallback callback; | |
1371 | |
1372 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1373 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1374 | |
1375 rv = callback.WaitForResult(); | |
1376 EXPECT_EQ(OK, rv); | |
1377 | |
1378 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); | |
1379 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
1380 if (rv == ERR_IO_PENDING) | |
1381 rv = callback.WaitForResult(); | |
1382 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); | |
1383 | |
1384 trans.reset(); | |
1385 base::MessageLoop::current()->RunUntilIdle(); | |
1386 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
1387 } | |
1388 | |
1389 // Test that we correctly reuse a keep-alive connection after not explicitly | |
1390 // reading the body. | |
1391 TEST_F(HttpNetworkTransactionSpdy3Test, KeepAliveAfterUnreadBody) { | |
1392 HttpRequestInfo request; | |
1393 request.method = "GET"; | |
1394 request.url = GURL("http://www.foo.com/"); | |
1395 request.load_flags = 0; | |
1396 | |
1397 CapturingNetLog net_log; | |
1398 session_deps_.net_log = &net_log; | |
1399 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1400 | |
1401 // Note that because all these reads happen in the same | |
1402 // StaticSocketDataProvider, it shows that the same socket is being reused for | |
1403 // all transactions. | |
1404 MockRead data1_reads[] = { | |
1405 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), | |
1406 MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), | |
1407 MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), | |
1408 MockRead("HTTP/1.1 302 Found\r\n" | |
1409 "Content-Length: 0\r\n\r\n"), | |
1410 MockRead("HTTP/1.1 302 Found\r\n" | |
1411 "Content-Length: 5\r\n\r\n" | |
1412 "hello"), | |
1413 MockRead("HTTP/1.1 301 Moved Permanently\r\n" | |
1414 "Content-Length: 0\r\n\r\n"), | |
1415 MockRead("HTTP/1.1 301 Moved Permanently\r\n" | |
1416 "Content-Length: 5\r\n\r\n" | |
1417 "hello"), | |
1418 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
1419 MockRead("hello"), | |
1420 }; | |
1421 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); | |
1422 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
1423 | |
1424 MockRead data2_reads[] = { | |
1425 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
1426 }; | |
1427 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); | |
1428 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1429 | |
1430 const int kNumUnreadBodies = arraysize(data1_reads) - 2; | |
1431 std::string response_lines[kNumUnreadBodies]; | |
1432 | |
1433 uint32 first_socket_log_id = NetLog::Source::kInvalidId; | |
1434 for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { | |
1435 TestCompletionCallback callback; | |
1436 | |
1437 scoped_ptr<HttpTransaction> trans( | |
1438 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1439 | |
1440 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1441 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1442 | |
1443 rv = callback.WaitForResult(); | |
1444 EXPECT_EQ(OK, rv); | |
1445 | |
1446 LoadTimingInfo load_timing_info; | |
1447 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
1448 if (i == 0) { | |
1449 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | |
1450 first_socket_log_id = load_timing_info.socket_log_id; | |
1451 } else { | |
1452 TestLoadTimingReused(load_timing_info); | |
1453 EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); | |
1454 } | |
1455 | |
1456 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1457 ASSERT_TRUE(response != NULL); | |
1458 | |
1459 ASSERT_TRUE(response->headers.get() != NULL); | |
1460 response_lines[i] = response->headers->GetStatusLine(); | |
1461 | |
1462 // We intentionally don't read the response bodies. | |
1463 } | |
1464 | |
1465 const char* const kStatusLines[] = { | |
1466 "HTTP/1.1 204 No Content", | |
1467 "HTTP/1.1 205 Reset Content", | |
1468 "HTTP/1.1 304 Not Modified", | |
1469 "HTTP/1.1 302 Found", | |
1470 "HTTP/1.1 302 Found", | |
1471 "HTTP/1.1 301 Moved Permanently", | |
1472 "HTTP/1.1 301 Moved Permanently", | |
1473 }; | |
1474 | |
1475 COMPILE_ASSERT(kNumUnreadBodies == arraysize(kStatusLines), | |
1476 forgot_to_update_kStatusLines); | |
1477 | |
1478 for (int i = 0; i < kNumUnreadBodies; ++i) | |
1479 EXPECT_EQ(kStatusLines[i], response_lines[i]); | |
1480 | |
1481 TestCompletionCallback callback; | |
1482 scoped_ptr<HttpTransaction> trans( | |
1483 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1484 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1485 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1486 rv = callback.WaitForResult(); | |
1487 EXPECT_EQ(OK, rv); | |
1488 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1489 ASSERT_TRUE(response != NULL); | |
1490 ASSERT_TRUE(response->headers.get() != NULL); | |
1491 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
1492 std::string response_data; | |
1493 rv = ReadTransaction(trans.get(), &response_data); | |
1494 EXPECT_EQ(OK, rv); | |
1495 EXPECT_EQ("hello", response_data); | |
1496 } | |
1497 | |
1498 // Test the request-challenge-retry sequence for basic auth. | |
1499 // (basic auth is the easiest to mock, because it has no randomness). | |
1500 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuth) { | |
1501 HttpRequestInfo request; | |
1502 request.method = "GET"; | |
1503 request.url = GURL("http://www.google.com/"); | |
1504 request.load_flags = 0; | |
1505 | |
1506 CapturingNetLog log; | |
1507 session_deps_.net_log = &log; | |
1508 scoped_ptr<HttpTransaction> trans( | |
1509 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
1510 CreateSession(&session_deps_))); | |
1511 | |
1512 MockWrite data_writes1[] = { | |
1513 MockWrite("GET / HTTP/1.1\r\n" | |
1514 "Host: www.google.com\r\n" | |
1515 "Connection: keep-alive\r\n\r\n"), | |
1516 }; | |
1517 | |
1518 MockRead data_reads1[] = { | |
1519 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
1520 // Give a couple authenticate options (only the middle one is actually | |
1521 // supported). | |
1522 MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. | |
1523 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
1524 MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), | |
1525 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1526 // Large content-length -- won't matter, as connection will be reset. | |
1527 MockRead("Content-Length: 10000\r\n\r\n"), | |
1528 MockRead(SYNCHRONOUS, ERR_FAILED), | |
1529 }; | |
1530 | |
1531 // After calling trans->RestartWithAuth(), this is the request we should | |
1532 // be issuing -- the final header line contains the credentials. | |
1533 MockWrite data_writes2[] = { | |
1534 MockWrite("GET / HTTP/1.1\r\n" | |
1535 "Host: www.google.com\r\n" | |
1536 "Connection: keep-alive\r\n" | |
1537 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
1538 }; | |
1539 | |
1540 // Lastly, the server responds with the actual content. | |
1541 MockRead data_reads2[] = { | |
1542 MockRead("HTTP/1.0 200 OK\r\n"), | |
1543 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1544 MockRead("Content-Length: 100\r\n\r\n"), | |
1545 MockRead(SYNCHRONOUS, OK), | |
1546 }; | |
1547 | |
1548 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
1549 data_writes1, arraysize(data_writes1)); | |
1550 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
1551 data_writes2, arraysize(data_writes2)); | |
1552 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
1553 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1554 | |
1555 TestCompletionCallback callback1; | |
1556 | |
1557 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
1558 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1559 | |
1560 rv = callback1.WaitForResult(); | |
1561 EXPECT_EQ(OK, rv); | |
1562 | |
1563 LoadTimingInfo load_timing_info1; | |
1564 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); | |
1565 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); | |
1566 | |
1567 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1568 ASSERT_TRUE(response != NULL); | |
1569 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
1570 | |
1571 TestCompletionCallback callback2; | |
1572 | |
1573 rv = trans->RestartWithAuth( | |
1574 AuthCredentials(kFoo, kBar), callback2.callback()); | |
1575 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1576 | |
1577 rv = callback2.WaitForResult(); | |
1578 EXPECT_EQ(OK, rv); | |
1579 | |
1580 LoadTimingInfo load_timing_info2; | |
1581 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); | |
1582 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); | |
1583 // The load timing after restart should have a new socket ID, and times after | |
1584 // those of the first load timing. | |
1585 EXPECT_LE(load_timing_info1.receive_headers_end, | |
1586 load_timing_info2.connect_timing.connect_start); | |
1587 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | |
1588 | |
1589 response = trans->GetResponseInfo(); | |
1590 ASSERT_TRUE(response != NULL); | |
1591 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
1592 EXPECT_EQ(100, response->headers->GetContentLength()); | |
1593 } | |
1594 | |
1595 TEST_F(HttpNetworkTransactionSpdy3Test, DoNotSendAuth) { | |
1596 HttpRequestInfo request; | |
1597 request.method = "GET"; | |
1598 request.url = GURL("http://www.google.com/"); | |
1599 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; | |
1600 | |
1601 scoped_ptr<HttpTransaction> trans( | |
1602 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
1603 CreateSession(&session_deps_))); | |
1604 | |
1605 MockWrite data_writes[] = { | |
1606 MockWrite("GET / HTTP/1.1\r\n" | |
1607 "Host: www.google.com\r\n" | |
1608 "Connection: keep-alive\r\n\r\n"), | |
1609 }; | |
1610 | |
1611 MockRead data_reads[] = { | |
1612 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
1613 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
1614 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1615 // Large content-length -- won't matter, as connection will be reset. | |
1616 MockRead("Content-Length: 10000\r\n\r\n"), | |
1617 MockRead(SYNCHRONOUS, ERR_FAILED), | |
1618 }; | |
1619 | |
1620 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
1621 data_writes, arraysize(data_writes)); | |
1622 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1623 TestCompletionCallback callback; | |
1624 | |
1625 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1626 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1627 | |
1628 rv = callback.WaitForResult(); | |
1629 EXPECT_EQ(0, rv); | |
1630 | |
1631 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1632 ASSERT_TRUE(response != NULL); | |
1633 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
1634 } | |
1635 | |
1636 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | |
1637 // connection. | |
1638 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthKeepAlive) { | |
1639 HttpRequestInfo request; | |
1640 request.method = "GET"; | |
1641 request.url = GURL("http://www.google.com/"); | |
1642 request.load_flags = 0; | |
1643 | |
1644 CapturingNetLog log; | |
1645 session_deps_.net_log = &log; | |
1646 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1647 | |
1648 MockWrite data_writes1[] = { | |
1649 MockWrite("GET / HTTP/1.1\r\n" | |
1650 "Host: www.google.com\r\n" | |
1651 "Connection: keep-alive\r\n\r\n"), | |
1652 | |
1653 // After calling trans->RestartWithAuth(), this is the request we should | |
1654 // be issuing -- the final header line contains the credentials. | |
1655 MockWrite("GET / HTTP/1.1\r\n" | |
1656 "Host: www.google.com\r\n" | |
1657 "Connection: keep-alive\r\n" | |
1658 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
1659 }; | |
1660 | |
1661 MockRead data_reads1[] = { | |
1662 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | |
1663 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
1664 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1665 MockRead("Content-Length: 14\r\n\r\n"), | |
1666 MockRead("Unauthorized\r\n"), | |
1667 | |
1668 // Lastly, the server responds with the actual content. | |
1669 MockRead("HTTP/1.1 200 OK\r\n"), | |
1670 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1671 MockRead("Content-Length: 5\r\n\r\n"), | |
1672 MockRead("Hello"), | |
1673 }; | |
1674 | |
1675 // If there is a regression where we disconnect a Keep-Alive | |
1676 // connection during an auth roundtrip, we'll end up reading this. | |
1677 MockRead data_reads2[] = { | |
1678 MockRead(SYNCHRONOUS, ERR_FAILED), | |
1679 }; | |
1680 | |
1681 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
1682 data_writes1, arraysize(data_writes1)); | |
1683 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
1684 NULL, 0); | |
1685 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
1686 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1687 | |
1688 TestCompletionCallback callback1; | |
1689 | |
1690 scoped_ptr<HttpTransaction> trans( | |
1691 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1692 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
1693 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1694 | |
1695 rv = callback1.WaitForResult(); | |
1696 EXPECT_EQ(OK, rv); | |
1697 | |
1698 LoadTimingInfo load_timing_info1; | |
1699 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); | |
1700 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); | |
1701 | |
1702 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1703 ASSERT_TRUE(response != NULL); | |
1704 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
1705 | |
1706 TestCompletionCallback callback2; | |
1707 | |
1708 rv = trans->RestartWithAuth( | |
1709 AuthCredentials(kFoo, kBar), callback2.callback()); | |
1710 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1711 | |
1712 rv = callback2.WaitForResult(); | |
1713 EXPECT_EQ(OK, rv); | |
1714 | |
1715 LoadTimingInfo load_timing_info2; | |
1716 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); | |
1717 TestLoadTimingReused(load_timing_info2); | |
1718 // The load timing after restart should have the same socket ID, and times | |
1719 // those of the first load timing. | |
1720 EXPECT_LE(load_timing_info1.receive_headers_end, | |
1721 load_timing_info2.send_start); | |
1722 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | |
1723 | |
1724 response = trans->GetResponseInfo(); | |
1725 ASSERT_TRUE(response != NULL); | |
1726 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
1727 EXPECT_EQ(5, response->headers->GetContentLength()); | |
1728 } | |
1729 | |
1730 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | |
1731 // connection and with no response body to drain. | |
1732 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthKeepAliveNoBody) { | |
1733 HttpRequestInfo request; | |
1734 request.method = "GET"; | |
1735 request.url = GURL("http://www.google.com/"); | |
1736 request.load_flags = 0; | |
1737 | |
1738 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1739 | |
1740 MockWrite data_writes1[] = { | |
1741 MockWrite("GET / HTTP/1.1\r\n" | |
1742 "Host: www.google.com\r\n" | |
1743 "Connection: keep-alive\r\n\r\n"), | |
1744 | |
1745 // After calling trans->RestartWithAuth(), this is the request we should | |
1746 // be issuing -- the final header line contains the credentials. | |
1747 MockWrite("GET / HTTP/1.1\r\n" | |
1748 "Host: www.google.com\r\n" | |
1749 "Connection: keep-alive\r\n" | |
1750 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
1751 }; | |
1752 | |
1753 MockRead data_reads1[] = { | |
1754 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | |
1755 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
1756 MockRead("Content-Length: 0\r\n\r\n"), // No response body. | |
1757 | |
1758 // Lastly, the server responds with the actual content. | |
1759 MockRead("HTTP/1.1 200 OK\r\n"), | |
1760 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1761 MockRead("Content-Length: 5\r\n\r\n"), | |
1762 MockRead("hello"), | |
1763 }; | |
1764 | |
1765 // An incorrect reconnect would cause this to be read. | |
1766 MockRead data_reads2[] = { | |
1767 MockRead(SYNCHRONOUS, ERR_FAILED), | |
1768 }; | |
1769 | |
1770 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
1771 data_writes1, arraysize(data_writes1)); | |
1772 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
1773 NULL, 0); | |
1774 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
1775 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1776 | |
1777 TestCompletionCallback callback1; | |
1778 | |
1779 scoped_ptr<HttpTransaction> trans( | |
1780 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1781 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
1782 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1783 | |
1784 rv = callback1.WaitForResult(); | |
1785 EXPECT_EQ(OK, rv); | |
1786 | |
1787 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1788 ASSERT_TRUE(response != NULL); | |
1789 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
1790 | |
1791 TestCompletionCallback callback2; | |
1792 | |
1793 rv = trans->RestartWithAuth( | |
1794 AuthCredentials(kFoo, kBar), callback2.callback()); | |
1795 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1796 | |
1797 rv = callback2.WaitForResult(); | |
1798 EXPECT_EQ(OK, rv); | |
1799 | |
1800 response = trans->GetResponseInfo(); | |
1801 ASSERT_TRUE(response != NULL); | |
1802 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
1803 EXPECT_EQ(5, response->headers->GetContentLength()); | |
1804 } | |
1805 | |
1806 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | |
1807 // connection and with a large response body to drain. | |
1808 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthKeepAliveLargeBody) { | |
1809 HttpRequestInfo request; | |
1810 request.method = "GET"; | |
1811 request.url = GURL("http://www.google.com/"); | |
1812 request.load_flags = 0; | |
1813 | |
1814 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1815 | |
1816 MockWrite data_writes1[] = { | |
1817 MockWrite("GET / HTTP/1.1\r\n" | |
1818 "Host: www.google.com\r\n" | |
1819 "Connection: keep-alive\r\n\r\n"), | |
1820 | |
1821 // After calling trans->RestartWithAuth(), this is the request we should | |
1822 // be issuing -- the final header line contains the credentials. | |
1823 MockWrite("GET / HTTP/1.1\r\n" | |
1824 "Host: www.google.com\r\n" | |
1825 "Connection: keep-alive\r\n" | |
1826 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
1827 }; | |
1828 | |
1829 // Respond with 5 kb of response body. | |
1830 std::string large_body_string("Unauthorized"); | |
1831 large_body_string.append(5 * 1024, ' '); | |
1832 large_body_string.append("\r\n"); | |
1833 | |
1834 MockRead data_reads1[] = { | |
1835 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | |
1836 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
1837 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1838 // 5134 = 12 + 5 * 1024 + 2 | |
1839 MockRead("Content-Length: 5134\r\n\r\n"), | |
1840 MockRead(ASYNC, large_body_string.data(), large_body_string.size()), | |
1841 | |
1842 // Lastly, the server responds with the actual content. | |
1843 MockRead("HTTP/1.1 200 OK\r\n"), | |
1844 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1845 MockRead("Content-Length: 5\r\n\r\n"), | |
1846 MockRead("hello"), | |
1847 }; | |
1848 | |
1849 // An incorrect reconnect would cause this to be read. | |
1850 MockRead data_reads2[] = { | |
1851 MockRead(SYNCHRONOUS, ERR_FAILED), | |
1852 }; | |
1853 | |
1854 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
1855 data_writes1, arraysize(data_writes1)); | |
1856 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
1857 NULL, 0); | |
1858 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
1859 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1860 | |
1861 TestCompletionCallback callback1; | |
1862 | |
1863 scoped_ptr<HttpTransaction> trans( | |
1864 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1865 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
1866 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1867 | |
1868 rv = callback1.WaitForResult(); | |
1869 EXPECT_EQ(OK, rv); | |
1870 | |
1871 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1872 ASSERT_TRUE(response != NULL); | |
1873 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
1874 | |
1875 TestCompletionCallback callback2; | |
1876 | |
1877 rv = trans->RestartWithAuth( | |
1878 AuthCredentials(kFoo, kBar), callback2.callback()); | |
1879 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1880 | |
1881 rv = callback2.WaitForResult(); | |
1882 EXPECT_EQ(OK, rv); | |
1883 | |
1884 response = trans->GetResponseInfo(); | |
1885 ASSERT_TRUE(response != NULL); | |
1886 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
1887 EXPECT_EQ(5, response->headers->GetContentLength()); | |
1888 } | |
1889 | |
1890 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | |
1891 // connection, but the server gets impatient and closes the connection. | |
1892 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthKeepAliveImpatientServer) { | |
1893 HttpRequestInfo request; | |
1894 request.method = "GET"; | |
1895 request.url = GURL("http://www.google.com/"); | |
1896 request.load_flags = 0; | |
1897 | |
1898 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1899 | |
1900 MockWrite data_writes1[] = { | |
1901 MockWrite("GET / HTTP/1.1\r\n" | |
1902 "Host: www.google.com\r\n" | |
1903 "Connection: keep-alive\r\n\r\n"), | |
1904 // This simulates the seemingly successful write to a closed connection | |
1905 // if the bug is not fixed. | |
1906 MockWrite("GET / HTTP/1.1\r\n" | |
1907 "Host: www.google.com\r\n" | |
1908 "Connection: keep-alive\r\n" | |
1909 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
1910 }; | |
1911 | |
1912 MockRead data_reads1[] = { | |
1913 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | |
1914 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
1915 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1916 MockRead("Content-Length: 14\r\n\r\n"), | |
1917 // Tell MockTCPClientSocket to simulate the server closing the connection. | |
1918 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
1919 MockRead("Unauthorized\r\n"), | |
1920 MockRead(SYNCHRONOUS, OK), // The server closes the connection. | |
1921 }; | |
1922 | |
1923 // After calling trans->RestartWithAuth(), this is the request we should | |
1924 // be issuing -- the final header line contains the credentials. | |
1925 MockWrite data_writes2[] = { | |
1926 MockWrite("GET / HTTP/1.1\r\n" | |
1927 "Host: www.google.com\r\n" | |
1928 "Connection: keep-alive\r\n" | |
1929 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
1930 }; | |
1931 | |
1932 // Lastly, the server responds with the actual content. | |
1933 MockRead data_reads2[] = { | |
1934 MockRead("HTTP/1.1 200 OK\r\n"), | |
1935 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
1936 MockRead("Content-Length: 5\r\n\r\n"), | |
1937 MockRead("hello"), | |
1938 }; | |
1939 | |
1940 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
1941 data_writes1, arraysize(data_writes1)); | |
1942 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
1943 data_writes2, arraysize(data_writes2)); | |
1944 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
1945 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1946 | |
1947 TestCompletionCallback callback1; | |
1948 | |
1949 scoped_ptr<HttpTransaction> trans( | |
1950 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1951 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
1952 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1953 | |
1954 rv = callback1.WaitForResult(); | |
1955 EXPECT_EQ(OK, rv); | |
1956 | |
1957 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
1958 ASSERT_TRUE(response != NULL); | |
1959 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
1960 | |
1961 TestCompletionCallback callback2; | |
1962 | |
1963 rv = trans->RestartWithAuth( | |
1964 AuthCredentials(kFoo, kBar), callback2.callback()); | |
1965 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1966 | |
1967 rv = callback2.WaitForResult(); | |
1968 EXPECT_EQ(OK, rv); | |
1969 | |
1970 response = trans->GetResponseInfo(); | |
1971 ASSERT_TRUE(response != NULL); | |
1972 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
1973 EXPECT_EQ(5, response->headers->GetContentLength()); | |
1974 } | |
1975 | |
1976 // Test the request-challenge-retry sequence for basic auth, over a connection | |
1977 // that requires a restart when setting up an SSL tunnel. | |
1978 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthProxyNoKeepAlive) { | |
1979 HttpRequestInfo request; | |
1980 request.method = "GET"; | |
1981 request.url = GURL("https://www.google.com/"); | |
1982 // when the no authentication data flag is set. | |
1983 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; | |
1984 | |
1985 // Configure against proxy server "myproxy:70". | |
1986 session_deps_.proxy_service.reset( | |
1987 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | |
1988 CapturingBoundNetLog log; | |
1989 session_deps_.net_log = log.bound().net_log(); | |
1990 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1991 | |
1992 // Since we have proxy, should try to establish tunnel. | |
1993 MockWrite data_writes1[] = { | |
1994 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
1995 "Host: www.google.com\r\n" | |
1996 "Proxy-Connection: keep-alive\r\n\r\n"), | |
1997 | |
1998 // After calling trans->RestartWithAuth(), this is the request we should | |
1999 // be issuing -- the final header line contains the credentials. | |
2000 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2001 "Host: www.google.com\r\n" | |
2002 "Proxy-Connection: keep-alive\r\n" | |
2003 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
2004 | |
2005 MockWrite("GET / HTTP/1.1\r\n" | |
2006 "Host: www.google.com\r\n" | |
2007 "Connection: keep-alive\r\n\r\n"), | |
2008 }; | |
2009 | |
2010 // The proxy responds to the connect with a 407, using a persistent | |
2011 // connection. | |
2012 MockRead data_reads1[] = { | |
2013 // No credentials. | |
2014 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
2015 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
2016 MockRead("Proxy-Connection: close\r\n\r\n"), | |
2017 | |
2018 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), | |
2019 | |
2020 MockRead("HTTP/1.1 200 OK\r\n"), | |
2021 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
2022 MockRead("Content-Length: 5\r\n\r\n"), | |
2023 MockRead(SYNCHRONOUS, "hello"), | |
2024 }; | |
2025 | |
2026 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
2027 data_writes1, arraysize(data_writes1)); | |
2028 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2029 SSLSocketDataProvider ssl(ASYNC, OK); | |
2030 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2031 | |
2032 TestCompletionCallback callback1; | |
2033 | |
2034 scoped_ptr<HttpTransaction> trans( | |
2035 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2036 | |
2037 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2038 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2039 | |
2040 rv = callback1.WaitForResult(); | |
2041 EXPECT_EQ(OK, rv); | |
2042 CapturingNetLog::CapturedEntryList entries; | |
2043 log.GetEntries(&entries); | |
2044 size_t pos = ExpectLogContainsSomewhere( | |
2045 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | |
2046 NetLog::PHASE_NONE); | |
2047 ExpectLogContainsSomewhere( | |
2048 entries, pos, | |
2049 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | |
2050 NetLog::PHASE_NONE); | |
2051 | |
2052 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2053 ASSERT_TRUE(response != NULL); | |
2054 ASSERT_FALSE(response->headers.get() == NULL); | |
2055 EXPECT_EQ(407, response->headers->response_code()); | |
2056 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
2057 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | |
2058 | |
2059 LoadTimingInfo load_timing_info; | |
2060 // CONNECT requests and responses are handled at the connect job level, so | |
2061 // the transaction does not yet have a connection. | |
2062 EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); | |
2063 | |
2064 TestCompletionCallback callback2; | |
2065 | |
2066 rv = trans->RestartWithAuth( | |
2067 AuthCredentials(kFoo, kBar), callback2.callback()); | |
2068 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2069 | |
2070 rv = callback2.WaitForResult(); | |
2071 EXPECT_EQ(OK, rv); | |
2072 | |
2073 response = trans->GetResponseInfo(); | |
2074 ASSERT_TRUE(response != NULL); | |
2075 | |
2076 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
2077 EXPECT_EQ(200, response->headers->response_code()); | |
2078 EXPECT_EQ(5, response->headers->GetContentLength()); | |
2079 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
2080 | |
2081 // The password prompt info should not be set. | |
2082 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
2083 | |
2084 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
2085 TestLoadTimingNotReusedWithPac(load_timing_info, | |
2086 CONNECT_TIMING_HAS_SSL_TIMES); | |
2087 | |
2088 trans.reset(); | |
2089 session->CloseAllConnections(); | |
2090 } | |
2091 | |
2092 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | |
2093 // proxy connection, when setting up an SSL tunnel. | |
2094 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthProxyKeepAlive) { | |
2095 HttpRequestInfo request; | |
2096 request.method = "GET"; | |
2097 request.url = GURL("https://www.google.com/"); | |
2098 // Ensure that proxy authentication is attempted even | |
2099 // when the no authentication data flag is set. | |
2100 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; | |
2101 | |
2102 // Configure against proxy server "myproxy:70". | |
2103 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
2104 CapturingBoundNetLog log; | |
2105 session_deps_.net_log = log.bound().net_log(); | |
2106 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2107 | |
2108 scoped_ptr<HttpTransaction> trans( | |
2109 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2110 | |
2111 // Since we have proxy, should try to establish tunnel. | |
2112 MockWrite data_writes1[] = { | |
2113 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2114 "Host: www.google.com\r\n" | |
2115 "Proxy-Connection: keep-alive\r\n\r\n"), | |
2116 | |
2117 // After calling trans->RestartWithAuth(), this is the request we should | |
2118 // be issuing -- the final header line contains the credentials. | |
2119 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2120 "Host: www.google.com\r\n" | |
2121 "Proxy-Connection: keep-alive\r\n" | |
2122 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), | |
2123 }; | |
2124 | |
2125 // The proxy responds to the connect with a 407, using a persistent | |
2126 // connection. | |
2127 MockRead data_reads1[] = { | |
2128 // No credentials. | |
2129 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
2130 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
2131 MockRead("Content-Length: 10\r\n\r\n"), | |
2132 MockRead("0123456789"), | |
2133 | |
2134 // Wrong credentials (wrong password). | |
2135 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
2136 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
2137 MockRead("Content-Length: 10\r\n\r\n"), | |
2138 // No response body because the test stops reading here. | |
2139 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
2140 }; | |
2141 | |
2142 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
2143 data_writes1, arraysize(data_writes1)); | |
2144 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2145 | |
2146 TestCompletionCallback callback1; | |
2147 | |
2148 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2149 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2150 | |
2151 rv = callback1.WaitForResult(); | |
2152 EXPECT_EQ(OK, rv); | |
2153 CapturingNetLog::CapturedEntryList entries; | |
2154 log.GetEntries(&entries); | |
2155 size_t pos = ExpectLogContainsSomewhere( | |
2156 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | |
2157 NetLog::PHASE_NONE); | |
2158 ExpectLogContainsSomewhere( | |
2159 entries, pos, | |
2160 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | |
2161 NetLog::PHASE_NONE); | |
2162 | |
2163 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2164 ASSERT_TRUE(response != NULL); | |
2165 ASSERT_FALSE(response->headers.get() == NULL); | |
2166 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
2167 EXPECT_EQ(407, response->headers->response_code()); | |
2168 EXPECT_EQ(10, response->headers->GetContentLength()); | |
2169 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
2170 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | |
2171 | |
2172 TestCompletionCallback callback2; | |
2173 | |
2174 // Wrong password (should be "bar"). | |
2175 rv = trans->RestartWithAuth( | |
2176 AuthCredentials(kFoo, kBaz), callback2.callback()); | |
2177 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2178 | |
2179 rv = callback2.WaitForResult(); | |
2180 EXPECT_EQ(OK, rv); | |
2181 | |
2182 response = trans->GetResponseInfo(); | |
2183 ASSERT_TRUE(response != NULL); | |
2184 ASSERT_FALSE(response->headers.get() == NULL); | |
2185 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
2186 EXPECT_EQ(407, response->headers->response_code()); | |
2187 EXPECT_EQ(10, response->headers->GetContentLength()); | |
2188 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
2189 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | |
2190 | |
2191 // Flush the idle socket before the NetLog and HttpNetworkTransaction go | |
2192 // out of scope. | |
2193 session->CloseAllConnections(); | |
2194 } | |
2195 | |
2196 // Test that we don't read the response body when we fail to establish a tunnel, | |
2197 // even if the user cancels the proxy's auth attempt. | |
2198 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthProxyCancelTunnel) { | |
2199 HttpRequestInfo request; | |
2200 request.method = "GET"; | |
2201 request.url = GURL("https://www.google.com/"); | |
2202 request.load_flags = 0; | |
2203 | |
2204 // Configure against proxy server "myproxy:70". | |
2205 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
2206 | |
2207 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2208 | |
2209 scoped_ptr<HttpTransaction> trans( | |
2210 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2211 | |
2212 // Since we have proxy, should try to establish tunnel. | |
2213 MockWrite data_writes[] = { | |
2214 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2215 "Host: www.google.com\r\n" | |
2216 "Proxy-Connection: keep-alive\r\n\r\n"), | |
2217 }; | |
2218 | |
2219 // The proxy responds to the connect with a 407. | |
2220 MockRead data_reads[] = { | |
2221 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
2222 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
2223 MockRead("Content-Length: 10\r\n\r\n"), | |
2224 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
2225 }; | |
2226 | |
2227 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
2228 data_writes, arraysize(data_writes)); | |
2229 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
2230 | |
2231 TestCompletionCallback callback; | |
2232 | |
2233 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
2234 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2235 | |
2236 rv = callback.WaitForResult(); | |
2237 EXPECT_EQ(OK, rv); | |
2238 | |
2239 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2240 ASSERT_TRUE(response != NULL); | |
2241 | |
2242 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
2243 EXPECT_EQ(407, response->headers->response_code()); | |
2244 EXPECT_EQ(10, response->headers->GetContentLength()); | |
2245 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
2246 | |
2247 std::string response_data; | |
2248 rv = ReadTransaction(trans.get(), &response_data); | |
2249 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
2250 | |
2251 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. | |
2252 session->CloseAllConnections(); | |
2253 } | |
2254 | |
2255 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). | |
2256 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. | |
2257 TEST_F(HttpNetworkTransactionSpdy3Test, UnexpectedProxyAuth) { | |
2258 HttpRequestInfo request; | |
2259 request.method = "GET"; | |
2260 request.url = GURL("http://www.google.com/"); | |
2261 request.load_flags = 0; | |
2262 | |
2263 // We are using a DIRECT connection (i.e. no proxy) for this session. | |
2264 scoped_ptr<HttpTransaction> trans( | |
2265 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
2266 CreateSession(&session_deps_))); | |
2267 | |
2268 MockWrite data_writes1[] = { | |
2269 MockWrite("GET / HTTP/1.1\r\n" | |
2270 "Host: www.google.com\r\n" | |
2271 "Connection: keep-alive\r\n\r\n"), | |
2272 }; | |
2273 | |
2274 MockRead data_reads1[] = { | |
2275 MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), | |
2276 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
2277 // Large content-length -- won't matter, as connection will be reset. | |
2278 MockRead("Content-Length: 10000\r\n\r\n"), | |
2279 MockRead(SYNCHRONOUS, ERR_FAILED), | |
2280 }; | |
2281 | |
2282 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
2283 data_writes1, arraysize(data_writes1)); | |
2284 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2285 | |
2286 TestCompletionCallback callback; | |
2287 | |
2288 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
2289 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2290 | |
2291 rv = callback.WaitForResult(); | |
2292 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); | |
2293 } | |
2294 | |
2295 // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) | |
2296 // through a non-authenticating proxy. The request should fail with | |
2297 // ERR_UNEXPECTED_PROXY_AUTH. | |
2298 // Note that it is impossible to detect if an HTTP server returns a 407 through | |
2299 // a non-authenticating proxy - there is nothing to indicate whether the | |
2300 // response came from the proxy or the server, so it is treated as if the proxy | |
2301 // issued the challenge. | |
2302 TEST_F(HttpNetworkTransactionSpdy3Test, | |
2303 HttpsServerRequestsProxyAuthThroughProxy) { | |
2304 HttpRequestInfo request; | |
2305 request.method = "GET"; | |
2306 request.url = GURL("https://www.google.com/"); | |
2307 | |
2308 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
2309 CapturingBoundNetLog log; | |
2310 session_deps_.net_log = log.bound().net_log(); | |
2311 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2312 | |
2313 // Since we have proxy, should try to establish tunnel. | |
2314 MockWrite data_writes1[] = { | |
2315 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2316 "Host: www.google.com\r\n" | |
2317 "Proxy-Connection: keep-alive\r\n\r\n"), | |
2318 | |
2319 MockWrite("GET / HTTP/1.1\r\n" | |
2320 "Host: www.google.com\r\n" | |
2321 "Connection: keep-alive\r\n\r\n"), | |
2322 }; | |
2323 | |
2324 MockRead data_reads1[] = { | |
2325 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), | |
2326 | |
2327 MockRead("HTTP/1.1 407 Unauthorized\r\n"), | |
2328 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
2329 MockRead("\r\n"), | |
2330 MockRead(SYNCHRONOUS, OK), | |
2331 }; | |
2332 | |
2333 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
2334 data_writes1, arraysize(data_writes1)); | |
2335 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2336 SSLSocketDataProvider ssl(ASYNC, OK); | |
2337 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2338 | |
2339 TestCompletionCallback callback1; | |
2340 | |
2341 scoped_ptr<HttpTransaction> trans( | |
2342 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2343 | |
2344 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2345 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2346 | |
2347 rv = callback1.WaitForResult(); | |
2348 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); | |
2349 CapturingNetLog::CapturedEntryList entries; | |
2350 log.GetEntries(&entries); | |
2351 size_t pos = ExpectLogContainsSomewhere( | |
2352 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | |
2353 NetLog::PHASE_NONE); | |
2354 ExpectLogContainsSomewhere( | |
2355 entries, pos, | |
2356 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | |
2357 NetLog::PHASE_NONE); | |
2358 } | |
2359 | |
2360 // Test the load timing for HTTPS requests with an HTTP proxy. | |
2361 TEST_F(HttpNetworkTransactionSpdy3Test, HttpProxyLoadTimingNoPacTwoRequests) { | |
2362 HttpRequestInfo request1; | |
2363 request1.method = "GET"; | |
2364 request1.url = GURL("https://www.google.com/1"); | |
2365 | |
2366 HttpRequestInfo request2; | |
2367 request2.method = "GET"; | |
2368 request2.url = GURL("https://www.google.com/2"); | |
2369 | |
2370 // Configure against proxy server "myproxy:70". | |
2371 session_deps_.proxy_service.reset( | |
2372 ProxyService::CreateFixed("PROXY myproxy:70")); | |
2373 CapturingBoundNetLog log; | |
2374 session_deps_.net_log = log.bound().net_log(); | |
2375 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2376 | |
2377 // Since we have proxy, should try to establish tunnel. | |
2378 MockWrite data_writes1[] = { | |
2379 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2380 "Host: www.google.com\r\n" | |
2381 "Proxy-Connection: keep-alive\r\n\r\n"), | |
2382 | |
2383 MockWrite("GET /1 HTTP/1.1\r\n" | |
2384 "Host: www.google.com\r\n" | |
2385 "Connection: keep-alive\r\n\r\n"), | |
2386 | |
2387 MockWrite("GET /2 HTTP/1.1\r\n" | |
2388 "Host: www.google.com\r\n" | |
2389 "Connection: keep-alive\r\n\r\n"), | |
2390 }; | |
2391 | |
2392 // The proxy responds to the connect with a 407, using a persistent | |
2393 // connection. | |
2394 MockRead data_reads1[] = { | |
2395 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), | |
2396 | |
2397 MockRead("HTTP/1.1 200 OK\r\n"), | |
2398 MockRead("Content-Length: 1\r\n\r\n"), | |
2399 MockRead(SYNCHRONOUS, "1"), | |
2400 | |
2401 MockRead("HTTP/1.1 200 OK\r\n"), | |
2402 MockRead("Content-Length: 2\r\n\r\n"), | |
2403 MockRead(SYNCHRONOUS, "22"), | |
2404 }; | |
2405 | |
2406 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
2407 data_writes1, arraysize(data_writes1)); | |
2408 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2409 SSLSocketDataProvider ssl(ASYNC, OK); | |
2410 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2411 | |
2412 TestCompletionCallback callback1; | |
2413 scoped_ptr<HttpTransaction> trans1( | |
2414 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2415 | |
2416 int rv = trans1->Start(&request1, callback1.callback(), log.bound()); | |
2417 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2418 | |
2419 rv = callback1.WaitForResult(); | |
2420 EXPECT_EQ(OK, rv); | |
2421 | |
2422 const HttpResponseInfo* response1 = trans1->GetResponseInfo(); | |
2423 ASSERT_TRUE(response1 != NULL); | |
2424 ASSERT_TRUE(response1->headers.get() != NULL); | |
2425 EXPECT_EQ(1, response1->headers->GetContentLength()); | |
2426 | |
2427 LoadTimingInfo load_timing_info1; | |
2428 EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); | |
2429 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); | |
2430 | |
2431 trans1.reset(); | |
2432 | |
2433 TestCompletionCallback callback2; | |
2434 scoped_ptr<HttpTransaction> trans2( | |
2435 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2436 | |
2437 rv = trans2->Start(&request2, callback2.callback(), log.bound()); | |
2438 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2439 | |
2440 rv = callback2.WaitForResult(); | |
2441 EXPECT_EQ(OK, rv); | |
2442 | |
2443 const HttpResponseInfo* response2 = trans2->GetResponseInfo(); | |
2444 ASSERT_TRUE(response2 != NULL); | |
2445 ASSERT_TRUE(response2->headers.get() != NULL); | |
2446 EXPECT_EQ(2, response2->headers->GetContentLength()); | |
2447 | |
2448 LoadTimingInfo load_timing_info2; | |
2449 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); | |
2450 TestLoadTimingReused(load_timing_info2); | |
2451 | |
2452 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | |
2453 | |
2454 trans2.reset(); | |
2455 session->CloseAllConnections(); | |
2456 } | |
2457 | |
2458 // Test the load timing for HTTPS requests with an HTTP proxy and a PAC script. | |
2459 TEST_F(HttpNetworkTransactionSpdy3Test, HttpProxyLoadTimingWithPacTwoRequests) { | |
2460 HttpRequestInfo request1; | |
2461 request1.method = "GET"; | |
2462 request1.url = GURL("https://www.google.com/1"); | |
2463 | |
2464 HttpRequestInfo request2; | |
2465 request2.method = "GET"; | |
2466 request2.url = GURL("https://www.google.com/2"); | |
2467 | |
2468 // Configure against proxy server "myproxy:70". | |
2469 session_deps_.proxy_service.reset( | |
2470 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | |
2471 CapturingBoundNetLog log; | |
2472 session_deps_.net_log = log.bound().net_log(); | |
2473 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2474 | |
2475 // Since we have proxy, should try to establish tunnel. | |
2476 MockWrite data_writes1[] = { | |
2477 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2478 "Host: www.google.com\r\n" | |
2479 "Proxy-Connection: keep-alive\r\n\r\n"), | |
2480 | |
2481 MockWrite("GET /1 HTTP/1.1\r\n" | |
2482 "Host: www.google.com\r\n" | |
2483 "Connection: keep-alive\r\n\r\n"), | |
2484 | |
2485 MockWrite("GET /2 HTTP/1.1\r\n" | |
2486 "Host: www.google.com\r\n" | |
2487 "Connection: keep-alive\r\n\r\n"), | |
2488 }; | |
2489 | |
2490 // The proxy responds to the connect with a 407, using a persistent | |
2491 // connection. | |
2492 MockRead data_reads1[] = { | |
2493 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), | |
2494 | |
2495 MockRead("HTTP/1.1 200 OK\r\n"), | |
2496 MockRead("Content-Length: 1\r\n\r\n"), | |
2497 MockRead(SYNCHRONOUS, "1"), | |
2498 | |
2499 MockRead("HTTP/1.1 200 OK\r\n"), | |
2500 MockRead("Content-Length: 2\r\n\r\n"), | |
2501 MockRead(SYNCHRONOUS, "22"), | |
2502 }; | |
2503 | |
2504 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
2505 data_writes1, arraysize(data_writes1)); | |
2506 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2507 SSLSocketDataProvider ssl(ASYNC, OK); | |
2508 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2509 | |
2510 TestCompletionCallback callback1; | |
2511 scoped_ptr<HttpTransaction> trans1( | |
2512 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2513 | |
2514 int rv = trans1->Start(&request1, callback1.callback(), log.bound()); | |
2515 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2516 | |
2517 rv = callback1.WaitForResult(); | |
2518 EXPECT_EQ(OK, rv); | |
2519 | |
2520 const HttpResponseInfo* response1 = trans1->GetResponseInfo(); | |
2521 ASSERT_TRUE(response1 != NULL); | |
2522 ASSERT_TRUE(response1->headers.get() != NULL); | |
2523 EXPECT_EQ(1, response1->headers->GetContentLength()); | |
2524 | |
2525 LoadTimingInfo load_timing_info1; | |
2526 EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); | |
2527 TestLoadTimingNotReusedWithPac(load_timing_info1, | |
2528 CONNECT_TIMING_HAS_SSL_TIMES); | |
2529 | |
2530 trans1.reset(); | |
2531 | |
2532 TestCompletionCallback callback2; | |
2533 scoped_ptr<HttpTransaction> trans2( | |
2534 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2535 | |
2536 rv = trans2->Start(&request2, callback2.callback(), log.bound()); | |
2537 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2538 | |
2539 rv = callback2.WaitForResult(); | |
2540 EXPECT_EQ(OK, rv); | |
2541 | |
2542 const HttpResponseInfo* response2 = trans2->GetResponseInfo(); | |
2543 ASSERT_TRUE(response2 != NULL); | |
2544 ASSERT_TRUE(response2->headers.get() != NULL); | |
2545 EXPECT_EQ(2, response2->headers->GetContentLength()); | |
2546 | |
2547 LoadTimingInfo load_timing_info2; | |
2548 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); | |
2549 TestLoadTimingReusedWithPac(load_timing_info2); | |
2550 | |
2551 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | |
2552 | |
2553 trans2.reset(); | |
2554 session->CloseAllConnections(); | |
2555 } | |
2556 | |
2557 // Test a simple get through an HTTPS Proxy. | |
2558 TEST_F(HttpNetworkTransactionSpdy3Test, HttpsProxyGet) { | |
2559 HttpRequestInfo request; | |
2560 request.method = "GET"; | |
2561 request.url = GURL("http://www.google.com/"); | |
2562 | |
2563 // Configure against https proxy server "proxy:70". | |
2564 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
2565 "https://proxy:70")); | |
2566 CapturingBoundNetLog log; | |
2567 session_deps_.net_log = log.bound().net_log(); | |
2568 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2569 | |
2570 // Since we have proxy, should use full url | |
2571 MockWrite data_writes1[] = { | |
2572 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
2573 "Host: www.google.com\r\n" | |
2574 "Proxy-Connection: keep-alive\r\n\r\n"), | |
2575 }; | |
2576 | |
2577 MockRead data_reads1[] = { | |
2578 MockRead("HTTP/1.1 200 OK\r\n"), | |
2579 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
2580 MockRead("Content-Length: 100\r\n\r\n"), | |
2581 MockRead(SYNCHRONOUS, OK), | |
2582 }; | |
2583 | |
2584 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
2585 data_writes1, arraysize(data_writes1)); | |
2586 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2587 SSLSocketDataProvider ssl(ASYNC, OK); | |
2588 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2589 | |
2590 TestCompletionCallback callback1; | |
2591 | |
2592 scoped_ptr<HttpTransaction> trans( | |
2593 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2594 | |
2595 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2596 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2597 | |
2598 rv = callback1.WaitForResult(); | |
2599 EXPECT_EQ(OK, rv); | |
2600 | |
2601 LoadTimingInfo load_timing_info; | |
2602 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
2603 TestLoadTimingNotReused(load_timing_info, | |
2604 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
2605 | |
2606 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2607 ASSERT_TRUE(response != NULL); | |
2608 | |
2609 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
2610 EXPECT_EQ(200, response->headers->response_code()); | |
2611 EXPECT_EQ(100, response->headers->GetContentLength()); | |
2612 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
2613 | |
2614 // The password prompt info should not be set. | |
2615 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
2616 } | |
2617 | |
2618 // Test a SPDY get through an HTTPS Proxy. | |
2619 TEST_F(HttpNetworkTransactionSpdy3Test, HttpsProxySpdyGet) { | |
2620 HttpRequestInfo request; | |
2621 request.method = "GET"; | |
2622 request.url = GURL("http://www.google.com/"); | |
2623 request.load_flags = 0; | |
2624 | |
2625 // Configure against https proxy server "proxy:70". | |
2626 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
2627 "https://proxy:70")); | |
2628 CapturingBoundNetLog log; | |
2629 session_deps_.net_log = log.bound().net_log(); | |
2630 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2631 | |
2632 // fetch http://www.google.com/ via SPDY | |
2633 scoped_ptr<SpdyFrame> req( | |
2634 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); | |
2635 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; | |
2636 | |
2637 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
2638 scoped_ptr<SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | |
2639 MockRead spdy_reads[] = { | |
2640 CreateMockRead(*resp), | |
2641 CreateMockRead(*data), | |
2642 MockRead(ASYNC, 0, 0), | |
2643 }; | |
2644 | |
2645 DelayedSocketData spdy_data( | |
2646 1, // wait for one write to finish before reading. | |
2647 spdy_reads, arraysize(spdy_reads), | |
2648 spdy_writes, arraysize(spdy_writes)); | |
2649 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
2650 | |
2651 SSLSocketDataProvider ssl(ASYNC, OK); | |
2652 ssl.SetNextProto(kProtoSPDY3); | |
2653 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2654 | |
2655 TestCompletionCallback callback1; | |
2656 | |
2657 scoped_ptr<HttpTransaction> trans( | |
2658 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2659 | |
2660 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2661 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2662 | |
2663 rv = callback1.WaitForResult(); | |
2664 EXPECT_EQ(OK, rv); | |
2665 | |
2666 LoadTimingInfo load_timing_info; | |
2667 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
2668 TestLoadTimingNotReused(load_timing_info, | |
2669 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
2670 | |
2671 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2672 ASSERT_TRUE(response != NULL); | |
2673 ASSERT_TRUE(response->headers.get() != NULL); | |
2674 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
2675 | |
2676 std::string response_data; | |
2677 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
2678 EXPECT_EQ(kUploadData, response_data); | |
2679 } | |
2680 | |
2681 // Test a SPDY get through an HTTPS Proxy. | |
2682 TEST_F(HttpNetworkTransactionSpdy3Test, HttpsProxySpdyGetWithProxyAuth) { | |
2683 HttpRequestInfo request; | |
2684 request.method = "GET"; | |
2685 request.url = GURL("http://www.google.com/"); | |
2686 request.load_flags = 0; | |
2687 | |
2688 // Configure against https proxy server "myproxy:70". | |
2689 session_deps_.proxy_service.reset( | |
2690 ProxyService::CreateFixed("https://myproxy:70")); | |
2691 CapturingBoundNetLog log; | |
2692 session_deps_.net_log = log.bound().net_log(); | |
2693 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2694 | |
2695 // The first request will be a bare GET, the second request will be a | |
2696 // GET with a Proxy-Authorization header. | |
2697 scoped_ptr<SpdyFrame> req_get( | |
2698 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); | |
2699 const char* const kExtraAuthorizationHeaders[] = { | |
2700 "proxy-authorization", "Basic Zm9vOmJhcg==" | |
2701 }; | |
2702 scoped_ptr<SpdyFrame> req_get_authorization( | |
2703 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, | |
2704 arraysize(kExtraAuthorizationHeaders) / 2, | |
2705 false, 3, LOWEST, false)); | |
2706 MockWrite spdy_writes[] = { | |
2707 CreateMockWrite(*req_get, 1), | |
2708 CreateMockWrite(*req_get_authorization, 4), | |
2709 }; | |
2710 | |
2711 // The first response is a 407 proxy authentication challenge, and the second | |
2712 // response will be a 200 response since the second request includes a valid | |
2713 // Authorization header. | |
2714 const char* const kExtraAuthenticationHeaders[] = { | |
2715 "proxy-authenticate", "Basic realm=\"MyRealm1\"" | |
2716 }; | |
2717 scoped_ptr<SpdyFrame> resp_authentication( | |
2718 ConstructSpdySynReplyError( | |
2719 "407 Proxy Authentication Required", | |
2720 kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, | |
2721 1)); | |
2722 scoped_ptr<SpdyFrame> body_authentication( | |
2723 ConstructSpdyBodyFrame(1, true)); | |
2724 scoped_ptr<SpdyFrame> resp_data(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
2725 scoped_ptr<SpdyFrame> body_data(ConstructSpdyBodyFrame(3, true)); | |
2726 MockRead spdy_reads[] = { | |
2727 CreateMockRead(*resp_authentication, 2), | |
2728 CreateMockRead(*body_authentication, 3), | |
2729 CreateMockRead(*resp_data, 5), | |
2730 CreateMockRead(*body_data, 6), | |
2731 MockRead(ASYNC, 0, 7), | |
2732 }; | |
2733 | |
2734 OrderedSocketData data( | |
2735 spdy_reads, arraysize(spdy_reads), | |
2736 spdy_writes, arraysize(spdy_writes)); | |
2737 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
2738 | |
2739 SSLSocketDataProvider ssl(ASYNC, OK); | |
2740 ssl.SetNextProto(kProtoSPDY3); | |
2741 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2742 | |
2743 TestCompletionCallback callback1; | |
2744 | |
2745 scoped_ptr<HttpTransaction> trans( | |
2746 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2747 | |
2748 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2749 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2750 | |
2751 rv = callback1.WaitForResult(); | |
2752 EXPECT_EQ(OK, rv); | |
2753 | |
2754 const HttpResponseInfo* const response = trans->GetResponseInfo(); | |
2755 | |
2756 ASSERT_TRUE(response != NULL); | |
2757 ASSERT_TRUE(response->headers.get() != NULL); | |
2758 EXPECT_EQ(407, response->headers->response_code()); | |
2759 EXPECT_TRUE(response->was_fetched_via_spdy); | |
2760 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | |
2761 | |
2762 TestCompletionCallback callback2; | |
2763 | |
2764 rv = trans->RestartWithAuth( | |
2765 AuthCredentials(kFoo, kBar), callback2.callback()); | |
2766 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2767 | |
2768 rv = callback2.WaitForResult(); | |
2769 EXPECT_EQ(OK, rv); | |
2770 | |
2771 const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); | |
2772 | |
2773 ASSERT_TRUE(response_restart != NULL); | |
2774 ASSERT_TRUE(response_restart->headers.get() != NULL); | |
2775 EXPECT_EQ(200, response_restart->headers->response_code()); | |
2776 // The password prompt info should not be set. | |
2777 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); | |
2778 } | |
2779 | |
2780 // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. | |
2781 TEST_F(HttpNetworkTransactionSpdy3Test, HttpsProxySpdyConnectHttps) { | |
2782 HttpRequestInfo request; | |
2783 request.method = "GET"; | |
2784 request.url = GURL("https://www.google.com/"); | |
2785 request.load_flags = 0; | |
2786 | |
2787 // Configure against https proxy server "proxy:70". | |
2788 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
2789 "https://proxy:70")); | |
2790 CapturingBoundNetLog log; | |
2791 session_deps_.net_log = log.bound().net_log(); | |
2792 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2793 | |
2794 scoped_ptr<HttpTransaction> trans( | |
2795 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2796 | |
2797 // CONNECT to www.google.com:443 via SPDY | |
2798 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
2799 // fetch https://www.google.com/ via HTTP | |
2800 | |
2801 const char get[] = "GET / HTTP/1.1\r\n" | |
2802 "Host: www.google.com\r\n" | |
2803 "Connection: keep-alive\r\n\r\n"; | |
2804 scoped_ptr<SpdyFrame> wrapped_get( | |
2805 ConstructSpdyBodyFrame(1, get, strlen(get), false)); | |
2806 scoped_ptr<SpdyFrame> conn_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
2807 const char resp[] = "HTTP/1.1 200 OK\r\n" | |
2808 "Content-Length: 10\r\n\r\n"; | |
2809 scoped_ptr<SpdyFrame> wrapped_get_resp( | |
2810 ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); | |
2811 scoped_ptr<SpdyFrame> wrapped_body( | |
2812 ConstructSpdyBodyFrame(1, "1234567890", 10, false)); | |
2813 scoped_ptr<SpdyFrame> window_update( | |
2814 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); | |
2815 | |
2816 MockWrite spdy_writes[] = { | |
2817 CreateMockWrite(*connect, 1), | |
2818 CreateMockWrite(*wrapped_get, 3), | |
2819 CreateMockWrite(*window_update, 5), | |
2820 }; | |
2821 | |
2822 MockRead spdy_reads[] = { | |
2823 CreateMockRead(*conn_resp, 2, ASYNC), | |
2824 CreateMockRead(*wrapped_get_resp, 4, ASYNC), | |
2825 CreateMockRead(*wrapped_body, 6, ASYNC), | |
2826 CreateMockRead(*wrapped_body, 7, ASYNC), | |
2827 MockRead(ASYNC, 0, 8), | |
2828 }; | |
2829 | |
2830 OrderedSocketData spdy_data( | |
2831 spdy_reads, arraysize(spdy_reads), | |
2832 spdy_writes, arraysize(spdy_writes)); | |
2833 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
2834 | |
2835 SSLSocketDataProvider ssl(ASYNC, OK); | |
2836 ssl.SetNextProto(kProtoSPDY3); | |
2837 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2838 SSLSocketDataProvider ssl2(ASYNC, OK); | |
2839 ssl2.was_npn_negotiated = false; | |
2840 ssl2.protocol_negotiated = kProtoUnknown; | |
2841 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); | |
2842 | |
2843 TestCompletionCallback callback1; | |
2844 | |
2845 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2846 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2847 | |
2848 rv = callback1.WaitForResult(); | |
2849 EXPECT_EQ(OK, rv); | |
2850 | |
2851 LoadTimingInfo load_timing_info; | |
2852 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
2853 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); | |
2854 | |
2855 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2856 ASSERT_TRUE(response != NULL); | |
2857 ASSERT_TRUE(response->headers.get() != NULL); | |
2858 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
2859 | |
2860 std::string response_data; | |
2861 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
2862 EXPECT_EQ("1234567890", response_data); | |
2863 } | |
2864 | |
2865 // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. | |
2866 TEST_F(HttpNetworkTransactionSpdy3Test, HttpsProxySpdyConnectSpdy) { | |
2867 HttpRequestInfo request; | |
2868 request.method = "GET"; | |
2869 request.url = GURL("https://www.google.com/"); | |
2870 request.load_flags = 0; | |
2871 | |
2872 // Configure against https proxy server "proxy:70". | |
2873 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
2874 "https://proxy:70")); | |
2875 CapturingBoundNetLog log; | |
2876 session_deps_.net_log = log.bound().net_log(); | |
2877 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2878 | |
2879 scoped_ptr<HttpTransaction> trans( | |
2880 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2881 | |
2882 // CONNECT to www.google.com:443 via SPDY | |
2883 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
2884 // fetch https://www.google.com/ via SPDY | |
2885 const char* const kMyUrl = "https://www.google.com/"; | |
2886 scoped_ptr<SpdyFrame> get( | |
2887 spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); | |
2888 scoped_ptr<SpdyFrame> wrapped_get(ConstructWrappedSpdyFrame(get, 1)); | |
2889 scoped_ptr<SpdyFrame> conn_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
2890 scoped_ptr<SpdyFrame> get_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
2891 scoped_ptr<SpdyFrame> wrapped_get_resp( | |
2892 ConstructWrappedSpdyFrame(get_resp, 1)); | |
2893 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | |
2894 scoped_ptr<SpdyFrame> wrapped_body(ConstructWrappedSpdyFrame(body, 1)); | |
2895 scoped_ptr<SpdyFrame> window_update_get_resp( | |
2896 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); | |
2897 scoped_ptr<SpdyFrame> window_update_body( | |
2898 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); | |
2899 | |
2900 MockWrite spdy_writes[] = { | |
2901 CreateMockWrite(*connect, 1), | |
2902 CreateMockWrite(*wrapped_get, 3), | |
2903 CreateMockWrite(*window_update_get_resp, 5), | |
2904 CreateMockWrite(*window_update_body, 7), | |
2905 }; | |
2906 | |
2907 MockRead spdy_reads[] = { | |
2908 CreateMockRead(*conn_resp, 2, ASYNC), | |
2909 CreateMockRead(*wrapped_get_resp, 4, ASYNC), | |
2910 CreateMockRead(*wrapped_body, 6, ASYNC), | |
2911 MockRead(ASYNC, 0, 8), | |
2912 }; | |
2913 | |
2914 OrderedSocketData spdy_data( | |
2915 spdy_reads, arraysize(spdy_reads), | |
2916 spdy_writes, arraysize(spdy_writes)); | |
2917 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
2918 | |
2919 SSLSocketDataProvider ssl(ASYNC, OK); | |
2920 ssl.SetNextProto(kProtoSPDY3); | |
2921 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2922 SSLSocketDataProvider ssl2(ASYNC, OK); | |
2923 ssl2.SetNextProto(kProtoSPDY3); | |
2924 ssl2.protocol_negotiated = kProtoSPDY3; | |
2925 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); | |
2926 | |
2927 TestCompletionCallback callback1; | |
2928 | |
2929 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2930 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2931 | |
2932 rv = callback1.WaitForResult(); | |
2933 EXPECT_EQ(OK, rv); | |
2934 | |
2935 LoadTimingInfo load_timing_info; | |
2936 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
2937 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); | |
2938 | |
2939 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2940 ASSERT_TRUE(response != NULL); | |
2941 ASSERT_TRUE(response->headers.get() != NULL); | |
2942 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
2943 | |
2944 std::string response_data; | |
2945 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
2946 EXPECT_EQ(kUploadData, response_data); | |
2947 } | |
2948 | |
2949 // Test a SPDY CONNECT failure through an HTTPS Proxy. | |
2950 TEST_F(HttpNetworkTransactionSpdy3Test, HttpsProxySpdyConnectFailure) { | |
2951 HttpRequestInfo request; | |
2952 request.method = "GET"; | |
2953 request.url = GURL("https://www.google.com/"); | |
2954 request.load_flags = 0; | |
2955 | |
2956 // Configure against https proxy server "proxy:70". | |
2957 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
2958 "https://proxy:70")); | |
2959 CapturingBoundNetLog log; | |
2960 session_deps_.net_log = log.bound().net_log(); | |
2961 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2962 | |
2963 scoped_ptr<HttpTransaction> trans( | |
2964 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2965 | |
2966 // CONNECT to www.google.com:443 via SPDY | |
2967 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
2968 scoped_ptr<SpdyFrame> get( | |
2969 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | |
2970 | |
2971 MockWrite spdy_writes[] = { | |
2972 CreateMockWrite(*connect, 1), | |
2973 CreateMockWrite(*get, 3), | |
2974 }; | |
2975 | |
2976 scoped_ptr<SpdyFrame> resp(ConstructSpdySynReplyError(1)); | |
2977 scoped_ptr<SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | |
2978 MockRead spdy_reads[] = { | |
2979 CreateMockRead(*resp, 2, ASYNC), | |
2980 MockRead(ASYNC, 0, 4), | |
2981 }; | |
2982 | |
2983 OrderedSocketData spdy_data( | |
2984 spdy_reads, arraysize(spdy_reads), | |
2985 spdy_writes, arraysize(spdy_writes)); | |
2986 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
2987 | |
2988 SSLSocketDataProvider ssl(ASYNC, OK); | |
2989 ssl.SetNextProto(kProtoSPDY3); | |
2990 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
2991 SSLSocketDataProvider ssl2(ASYNC, OK); | |
2992 ssl2.SetNextProto(kProtoSPDY3); | |
2993 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); | |
2994 | |
2995 TestCompletionCallback callback1; | |
2996 | |
2997 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
2998 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2999 | |
3000 rv = callback1.WaitForResult(); | |
3001 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
3002 | |
3003 // TODO(ttuttle): Anything else to check here? | |
3004 } | |
3005 | |
3006 // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY | |
3007 // HTTPS Proxy to different servers. | |
3008 TEST_F(HttpNetworkTransactionSpdy3Test, | |
3009 HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { | |
3010 // Configure against https proxy server "proxy:70". | |
3011 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
3012 "https://proxy:70")); | |
3013 CapturingBoundNetLog log; | |
3014 session_deps_.net_log = log.bound().net_log(); | |
3015 scoped_refptr<HttpNetworkSession> session( | |
3016 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); | |
3017 | |
3018 HttpRequestInfo request1; | |
3019 request1.method = "GET"; | |
3020 request1.url = GURL("https://www.google.com/"); | |
3021 request1.load_flags = 0; | |
3022 | |
3023 HttpRequestInfo request2; | |
3024 request2.method = "GET"; | |
3025 request2.url = GURL("https://news.google.com/"); | |
3026 request2.load_flags = 0; | |
3027 | |
3028 // CONNECT to www.google.com:443 via SPDY. | |
3029 scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
3030 scoped_ptr<SpdyFrame> conn_resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
3031 | |
3032 // Fetch https://www.google.com/ via HTTP. | |
3033 const char get1[] = "GET / HTTP/1.1\r\n" | |
3034 "Host: www.google.com\r\n" | |
3035 "Connection: keep-alive\r\n\r\n"; | |
3036 scoped_ptr<SpdyFrame> wrapped_get1( | |
3037 ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); | |
3038 const char resp1[] = "HTTP/1.1 200 OK\r\n" | |
3039 "Content-Length: 1\r\n\r\n"; | |
3040 scoped_ptr<SpdyFrame> wrapped_get_resp1( | |
3041 ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); | |
3042 scoped_ptr<SpdyFrame> wrapped_body1(ConstructSpdyBodyFrame(1, "1", 1, false)); | |
3043 scoped_ptr<SpdyFrame> window_update( | |
3044 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); | |
3045 | |
3046 // CONNECT to news.google.com:443 via SPDY. | |
3047 const char* const kConnectHeaders2[] = { | |
3048 ":method", "CONNECT", | |
3049 ":path", "news.google.com:443", | |
3050 ":host", "news.google.com", | |
3051 ":version", "HTTP/1.1", | |
3052 }; | |
3053 scoped_ptr<SpdyFrame> connect2( | |
3054 spdy_util_.ConstructSpdyControlFrame(NULL, | |
3055 0, | |
3056 /*compressed*/ false, | |
3057 3, | |
3058 LOWEST, | |
3059 SYN_STREAM, | |
3060 CONTROL_FLAG_NONE, | |
3061 kConnectHeaders2, | |
3062 arraysize(kConnectHeaders2), | |
3063 0)); | |
3064 scoped_ptr<SpdyFrame> conn_resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
3065 | |
3066 // Fetch https://news.google.com/ via HTTP. | |
3067 const char get2[] = "GET / HTTP/1.1\r\n" | |
3068 "Host: news.google.com\r\n" | |
3069 "Connection: keep-alive\r\n\r\n"; | |
3070 scoped_ptr<SpdyFrame> wrapped_get2( | |
3071 ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); | |
3072 const char resp2[] = "HTTP/1.1 200 OK\r\n" | |
3073 "Content-Length: 2\r\n\r\n"; | |
3074 scoped_ptr<SpdyFrame> wrapped_get_resp2( | |
3075 ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); | |
3076 scoped_ptr<SpdyFrame> wrapped_body2( | |
3077 ConstructSpdyBodyFrame(3, "22", 2, false)); | |
3078 | |
3079 MockWrite spdy_writes[] = { | |
3080 CreateMockWrite(*connect1, 0), | |
3081 CreateMockWrite(*wrapped_get1, 2), | |
3082 CreateMockWrite(*connect2, 5), | |
3083 CreateMockWrite(*wrapped_get2, 7), | |
3084 }; | |
3085 | |
3086 MockRead spdy_reads[] = { | |
3087 CreateMockRead(*conn_resp1, 1, ASYNC), | |
3088 CreateMockRead(*wrapped_get_resp1, 3, ASYNC), | |
3089 CreateMockRead(*wrapped_body1, 4, ASYNC), | |
3090 CreateMockRead(*conn_resp2, 6, ASYNC), | |
3091 CreateMockRead(*wrapped_get_resp2, 8, ASYNC), | |
3092 CreateMockRead(*wrapped_body2, 9, ASYNC), | |
3093 MockRead(ASYNC, 0, 10), | |
3094 }; | |
3095 | |
3096 DeterministicSocketData spdy_data( | |
3097 spdy_reads, arraysize(spdy_reads), | |
3098 spdy_writes, arraysize(spdy_writes)); | |
3099 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); | |
3100 | |
3101 SSLSocketDataProvider ssl(ASYNC, OK); | |
3102 ssl.SetNextProto(kProtoSPDY3); | |
3103 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); | |
3104 SSLSocketDataProvider ssl2(ASYNC, OK); | |
3105 ssl2.was_npn_negotiated = false; | |
3106 ssl2.protocol_negotiated = kProtoUnknown; | |
3107 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); | |
3108 SSLSocketDataProvider ssl3(ASYNC, OK); | |
3109 ssl3.was_npn_negotiated = false; | |
3110 ssl3.protocol_negotiated = kProtoUnknown; | |
3111 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); | |
3112 | |
3113 TestCompletionCallback callback; | |
3114 | |
3115 scoped_ptr<HttpTransaction> trans( | |
3116 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3117 int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); | |
3118 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3119 // The first connect and request, each of their responses, and the body. | |
3120 spdy_data.RunFor(5); | |
3121 | |
3122 rv = callback.WaitForResult(); | |
3123 EXPECT_EQ(OK, rv); | |
3124 | |
3125 LoadTimingInfo load_timing_info; | |
3126 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
3127 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); | |
3128 | |
3129 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
3130 ASSERT_TRUE(response != NULL); | |
3131 ASSERT_TRUE(response->headers.get() != NULL); | |
3132 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
3133 | |
3134 std::string response_data; | |
3135 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | |
3136 EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); | |
3137 | |
3138 scoped_ptr<HttpTransaction> trans2( | |
3139 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3140 rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); | |
3141 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3142 | |
3143 // The second connect and request, each of their responses, and the body. | |
3144 spdy_data.RunFor(5); | |
3145 rv = callback.WaitForResult(); | |
3146 EXPECT_EQ(OK, rv); | |
3147 | |
3148 LoadTimingInfo load_timing_info2; | |
3149 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); | |
3150 // Even though the SPDY connection is reused, a new tunnelled connection has | |
3151 // to be created, so the socket's load timing looks like a fresh connection. | |
3152 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); | |
3153 | |
3154 // The requests should have different IDs, since they each are using their own | |
3155 // separate stream. | |
3156 EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); | |
3157 | |
3158 EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); | |
3159 } | |
3160 | |
3161 // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY | |
3162 // HTTPS Proxy to the same server. | |
3163 TEST_F(HttpNetworkTransactionSpdy3Test, | |
3164 HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { | |
3165 // Configure against https proxy server "proxy:70". | |
3166 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
3167 "https://proxy:70")); | |
3168 CapturingBoundNetLog log; | |
3169 session_deps_.net_log = log.bound().net_log(); | |
3170 scoped_refptr<HttpNetworkSession> session( | |
3171 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); | |
3172 | |
3173 HttpRequestInfo request1; | |
3174 request1.method = "GET"; | |
3175 request1.url = GURL("https://www.google.com/"); | |
3176 request1.load_flags = 0; | |
3177 | |
3178 HttpRequestInfo request2; | |
3179 request2.method = "GET"; | |
3180 request2.url = GURL("https://www.google.com/2"); | |
3181 request2.load_flags = 0; | |
3182 | |
3183 // CONNECT to www.google.com:443 via SPDY. | |
3184 scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
3185 scoped_ptr<SpdyFrame> conn_resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
3186 | |
3187 // Fetch https://www.google.com/ via HTTP. | |
3188 const char get1[] = "GET / HTTP/1.1\r\n" | |
3189 "Host: www.google.com\r\n" | |
3190 "Connection: keep-alive\r\n\r\n"; | |
3191 scoped_ptr<SpdyFrame> wrapped_get1( | |
3192 ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); | |
3193 const char resp1[] = "HTTP/1.1 200 OK\r\n" | |
3194 "Content-Length: 1\r\n\r\n"; | |
3195 scoped_ptr<SpdyFrame> wrapped_get_resp1( | |
3196 ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); | |
3197 scoped_ptr<SpdyFrame> wrapped_body1(ConstructSpdyBodyFrame(1, "1", 1, false)); | |
3198 scoped_ptr<SpdyFrame> window_update( | |
3199 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); | |
3200 | |
3201 // Fetch https://www.google.com/2 via HTTP. | |
3202 const char get2[] = "GET /2 HTTP/1.1\r\n" | |
3203 "Host: www.google.com\r\n" | |
3204 "Connection: keep-alive\r\n\r\n"; | |
3205 scoped_ptr<SpdyFrame> wrapped_get2( | |
3206 ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); | |
3207 const char resp2[] = "HTTP/1.1 200 OK\r\n" | |
3208 "Content-Length: 2\r\n\r\n"; | |
3209 scoped_ptr<SpdyFrame> wrapped_get_resp2( | |
3210 ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); | |
3211 scoped_ptr<SpdyFrame> wrapped_body2( | |
3212 ConstructSpdyBodyFrame(1, "22", 2, false)); | |
3213 | |
3214 MockWrite spdy_writes[] = { | |
3215 CreateMockWrite(*connect1, 0), | |
3216 CreateMockWrite(*wrapped_get1, 2), | |
3217 CreateMockWrite(*wrapped_get2, 5), | |
3218 }; | |
3219 | |
3220 MockRead spdy_reads[] = { | |
3221 CreateMockRead(*conn_resp1, 1, ASYNC), | |
3222 CreateMockRead(*wrapped_get_resp1, 3, ASYNC), | |
3223 CreateMockRead(*wrapped_body1, 4, ASYNC), | |
3224 CreateMockRead(*wrapped_get_resp2, 6, ASYNC), | |
3225 CreateMockRead(*wrapped_body2, 7, ASYNC), | |
3226 MockRead(ASYNC, 0, 8), | |
3227 }; | |
3228 | |
3229 DeterministicSocketData spdy_data( | |
3230 spdy_reads, arraysize(spdy_reads), | |
3231 spdy_writes, arraysize(spdy_writes)); | |
3232 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); | |
3233 | |
3234 SSLSocketDataProvider ssl(ASYNC, OK); | |
3235 ssl.SetNextProto(kProtoSPDY3); | |
3236 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); | |
3237 SSLSocketDataProvider ssl2(ASYNC, OK); | |
3238 ssl2.was_npn_negotiated = false; | |
3239 ssl2.protocol_negotiated = kProtoUnknown; | |
3240 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); | |
3241 | |
3242 TestCompletionCallback callback; | |
3243 | |
3244 scoped_ptr<HttpTransaction> trans( | |
3245 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3246 int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); | |
3247 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3248 // The first connect and request, each of their responses, and the body. | |
3249 spdy_data.RunFor(5); | |
3250 | |
3251 rv = callback.WaitForResult(); | |
3252 EXPECT_EQ(OK, rv); | |
3253 | |
3254 LoadTimingInfo load_timing_info; | |
3255 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
3256 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); | |
3257 | |
3258 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
3259 ASSERT_TRUE(response != NULL); | |
3260 ASSERT_TRUE(response->headers.get() != NULL); | |
3261 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
3262 | |
3263 std::string response_data; | |
3264 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | |
3265 EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); | |
3266 // Delete the first request, so the second one can reuse the socket. | |
3267 trans.reset(); | |
3268 | |
3269 scoped_ptr<HttpTransaction> trans2( | |
3270 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3271 rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); | |
3272 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3273 | |
3274 // The second request, response, and body. There should not be a second | |
3275 // connect. | |
3276 spdy_data.RunFor(3); | |
3277 rv = callback.WaitForResult(); | |
3278 EXPECT_EQ(OK, rv); | |
3279 | |
3280 LoadTimingInfo load_timing_info2; | |
3281 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); | |
3282 TestLoadTimingReused(load_timing_info2); | |
3283 | |
3284 // The requests should have the same ID. | |
3285 EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); | |
3286 | |
3287 EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); | |
3288 } | |
3289 | |
3290 // Test load timing in the case of of two HTTP requests through a SPDY HTTPS | |
3291 // Proxy to different servers. | |
3292 TEST_F(HttpNetworkTransactionSpdy3Test, | |
3293 HttpsProxySpdyLoadTimingTwoHttpRequests) { | |
3294 const char* const url1 = "http://www.google.com/"; | |
3295 const char* const url2 = "http://news.google.com/"; | |
3296 | |
3297 // Configure against https proxy server "proxy:70". | |
3298 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
3299 "https://proxy:70")); | |
3300 CapturingBoundNetLog log; | |
3301 session_deps_.net_log = log.bound().net_log(); | |
3302 scoped_refptr<HttpNetworkSession> session( | |
3303 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); | |
3304 | |
3305 HttpRequestInfo request1; | |
3306 request1.method = "GET"; | |
3307 request1.url = GURL(url1); | |
3308 request1.load_flags = 0; | |
3309 | |
3310 HttpRequestInfo request2; | |
3311 request2.method = "GET"; | |
3312 request2.url = GURL(url2); | |
3313 request2.load_flags = 0; | |
3314 | |
3315 scoped_ptr<SpdyFrame> get1( | |
3316 spdy_util_.ConstructSpdyGet(url1, false, 1, LOWEST)); | |
3317 scoped_ptr<SpdyFrame> get_resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
3318 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, "1", 1, true)); | |
3319 | |
3320 // http://news.google.com/ | |
3321 scoped_ptr<SpdyFrame> get2( | |
3322 spdy_util_.ConstructSpdyGet(url2, false, 3, LOWEST)); | |
3323 scoped_ptr<SpdyFrame> get_resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
3324 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, "22", 2, true)); | |
3325 | |
3326 MockWrite spdy_writes[] = { | |
3327 CreateMockWrite(*get1, 0), | |
3328 CreateMockWrite(*get2, 3), | |
3329 }; | |
3330 | |
3331 MockRead spdy_reads[] = { | |
3332 CreateMockRead(*get_resp1, 1, ASYNC), | |
3333 CreateMockRead(*body1, 2, ASYNC), | |
3334 CreateMockRead(*get_resp2, 4, ASYNC), | |
3335 CreateMockRead(*body2, 5, ASYNC), | |
3336 MockRead(ASYNC, 0, 6), | |
3337 }; | |
3338 | |
3339 DeterministicSocketData spdy_data( | |
3340 spdy_reads, arraysize(spdy_reads), | |
3341 spdy_writes, arraysize(spdy_writes)); | |
3342 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); | |
3343 | |
3344 SSLSocketDataProvider ssl(ASYNC, OK); | |
3345 ssl.SetNextProto(kProtoSPDY3); | |
3346 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); | |
3347 | |
3348 TestCompletionCallback callback; | |
3349 | |
3350 scoped_ptr<HttpTransaction> trans( | |
3351 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3352 int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); | |
3353 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3354 spdy_data.RunFor(2); | |
3355 | |
3356 rv = callback.WaitForResult(); | |
3357 EXPECT_EQ(OK, rv); | |
3358 | |
3359 LoadTimingInfo load_timing_info; | |
3360 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
3361 TestLoadTimingNotReused(load_timing_info, | |
3362 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
3363 | |
3364 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
3365 ASSERT_TRUE(response != NULL); | |
3366 ASSERT_TRUE(response->headers.get() != NULL); | |
3367 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
3368 | |
3369 std::string response_data; | |
3370 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | |
3371 EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); | |
3372 spdy_data.RunFor(1); | |
3373 EXPECT_EQ(1, callback.WaitForResult()); | |
3374 // Delete the first request, so the second one can reuse the socket. | |
3375 trans.reset(); | |
3376 | |
3377 scoped_ptr<HttpTransaction> trans2( | |
3378 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3379 rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); | |
3380 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3381 | |
3382 spdy_data.RunFor(2); | |
3383 rv = callback.WaitForResult(); | |
3384 EXPECT_EQ(OK, rv); | |
3385 | |
3386 LoadTimingInfo load_timing_info2; | |
3387 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); | |
3388 TestLoadTimingReused(load_timing_info2); | |
3389 | |
3390 // The requests should have the same ID. | |
3391 EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); | |
3392 | |
3393 EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); | |
3394 spdy_data.RunFor(1); | |
3395 EXPECT_EQ(2, callback.WaitForResult()); | |
3396 } | |
3397 | |
3398 // Test the challenge-response-retry sequence through an HTTPS Proxy | |
3399 TEST_F(HttpNetworkTransactionSpdy3Test, HttpsProxyAuthRetry) { | |
3400 HttpRequestInfo request; | |
3401 request.method = "GET"; | |
3402 request.url = GURL("http://www.google.com/"); | |
3403 // when the no authentication data flag is set. | |
3404 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; | |
3405 | |
3406 // Configure against https proxy server "myproxy:70". | |
3407 session_deps_.proxy_service.reset( | |
3408 ProxyService::CreateFixed("https://myproxy:70")); | |
3409 CapturingBoundNetLog log; | |
3410 session_deps_.net_log = log.bound().net_log(); | |
3411 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
3412 | |
3413 // Since we have proxy, should use full url | |
3414 MockWrite data_writes1[] = { | |
3415 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
3416 "Host: www.google.com\r\n" | |
3417 "Proxy-Connection: keep-alive\r\n\r\n"), | |
3418 | |
3419 // After calling trans->RestartWithAuth(), this is the request we should | |
3420 // be issuing -- the final header line contains the credentials. | |
3421 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
3422 "Host: www.google.com\r\n" | |
3423 "Proxy-Connection: keep-alive\r\n" | |
3424 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
3425 }; | |
3426 | |
3427 // The proxy responds to the GET with a 407, using a persistent | |
3428 // connection. | |
3429 MockRead data_reads1[] = { | |
3430 // No credentials. | |
3431 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
3432 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
3433 MockRead("Proxy-Connection: keep-alive\r\n"), | |
3434 MockRead("Content-Length: 0\r\n\r\n"), | |
3435 | |
3436 MockRead("HTTP/1.1 200 OK\r\n"), | |
3437 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
3438 MockRead("Content-Length: 100\r\n\r\n"), | |
3439 MockRead(SYNCHRONOUS, OK), | |
3440 }; | |
3441 | |
3442 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
3443 data_writes1, arraysize(data_writes1)); | |
3444 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
3445 SSLSocketDataProvider ssl(ASYNC, OK); | |
3446 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
3447 | |
3448 TestCompletionCallback callback1; | |
3449 | |
3450 scoped_ptr<HttpTransaction> trans( | |
3451 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3452 | |
3453 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
3454 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3455 | |
3456 rv = callback1.WaitForResult(); | |
3457 EXPECT_EQ(OK, rv); | |
3458 | |
3459 LoadTimingInfo load_timing_info; | |
3460 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
3461 TestLoadTimingNotReused(load_timing_info, | |
3462 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
3463 | |
3464 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
3465 ASSERT_TRUE(response != NULL); | |
3466 ASSERT_FALSE(response->headers.get() == NULL); | |
3467 EXPECT_EQ(407, response->headers->response_code()); | |
3468 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
3469 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | |
3470 | |
3471 TestCompletionCallback callback2; | |
3472 | |
3473 rv = trans->RestartWithAuth( | |
3474 AuthCredentials(kFoo, kBar), callback2.callback()); | |
3475 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3476 | |
3477 rv = callback2.WaitForResult(); | |
3478 EXPECT_EQ(OK, rv); | |
3479 | |
3480 load_timing_info = LoadTimingInfo(); | |
3481 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
3482 // Retrying with HTTP AUTH is considered to be reusing a socket. | |
3483 TestLoadTimingReused(load_timing_info); | |
3484 | |
3485 response = trans->GetResponseInfo(); | |
3486 ASSERT_TRUE(response != NULL); | |
3487 | |
3488 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
3489 EXPECT_EQ(200, response->headers->response_code()); | |
3490 EXPECT_EQ(100, response->headers->GetContentLength()); | |
3491 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
3492 | |
3493 // The password prompt info should not be set. | |
3494 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
3495 } | |
3496 | |
3497 void HttpNetworkTransactionSpdy3Test::ConnectStatusHelperWithExpectedStatus( | |
3498 const MockRead& status, int expected_status) { | |
3499 HttpRequestInfo request; | |
3500 request.method = "GET"; | |
3501 request.url = GURL("https://www.google.com/"); | |
3502 request.load_flags = 0; | |
3503 | |
3504 // Configure against proxy server "myproxy:70". | |
3505 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
3506 | |
3507 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
3508 | |
3509 // Since we have proxy, should try to establish tunnel. | |
3510 MockWrite data_writes[] = { | |
3511 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
3512 "Host: www.google.com\r\n" | |
3513 "Proxy-Connection: keep-alive\r\n\r\n"), | |
3514 }; | |
3515 | |
3516 MockRead data_reads[] = { | |
3517 status, | |
3518 MockRead("Content-Length: 10\r\n\r\n"), | |
3519 // No response body because the test stops reading here. | |
3520 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
3521 }; | |
3522 | |
3523 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
3524 data_writes, arraysize(data_writes)); | |
3525 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
3526 | |
3527 TestCompletionCallback callback; | |
3528 | |
3529 scoped_ptr<HttpTransaction> trans( | |
3530 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3531 | |
3532 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
3533 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3534 | |
3535 rv = callback.WaitForResult(); | |
3536 EXPECT_EQ(expected_status, rv); | |
3537 } | |
3538 | |
3539 void HttpNetworkTransactionSpdy3Test::ConnectStatusHelper( | |
3540 const MockRead& status) { | |
3541 ConnectStatusHelperWithExpectedStatus( | |
3542 status, ERR_TUNNEL_CONNECTION_FAILED); | |
3543 } | |
3544 | |
3545 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus100) { | |
3546 ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); | |
3547 } | |
3548 | |
3549 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus101) { | |
3550 ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); | |
3551 } | |
3552 | |
3553 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus201) { | |
3554 ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); | |
3555 } | |
3556 | |
3557 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus202) { | |
3558 ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); | |
3559 } | |
3560 | |
3561 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus203) { | |
3562 ConnectStatusHelper( | |
3563 MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); | |
3564 } | |
3565 | |
3566 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus204) { | |
3567 ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); | |
3568 } | |
3569 | |
3570 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus205) { | |
3571 ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); | |
3572 } | |
3573 | |
3574 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus206) { | |
3575 ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); | |
3576 } | |
3577 | |
3578 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus300) { | |
3579 ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); | |
3580 } | |
3581 | |
3582 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus301) { | |
3583 ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); | |
3584 } | |
3585 | |
3586 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus302) { | |
3587 ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); | |
3588 } | |
3589 | |
3590 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus303) { | |
3591 ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); | |
3592 } | |
3593 | |
3594 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus304) { | |
3595 ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); | |
3596 } | |
3597 | |
3598 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus305) { | |
3599 ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); | |
3600 } | |
3601 | |
3602 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus306) { | |
3603 ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); | |
3604 } | |
3605 | |
3606 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus307) { | |
3607 ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); | |
3608 } | |
3609 | |
3610 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus400) { | |
3611 ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); | |
3612 } | |
3613 | |
3614 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus401) { | |
3615 ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); | |
3616 } | |
3617 | |
3618 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus402) { | |
3619 ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); | |
3620 } | |
3621 | |
3622 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus403) { | |
3623 ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); | |
3624 } | |
3625 | |
3626 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus404) { | |
3627 ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); | |
3628 } | |
3629 | |
3630 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus405) { | |
3631 ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); | |
3632 } | |
3633 | |
3634 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus406) { | |
3635 ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); | |
3636 } | |
3637 | |
3638 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus407) { | |
3639 ConnectStatusHelperWithExpectedStatus( | |
3640 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
3641 ERR_PROXY_AUTH_UNSUPPORTED); | |
3642 } | |
3643 | |
3644 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus408) { | |
3645 ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); | |
3646 } | |
3647 | |
3648 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus409) { | |
3649 ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); | |
3650 } | |
3651 | |
3652 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus410) { | |
3653 ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); | |
3654 } | |
3655 | |
3656 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus411) { | |
3657 ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); | |
3658 } | |
3659 | |
3660 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus412) { | |
3661 ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); | |
3662 } | |
3663 | |
3664 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus413) { | |
3665 ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); | |
3666 } | |
3667 | |
3668 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus414) { | |
3669 ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); | |
3670 } | |
3671 | |
3672 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus415) { | |
3673 ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); | |
3674 } | |
3675 | |
3676 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus416) { | |
3677 ConnectStatusHelper( | |
3678 MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); | |
3679 } | |
3680 | |
3681 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus417) { | |
3682 ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); | |
3683 } | |
3684 | |
3685 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus500) { | |
3686 ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); | |
3687 } | |
3688 | |
3689 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus501) { | |
3690 ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); | |
3691 } | |
3692 | |
3693 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus502) { | |
3694 ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); | |
3695 } | |
3696 | |
3697 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus503) { | |
3698 ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); | |
3699 } | |
3700 | |
3701 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus504) { | |
3702 ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); | |
3703 } | |
3704 | |
3705 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectStatus505) { | |
3706 ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); | |
3707 } | |
3708 | |
3709 // Test the flow when both the proxy server AND origin server require | |
3710 // authentication. Again, this uses basic auth for both since that is | |
3711 // the simplest to mock. | |
3712 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthProxyThenServer) { | |
3713 HttpRequestInfo request; | |
3714 request.method = "GET"; | |
3715 request.url = GURL("http://www.google.com/"); | |
3716 request.load_flags = 0; | |
3717 | |
3718 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
3719 | |
3720 // Configure against proxy server "myproxy:70". | |
3721 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
3722 CreateSession(&session_deps_))); | |
3723 | |
3724 MockWrite data_writes1[] = { | |
3725 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
3726 "Host: www.google.com\r\n" | |
3727 "Proxy-Connection: keep-alive\r\n\r\n"), | |
3728 }; | |
3729 | |
3730 MockRead data_reads1[] = { | |
3731 MockRead("HTTP/1.0 407 Unauthorized\r\n"), | |
3732 // Give a couple authenticate options (only the middle one is actually | |
3733 // supported). | |
3734 MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. | |
3735 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
3736 MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), | |
3737 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
3738 // Large content-length -- won't matter, as connection will be reset. | |
3739 MockRead("Content-Length: 10000\r\n\r\n"), | |
3740 MockRead(SYNCHRONOUS, ERR_FAILED), | |
3741 }; | |
3742 | |
3743 // After calling trans->RestartWithAuth() the first time, this is the | |
3744 // request we should be issuing -- the final header line contains the | |
3745 // proxy's credentials. | |
3746 MockWrite data_writes2[] = { | |
3747 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
3748 "Host: www.google.com\r\n" | |
3749 "Proxy-Connection: keep-alive\r\n" | |
3750 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
3751 }; | |
3752 | |
3753 // Now the proxy server lets the request pass through to origin server. | |
3754 // The origin server responds with a 401. | |
3755 MockRead data_reads2[] = { | |
3756 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
3757 // Note: We are using the same realm-name as the proxy server. This is | |
3758 // completely valid, as realms are unique across hosts. | |
3759 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
3760 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
3761 MockRead("Content-Length: 2000\r\n\r\n"), | |
3762 MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. | |
3763 }; | |
3764 | |
3765 // After calling trans->RestartWithAuth() the second time, we should send | |
3766 // the credentials for both the proxy and origin server. | |
3767 MockWrite data_writes3[] = { | |
3768 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
3769 "Host: www.google.com\r\n" | |
3770 "Proxy-Connection: keep-alive\r\n" | |
3771 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" | |
3772 "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), | |
3773 }; | |
3774 | |
3775 // Lastly we get the desired content. | |
3776 MockRead data_reads3[] = { | |
3777 MockRead("HTTP/1.0 200 OK\r\n"), | |
3778 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
3779 MockRead("Content-Length: 100\r\n\r\n"), | |
3780 MockRead(SYNCHRONOUS, OK), | |
3781 }; | |
3782 | |
3783 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
3784 data_writes1, arraysize(data_writes1)); | |
3785 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
3786 data_writes2, arraysize(data_writes2)); | |
3787 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), | |
3788 data_writes3, arraysize(data_writes3)); | |
3789 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
3790 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
3791 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
3792 | |
3793 TestCompletionCallback callback1; | |
3794 | |
3795 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
3796 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3797 | |
3798 rv = callback1.WaitForResult(); | |
3799 EXPECT_EQ(OK, rv); | |
3800 | |
3801 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
3802 ASSERT_TRUE(response != NULL); | |
3803 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | |
3804 | |
3805 TestCompletionCallback callback2; | |
3806 | |
3807 rv = trans->RestartWithAuth( | |
3808 AuthCredentials(kFoo, kBar), callback2.callback()); | |
3809 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3810 | |
3811 rv = callback2.WaitForResult(); | |
3812 EXPECT_EQ(OK, rv); | |
3813 | |
3814 response = trans->GetResponseInfo(); | |
3815 ASSERT_TRUE(response != NULL); | |
3816 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
3817 | |
3818 TestCompletionCallback callback3; | |
3819 | |
3820 rv = trans->RestartWithAuth( | |
3821 AuthCredentials(kFoo2, kBar2), callback3.callback()); | |
3822 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3823 | |
3824 rv = callback3.WaitForResult(); | |
3825 EXPECT_EQ(OK, rv); | |
3826 | |
3827 response = trans->GetResponseInfo(); | |
3828 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
3829 EXPECT_EQ(100, response->headers->GetContentLength()); | |
3830 } | |
3831 | |
3832 // For the NTLM implementation using SSPI, we skip the NTLM tests since we | |
3833 // can't hook into its internals to cause it to generate predictable NTLM | |
3834 // authorization headers. | |
3835 #if defined(NTLM_PORTABLE) | |
3836 // The NTLM authentication unit tests were generated by capturing the HTTP | |
3837 // requests and responses using Fiddler 2 and inspecting the generated random | |
3838 // bytes in the debugger. | |
3839 | |
3840 // Enter the correct password and authenticate successfully. | |
3841 TEST_F(HttpNetworkTransactionSpdy3Test, NTLMAuth1) { | |
3842 HttpRequestInfo request; | |
3843 request.method = "GET"; | |
3844 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | |
3845 request.load_flags = 0; | |
3846 | |
3847 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, | |
3848 MockGetHostName); | |
3849 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
3850 | |
3851 MockWrite data_writes1[] = { | |
3852 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
3853 "Host: 172.22.68.17\r\n" | |
3854 "Connection: keep-alive\r\n\r\n"), | |
3855 }; | |
3856 | |
3857 MockRead data_reads1[] = { | |
3858 MockRead("HTTP/1.1 401 Access Denied\r\n"), | |
3859 // Negotiate and NTLM are often requested together. However, we only want | |
3860 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip | |
3861 // the header that requests Negotiate for this test. | |
3862 MockRead("WWW-Authenticate: NTLM\r\n"), | |
3863 MockRead("Connection: close\r\n"), | |
3864 MockRead("Content-Length: 42\r\n"), | |
3865 MockRead("Content-Type: text/html\r\n\r\n"), | |
3866 // Missing content -- won't matter, as connection will be reset. | |
3867 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), | |
3868 }; | |
3869 | |
3870 MockWrite data_writes2[] = { | |
3871 // After restarting with a null identity, this is the | |
3872 // request we should be issuing -- the final header line contains a Type | |
3873 // 1 message. | |
3874 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
3875 "Host: 172.22.68.17\r\n" | |
3876 "Connection: keep-alive\r\n" | |
3877 "Authorization: NTLM " | |
3878 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), | |
3879 | |
3880 // After calling trans->RestartWithAuth(), we should send a Type 3 message | |
3881 // (the credentials for the origin server). The second request continues | |
3882 // on the same connection. | |
3883 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
3884 "Host: 172.22.68.17\r\n" | |
3885 "Connection: keep-alive\r\n" | |
3886 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" | |
3887 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" | |
3888 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" | |
3889 "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" | |
3890 "ahlhx5I=\r\n\r\n"), | |
3891 }; | |
3892 | |
3893 MockRead data_reads2[] = { | |
3894 // The origin server responds with a Type 2 message. | |
3895 MockRead("HTTP/1.1 401 Access Denied\r\n"), | |
3896 MockRead("WWW-Authenticate: NTLM " | |
3897 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" | |
3898 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" | |
3899 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" | |
3900 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" | |
3901 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" | |
3902 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" | |
3903 "BtAAAAAAA=\r\n"), | |
3904 MockRead("Content-Length: 42\r\n"), | |
3905 MockRead("Content-Type: text/html\r\n\r\n"), | |
3906 MockRead("You are not authorized to view this page\r\n"), | |
3907 | |
3908 // Lastly we get the desired content. | |
3909 MockRead("HTTP/1.1 200 OK\r\n"), | |
3910 MockRead("Content-Type: text/html; charset=utf-8\r\n"), | |
3911 MockRead("Content-Length: 13\r\n\r\n"), | |
3912 MockRead("Please Login\r\n"), | |
3913 MockRead(SYNCHRONOUS, OK), | |
3914 }; | |
3915 | |
3916 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
3917 data_writes1, arraysize(data_writes1)); | |
3918 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
3919 data_writes2, arraysize(data_writes2)); | |
3920 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
3921 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
3922 | |
3923 TestCompletionCallback callback1; | |
3924 | |
3925 scoped_ptr<HttpTransaction> trans( | |
3926 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
3927 | |
3928 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
3929 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3930 | |
3931 rv = callback1.WaitForResult(); | |
3932 EXPECT_EQ(OK, rv); | |
3933 | |
3934 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
3935 | |
3936 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
3937 ASSERT_FALSE(response == NULL); | |
3938 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); | |
3939 | |
3940 TestCompletionCallback callback2; | |
3941 | |
3942 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), | |
3943 callback2.callback()); | |
3944 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3945 | |
3946 rv = callback2.WaitForResult(); | |
3947 EXPECT_EQ(OK, rv); | |
3948 | |
3949 EXPECT_TRUE(trans->IsReadyToRestartForAuth()); | |
3950 | |
3951 response = trans->GetResponseInfo(); | |
3952 ASSERT_TRUE(response != NULL); | |
3953 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
3954 | |
3955 TestCompletionCallback callback3; | |
3956 | |
3957 rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); | |
3958 EXPECT_EQ(ERR_IO_PENDING, rv); | |
3959 | |
3960 rv = callback3.WaitForResult(); | |
3961 EXPECT_EQ(OK, rv); | |
3962 | |
3963 response = trans->GetResponseInfo(); | |
3964 ASSERT_TRUE(response != NULL); | |
3965 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
3966 EXPECT_EQ(13, response->headers->GetContentLength()); | |
3967 } | |
3968 | |
3969 // Enter a wrong password, and then the correct one. | |
3970 TEST_F(HttpNetworkTransactionSpdy3Test, NTLMAuth2) { | |
3971 HttpRequestInfo request; | |
3972 request.method = "GET"; | |
3973 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | |
3974 request.load_flags = 0; | |
3975 | |
3976 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, | |
3977 MockGetHostName); | |
3978 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
3979 | |
3980 MockWrite data_writes1[] = { | |
3981 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
3982 "Host: 172.22.68.17\r\n" | |
3983 "Connection: keep-alive\r\n\r\n"), | |
3984 }; | |
3985 | |
3986 MockRead data_reads1[] = { | |
3987 MockRead("HTTP/1.1 401 Access Denied\r\n"), | |
3988 // Negotiate and NTLM are often requested together. However, we only want | |
3989 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip | |
3990 // the header that requests Negotiate for this test. | |
3991 MockRead("WWW-Authenticate: NTLM\r\n"), | |
3992 MockRead("Connection: close\r\n"), | |
3993 MockRead("Content-Length: 42\r\n"), | |
3994 MockRead("Content-Type: text/html\r\n\r\n"), | |
3995 // Missing content -- won't matter, as connection will be reset. | |
3996 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), | |
3997 }; | |
3998 | |
3999 MockWrite data_writes2[] = { | |
4000 // After restarting with a null identity, this is the | |
4001 // request we should be issuing -- the final header line contains a Type | |
4002 // 1 message. | |
4003 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
4004 "Host: 172.22.68.17\r\n" | |
4005 "Connection: keep-alive\r\n" | |
4006 "Authorization: NTLM " | |
4007 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), | |
4008 | |
4009 // After calling trans->RestartWithAuth(), we should send a Type 3 message | |
4010 // (the credentials for the origin server). The second request continues | |
4011 // on the same connection. | |
4012 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
4013 "Host: 172.22.68.17\r\n" | |
4014 "Connection: keep-alive\r\n" | |
4015 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" | |
4016 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" | |
4017 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" | |
4018 "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" | |
4019 "4Ww7b7E=\r\n\r\n"), | |
4020 }; | |
4021 | |
4022 MockRead data_reads2[] = { | |
4023 // The origin server responds with a Type 2 message. | |
4024 MockRead("HTTP/1.1 401 Access Denied\r\n"), | |
4025 MockRead("WWW-Authenticate: NTLM " | |
4026 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" | |
4027 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" | |
4028 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" | |
4029 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" | |
4030 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" | |
4031 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" | |
4032 "BtAAAAAAA=\r\n"), | |
4033 MockRead("Content-Length: 42\r\n"), | |
4034 MockRead("Content-Type: text/html\r\n\r\n"), | |
4035 MockRead("You are not authorized to view this page\r\n"), | |
4036 | |
4037 // Wrong password. | |
4038 MockRead("HTTP/1.1 401 Access Denied\r\n"), | |
4039 MockRead("WWW-Authenticate: NTLM\r\n"), | |
4040 MockRead("Connection: close\r\n"), | |
4041 MockRead("Content-Length: 42\r\n"), | |
4042 MockRead("Content-Type: text/html\r\n\r\n"), | |
4043 // Missing content -- won't matter, as connection will be reset. | |
4044 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), | |
4045 }; | |
4046 | |
4047 MockWrite data_writes3[] = { | |
4048 // After restarting with a null identity, this is the | |
4049 // request we should be issuing -- the final header line contains a Type | |
4050 // 1 message. | |
4051 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
4052 "Host: 172.22.68.17\r\n" | |
4053 "Connection: keep-alive\r\n" | |
4054 "Authorization: NTLM " | |
4055 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), | |
4056 | |
4057 // After calling trans->RestartWithAuth(), we should send a Type 3 message | |
4058 // (the credentials for the origin server). The second request continues | |
4059 // on the same connection. | |
4060 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | |
4061 "Host: 172.22.68.17\r\n" | |
4062 "Connection: keep-alive\r\n" | |
4063 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" | |
4064 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" | |
4065 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" | |
4066 "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" | |
4067 "+4MUm7c=\r\n\r\n"), | |
4068 }; | |
4069 | |
4070 MockRead data_reads3[] = { | |
4071 // The origin server responds with a Type 2 message. | |
4072 MockRead("HTTP/1.1 401 Access Denied\r\n"), | |
4073 MockRead("WWW-Authenticate: NTLM " | |
4074 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" | |
4075 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" | |
4076 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" | |
4077 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" | |
4078 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" | |
4079 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" | |
4080 "BtAAAAAAA=\r\n"), | |
4081 MockRead("Content-Length: 42\r\n"), | |
4082 MockRead("Content-Type: text/html\r\n\r\n"), | |
4083 MockRead("You are not authorized to view this page\r\n"), | |
4084 | |
4085 // Lastly we get the desired content. | |
4086 MockRead("HTTP/1.1 200 OK\r\n"), | |
4087 MockRead("Content-Type: text/html; charset=utf-8\r\n"), | |
4088 MockRead("Content-Length: 13\r\n\r\n"), | |
4089 MockRead("Please Login\r\n"), | |
4090 MockRead(SYNCHRONOUS, OK), | |
4091 }; | |
4092 | |
4093 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
4094 data_writes1, arraysize(data_writes1)); | |
4095 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
4096 data_writes2, arraysize(data_writes2)); | |
4097 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), | |
4098 data_writes3, arraysize(data_writes3)); | |
4099 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
4100 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
4101 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
4102 | |
4103 TestCompletionCallback callback1; | |
4104 | |
4105 scoped_ptr<HttpTransaction> trans( | |
4106 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4107 | |
4108 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
4109 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4110 | |
4111 rv = callback1.WaitForResult(); | |
4112 EXPECT_EQ(OK, rv); | |
4113 | |
4114 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
4115 | |
4116 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4117 ASSERT_TRUE(response != NULL); | |
4118 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); | |
4119 | |
4120 TestCompletionCallback callback2; | |
4121 | |
4122 // Enter the wrong password. | |
4123 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), | |
4124 callback2.callback()); | |
4125 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4126 | |
4127 rv = callback2.WaitForResult(); | |
4128 EXPECT_EQ(OK, rv); | |
4129 | |
4130 EXPECT_TRUE(trans->IsReadyToRestartForAuth()); | |
4131 TestCompletionCallback callback3; | |
4132 rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); | |
4133 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4134 rv = callback3.WaitForResult(); | |
4135 EXPECT_EQ(OK, rv); | |
4136 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
4137 | |
4138 response = trans->GetResponseInfo(); | |
4139 ASSERT_FALSE(response == NULL); | |
4140 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); | |
4141 | |
4142 TestCompletionCallback callback4; | |
4143 | |
4144 // Now enter the right password. | |
4145 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), | |
4146 callback4.callback()); | |
4147 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4148 | |
4149 rv = callback4.WaitForResult(); | |
4150 EXPECT_EQ(OK, rv); | |
4151 | |
4152 EXPECT_TRUE(trans->IsReadyToRestartForAuth()); | |
4153 | |
4154 TestCompletionCallback callback5; | |
4155 | |
4156 // One more roundtrip | |
4157 rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); | |
4158 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4159 | |
4160 rv = callback5.WaitForResult(); | |
4161 EXPECT_EQ(OK, rv); | |
4162 | |
4163 response = trans->GetResponseInfo(); | |
4164 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
4165 EXPECT_EQ(13, response->headers->GetContentLength()); | |
4166 } | |
4167 #endif // NTLM_PORTABLE | |
4168 | |
4169 // Test reading a server response which has only headers, and no body. | |
4170 // After some maximum number of bytes is consumed, the transaction should | |
4171 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. | |
4172 TEST_F(HttpNetworkTransactionSpdy3Test, LargeHeadersNoBody) { | |
4173 HttpRequestInfo request; | |
4174 request.method = "GET"; | |
4175 request.url = GURL("http://www.google.com/"); | |
4176 request.load_flags = 0; | |
4177 | |
4178 scoped_ptr<HttpTransaction> trans( | |
4179 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
4180 CreateSession(&session_deps_))); | |
4181 | |
4182 // Respond with 300 kb of headers (we should fail after 256 kb). | |
4183 std::string large_headers_string; | |
4184 FillLargeHeadersString(&large_headers_string, 300 * 1024); | |
4185 | |
4186 MockRead data_reads[] = { | |
4187 MockRead("HTTP/1.0 200 OK\r\n"), | |
4188 MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), | |
4189 MockRead("\r\nBODY"), | |
4190 MockRead(SYNCHRONOUS, OK), | |
4191 }; | |
4192 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
4193 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
4194 | |
4195 TestCompletionCallback callback; | |
4196 | |
4197 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
4198 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4199 | |
4200 rv = callback.WaitForResult(); | |
4201 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); | |
4202 | |
4203 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4204 EXPECT_TRUE(response == NULL); | |
4205 } | |
4206 | |
4207 // Make sure that we don't try to reuse a TCPClientSocket when failing to | |
4208 // establish tunnel. | |
4209 // http://code.google.com/p/chromium/issues/detail?id=3772 | |
4210 TEST_F(HttpNetworkTransactionSpdy3Test, | |
4211 DontRecycleTransportSocketForSSLTunnel) { | |
4212 HttpRequestInfo request; | |
4213 request.method = "GET"; | |
4214 request.url = GURL("https://www.google.com/"); | |
4215 request.load_flags = 0; | |
4216 | |
4217 // Configure against proxy server "myproxy:70". | |
4218 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
4219 | |
4220 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
4221 | |
4222 scoped_ptr<HttpTransaction> trans( | |
4223 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4224 | |
4225 // Since we have proxy, should try to establish tunnel. | |
4226 MockWrite data_writes1[] = { | |
4227 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
4228 "Host: www.google.com\r\n" | |
4229 "Proxy-Connection: keep-alive\r\n\r\n"), | |
4230 }; | |
4231 | |
4232 // The proxy responds to the connect with a 404, using a persistent | |
4233 // connection. Usually a proxy would return 501 (not implemented), | |
4234 // or 200 (tunnel established). | |
4235 MockRead data_reads1[] = { | |
4236 MockRead("HTTP/1.1 404 Not Found\r\n"), | |
4237 MockRead("Content-Length: 10\r\n\r\n"), | |
4238 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
4239 }; | |
4240 | |
4241 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
4242 data_writes1, arraysize(data_writes1)); | |
4243 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
4244 | |
4245 TestCompletionCallback callback1; | |
4246 | |
4247 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
4248 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4249 | |
4250 rv = callback1.WaitForResult(); | |
4251 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
4252 | |
4253 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4254 EXPECT_TRUE(response == NULL); | |
4255 | |
4256 // Empty the current queue. This is necessary because idle sockets are | |
4257 // added to the connection pool asynchronously with a PostTask. | |
4258 base::MessageLoop::current()->RunUntilIdle(); | |
4259 | |
4260 // We now check to make sure the TCPClientSocket was not added back to | |
4261 // the pool. | |
4262 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4263 trans.reset(); | |
4264 base::MessageLoop::current()->RunUntilIdle(); | |
4265 // Make sure that the socket didn't get recycled after calling the destructor. | |
4266 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4267 } | |
4268 | |
4269 // Make sure that we recycle a socket after reading all of the response body. | |
4270 TEST_F(HttpNetworkTransactionSpdy3Test, RecycleSocket) { | |
4271 HttpRequestInfo request; | |
4272 request.method = "GET"; | |
4273 request.url = GURL("http://www.google.com/"); | |
4274 request.load_flags = 0; | |
4275 | |
4276 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
4277 | |
4278 scoped_ptr<HttpTransaction> trans( | |
4279 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4280 | |
4281 MockRead data_reads[] = { | |
4282 // A part of the response body is received with the response headers. | |
4283 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), | |
4284 // The rest of the response body is received in two parts. | |
4285 MockRead("lo"), | |
4286 MockRead(" world"), | |
4287 MockRead("junk"), // Should not be read!! | |
4288 MockRead(SYNCHRONOUS, OK), | |
4289 }; | |
4290 | |
4291 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
4292 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
4293 | |
4294 TestCompletionCallback callback; | |
4295 | |
4296 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
4297 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4298 | |
4299 rv = callback.WaitForResult(); | |
4300 EXPECT_EQ(OK, rv); | |
4301 | |
4302 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4303 ASSERT_TRUE(response != NULL); | |
4304 | |
4305 EXPECT_TRUE(response->headers.get() != NULL); | |
4306 std::string status_line = response->headers->GetStatusLine(); | |
4307 EXPECT_EQ("HTTP/1.1 200 OK", status_line); | |
4308 | |
4309 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4310 | |
4311 std::string response_data; | |
4312 rv = ReadTransaction(trans.get(), &response_data); | |
4313 EXPECT_EQ(OK, rv); | |
4314 EXPECT_EQ("hello world", response_data); | |
4315 | |
4316 // Empty the current queue. This is necessary because idle sockets are | |
4317 // added to the connection pool asynchronously with a PostTask. | |
4318 base::MessageLoop::current()->RunUntilIdle(); | |
4319 | |
4320 // We now check to make sure the socket was added back to the pool. | |
4321 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4322 } | |
4323 | |
4324 // Make sure that we recycle a SSL socket after reading all of the response | |
4325 // body. | |
4326 TEST_F(HttpNetworkTransactionSpdy3Test, RecycleSSLSocket) { | |
4327 HttpRequestInfo request; | |
4328 request.method = "GET"; | |
4329 request.url = GURL("https://www.google.com/"); | |
4330 request.load_flags = 0; | |
4331 | |
4332 MockWrite data_writes[] = { | |
4333 MockWrite("GET / HTTP/1.1\r\n" | |
4334 "Host: www.google.com\r\n" | |
4335 "Connection: keep-alive\r\n\r\n"), | |
4336 }; | |
4337 | |
4338 MockRead data_reads[] = { | |
4339 MockRead("HTTP/1.1 200 OK\r\n"), | |
4340 MockRead("Content-Length: 11\r\n\r\n"), | |
4341 MockRead("hello world"), | |
4342 MockRead(SYNCHRONOUS, OK), | |
4343 }; | |
4344 | |
4345 SSLSocketDataProvider ssl(ASYNC, OK); | |
4346 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
4347 | |
4348 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
4349 data_writes, arraysize(data_writes)); | |
4350 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
4351 | |
4352 TestCompletionCallback callback; | |
4353 | |
4354 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
4355 scoped_ptr<HttpTransaction> trans( | |
4356 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4357 | |
4358 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
4359 | |
4360 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4361 EXPECT_EQ(OK, callback.WaitForResult()); | |
4362 | |
4363 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4364 ASSERT_TRUE(response != NULL); | |
4365 ASSERT_TRUE(response->headers.get() != NULL); | |
4366 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
4367 | |
4368 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4369 | |
4370 std::string response_data; | |
4371 rv = ReadTransaction(trans.get(), &response_data); | |
4372 EXPECT_EQ(OK, rv); | |
4373 EXPECT_EQ("hello world", response_data); | |
4374 | |
4375 // Empty the current queue. This is necessary because idle sockets are | |
4376 // added to the connection pool asynchronously with a PostTask. | |
4377 base::MessageLoop::current()->RunUntilIdle(); | |
4378 | |
4379 // We now check to make sure the socket was added back to the pool. | |
4380 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); | |
4381 } | |
4382 | |
4383 // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it | |
4384 // from the pool and make sure that we recover okay. | |
4385 TEST_F(HttpNetworkTransactionSpdy3Test, RecycleDeadSSLSocket) { | |
4386 HttpRequestInfo request; | |
4387 request.method = "GET"; | |
4388 request.url = GURL("https://www.google.com/"); | |
4389 request.load_flags = 0; | |
4390 | |
4391 MockWrite data_writes[] = { | |
4392 MockWrite("GET / HTTP/1.1\r\n" | |
4393 "Host: www.google.com\r\n" | |
4394 "Connection: keep-alive\r\n\r\n"), | |
4395 MockWrite("GET / HTTP/1.1\r\n" | |
4396 "Host: www.google.com\r\n" | |
4397 "Connection: keep-alive\r\n\r\n"), | |
4398 }; | |
4399 | |
4400 MockRead data_reads[] = { | |
4401 MockRead("HTTP/1.1 200 OK\r\n"), | |
4402 MockRead("Content-Length: 11\r\n\r\n"), | |
4403 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
4404 MockRead("hello world"), | |
4405 MockRead(ASYNC, 0, 0) // EOF | |
4406 }; | |
4407 | |
4408 SSLSocketDataProvider ssl(ASYNC, OK); | |
4409 SSLSocketDataProvider ssl2(ASYNC, OK); | |
4410 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
4411 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); | |
4412 | |
4413 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
4414 data_writes, arraysize(data_writes)); | |
4415 StaticSocketDataProvider data2(data_reads, arraysize(data_reads), | |
4416 data_writes, arraysize(data_writes)); | |
4417 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
4418 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
4419 | |
4420 TestCompletionCallback callback; | |
4421 | |
4422 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
4423 scoped_ptr<HttpTransaction> trans( | |
4424 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4425 | |
4426 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
4427 | |
4428 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4429 EXPECT_EQ(OK, callback.WaitForResult()); | |
4430 | |
4431 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4432 ASSERT_TRUE(response != NULL); | |
4433 ASSERT_TRUE(response->headers.get() != NULL); | |
4434 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
4435 | |
4436 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4437 | |
4438 std::string response_data; | |
4439 rv = ReadTransaction(trans.get(), &response_data); | |
4440 EXPECT_EQ(OK, rv); | |
4441 EXPECT_EQ("hello world", response_data); | |
4442 | |
4443 // Empty the current queue. This is necessary because idle sockets are | |
4444 // added to the connection pool asynchronously with a PostTask. | |
4445 base::MessageLoop::current()->RunUntilIdle(); | |
4446 | |
4447 // We now check to make sure the socket was added back to the pool. | |
4448 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); | |
4449 | |
4450 // Now start the second transaction, which should reuse the previous socket. | |
4451 | |
4452 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4453 | |
4454 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
4455 | |
4456 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4457 EXPECT_EQ(OK, callback.WaitForResult()); | |
4458 | |
4459 response = trans->GetResponseInfo(); | |
4460 ASSERT_TRUE(response != NULL); | |
4461 ASSERT_TRUE(response->headers.get() != NULL); | |
4462 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
4463 | |
4464 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4465 | |
4466 rv = ReadTransaction(trans.get(), &response_data); | |
4467 EXPECT_EQ(OK, rv); | |
4468 EXPECT_EQ("hello world", response_data); | |
4469 | |
4470 // Empty the current queue. This is necessary because idle sockets are | |
4471 // added to the connection pool asynchronously with a PostTask. | |
4472 base::MessageLoop::current()->RunUntilIdle(); | |
4473 | |
4474 // We now check to make sure the socket was added back to the pool. | |
4475 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); | |
4476 } | |
4477 | |
4478 // Make sure that we recycle a socket after a zero-length response. | |
4479 // http://crbug.com/9880 | |
4480 TEST_F(HttpNetworkTransactionSpdy3Test, RecycleSocketAfterZeroContentLength) { | |
4481 HttpRequestInfo request; | |
4482 request.method = "GET"; | |
4483 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" | |
4484 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" | |
4485 "e=17259,18167,19592,19773,19981,20133,20173,20233&" | |
4486 "rt=prt.2642,ol.2649,xjs.2951"); | |
4487 request.load_flags = 0; | |
4488 | |
4489 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
4490 | |
4491 scoped_ptr<HttpTransaction> trans( | |
4492 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4493 | |
4494 MockRead data_reads[] = { | |
4495 MockRead("HTTP/1.1 204 No Content\r\n" | |
4496 "Content-Length: 0\r\n" | |
4497 "Content-Type: text/html\r\n\r\n"), | |
4498 MockRead("junk"), // Should not be read!! | |
4499 MockRead(SYNCHRONOUS, OK), | |
4500 }; | |
4501 | |
4502 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
4503 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
4504 | |
4505 TestCompletionCallback callback; | |
4506 | |
4507 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
4508 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4509 | |
4510 rv = callback.WaitForResult(); | |
4511 EXPECT_EQ(OK, rv); | |
4512 | |
4513 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4514 ASSERT_TRUE(response != NULL); | |
4515 | |
4516 EXPECT_TRUE(response->headers.get() != NULL); | |
4517 std::string status_line = response->headers->GetStatusLine(); | |
4518 EXPECT_EQ("HTTP/1.1 204 No Content", status_line); | |
4519 | |
4520 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4521 | |
4522 std::string response_data; | |
4523 rv = ReadTransaction(trans.get(), &response_data); | |
4524 EXPECT_EQ(OK, rv); | |
4525 EXPECT_EQ("", response_data); | |
4526 | |
4527 // Empty the current queue. This is necessary because idle sockets are | |
4528 // added to the connection pool asynchronously with a PostTask. | |
4529 base::MessageLoop::current()->RunUntilIdle(); | |
4530 | |
4531 // We now check to make sure the socket was added back to the pool. | |
4532 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); | |
4533 } | |
4534 | |
4535 TEST_F(HttpNetworkTransactionSpdy3Test, ResendRequestOnWriteBodyError) { | |
4536 ScopedVector<UploadElementReader> element_readers; | |
4537 element_readers.push_back(new UploadBytesElementReader("foo", 3)); | |
4538 UploadDataStream upload_data_stream(&element_readers, 0); | |
4539 | |
4540 HttpRequestInfo request[2]; | |
4541 // Transaction 1: a GET request that succeeds. The socket is recycled | |
4542 // after use. | |
4543 request[0].method = "GET"; | |
4544 request[0].url = GURL("http://www.google.com/"); | |
4545 request[0].load_flags = 0; | |
4546 // Transaction 2: a POST request. Reuses the socket kept alive from | |
4547 // transaction 1. The first attempts fails when writing the POST data. | |
4548 // This causes the transaction to retry with a new socket. The second | |
4549 // attempt succeeds. | |
4550 request[1].method = "POST"; | |
4551 request[1].url = GURL("http://www.google.com/login.cgi"); | |
4552 request[1].upload_data_stream = &upload_data_stream; | |
4553 request[1].load_flags = 0; | |
4554 | |
4555 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
4556 | |
4557 // The first socket is used for transaction 1 and the first attempt of | |
4558 // transaction 2. | |
4559 | |
4560 // The response of transaction 1. | |
4561 MockRead data_reads1[] = { | |
4562 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), | |
4563 MockRead("hello world"), | |
4564 MockRead(SYNCHRONOUS, OK), | |
4565 }; | |
4566 // The mock write results of transaction 1 and the first attempt of | |
4567 // transaction 2. | |
4568 MockWrite data_writes1[] = { | |
4569 MockWrite(SYNCHRONOUS, 64), // GET | |
4570 MockWrite(SYNCHRONOUS, 93), // POST | |
4571 MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data | |
4572 }; | |
4573 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
4574 data_writes1, arraysize(data_writes1)); | |
4575 | |
4576 // The second socket is used for the second attempt of transaction 2. | |
4577 | |
4578 // The response of transaction 2. | |
4579 MockRead data_reads2[] = { | |
4580 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), | |
4581 MockRead("welcome"), | |
4582 MockRead(SYNCHRONOUS, OK), | |
4583 }; | |
4584 // The mock write results of the second attempt of transaction 2. | |
4585 MockWrite data_writes2[] = { | |
4586 MockWrite(SYNCHRONOUS, 93), // POST | |
4587 MockWrite(SYNCHRONOUS, 3), // POST data | |
4588 }; | |
4589 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
4590 data_writes2, arraysize(data_writes2)); | |
4591 | |
4592 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
4593 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
4594 | |
4595 const char* kExpectedResponseData[] = { | |
4596 "hello world", "welcome" | |
4597 }; | |
4598 | |
4599 for (int i = 0; i < 2; ++i) { | |
4600 scoped_ptr<HttpTransaction> trans( | |
4601 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4602 | |
4603 TestCompletionCallback callback; | |
4604 | |
4605 int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); | |
4606 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4607 | |
4608 rv = callback.WaitForResult(); | |
4609 EXPECT_EQ(OK, rv); | |
4610 | |
4611 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4612 ASSERT_TRUE(response != NULL); | |
4613 | |
4614 EXPECT_TRUE(response->headers.get() != NULL); | |
4615 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
4616 | |
4617 std::string response_data; | |
4618 rv = ReadTransaction(trans.get(), &response_data); | |
4619 EXPECT_EQ(OK, rv); | |
4620 EXPECT_EQ(kExpectedResponseData[i], response_data); | |
4621 } | |
4622 } | |
4623 | |
4624 // Test the request-challenge-retry sequence for basic auth when there is | |
4625 // an identity in the URL. The request should be sent as normal, but when | |
4626 // it fails the identity from the URL is used to answer the challenge. | |
4627 TEST_F(HttpNetworkTransactionSpdy3Test, AuthIdentityInURL) { | |
4628 HttpRequestInfo request; | |
4629 request.method = "GET"; | |
4630 request.url = GURL("http://foo:b@r@www.google.com/"); | |
4631 request.load_flags = LOAD_NORMAL; | |
4632 | |
4633 scoped_ptr<HttpTransaction> trans( | |
4634 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
4635 CreateSession(&session_deps_))); | |
4636 | |
4637 // The password contains an escaped character -- for this test to pass it | |
4638 // will need to be unescaped by HttpNetworkTransaction. | |
4639 EXPECT_EQ("b%40r", request.url.password()); | |
4640 | |
4641 MockWrite data_writes1[] = { | |
4642 MockWrite("GET / HTTP/1.1\r\n" | |
4643 "Host: www.google.com\r\n" | |
4644 "Connection: keep-alive\r\n\r\n"), | |
4645 }; | |
4646 | |
4647 MockRead data_reads1[] = { | |
4648 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
4649 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
4650 MockRead("Content-Length: 10\r\n\r\n"), | |
4651 MockRead(SYNCHRONOUS, ERR_FAILED), | |
4652 }; | |
4653 | |
4654 // After the challenge above, the transaction will be restarted using the | |
4655 // identity from the url (foo, b@r) to answer the challenge. | |
4656 MockWrite data_writes2[] = { | |
4657 MockWrite("GET / HTTP/1.1\r\n" | |
4658 "Host: www.google.com\r\n" | |
4659 "Connection: keep-alive\r\n" | |
4660 "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), | |
4661 }; | |
4662 | |
4663 MockRead data_reads2[] = { | |
4664 MockRead("HTTP/1.0 200 OK\r\n"), | |
4665 MockRead("Content-Length: 100\r\n\r\n"), | |
4666 MockRead(SYNCHRONOUS, OK), | |
4667 }; | |
4668 | |
4669 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
4670 data_writes1, arraysize(data_writes1)); | |
4671 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
4672 data_writes2, arraysize(data_writes2)); | |
4673 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
4674 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
4675 | |
4676 TestCompletionCallback callback1; | |
4677 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
4678 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4679 rv = callback1.WaitForResult(); | |
4680 EXPECT_EQ(OK, rv); | |
4681 EXPECT_TRUE(trans->IsReadyToRestartForAuth()); | |
4682 | |
4683 TestCompletionCallback callback2; | |
4684 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); | |
4685 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4686 rv = callback2.WaitForResult(); | |
4687 EXPECT_EQ(OK, rv); | |
4688 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
4689 | |
4690 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4691 ASSERT_TRUE(response != NULL); | |
4692 | |
4693 // There is no challenge info, since the identity in URL worked. | |
4694 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
4695 | |
4696 EXPECT_EQ(100, response->headers->GetContentLength()); | |
4697 | |
4698 // Empty the current queue. | |
4699 base::MessageLoop::current()->RunUntilIdle(); | |
4700 } | |
4701 | |
4702 // Test the request-challenge-retry sequence for basic auth when there is an | |
4703 // incorrect identity in the URL. The identity from the URL should be used only | |
4704 // once. | |
4705 TEST_F(HttpNetworkTransactionSpdy3Test, WrongAuthIdentityInURL) { | |
4706 HttpRequestInfo request; | |
4707 request.method = "GET"; | |
4708 // Note: the URL has a username:password in it. The password "baz" is | |
4709 // wrong (should be "bar"). | |
4710 request.url = GURL("http://foo:baz@www.google.com/"); | |
4711 | |
4712 request.load_flags = LOAD_NORMAL; | |
4713 | |
4714 scoped_ptr<HttpTransaction> trans( | |
4715 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
4716 CreateSession(&session_deps_))); | |
4717 | |
4718 MockWrite data_writes1[] = { | |
4719 MockWrite("GET / HTTP/1.1\r\n" | |
4720 "Host: www.google.com\r\n" | |
4721 "Connection: keep-alive\r\n\r\n"), | |
4722 }; | |
4723 | |
4724 MockRead data_reads1[] = { | |
4725 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
4726 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
4727 MockRead("Content-Length: 10\r\n\r\n"), | |
4728 MockRead(SYNCHRONOUS, ERR_FAILED), | |
4729 }; | |
4730 | |
4731 // After the challenge above, the transaction will be restarted using the | |
4732 // identity from the url (foo, baz) to answer the challenge. | |
4733 MockWrite data_writes2[] = { | |
4734 MockWrite("GET / HTTP/1.1\r\n" | |
4735 "Host: www.google.com\r\n" | |
4736 "Connection: keep-alive\r\n" | |
4737 "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), | |
4738 }; | |
4739 | |
4740 MockRead data_reads2[] = { | |
4741 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
4742 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
4743 MockRead("Content-Length: 10\r\n\r\n"), | |
4744 MockRead(SYNCHRONOUS, ERR_FAILED), | |
4745 }; | |
4746 | |
4747 // After the challenge above, the transaction will be restarted using the | |
4748 // identity supplied by the user (foo, bar) to answer the challenge. | |
4749 MockWrite data_writes3[] = { | |
4750 MockWrite("GET / HTTP/1.1\r\n" | |
4751 "Host: www.google.com\r\n" | |
4752 "Connection: keep-alive\r\n" | |
4753 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
4754 }; | |
4755 | |
4756 MockRead data_reads3[] = { | |
4757 MockRead("HTTP/1.0 200 OK\r\n"), | |
4758 MockRead("Content-Length: 100\r\n\r\n"), | |
4759 MockRead(SYNCHRONOUS, OK), | |
4760 }; | |
4761 | |
4762 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
4763 data_writes1, arraysize(data_writes1)); | |
4764 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
4765 data_writes2, arraysize(data_writes2)); | |
4766 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), | |
4767 data_writes3, arraysize(data_writes3)); | |
4768 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
4769 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
4770 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
4771 | |
4772 TestCompletionCallback callback1; | |
4773 | |
4774 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
4775 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4776 | |
4777 rv = callback1.WaitForResult(); | |
4778 EXPECT_EQ(OK, rv); | |
4779 | |
4780 EXPECT_TRUE(trans->IsReadyToRestartForAuth()); | |
4781 TestCompletionCallback callback2; | |
4782 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); | |
4783 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4784 rv = callback2.WaitForResult(); | |
4785 EXPECT_EQ(OK, rv); | |
4786 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
4787 | |
4788 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4789 ASSERT_TRUE(response != NULL); | |
4790 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
4791 | |
4792 TestCompletionCallback callback3; | |
4793 rv = trans->RestartWithAuth( | |
4794 AuthCredentials(kFoo, kBar), callback3.callback()); | |
4795 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4796 rv = callback3.WaitForResult(); | |
4797 EXPECT_EQ(OK, rv); | |
4798 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
4799 | |
4800 response = trans->GetResponseInfo(); | |
4801 ASSERT_TRUE(response != NULL); | |
4802 | |
4803 // There is no challenge info, since the identity worked. | |
4804 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
4805 | |
4806 EXPECT_EQ(100, response->headers->GetContentLength()); | |
4807 | |
4808 // Empty the current queue. | |
4809 base::MessageLoop::current()->RunUntilIdle(); | |
4810 } | |
4811 | |
4812 // Test that previously tried username/passwords for a realm get re-used. | |
4813 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthCacheAndPreauth) { | |
4814 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
4815 | |
4816 // Transaction 1: authenticate (foo, bar) on MyRealm1 | |
4817 { | |
4818 HttpRequestInfo request; | |
4819 request.method = "GET"; | |
4820 request.url = GURL("http://www.google.com/x/y/z"); | |
4821 request.load_flags = 0; | |
4822 | |
4823 scoped_ptr<HttpTransaction> trans( | |
4824 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4825 | |
4826 MockWrite data_writes1[] = { | |
4827 MockWrite("GET /x/y/z HTTP/1.1\r\n" | |
4828 "Host: www.google.com\r\n" | |
4829 "Connection: keep-alive\r\n\r\n"), | |
4830 }; | |
4831 | |
4832 MockRead data_reads1[] = { | |
4833 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
4834 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
4835 MockRead("Content-Length: 10000\r\n\r\n"), | |
4836 MockRead(SYNCHRONOUS, ERR_FAILED), | |
4837 }; | |
4838 | |
4839 // Resend with authorization (username=foo, password=bar) | |
4840 MockWrite data_writes2[] = { | |
4841 MockWrite("GET /x/y/z HTTP/1.1\r\n" | |
4842 "Host: www.google.com\r\n" | |
4843 "Connection: keep-alive\r\n" | |
4844 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
4845 }; | |
4846 | |
4847 // Sever accepts the authorization. | |
4848 MockRead data_reads2[] = { | |
4849 MockRead("HTTP/1.0 200 OK\r\n"), | |
4850 MockRead("Content-Length: 100\r\n\r\n"), | |
4851 MockRead(SYNCHRONOUS, OK), | |
4852 }; | |
4853 | |
4854 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
4855 data_writes1, arraysize(data_writes1)); | |
4856 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
4857 data_writes2, arraysize(data_writes2)); | |
4858 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
4859 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
4860 | |
4861 TestCompletionCallback callback1; | |
4862 | |
4863 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
4864 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4865 | |
4866 rv = callback1.WaitForResult(); | |
4867 EXPECT_EQ(OK, rv); | |
4868 | |
4869 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4870 ASSERT_TRUE(response != NULL); | |
4871 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
4872 | |
4873 TestCompletionCallback callback2; | |
4874 | |
4875 rv = trans->RestartWithAuth( | |
4876 AuthCredentials(kFoo, kBar), callback2.callback()); | |
4877 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4878 | |
4879 rv = callback2.WaitForResult(); | |
4880 EXPECT_EQ(OK, rv); | |
4881 | |
4882 response = trans->GetResponseInfo(); | |
4883 ASSERT_TRUE(response != NULL); | |
4884 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
4885 EXPECT_EQ(100, response->headers->GetContentLength()); | |
4886 } | |
4887 | |
4888 // ------------------------------------------------------------------------ | |
4889 | |
4890 // Transaction 2: authenticate (foo2, bar2) on MyRealm2 | |
4891 { | |
4892 HttpRequestInfo request; | |
4893 request.method = "GET"; | |
4894 // Note that Transaction 1 was at /x/y/z, so this is in the same | |
4895 // protection space as MyRealm1. | |
4896 request.url = GURL("http://www.google.com/x/y/a/b"); | |
4897 request.load_flags = 0; | |
4898 | |
4899 scoped_ptr<HttpTransaction> trans( | |
4900 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4901 | |
4902 MockWrite data_writes1[] = { | |
4903 MockWrite("GET /x/y/a/b HTTP/1.1\r\n" | |
4904 "Host: www.google.com\r\n" | |
4905 "Connection: keep-alive\r\n" | |
4906 // Send preemptive authorization for MyRealm1 | |
4907 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
4908 }; | |
4909 | |
4910 // The server didn't like the preemptive authorization, and | |
4911 // challenges us for a different realm (MyRealm2). | |
4912 MockRead data_reads1[] = { | |
4913 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
4914 MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), | |
4915 MockRead("Content-Length: 10000\r\n\r\n"), | |
4916 MockRead(SYNCHRONOUS, ERR_FAILED), | |
4917 }; | |
4918 | |
4919 // Resend with authorization for MyRealm2 (username=foo2, password=bar2) | |
4920 MockWrite data_writes2[] = { | |
4921 MockWrite("GET /x/y/a/b HTTP/1.1\r\n" | |
4922 "Host: www.google.com\r\n" | |
4923 "Connection: keep-alive\r\n" | |
4924 "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), | |
4925 }; | |
4926 | |
4927 // Sever accepts the authorization. | |
4928 MockRead data_reads2[] = { | |
4929 MockRead("HTTP/1.0 200 OK\r\n"), | |
4930 MockRead("Content-Length: 100\r\n\r\n"), | |
4931 MockRead(SYNCHRONOUS, OK), | |
4932 }; | |
4933 | |
4934 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
4935 data_writes1, arraysize(data_writes1)); | |
4936 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
4937 data_writes2, arraysize(data_writes2)); | |
4938 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
4939 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
4940 | |
4941 TestCompletionCallback callback1; | |
4942 | |
4943 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
4944 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4945 | |
4946 rv = callback1.WaitForResult(); | |
4947 EXPECT_EQ(OK, rv); | |
4948 | |
4949 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4950 ASSERT_TRUE(response != NULL); | |
4951 ASSERT_TRUE(response->auth_challenge.get()); | |
4952 EXPECT_FALSE(response->auth_challenge->is_proxy); | |
4953 EXPECT_EQ("www.google.com:80", | |
4954 response->auth_challenge->challenger.ToString()); | |
4955 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); | |
4956 EXPECT_EQ("basic", response->auth_challenge->scheme); | |
4957 | |
4958 TestCompletionCallback callback2; | |
4959 | |
4960 rv = trans->RestartWithAuth( | |
4961 AuthCredentials(kFoo2, kBar2), callback2.callback()); | |
4962 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4963 | |
4964 rv = callback2.WaitForResult(); | |
4965 EXPECT_EQ(OK, rv); | |
4966 | |
4967 response = trans->GetResponseInfo(); | |
4968 ASSERT_TRUE(response != NULL); | |
4969 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
4970 EXPECT_EQ(100, response->headers->GetContentLength()); | |
4971 } | |
4972 | |
4973 // ------------------------------------------------------------------------ | |
4974 | |
4975 // Transaction 3: Resend a request in MyRealm's protection space -- | |
4976 // succeed with preemptive authorization. | |
4977 { | |
4978 HttpRequestInfo request; | |
4979 request.method = "GET"; | |
4980 request.url = GURL("http://www.google.com/x/y/z2"); | |
4981 request.load_flags = 0; | |
4982 | |
4983 scoped_ptr<HttpTransaction> trans( | |
4984 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
4985 | |
4986 MockWrite data_writes1[] = { | |
4987 MockWrite("GET /x/y/z2 HTTP/1.1\r\n" | |
4988 "Host: www.google.com\r\n" | |
4989 "Connection: keep-alive\r\n" | |
4990 // The authorization for MyRealm1 gets sent preemptively | |
4991 // (since the url is in the same protection space) | |
4992 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
4993 }; | |
4994 | |
4995 // Sever accepts the preemptive authorization | |
4996 MockRead data_reads1[] = { | |
4997 MockRead("HTTP/1.0 200 OK\r\n"), | |
4998 MockRead("Content-Length: 100\r\n\r\n"), | |
4999 MockRead(SYNCHRONOUS, OK), | |
5000 }; | |
5001 | |
5002 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
5003 data_writes1, arraysize(data_writes1)); | |
5004 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
5005 | |
5006 TestCompletionCallback callback1; | |
5007 | |
5008 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
5009 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5010 | |
5011 rv = callback1.WaitForResult(); | |
5012 EXPECT_EQ(OK, rv); | |
5013 | |
5014 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5015 ASSERT_TRUE(response != NULL); | |
5016 | |
5017 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
5018 EXPECT_EQ(100, response->headers->GetContentLength()); | |
5019 } | |
5020 | |
5021 // ------------------------------------------------------------------------ | |
5022 | |
5023 // Transaction 4: request another URL in MyRealm (however the | |
5024 // url is not known to belong to the protection space, so no pre-auth). | |
5025 { | |
5026 HttpRequestInfo request; | |
5027 request.method = "GET"; | |
5028 request.url = GURL("http://www.google.com/x/1"); | |
5029 request.load_flags = 0; | |
5030 | |
5031 scoped_ptr<HttpTransaction> trans( | |
5032 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
5033 | |
5034 MockWrite data_writes1[] = { | |
5035 MockWrite("GET /x/1 HTTP/1.1\r\n" | |
5036 "Host: www.google.com\r\n" | |
5037 "Connection: keep-alive\r\n\r\n"), | |
5038 }; | |
5039 | |
5040 MockRead data_reads1[] = { | |
5041 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
5042 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
5043 MockRead("Content-Length: 10000\r\n\r\n"), | |
5044 MockRead(SYNCHRONOUS, ERR_FAILED), | |
5045 }; | |
5046 | |
5047 // Resend with authorization from MyRealm's cache. | |
5048 MockWrite data_writes2[] = { | |
5049 MockWrite("GET /x/1 HTTP/1.1\r\n" | |
5050 "Host: www.google.com\r\n" | |
5051 "Connection: keep-alive\r\n" | |
5052 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
5053 }; | |
5054 | |
5055 // Sever accepts the authorization. | |
5056 MockRead data_reads2[] = { | |
5057 MockRead("HTTP/1.0 200 OK\r\n"), | |
5058 MockRead("Content-Length: 100\r\n\r\n"), | |
5059 MockRead(SYNCHRONOUS, OK), | |
5060 }; | |
5061 | |
5062 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
5063 data_writes1, arraysize(data_writes1)); | |
5064 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
5065 data_writes2, arraysize(data_writes2)); | |
5066 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
5067 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
5068 | |
5069 TestCompletionCallback callback1; | |
5070 | |
5071 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
5072 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5073 | |
5074 rv = callback1.WaitForResult(); | |
5075 EXPECT_EQ(OK, rv); | |
5076 | |
5077 EXPECT_TRUE(trans->IsReadyToRestartForAuth()); | |
5078 TestCompletionCallback callback2; | |
5079 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); | |
5080 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5081 rv = callback2.WaitForResult(); | |
5082 EXPECT_EQ(OK, rv); | |
5083 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
5084 | |
5085 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5086 ASSERT_TRUE(response != NULL); | |
5087 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
5088 EXPECT_EQ(100, response->headers->GetContentLength()); | |
5089 } | |
5090 | |
5091 // ------------------------------------------------------------------------ | |
5092 | |
5093 // Transaction 5: request a URL in MyRealm, but the server rejects the | |
5094 // cached identity. Should invalidate and re-prompt. | |
5095 { | |
5096 HttpRequestInfo request; | |
5097 request.method = "GET"; | |
5098 request.url = GURL("http://www.google.com/p/q/t"); | |
5099 request.load_flags = 0; | |
5100 | |
5101 scoped_ptr<HttpTransaction> trans( | |
5102 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
5103 | |
5104 MockWrite data_writes1[] = { | |
5105 MockWrite("GET /p/q/t HTTP/1.1\r\n" | |
5106 "Host: www.google.com\r\n" | |
5107 "Connection: keep-alive\r\n\r\n"), | |
5108 }; | |
5109 | |
5110 MockRead data_reads1[] = { | |
5111 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
5112 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
5113 MockRead("Content-Length: 10000\r\n\r\n"), | |
5114 MockRead(SYNCHRONOUS, ERR_FAILED), | |
5115 }; | |
5116 | |
5117 // Resend with authorization from cache for MyRealm. | |
5118 MockWrite data_writes2[] = { | |
5119 MockWrite("GET /p/q/t HTTP/1.1\r\n" | |
5120 "Host: www.google.com\r\n" | |
5121 "Connection: keep-alive\r\n" | |
5122 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
5123 }; | |
5124 | |
5125 // Sever rejects the authorization. | |
5126 MockRead data_reads2[] = { | |
5127 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
5128 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
5129 MockRead("Content-Length: 10000\r\n\r\n"), | |
5130 MockRead(SYNCHRONOUS, ERR_FAILED), | |
5131 }; | |
5132 | |
5133 // At this point we should prompt for new credentials for MyRealm. | |
5134 // Restart with username=foo3, password=foo4. | |
5135 MockWrite data_writes3[] = { | |
5136 MockWrite("GET /p/q/t HTTP/1.1\r\n" | |
5137 "Host: www.google.com\r\n" | |
5138 "Connection: keep-alive\r\n" | |
5139 "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), | |
5140 }; | |
5141 | |
5142 // Sever accepts the authorization. | |
5143 MockRead data_reads3[] = { | |
5144 MockRead("HTTP/1.0 200 OK\r\n"), | |
5145 MockRead("Content-Length: 100\r\n\r\n"), | |
5146 MockRead(SYNCHRONOUS, OK), | |
5147 }; | |
5148 | |
5149 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
5150 data_writes1, arraysize(data_writes1)); | |
5151 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
5152 data_writes2, arraysize(data_writes2)); | |
5153 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), | |
5154 data_writes3, arraysize(data_writes3)); | |
5155 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
5156 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
5157 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
5158 | |
5159 TestCompletionCallback callback1; | |
5160 | |
5161 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
5162 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5163 | |
5164 rv = callback1.WaitForResult(); | |
5165 EXPECT_EQ(OK, rv); | |
5166 | |
5167 EXPECT_TRUE(trans->IsReadyToRestartForAuth()); | |
5168 TestCompletionCallback callback2; | |
5169 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); | |
5170 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5171 rv = callback2.WaitForResult(); | |
5172 EXPECT_EQ(OK, rv); | |
5173 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); | |
5174 | |
5175 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5176 ASSERT_TRUE(response != NULL); | |
5177 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
5178 | |
5179 TestCompletionCallback callback3; | |
5180 | |
5181 rv = trans->RestartWithAuth( | |
5182 AuthCredentials(kFoo3, kBar3), callback3.callback()); | |
5183 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5184 | |
5185 rv = callback3.WaitForResult(); | |
5186 EXPECT_EQ(OK, rv); | |
5187 | |
5188 response = trans->GetResponseInfo(); | |
5189 ASSERT_TRUE(response != NULL); | |
5190 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
5191 EXPECT_EQ(100, response->headers->GetContentLength()); | |
5192 } | |
5193 } | |
5194 | |
5195 // Tests that nonce count increments when multiple auth attempts | |
5196 // are started with the same nonce. | |
5197 TEST_F(HttpNetworkTransactionSpdy3Test, DigestPreAuthNonceCount) { | |
5198 HttpAuthHandlerDigest::Factory* digest_factory = | |
5199 new HttpAuthHandlerDigest::Factory(); | |
5200 HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = | |
5201 new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); | |
5202 digest_factory->set_nonce_generator(nonce_generator); | |
5203 session_deps_.http_auth_handler_factory.reset(digest_factory); | |
5204 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
5205 | |
5206 // Transaction 1: authenticate (foo, bar) on MyRealm1 | |
5207 { | |
5208 HttpRequestInfo request; | |
5209 request.method = "GET"; | |
5210 request.url = GURL("http://www.google.com/x/y/z"); | |
5211 request.load_flags = 0; | |
5212 | |
5213 scoped_ptr<HttpTransaction> trans( | |
5214 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
5215 | |
5216 MockWrite data_writes1[] = { | |
5217 MockWrite("GET /x/y/z HTTP/1.1\r\n" | |
5218 "Host: www.google.com\r\n" | |
5219 "Connection: keep-alive\r\n\r\n"), | |
5220 }; | |
5221 | |
5222 MockRead data_reads1[] = { | |
5223 MockRead("HTTP/1.0 401 Unauthorized\r\n"), | |
5224 MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " | |
5225 "algorithm=MD5, qop=\"auth\"\r\n\r\n"), | |
5226 MockRead(SYNCHRONOUS, OK), | |
5227 }; | |
5228 | |
5229 // Resend with authorization (username=foo, password=bar) | |
5230 MockWrite data_writes2[] = { | |
5231 MockWrite("GET /x/y/z HTTP/1.1\r\n" | |
5232 "Host: www.google.com\r\n" | |
5233 "Connection: keep-alive\r\n" | |
5234 "Authorization: Digest username=\"foo\", realm=\"digestive\", " | |
5235 "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " | |
5236 "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " | |
5237 "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), | |
5238 }; | |
5239 | |
5240 // Sever accepts the authorization. | |
5241 MockRead data_reads2[] = { | |
5242 MockRead("HTTP/1.0 200 OK\r\n"), | |
5243 MockRead(SYNCHRONOUS, OK), | |
5244 }; | |
5245 | |
5246 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
5247 data_writes1, arraysize(data_writes1)); | |
5248 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
5249 data_writes2, arraysize(data_writes2)); | |
5250 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
5251 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
5252 | |
5253 TestCompletionCallback callback1; | |
5254 | |
5255 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
5256 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5257 | |
5258 rv = callback1.WaitForResult(); | |
5259 EXPECT_EQ(OK, rv); | |
5260 | |
5261 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5262 ASSERT_TRUE(response != NULL); | |
5263 EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); | |
5264 | |
5265 TestCompletionCallback callback2; | |
5266 | |
5267 rv = trans->RestartWithAuth( | |
5268 AuthCredentials(kFoo, kBar), callback2.callback()); | |
5269 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5270 | |
5271 rv = callback2.WaitForResult(); | |
5272 EXPECT_EQ(OK, rv); | |
5273 | |
5274 response = trans->GetResponseInfo(); | |
5275 ASSERT_TRUE(response != NULL); | |
5276 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
5277 } | |
5278 | |
5279 // ------------------------------------------------------------------------ | |
5280 | |
5281 // Transaction 2: Request another resource in digestive's protection space. | |
5282 // This will preemptively add an Authorization header which should have an | |
5283 // "nc" value of 2 (as compared to 1 in the first use. | |
5284 { | |
5285 HttpRequestInfo request; | |
5286 request.method = "GET"; | |
5287 // Note that Transaction 1 was at /x/y/z, so this is in the same | |
5288 // protection space as digest. | |
5289 request.url = GURL("http://www.google.com/x/y/a/b"); | |
5290 request.load_flags = 0; | |
5291 | |
5292 scoped_ptr<HttpTransaction> trans( | |
5293 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
5294 | |
5295 MockWrite data_writes1[] = { | |
5296 MockWrite("GET /x/y/a/b HTTP/1.1\r\n" | |
5297 "Host: www.google.com\r\n" | |
5298 "Connection: keep-alive\r\n" | |
5299 "Authorization: Digest username=\"foo\", realm=\"digestive\", " | |
5300 "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " | |
5301 "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " | |
5302 "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), | |
5303 }; | |
5304 | |
5305 // Sever accepts the authorization. | |
5306 MockRead data_reads1[] = { | |
5307 MockRead("HTTP/1.0 200 OK\r\n"), | |
5308 MockRead("Content-Length: 100\r\n\r\n"), | |
5309 MockRead(SYNCHRONOUS, OK), | |
5310 }; | |
5311 | |
5312 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
5313 data_writes1, arraysize(data_writes1)); | |
5314 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
5315 | |
5316 TestCompletionCallback callback1; | |
5317 | |
5318 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
5319 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5320 | |
5321 rv = callback1.WaitForResult(); | |
5322 EXPECT_EQ(OK, rv); | |
5323 | |
5324 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5325 ASSERT_TRUE(response != NULL); | |
5326 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
5327 } | |
5328 } | |
5329 | |
5330 // Test the ResetStateForRestart() private method. | |
5331 TEST_F(HttpNetworkTransactionSpdy3Test, ResetStateForRestart) { | |
5332 // Create a transaction (the dependencies aren't important). | |
5333 scoped_ptr<HttpNetworkTransaction> trans( | |
5334 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5335 CreateSession(&session_deps_))); | |
5336 | |
5337 // Setup some state (which we expect ResetStateForRestart() will clear). | |
5338 trans->read_buf_ = new IOBuffer(15); | |
5339 trans->read_buf_len_ = 15; | |
5340 trans->request_headers_.SetHeader("Authorization", "NTLM"); | |
5341 | |
5342 // Setup state in response_ | |
5343 HttpResponseInfo* response = &trans->response_; | |
5344 response->auth_challenge = new AuthChallengeInfo(); | |
5345 response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. | |
5346 response->response_time = base::Time::Now(); | |
5347 response->was_cached = true; // (Wouldn't ever actually be true...) | |
5348 | |
5349 { // Setup state for response_.vary_data | |
5350 HttpRequestInfo request; | |
5351 std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); | |
5352 std::replace(temp.begin(), temp.end(), '\n', '\0'); | |
5353 scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); | |
5354 request.extra_headers.SetHeader("Foo", "1"); | |
5355 request.extra_headers.SetHeader("bar", "23"); | |
5356 EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); | |
5357 } | |
5358 | |
5359 // Cause the above state to be reset. | |
5360 trans->ResetStateForRestart(); | |
5361 | |
5362 // Verify that the state that needed to be reset, has been reset. | |
5363 EXPECT_TRUE(trans->read_buf_.get() == NULL); | |
5364 EXPECT_EQ(0, trans->read_buf_len_); | |
5365 EXPECT_TRUE(trans->request_headers_.IsEmpty()); | |
5366 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
5367 EXPECT_TRUE(response->headers.get() == NULL); | |
5368 EXPECT_FALSE(response->was_cached); | |
5369 EXPECT_EQ(0U, response->ssl_info.cert_status); | |
5370 EXPECT_FALSE(response->vary_data.is_valid()); | |
5371 } | |
5372 | |
5373 // Test HTTPS connections to a site with a bad certificate | |
5374 TEST_F(HttpNetworkTransactionSpdy3Test, HTTPSBadCertificate) { | |
5375 HttpRequestInfo request; | |
5376 request.method = "GET"; | |
5377 request.url = GURL("https://www.google.com/"); | |
5378 request.load_flags = 0; | |
5379 | |
5380 scoped_ptr<HttpTransaction> trans( | |
5381 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5382 CreateSession(&session_deps_))); | |
5383 | |
5384 MockWrite data_writes[] = { | |
5385 MockWrite("GET / HTTP/1.1\r\n" | |
5386 "Host: www.google.com\r\n" | |
5387 "Connection: keep-alive\r\n\r\n"), | |
5388 }; | |
5389 | |
5390 MockRead data_reads[] = { | |
5391 MockRead("HTTP/1.0 200 OK\r\n"), | |
5392 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
5393 MockRead("Content-Length: 100\r\n\r\n"), | |
5394 MockRead(SYNCHRONOUS, OK), | |
5395 }; | |
5396 | |
5397 StaticSocketDataProvider ssl_bad_certificate; | |
5398 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
5399 data_writes, arraysize(data_writes)); | |
5400 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); | |
5401 SSLSocketDataProvider ssl(ASYNC, OK); | |
5402 | |
5403 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); | |
5404 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
5405 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); | |
5406 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
5407 | |
5408 TestCompletionCallback callback; | |
5409 | |
5410 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
5411 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5412 | |
5413 rv = callback.WaitForResult(); | |
5414 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); | |
5415 | |
5416 rv = trans->RestartIgnoringLastError(callback.callback()); | |
5417 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5418 | |
5419 rv = callback.WaitForResult(); | |
5420 EXPECT_EQ(OK, rv); | |
5421 | |
5422 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5423 | |
5424 ASSERT_TRUE(response != NULL); | |
5425 EXPECT_EQ(100, response->headers->GetContentLength()); | |
5426 } | |
5427 | |
5428 // Test HTTPS connections to a site with a bad certificate, going through a | |
5429 // proxy | |
5430 TEST_F(HttpNetworkTransactionSpdy3Test, HTTPSBadCertificateViaProxy) { | |
5431 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
5432 | |
5433 HttpRequestInfo request; | |
5434 request.method = "GET"; | |
5435 request.url = GURL("https://www.google.com/"); | |
5436 request.load_flags = 0; | |
5437 | |
5438 MockWrite proxy_writes[] = { | |
5439 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
5440 "Host: www.google.com\r\n" | |
5441 "Proxy-Connection: keep-alive\r\n\r\n"), | |
5442 }; | |
5443 | |
5444 MockRead proxy_reads[] = { | |
5445 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), | |
5446 MockRead(SYNCHRONOUS, OK) | |
5447 }; | |
5448 | |
5449 MockWrite data_writes[] = { | |
5450 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
5451 "Host: www.google.com\r\n" | |
5452 "Proxy-Connection: keep-alive\r\n\r\n"), | |
5453 MockWrite("GET / HTTP/1.1\r\n" | |
5454 "Host: www.google.com\r\n" | |
5455 "Connection: keep-alive\r\n\r\n"), | |
5456 }; | |
5457 | |
5458 MockRead data_reads[] = { | |
5459 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), | |
5460 MockRead("HTTP/1.0 200 OK\r\n"), | |
5461 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
5462 MockRead("Content-Length: 100\r\n\r\n"), | |
5463 MockRead(SYNCHRONOUS, OK), | |
5464 }; | |
5465 | |
5466 StaticSocketDataProvider ssl_bad_certificate( | |
5467 proxy_reads, arraysize(proxy_reads), | |
5468 proxy_writes, arraysize(proxy_writes)); | |
5469 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
5470 data_writes, arraysize(data_writes)); | |
5471 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); | |
5472 SSLSocketDataProvider ssl(ASYNC, OK); | |
5473 | |
5474 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); | |
5475 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
5476 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); | |
5477 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
5478 | |
5479 TestCompletionCallback callback; | |
5480 | |
5481 for (int i = 0; i < 2; i++) { | |
5482 session_deps_.socket_factory->ResetNextMockIndexes(); | |
5483 | |
5484 scoped_ptr<HttpNetworkTransaction> trans( | |
5485 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5486 CreateSession(&session_deps_))); | |
5487 | |
5488 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
5489 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5490 | |
5491 rv = callback.WaitForResult(); | |
5492 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); | |
5493 | |
5494 rv = trans->RestartIgnoringLastError(callback.callback()); | |
5495 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5496 | |
5497 rv = callback.WaitForResult(); | |
5498 EXPECT_EQ(OK, rv); | |
5499 | |
5500 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5501 | |
5502 ASSERT_TRUE(response != NULL); | |
5503 EXPECT_EQ(100, response->headers->GetContentLength()); | |
5504 } | |
5505 } | |
5506 | |
5507 | |
5508 // Test HTTPS connections to a site, going through an HTTPS proxy | |
5509 TEST_F(HttpNetworkTransactionSpdy3Test, HTTPSViaHttpsProxy) { | |
5510 session_deps_.proxy_service.reset( | |
5511 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); | |
5512 CapturingNetLog net_log; | |
5513 session_deps_.net_log = &net_log; | |
5514 | |
5515 HttpRequestInfo request; | |
5516 request.method = "GET"; | |
5517 request.url = GURL("https://www.google.com/"); | |
5518 request.load_flags = 0; | |
5519 | |
5520 MockWrite data_writes[] = { | |
5521 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
5522 "Host: www.google.com\r\n" | |
5523 "Proxy-Connection: keep-alive\r\n\r\n"), | |
5524 MockWrite("GET / HTTP/1.1\r\n" | |
5525 "Host: www.google.com\r\n" | |
5526 "Connection: keep-alive\r\n\r\n"), | |
5527 }; | |
5528 | |
5529 MockRead data_reads[] = { | |
5530 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), | |
5531 MockRead("HTTP/1.1 200 OK\r\n"), | |
5532 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
5533 MockRead("Content-Length: 100\r\n\r\n"), | |
5534 MockRead(SYNCHRONOUS, OK), | |
5535 }; | |
5536 | |
5537 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
5538 data_writes, arraysize(data_writes)); | |
5539 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy | |
5540 SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel | |
5541 | |
5542 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
5543 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); | |
5544 session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); | |
5545 | |
5546 TestCompletionCallback callback; | |
5547 | |
5548 scoped_ptr<HttpTransaction> trans( | |
5549 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5550 CreateSession(&session_deps_))); | |
5551 | |
5552 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
5553 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5554 | |
5555 rv = callback.WaitForResult(); | |
5556 EXPECT_EQ(OK, rv); | |
5557 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5558 | |
5559 ASSERT_TRUE(response != NULL); | |
5560 | |
5561 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
5562 EXPECT_EQ(200, response->headers->response_code()); | |
5563 EXPECT_EQ(100, response->headers->GetContentLength()); | |
5564 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
5565 | |
5566 LoadTimingInfo load_timing_info; | |
5567 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
5568 TestLoadTimingNotReusedWithPac(load_timing_info, | |
5569 CONNECT_TIMING_HAS_SSL_TIMES); | |
5570 } | |
5571 | |
5572 // Test an HTTPS Proxy's ability to redirect a CONNECT request | |
5573 TEST_F(HttpNetworkTransactionSpdy3Test, RedirectOfHttpsConnectViaHttpsProxy) { | |
5574 session_deps_.proxy_service.reset( | |
5575 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); | |
5576 CapturingNetLog net_log; | |
5577 session_deps_.net_log = &net_log; | |
5578 | |
5579 HttpRequestInfo request; | |
5580 request.method = "GET"; | |
5581 request.url = GURL("https://www.google.com/"); | |
5582 request.load_flags = 0; | |
5583 | |
5584 MockWrite data_writes[] = { | |
5585 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
5586 "Host: www.google.com\r\n" | |
5587 "Proxy-Connection: keep-alive\r\n\r\n"), | |
5588 }; | |
5589 | |
5590 MockRead data_reads[] = { | |
5591 MockRead("HTTP/1.1 302 Redirect\r\n"), | |
5592 MockRead("Location: http://login.example.com/\r\n"), | |
5593 MockRead("Content-Length: 0\r\n\r\n"), | |
5594 MockRead(SYNCHRONOUS, OK), | |
5595 }; | |
5596 | |
5597 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
5598 data_writes, arraysize(data_writes)); | |
5599 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy | |
5600 | |
5601 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
5602 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); | |
5603 | |
5604 TestCompletionCallback callback; | |
5605 | |
5606 scoped_ptr<HttpTransaction> trans( | |
5607 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5608 CreateSession(&session_deps_))); | |
5609 | |
5610 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
5611 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5612 | |
5613 rv = callback.WaitForResult(); | |
5614 EXPECT_EQ(OK, rv); | |
5615 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5616 | |
5617 ASSERT_TRUE(response != NULL); | |
5618 | |
5619 EXPECT_EQ(302, response->headers->response_code()); | |
5620 std::string url; | |
5621 EXPECT_TRUE(response->headers->IsRedirect(&url)); | |
5622 EXPECT_EQ("http://login.example.com/", url); | |
5623 | |
5624 // In the case of redirects from proxies, HttpNetworkTransaction returns | |
5625 // timing for the proxy connection instead of the connection to the host, | |
5626 // and no send / receive times. | |
5627 // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. | |
5628 LoadTimingInfo load_timing_info; | |
5629 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
5630 | |
5631 EXPECT_FALSE(load_timing_info.socket_reused); | |
5632 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
5633 | |
5634 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); | |
5635 EXPECT_LE(load_timing_info.proxy_resolve_start, | |
5636 load_timing_info.proxy_resolve_end); | |
5637 EXPECT_LE(load_timing_info.proxy_resolve_end, | |
5638 load_timing_info.connect_timing.connect_start); | |
5639 ExpectConnectTimingHasTimes( | |
5640 load_timing_info.connect_timing, | |
5641 CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); | |
5642 | |
5643 EXPECT_TRUE(load_timing_info.send_start.is_null()); | |
5644 EXPECT_TRUE(load_timing_info.send_end.is_null()); | |
5645 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
5646 } | |
5647 | |
5648 // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request | |
5649 TEST_F(HttpNetworkTransactionSpdy3Test, RedirectOfHttpsConnectViaSpdyProxy) { | |
5650 session_deps_.proxy_service.reset( | |
5651 ProxyService::CreateFixed("https://proxy:70")); | |
5652 | |
5653 HttpRequestInfo request; | |
5654 request.method = "GET"; | |
5655 request.url = GURL("https://www.google.com/"); | |
5656 request.load_flags = 0; | |
5657 | |
5658 scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
5659 scoped_ptr<SpdyFrame> goaway( | |
5660 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | |
5661 MockWrite data_writes[] = { | |
5662 CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), | |
5663 }; | |
5664 | |
5665 static const char* const kExtraHeaders[] = { | |
5666 "location", | |
5667 "http://login.example.com/", | |
5668 }; | |
5669 scoped_ptr<SpdyFrame> resp( | |
5670 ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, | |
5671 arraysize(kExtraHeaders)/2, 1)); | |
5672 MockRead data_reads[] = { | |
5673 CreateMockRead(*resp.get(), 1, SYNCHRONOUS), | |
5674 MockRead(ASYNC, 0, 2), // EOF | |
5675 }; | |
5676 | |
5677 DelayedSocketData data( | |
5678 1, // wait for one write to finish before reading. | |
5679 data_reads, arraysize(data_reads), | |
5680 data_writes, arraysize(data_writes)); | |
5681 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy | |
5682 proxy_ssl.SetNextProto(kProtoSPDY3); | |
5683 | |
5684 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
5685 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); | |
5686 | |
5687 TestCompletionCallback callback; | |
5688 | |
5689 scoped_ptr<HttpTransaction> trans( | |
5690 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5691 CreateSession(&session_deps_))); | |
5692 | |
5693 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
5694 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5695 | |
5696 rv = callback.WaitForResult(); | |
5697 EXPECT_EQ(OK, rv); | |
5698 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5699 | |
5700 ASSERT_TRUE(response != NULL); | |
5701 | |
5702 EXPECT_EQ(302, response->headers->response_code()); | |
5703 std::string url; | |
5704 EXPECT_TRUE(response->headers->IsRedirect(&url)); | |
5705 EXPECT_EQ("http://login.example.com/", url); | |
5706 } | |
5707 | |
5708 // Test that an HTTPS proxy's response to a CONNECT request is filtered. | |
5709 TEST_F(HttpNetworkTransactionSpdy3Test, | |
5710 ErrorResponseToHttpsConnectViaHttpsProxy) { | |
5711 session_deps_.proxy_service.reset( | |
5712 ProxyService::CreateFixed("https://proxy:70")); | |
5713 | |
5714 HttpRequestInfo request; | |
5715 request.method = "GET"; | |
5716 request.url = GURL("https://www.google.com/"); | |
5717 request.load_flags = 0; | |
5718 | |
5719 MockWrite data_writes[] = { | |
5720 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
5721 "Host: www.google.com\r\n" | |
5722 "Proxy-Connection: keep-alive\r\n\r\n"), | |
5723 }; | |
5724 | |
5725 MockRead data_reads[] = { | |
5726 MockRead("HTTP/1.1 404 Not Found\r\n"), | |
5727 MockRead("Content-Length: 23\r\n\r\n"), | |
5728 MockRead("The host does not exist"), | |
5729 MockRead(SYNCHRONOUS, OK), | |
5730 }; | |
5731 | |
5732 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
5733 data_writes, arraysize(data_writes)); | |
5734 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy | |
5735 | |
5736 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
5737 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); | |
5738 | |
5739 TestCompletionCallback callback; | |
5740 | |
5741 scoped_ptr<HttpTransaction> trans( | |
5742 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5743 CreateSession(&session_deps_))); | |
5744 | |
5745 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
5746 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5747 | |
5748 rv = callback.WaitForResult(); | |
5749 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
5750 | |
5751 // TODO(ttuttle): Anything else to check here? | |
5752 } | |
5753 | |
5754 // Test that a SPDY proxy's response to a CONNECT request is filtered. | |
5755 TEST_F(HttpNetworkTransactionSpdy3Test, | |
5756 ErrorResponseToHttpsConnectViaSpdyProxy) { | |
5757 session_deps_.proxy_service.reset( | |
5758 ProxyService::CreateFixed("https://proxy:70")); | |
5759 | |
5760 HttpRequestInfo request; | |
5761 request.method = "GET"; | |
5762 request.url = GURL("https://www.google.com/"); | |
5763 request.load_flags = 0; | |
5764 | |
5765 scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
5766 scoped_ptr<SpdyFrame> rst( | |
5767 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | |
5768 MockWrite data_writes[] = { | |
5769 CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), | |
5770 CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), | |
5771 }; | |
5772 | |
5773 static const char* const kExtraHeaders[] = { | |
5774 "location", | |
5775 "http://login.example.com/", | |
5776 }; | |
5777 scoped_ptr<SpdyFrame> resp( | |
5778 ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, | |
5779 arraysize(kExtraHeaders)/2, 1)); | |
5780 scoped_ptr<SpdyFrame> body( | |
5781 ConstructSpdyBodyFrame(1, "The host does not exist", 23, true)); | |
5782 MockRead data_reads[] = { | |
5783 CreateMockRead(*resp.get(), 1, SYNCHRONOUS), | |
5784 CreateMockRead(*body.get(), 2, SYNCHRONOUS), | |
5785 MockRead(ASYNC, 0, 4), // EOF | |
5786 }; | |
5787 | |
5788 DelayedSocketData data( | |
5789 1, // wait for one write to finish before reading. | |
5790 data_reads, arraysize(data_reads), | |
5791 data_writes, arraysize(data_writes)); | |
5792 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy | |
5793 proxy_ssl.SetNextProto(kProtoSPDY3); | |
5794 | |
5795 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
5796 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); | |
5797 | |
5798 TestCompletionCallback callback; | |
5799 | |
5800 scoped_ptr<HttpTransaction> trans( | |
5801 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
5802 CreateSession(&session_deps_))); | |
5803 | |
5804 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
5805 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5806 | |
5807 rv = callback.WaitForResult(); | |
5808 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
5809 | |
5810 // TODO(ttuttle): Anything else to check here? | |
5811 } | |
5812 | |
5813 // Test the request-challenge-retry sequence for basic auth, through | |
5814 // a SPDY proxy over a single SPDY session. | |
5815 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthSpdyProxy) { | |
5816 HttpRequestInfo request; | |
5817 request.method = "GET"; | |
5818 request.url = GURL("https://www.google.com/"); | |
5819 // when the no authentication data flag is set. | |
5820 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; | |
5821 | |
5822 // Configure against https proxy server "myproxy:70". | |
5823 session_deps_.proxy_service.reset( | |
5824 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); | |
5825 CapturingBoundNetLog log; | |
5826 session_deps_.net_log = log.bound().net_log(); | |
5827 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
5828 | |
5829 // Since we have proxy, should try to establish tunnel. | |
5830 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
5831 scoped_ptr<SpdyFrame> rst( | |
5832 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | |
5833 | |
5834 // After calling trans->RestartWithAuth(), this is the request we should | |
5835 // be issuing -- the final header line contains the credentials. | |
5836 const char* const kAuthCredentials[] = { | |
5837 "proxy-authorization", "Basic Zm9vOmJhcg==", | |
5838 }; | |
5839 scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( | |
5840 kAuthCredentials, arraysize(kAuthCredentials) / 2, 3)); | |
5841 // fetch https://www.google.com/ via HTTP | |
5842 const char get[] = "GET / HTTP/1.1\r\n" | |
5843 "Host: www.google.com\r\n" | |
5844 "Connection: keep-alive\r\n\r\n"; | |
5845 scoped_ptr<SpdyFrame> wrapped_get( | |
5846 ConstructSpdyBodyFrame(3, get, strlen(get), false)); | |
5847 | |
5848 MockWrite spdy_writes[] = { | |
5849 CreateMockWrite(*req, 1, ASYNC), | |
5850 CreateMockWrite(*rst, 4, ASYNC), | |
5851 CreateMockWrite(*connect2, 5), | |
5852 CreateMockWrite(*wrapped_get, 8), | |
5853 }; | |
5854 | |
5855 // The proxy responds to the connect with a 407, using a persistent | |
5856 // connection. | |
5857 const char* const kAuthChallenge[] = { | |
5858 ":status", "407 Proxy Authentication Required", | |
5859 ":version", "HTTP/1.1", | |
5860 "proxy-authenticate", "Basic realm=\"MyRealm1\"", | |
5861 }; | |
5862 | |
5863 scoped_ptr<SpdyFrame> conn_auth_resp( | |
5864 spdy_util_.ConstructSpdyControlFrame(NULL, | |
5865 0, | |
5866 false, | |
5867 1, | |
5868 LOWEST, | |
5869 SYN_REPLY, | |
5870 CONTROL_FLAG_NONE, | |
5871 kAuthChallenge, | |
5872 arraysize(kAuthChallenge), | |
5873 0)); | |
5874 | |
5875 scoped_ptr<SpdyFrame> conn_resp(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
5876 const char resp[] = "HTTP/1.1 200 OK\r\n" | |
5877 "Content-Length: 5\r\n\r\n"; | |
5878 | |
5879 scoped_ptr<SpdyFrame> wrapped_get_resp( | |
5880 ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); | |
5881 scoped_ptr<SpdyFrame> wrapped_body( | |
5882 ConstructSpdyBodyFrame(3, "hello", 5, false)); | |
5883 MockRead spdy_reads[] = { | |
5884 CreateMockRead(*conn_auth_resp, 2, ASYNC), | |
5885 CreateMockRead(*conn_resp, 6, ASYNC), | |
5886 CreateMockRead(*wrapped_get_resp, 9, ASYNC), | |
5887 CreateMockRead(*wrapped_body, 10, ASYNC), | |
5888 MockRead(SYNCHRONOUS, ERR_IO_PENDING), // EOF. May or may not be read. | |
5889 }; | |
5890 | |
5891 OrderedSocketData spdy_data( | |
5892 spdy_reads, arraysize(spdy_reads), | |
5893 spdy_writes, arraysize(spdy_writes)); | |
5894 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
5895 // Negotiate SPDY to the proxy | |
5896 SSLSocketDataProvider proxy(ASYNC, OK); | |
5897 proxy.SetNextProto(kProtoSPDY3); | |
5898 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); | |
5899 // Vanilla SSL to the server | |
5900 SSLSocketDataProvider server(ASYNC, OK); | |
5901 session_deps_.socket_factory->AddSSLSocketDataProvider(&server); | |
5902 | |
5903 TestCompletionCallback callback1; | |
5904 | |
5905 scoped_ptr<HttpTransaction> trans( | |
5906 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
5907 | |
5908 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
5909 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5910 | |
5911 rv = callback1.WaitForResult(); | |
5912 EXPECT_EQ(OK, rv); | |
5913 CapturingNetLog::CapturedEntryList entries; | |
5914 log.GetEntries(&entries); | |
5915 size_t pos = ExpectLogContainsSomewhere( | |
5916 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | |
5917 NetLog::PHASE_NONE); | |
5918 ExpectLogContainsSomewhere( | |
5919 entries, pos, | |
5920 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | |
5921 NetLog::PHASE_NONE); | |
5922 | |
5923 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
5924 ASSERT_TRUE(response != NULL); | |
5925 ASSERT_FALSE(response->headers.get() == NULL); | |
5926 EXPECT_EQ(407, response->headers->response_code()); | |
5927 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
5928 EXPECT_TRUE(response->auth_challenge.get() != NULL); | |
5929 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | |
5930 | |
5931 TestCompletionCallback callback2; | |
5932 | |
5933 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), | |
5934 callback2.callback()); | |
5935 EXPECT_EQ(ERR_IO_PENDING, rv); | |
5936 | |
5937 rv = callback2.WaitForResult(); | |
5938 EXPECT_EQ(OK, rv); | |
5939 | |
5940 response = trans->GetResponseInfo(); | |
5941 ASSERT_TRUE(response != NULL); | |
5942 | |
5943 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
5944 EXPECT_EQ(200, response->headers->response_code()); | |
5945 EXPECT_EQ(5, response->headers->GetContentLength()); | |
5946 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
5947 | |
5948 // The password prompt info should not be set. | |
5949 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
5950 | |
5951 LoadTimingInfo load_timing_info; | |
5952 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
5953 TestLoadTimingNotReusedWithPac(load_timing_info, | |
5954 CONNECT_TIMING_HAS_SSL_TIMES); | |
5955 | |
5956 trans.reset(); | |
5957 session->CloseAllConnections(); | |
5958 } | |
5959 | |
5960 // Test that an explicitly trusted SPDY proxy can push a resource from an | |
5961 // origin that is different from that of its associated resource. | |
5962 TEST_F(HttpNetworkTransactionSpdy3Test, CrossOriginProxyPush) { | |
5963 HttpRequestInfo request; | |
5964 HttpRequestInfo push_request; | |
5965 | |
5966 static const unsigned char kPushBodyFrame[] = { | |
5967 0x00, 0x00, 0x00, 0x02, // header, ID | |
5968 0x01, 0x00, 0x00, 0x06, // FIN, length | |
5969 'p', 'u', 's', 'h', 'e', 'd' // "pushed" | |
5970 }; | |
5971 | |
5972 request.method = "GET"; | |
5973 request.url = GURL("http://www.google.com/"); | |
5974 push_request.method = "GET"; | |
5975 push_request.url = GURL("http://www.another-origin.com/foo.dat"); | |
5976 | |
5977 // Configure against https proxy server "myproxy:70". | |
5978 session_deps_.proxy_service.reset( | |
5979 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); | |
5980 CapturingBoundNetLog log; | |
5981 session_deps_.net_log = log.bound().net_log(); | |
5982 | |
5983 // Enable cross-origin push. | |
5984 session_deps_.trusted_spdy_proxy = "myproxy:70"; | |
5985 | |
5986 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
5987 | |
5988 scoped_ptr<SpdyFrame> stream1_syn( | |
5989 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); | |
5990 | |
5991 MockWrite spdy_writes[] = { | |
5992 CreateMockWrite(*stream1_syn, 1, ASYNC), | |
5993 }; | |
5994 | |
5995 scoped_ptr<SpdyFrame> | |
5996 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
5997 | |
5998 scoped_ptr<SpdyFrame> | |
5999 stream1_body(ConstructSpdyBodyFrame(1, true)); | |
6000 | |
6001 scoped_ptr<SpdyFrame> | |
6002 stream2_syn(ConstructSpdyPush(NULL, | |
6003 0, | |
6004 2, | |
6005 1, | |
6006 "http://www.another-origin.com/foo.dat")); | |
6007 | |
6008 MockRead spdy_reads[] = { | |
6009 CreateMockRead(*stream1_reply, 2, ASYNC), | |
6010 CreateMockRead(*stream2_syn, 3, ASYNC), | |
6011 CreateMockRead(*stream1_body, 4, ASYNC), | |
6012 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), | |
6013 arraysize(kPushBodyFrame), 5), | |
6014 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause | |
6015 }; | |
6016 | |
6017 OrderedSocketData spdy_data( | |
6018 spdy_reads, arraysize(spdy_reads), | |
6019 spdy_writes, arraysize(spdy_writes)); | |
6020 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
6021 // Negotiate SPDY to the proxy | |
6022 SSLSocketDataProvider proxy(ASYNC, OK); | |
6023 proxy.SetNextProto(kProtoSPDY3); | |
6024 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); | |
6025 | |
6026 scoped_ptr<HttpTransaction> trans( | |
6027 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
6028 TestCompletionCallback callback; | |
6029 int rv = trans->Start(&request, callback.callback(), log.bound()); | |
6030 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6031 | |
6032 rv = callback.WaitForResult(); | |
6033 EXPECT_EQ(OK, rv); | |
6034 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6035 | |
6036 scoped_ptr<HttpTransaction> push_trans( | |
6037 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
6038 rv = push_trans->Start(&push_request, callback.callback(), log.bound()); | |
6039 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6040 | |
6041 rv = callback.WaitForResult(); | |
6042 EXPECT_EQ(OK, rv); | |
6043 const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); | |
6044 | |
6045 ASSERT_TRUE(response != NULL); | |
6046 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
6047 | |
6048 EXPECT_EQ(200, response->headers->response_code()); | |
6049 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
6050 | |
6051 std::string response_data; | |
6052 rv = ReadTransaction(trans.get(), &response_data); | |
6053 EXPECT_EQ(OK, rv); | |
6054 EXPECT_EQ("hello!", response_data); | |
6055 | |
6056 LoadTimingInfo load_timing_info; | |
6057 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
6058 TestLoadTimingNotReusedWithPac(load_timing_info, | |
6059 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
6060 | |
6061 // Verify the pushed stream. | |
6062 EXPECT_TRUE(push_response->headers.get() != NULL); | |
6063 EXPECT_EQ(200, push_response->headers->response_code()); | |
6064 | |
6065 rv = ReadTransaction(push_trans.get(), &response_data); | |
6066 EXPECT_EQ(OK, rv); | |
6067 EXPECT_EQ("pushed", response_data); | |
6068 | |
6069 LoadTimingInfo push_load_timing_info; | |
6070 EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); | |
6071 TestLoadTimingReusedWithPac(push_load_timing_info); | |
6072 // The transactions should share a socket ID, despite being for different | |
6073 // origins. | |
6074 EXPECT_EQ(load_timing_info.socket_log_id, | |
6075 push_load_timing_info.socket_log_id); | |
6076 | |
6077 trans.reset(); | |
6078 push_trans.reset(); | |
6079 session->CloseAllConnections(); | |
6080 } | |
6081 | |
6082 // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. | |
6083 TEST_F(HttpNetworkTransactionSpdy3Test, CrossOriginProxyPushCorrectness) { | |
6084 HttpRequestInfo request; | |
6085 | |
6086 request.method = "GET"; | |
6087 request.url = GURL("http://www.google.com/"); | |
6088 | |
6089 // Configure against https proxy server "myproxy:70". | |
6090 session_deps_.proxy_service.reset( | |
6091 ProxyService::CreateFixed("https://myproxy:70")); | |
6092 CapturingBoundNetLog log; | |
6093 session_deps_.net_log = log.bound().net_log(); | |
6094 | |
6095 // Enable cross-origin push. | |
6096 session_deps_.trusted_spdy_proxy = "myproxy:70"; | |
6097 | |
6098 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
6099 | |
6100 scoped_ptr<SpdyFrame> stream1_syn( | |
6101 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); | |
6102 | |
6103 scoped_ptr<SpdyFrame> push_rst( | |
6104 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | |
6105 | |
6106 MockWrite spdy_writes[] = { | |
6107 CreateMockWrite(*stream1_syn, 1, ASYNC), | |
6108 CreateMockWrite(*push_rst, 4), | |
6109 }; | |
6110 | |
6111 scoped_ptr<SpdyFrame> | |
6112 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
6113 | |
6114 scoped_ptr<SpdyFrame> | |
6115 stream1_body(ConstructSpdyBodyFrame(1, true)); | |
6116 | |
6117 scoped_ptr<SpdyFrame> | |
6118 stream2_syn(ConstructSpdyPush(NULL, | |
6119 0, | |
6120 2, | |
6121 1, | |
6122 "https://www.another-origin.com/foo.dat")); | |
6123 | |
6124 MockRead spdy_reads[] = { | |
6125 CreateMockRead(*stream1_reply, 2, ASYNC), | |
6126 CreateMockRead(*stream2_syn, 3, ASYNC), | |
6127 CreateMockRead(*stream1_body, 5, ASYNC), | |
6128 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause | |
6129 }; | |
6130 | |
6131 OrderedSocketData spdy_data( | |
6132 spdy_reads, arraysize(spdy_reads), | |
6133 spdy_writes, arraysize(spdy_writes)); | |
6134 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
6135 // Negotiate SPDY to the proxy | |
6136 SSLSocketDataProvider proxy(ASYNC, OK); | |
6137 proxy.SetNextProto(kProtoSPDY3); | |
6138 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); | |
6139 | |
6140 scoped_ptr<HttpTransaction> trans( | |
6141 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
6142 TestCompletionCallback callback; | |
6143 int rv = trans->Start(&request, callback.callback(), log.bound()); | |
6144 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6145 | |
6146 rv = callback.WaitForResult(); | |
6147 EXPECT_EQ(OK, rv); | |
6148 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6149 | |
6150 ASSERT_TRUE(response != NULL); | |
6151 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
6152 | |
6153 EXPECT_EQ(200, response->headers->response_code()); | |
6154 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
6155 | |
6156 std::string response_data; | |
6157 rv = ReadTransaction(trans.get(), &response_data); | |
6158 EXPECT_EQ(OK, rv); | |
6159 EXPECT_EQ("hello!", response_data); | |
6160 | |
6161 trans.reset(); | |
6162 session->CloseAllConnections(); | |
6163 } | |
6164 | |
6165 // Test HTTPS connections to a site with a bad certificate, going through an | |
6166 // HTTPS proxy | |
6167 TEST_F(HttpNetworkTransactionSpdy3Test, HTTPSBadCertificateViaHttpsProxy) { | |
6168 session_deps_.proxy_service.reset(ProxyService::CreateFixed( | |
6169 "https://proxy:70")); | |
6170 | |
6171 HttpRequestInfo request; | |
6172 request.method = "GET"; | |
6173 request.url = GURL("https://www.google.com/"); | |
6174 request.load_flags = 0; | |
6175 | |
6176 // Attempt to fetch the URL from a server with a bad cert | |
6177 MockWrite bad_cert_writes[] = { | |
6178 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
6179 "Host: www.google.com\r\n" | |
6180 "Proxy-Connection: keep-alive\r\n\r\n"), | |
6181 }; | |
6182 | |
6183 MockRead bad_cert_reads[] = { | |
6184 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), | |
6185 MockRead(SYNCHRONOUS, OK) | |
6186 }; | |
6187 | |
6188 // Attempt to fetch the URL with a good cert | |
6189 MockWrite good_data_writes[] = { | |
6190 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
6191 "Host: www.google.com\r\n" | |
6192 "Proxy-Connection: keep-alive\r\n\r\n"), | |
6193 MockWrite("GET / HTTP/1.1\r\n" | |
6194 "Host: www.google.com\r\n" | |
6195 "Connection: keep-alive\r\n\r\n"), | |
6196 }; | |
6197 | |
6198 MockRead good_cert_reads[] = { | |
6199 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), | |
6200 MockRead("HTTP/1.0 200 OK\r\n"), | |
6201 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6202 MockRead("Content-Length: 100\r\n\r\n"), | |
6203 MockRead(SYNCHRONOUS, OK), | |
6204 }; | |
6205 | |
6206 StaticSocketDataProvider ssl_bad_certificate( | |
6207 bad_cert_reads, arraysize(bad_cert_reads), | |
6208 bad_cert_writes, arraysize(bad_cert_writes)); | |
6209 StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), | |
6210 good_data_writes, arraysize(good_data_writes)); | |
6211 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); | |
6212 SSLSocketDataProvider ssl(ASYNC, OK); | |
6213 | |
6214 // SSL to the proxy, then CONNECT request, then SSL with bad certificate | |
6215 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
6216 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); | |
6217 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); | |
6218 | |
6219 // SSL to the proxy, then CONNECT request, then valid SSL certificate | |
6220 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
6221 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6222 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
6223 | |
6224 TestCompletionCallback callback; | |
6225 | |
6226 scoped_ptr<HttpTransaction> trans( | |
6227 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6228 CreateSession(&session_deps_))); | |
6229 | |
6230 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6231 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6232 | |
6233 rv = callback.WaitForResult(); | |
6234 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); | |
6235 | |
6236 rv = trans->RestartIgnoringLastError(callback.callback()); | |
6237 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6238 | |
6239 rv = callback.WaitForResult(); | |
6240 EXPECT_EQ(OK, rv); | |
6241 | |
6242 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6243 | |
6244 ASSERT_TRUE(response != NULL); | |
6245 EXPECT_EQ(100, response->headers->GetContentLength()); | |
6246 } | |
6247 | |
6248 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_UserAgent) { | |
6249 HttpRequestInfo request; | |
6250 request.method = "GET"; | |
6251 request.url = GURL("http://www.google.com/"); | |
6252 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | |
6253 "Chromium Ultra Awesome X Edition"); | |
6254 | |
6255 scoped_ptr<HttpTransaction> trans( | |
6256 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6257 CreateSession(&session_deps_))); | |
6258 | |
6259 MockWrite data_writes[] = { | |
6260 MockWrite("GET / HTTP/1.1\r\n" | |
6261 "Host: www.google.com\r\n" | |
6262 "Connection: keep-alive\r\n" | |
6263 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), | |
6264 }; | |
6265 | |
6266 // Lastly, the server responds with the actual content. | |
6267 MockRead data_reads[] = { | |
6268 MockRead("HTTP/1.0 200 OK\r\n"), | |
6269 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6270 MockRead("Content-Length: 100\r\n\r\n"), | |
6271 MockRead(SYNCHRONOUS, OK), | |
6272 }; | |
6273 | |
6274 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6275 data_writes, arraysize(data_writes)); | |
6276 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6277 | |
6278 TestCompletionCallback callback; | |
6279 | |
6280 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6281 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6282 | |
6283 rv = callback.WaitForResult(); | |
6284 EXPECT_EQ(OK, rv); | |
6285 } | |
6286 | |
6287 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_UserAgentOverTunnel) { | |
6288 HttpRequestInfo request; | |
6289 request.method = "GET"; | |
6290 request.url = GURL("https://www.google.com/"); | |
6291 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | |
6292 "Chromium Ultra Awesome X Edition"); | |
6293 | |
6294 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
6295 scoped_ptr<HttpTransaction> trans( | |
6296 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6297 CreateSession(&session_deps_))); | |
6298 | |
6299 MockWrite data_writes[] = { | |
6300 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
6301 "Host: www.google.com\r\n" | |
6302 "Proxy-Connection: keep-alive\r\n" | |
6303 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), | |
6304 }; | |
6305 MockRead data_reads[] = { | |
6306 // Return an error, so the transaction stops here (this test isn't | |
6307 // interested in the rest). | |
6308 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
6309 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
6310 MockRead("Proxy-Connection: close\r\n\r\n"), | |
6311 }; | |
6312 | |
6313 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6314 data_writes, arraysize(data_writes)); | |
6315 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6316 | |
6317 TestCompletionCallback callback; | |
6318 | |
6319 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6320 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6321 | |
6322 rv = callback.WaitForResult(); | |
6323 EXPECT_EQ(OK, rv); | |
6324 } | |
6325 | |
6326 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_Referer) { | |
6327 HttpRequestInfo request; | |
6328 request.method = "GET"; | |
6329 request.url = GURL("http://www.google.com/"); | |
6330 request.load_flags = 0; | |
6331 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, | |
6332 "http://the.previous.site.com/"); | |
6333 | |
6334 scoped_ptr<HttpTransaction> trans( | |
6335 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6336 CreateSession(&session_deps_))); | |
6337 | |
6338 MockWrite data_writes[] = { | |
6339 MockWrite("GET / HTTP/1.1\r\n" | |
6340 "Host: www.google.com\r\n" | |
6341 "Connection: keep-alive\r\n" | |
6342 "Referer: http://the.previous.site.com/\r\n\r\n"), | |
6343 }; | |
6344 | |
6345 // Lastly, the server responds with the actual content. | |
6346 MockRead data_reads[] = { | |
6347 MockRead("HTTP/1.0 200 OK\r\n"), | |
6348 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6349 MockRead("Content-Length: 100\r\n\r\n"), | |
6350 MockRead(SYNCHRONOUS, OK), | |
6351 }; | |
6352 | |
6353 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6354 data_writes, arraysize(data_writes)); | |
6355 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6356 | |
6357 TestCompletionCallback callback; | |
6358 | |
6359 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6360 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6361 | |
6362 rv = callback.WaitForResult(); | |
6363 EXPECT_EQ(OK, rv); | |
6364 } | |
6365 | |
6366 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_PostContentLengthZero) { | |
6367 HttpRequestInfo request; | |
6368 request.method = "POST"; | |
6369 request.url = GURL("http://www.google.com/"); | |
6370 | |
6371 scoped_ptr<HttpTransaction> trans( | |
6372 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6373 CreateSession(&session_deps_))); | |
6374 | |
6375 MockWrite data_writes[] = { | |
6376 MockWrite("POST / HTTP/1.1\r\n" | |
6377 "Host: www.google.com\r\n" | |
6378 "Connection: keep-alive\r\n" | |
6379 "Content-Length: 0\r\n\r\n"), | |
6380 }; | |
6381 | |
6382 // Lastly, the server responds with the actual content. | |
6383 MockRead data_reads[] = { | |
6384 MockRead("HTTP/1.0 200 OK\r\n"), | |
6385 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6386 MockRead("Content-Length: 100\r\n\r\n"), | |
6387 MockRead(SYNCHRONOUS, OK), | |
6388 }; | |
6389 | |
6390 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6391 data_writes, arraysize(data_writes)); | |
6392 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6393 | |
6394 TestCompletionCallback callback; | |
6395 | |
6396 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6397 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6398 | |
6399 rv = callback.WaitForResult(); | |
6400 EXPECT_EQ(OK, rv); | |
6401 } | |
6402 | |
6403 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_PutContentLengthZero) { | |
6404 HttpRequestInfo request; | |
6405 request.method = "PUT"; | |
6406 request.url = GURL("http://www.google.com/"); | |
6407 | |
6408 scoped_ptr<HttpTransaction> trans( | |
6409 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6410 CreateSession(&session_deps_))); | |
6411 | |
6412 MockWrite data_writes[] = { | |
6413 MockWrite("PUT / HTTP/1.1\r\n" | |
6414 "Host: www.google.com\r\n" | |
6415 "Connection: keep-alive\r\n" | |
6416 "Content-Length: 0\r\n\r\n"), | |
6417 }; | |
6418 | |
6419 // Lastly, the server responds with the actual content. | |
6420 MockRead data_reads[] = { | |
6421 MockRead("HTTP/1.0 200 OK\r\n"), | |
6422 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6423 MockRead("Content-Length: 100\r\n\r\n"), | |
6424 MockRead(SYNCHRONOUS, OK), | |
6425 }; | |
6426 | |
6427 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6428 data_writes, arraysize(data_writes)); | |
6429 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6430 | |
6431 TestCompletionCallback callback; | |
6432 | |
6433 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6434 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6435 | |
6436 rv = callback.WaitForResult(); | |
6437 EXPECT_EQ(OK, rv); | |
6438 } | |
6439 | |
6440 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_HeadContentLengthZero) { | |
6441 HttpRequestInfo request; | |
6442 request.method = "HEAD"; | |
6443 request.url = GURL("http://www.google.com/"); | |
6444 | |
6445 scoped_ptr<HttpTransaction> trans( | |
6446 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6447 CreateSession(&session_deps_))); | |
6448 | |
6449 MockWrite data_writes[] = { | |
6450 MockWrite("HEAD / HTTP/1.1\r\n" | |
6451 "Host: www.google.com\r\n" | |
6452 "Connection: keep-alive\r\n" | |
6453 "Content-Length: 0\r\n\r\n"), | |
6454 }; | |
6455 | |
6456 // Lastly, the server responds with the actual content. | |
6457 MockRead data_reads[] = { | |
6458 MockRead("HTTP/1.0 200 OK\r\n"), | |
6459 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6460 MockRead("Content-Length: 100\r\n\r\n"), | |
6461 MockRead(SYNCHRONOUS, OK), | |
6462 }; | |
6463 | |
6464 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6465 data_writes, arraysize(data_writes)); | |
6466 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6467 | |
6468 TestCompletionCallback callback; | |
6469 | |
6470 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6471 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6472 | |
6473 rv = callback.WaitForResult(); | |
6474 EXPECT_EQ(OK, rv); | |
6475 } | |
6476 | |
6477 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_CacheControlNoCache) { | |
6478 HttpRequestInfo request; | |
6479 request.method = "GET"; | |
6480 request.url = GURL("http://www.google.com/"); | |
6481 request.load_flags = LOAD_BYPASS_CACHE; | |
6482 | |
6483 scoped_ptr<HttpTransaction> trans( | |
6484 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6485 CreateSession(&session_deps_))); | |
6486 | |
6487 MockWrite data_writes[] = { | |
6488 MockWrite("GET / HTTP/1.1\r\n" | |
6489 "Host: www.google.com\r\n" | |
6490 "Connection: keep-alive\r\n" | |
6491 "Pragma: no-cache\r\n" | |
6492 "Cache-Control: no-cache\r\n\r\n"), | |
6493 }; | |
6494 | |
6495 // Lastly, the server responds with the actual content. | |
6496 MockRead data_reads[] = { | |
6497 MockRead("HTTP/1.0 200 OK\r\n"), | |
6498 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6499 MockRead("Content-Length: 100\r\n\r\n"), | |
6500 MockRead(SYNCHRONOUS, OK), | |
6501 }; | |
6502 | |
6503 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6504 data_writes, arraysize(data_writes)); | |
6505 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6506 | |
6507 TestCompletionCallback callback; | |
6508 | |
6509 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6510 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6511 | |
6512 rv = callback.WaitForResult(); | |
6513 EXPECT_EQ(OK, rv); | |
6514 } | |
6515 | |
6516 TEST_F(HttpNetworkTransactionSpdy3Test, | |
6517 BuildRequest_CacheControlValidateCache) { | |
6518 HttpRequestInfo request; | |
6519 request.method = "GET"; | |
6520 request.url = GURL("http://www.google.com/"); | |
6521 request.load_flags = LOAD_VALIDATE_CACHE; | |
6522 | |
6523 scoped_ptr<HttpTransaction> trans( | |
6524 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6525 CreateSession(&session_deps_))); | |
6526 | |
6527 MockWrite data_writes[] = { | |
6528 MockWrite("GET / HTTP/1.1\r\n" | |
6529 "Host: www.google.com\r\n" | |
6530 "Connection: keep-alive\r\n" | |
6531 "Cache-Control: max-age=0\r\n\r\n"), | |
6532 }; | |
6533 | |
6534 // Lastly, the server responds with the actual content. | |
6535 MockRead data_reads[] = { | |
6536 MockRead("HTTP/1.0 200 OK\r\n"), | |
6537 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6538 MockRead("Content-Length: 100\r\n\r\n"), | |
6539 MockRead(SYNCHRONOUS, OK), | |
6540 }; | |
6541 | |
6542 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6543 data_writes, arraysize(data_writes)); | |
6544 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6545 | |
6546 TestCompletionCallback callback; | |
6547 | |
6548 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6549 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6550 | |
6551 rv = callback.WaitForResult(); | |
6552 EXPECT_EQ(OK, rv); | |
6553 } | |
6554 | |
6555 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_ExtraHeaders) { | |
6556 HttpRequestInfo request; | |
6557 request.method = "GET"; | |
6558 request.url = GURL("http://www.google.com/"); | |
6559 request.extra_headers.SetHeader("FooHeader", "Bar"); | |
6560 | |
6561 scoped_ptr<HttpTransaction> trans( | |
6562 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6563 CreateSession(&session_deps_))); | |
6564 | |
6565 MockWrite data_writes[] = { | |
6566 MockWrite("GET / HTTP/1.1\r\n" | |
6567 "Host: www.google.com\r\n" | |
6568 "Connection: keep-alive\r\n" | |
6569 "FooHeader: Bar\r\n\r\n"), | |
6570 }; | |
6571 | |
6572 // Lastly, the server responds with the actual content. | |
6573 MockRead data_reads[] = { | |
6574 MockRead("HTTP/1.0 200 OK\r\n"), | |
6575 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6576 MockRead("Content-Length: 100\r\n\r\n"), | |
6577 MockRead(SYNCHRONOUS, OK), | |
6578 }; | |
6579 | |
6580 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6581 data_writes, arraysize(data_writes)); | |
6582 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6583 | |
6584 TestCompletionCallback callback; | |
6585 | |
6586 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6587 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6588 | |
6589 rv = callback.WaitForResult(); | |
6590 EXPECT_EQ(OK, rv); | |
6591 } | |
6592 | |
6593 TEST_F(HttpNetworkTransactionSpdy3Test, BuildRequest_ExtraHeadersStripped) { | |
6594 HttpRequestInfo request; | |
6595 request.method = "GET"; | |
6596 request.url = GURL("http://www.google.com/"); | |
6597 request.extra_headers.SetHeader("referer", "www.foo.com"); | |
6598 request.extra_headers.SetHeader("hEllo", "Kitty"); | |
6599 request.extra_headers.SetHeader("FoO", "bar"); | |
6600 | |
6601 scoped_ptr<HttpTransaction> trans( | |
6602 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6603 CreateSession(&session_deps_))); | |
6604 | |
6605 MockWrite data_writes[] = { | |
6606 MockWrite("GET / HTTP/1.1\r\n" | |
6607 "Host: www.google.com\r\n" | |
6608 "Connection: keep-alive\r\n" | |
6609 "referer: www.foo.com\r\n" | |
6610 "hEllo: Kitty\r\n" | |
6611 "FoO: bar\r\n\r\n"), | |
6612 }; | |
6613 | |
6614 // Lastly, the server responds with the actual content. | |
6615 MockRead data_reads[] = { | |
6616 MockRead("HTTP/1.0 200 OK\r\n"), | |
6617 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
6618 MockRead("Content-Length: 100\r\n\r\n"), | |
6619 MockRead(SYNCHRONOUS, OK), | |
6620 }; | |
6621 | |
6622 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6623 data_writes, arraysize(data_writes)); | |
6624 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6625 | |
6626 TestCompletionCallback callback; | |
6627 | |
6628 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6629 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6630 | |
6631 rv = callback.WaitForResult(); | |
6632 EXPECT_EQ(OK, rv); | |
6633 } | |
6634 | |
6635 TEST_F(HttpNetworkTransactionSpdy3Test, SOCKS4_HTTP_GET) { | |
6636 HttpRequestInfo request; | |
6637 request.method = "GET"; | |
6638 request.url = GURL("http://www.google.com/"); | |
6639 request.load_flags = 0; | |
6640 | |
6641 session_deps_.proxy_service.reset( | |
6642 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); | |
6643 CapturingNetLog net_log; | |
6644 session_deps_.net_log = &net_log; | |
6645 | |
6646 scoped_ptr<HttpTransaction> trans( | |
6647 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6648 CreateSession(&session_deps_))); | |
6649 | |
6650 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; | |
6651 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; | |
6652 | |
6653 MockWrite data_writes[] = { | |
6654 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), | |
6655 MockWrite("GET / HTTP/1.1\r\n" | |
6656 "Host: www.google.com\r\n" | |
6657 "Connection: keep-alive\r\n\r\n") | |
6658 }; | |
6659 | |
6660 MockRead data_reads[] = { | |
6661 MockRead(ASYNC, read_buffer, arraysize(read_buffer)), | |
6662 MockRead("HTTP/1.0 200 OK\r\n"), | |
6663 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), | |
6664 MockRead("Payload"), | |
6665 MockRead(SYNCHRONOUS, OK) | |
6666 }; | |
6667 | |
6668 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6669 data_writes, arraysize(data_writes)); | |
6670 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6671 | |
6672 TestCompletionCallback callback; | |
6673 | |
6674 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6675 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6676 | |
6677 rv = callback.WaitForResult(); | |
6678 EXPECT_EQ(OK, rv); | |
6679 | |
6680 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6681 ASSERT_TRUE(response != NULL); | |
6682 | |
6683 LoadTimingInfo load_timing_info; | |
6684 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
6685 TestLoadTimingNotReusedWithPac(load_timing_info, | |
6686 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
6687 | |
6688 std::string response_text; | |
6689 rv = ReadTransaction(trans.get(), &response_text); | |
6690 EXPECT_EQ(OK, rv); | |
6691 EXPECT_EQ("Payload", response_text); | |
6692 } | |
6693 | |
6694 TEST_F(HttpNetworkTransactionSpdy3Test, SOCKS4_SSL_GET) { | |
6695 HttpRequestInfo request; | |
6696 request.method = "GET"; | |
6697 request.url = GURL("https://www.google.com/"); | |
6698 request.load_flags = 0; | |
6699 | |
6700 session_deps_.proxy_service.reset( | |
6701 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); | |
6702 CapturingNetLog net_log; | |
6703 session_deps_.net_log = &net_log; | |
6704 | |
6705 scoped_ptr<HttpTransaction> trans( | |
6706 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6707 CreateSession(&session_deps_))); | |
6708 | |
6709 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; | |
6710 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; | |
6711 | |
6712 MockWrite data_writes[] = { | |
6713 MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), | |
6714 arraysize(write_buffer)), | |
6715 MockWrite("GET / HTTP/1.1\r\n" | |
6716 "Host: www.google.com\r\n" | |
6717 "Connection: keep-alive\r\n\r\n") | |
6718 }; | |
6719 | |
6720 MockRead data_reads[] = { | |
6721 MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), | |
6722 arraysize(read_buffer)), | |
6723 MockRead("HTTP/1.0 200 OK\r\n"), | |
6724 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), | |
6725 MockRead("Payload"), | |
6726 MockRead(SYNCHRONOUS, OK) | |
6727 }; | |
6728 | |
6729 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6730 data_writes, arraysize(data_writes)); | |
6731 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6732 | |
6733 SSLSocketDataProvider ssl(ASYNC, OK); | |
6734 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
6735 | |
6736 TestCompletionCallback callback; | |
6737 | |
6738 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6739 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6740 | |
6741 rv = callback.WaitForResult(); | |
6742 EXPECT_EQ(OK, rv); | |
6743 | |
6744 LoadTimingInfo load_timing_info; | |
6745 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
6746 TestLoadTimingNotReusedWithPac(load_timing_info, | |
6747 CONNECT_TIMING_HAS_SSL_TIMES); | |
6748 | |
6749 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6750 ASSERT_TRUE(response != NULL); | |
6751 | |
6752 std::string response_text; | |
6753 rv = ReadTransaction(trans.get(), &response_text); | |
6754 EXPECT_EQ(OK, rv); | |
6755 EXPECT_EQ("Payload", response_text); | |
6756 } | |
6757 | |
6758 TEST_F(HttpNetworkTransactionSpdy3Test, SOCKS4_HTTP_GET_no_PAC) { | |
6759 HttpRequestInfo request; | |
6760 request.method = "GET"; | |
6761 request.url = GURL("http://www.google.com/"); | |
6762 request.load_flags = 0; | |
6763 | |
6764 session_deps_.proxy_service.reset( | |
6765 ProxyService::CreateFixed("socks4://myproxy:1080")); | |
6766 CapturingNetLog net_log; | |
6767 session_deps_.net_log = &net_log; | |
6768 | |
6769 scoped_ptr<HttpTransaction> trans( | |
6770 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6771 CreateSession(&session_deps_))); | |
6772 | |
6773 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; | |
6774 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; | |
6775 | |
6776 MockWrite data_writes[] = { | |
6777 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), | |
6778 MockWrite("GET / HTTP/1.1\r\n" | |
6779 "Host: www.google.com\r\n" | |
6780 "Connection: keep-alive\r\n\r\n") | |
6781 }; | |
6782 | |
6783 MockRead data_reads[] = { | |
6784 MockRead(ASYNC, read_buffer, arraysize(read_buffer)), | |
6785 MockRead("HTTP/1.0 200 OK\r\n"), | |
6786 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), | |
6787 MockRead("Payload"), | |
6788 MockRead(SYNCHRONOUS, OK) | |
6789 }; | |
6790 | |
6791 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6792 data_writes, arraysize(data_writes)); | |
6793 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6794 | |
6795 TestCompletionCallback callback; | |
6796 | |
6797 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6798 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6799 | |
6800 rv = callback.WaitForResult(); | |
6801 EXPECT_EQ(OK, rv); | |
6802 | |
6803 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6804 ASSERT_TRUE(response != NULL); | |
6805 | |
6806 LoadTimingInfo load_timing_info; | |
6807 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
6808 TestLoadTimingNotReused(load_timing_info, | |
6809 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
6810 | |
6811 std::string response_text; | |
6812 rv = ReadTransaction(trans.get(), &response_text); | |
6813 EXPECT_EQ(OK, rv); | |
6814 EXPECT_EQ("Payload", response_text); | |
6815 } | |
6816 | |
6817 TEST_F(HttpNetworkTransactionSpdy3Test, SOCKS5_HTTP_GET) { | |
6818 HttpRequestInfo request; | |
6819 request.method = "GET"; | |
6820 request.url = GURL("http://www.google.com/"); | |
6821 request.load_flags = 0; | |
6822 | |
6823 session_deps_.proxy_service.reset( | |
6824 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); | |
6825 CapturingNetLog net_log; | |
6826 session_deps_.net_log = &net_log; | |
6827 | |
6828 scoped_ptr<HttpTransaction> trans( | |
6829 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6830 CreateSession(&session_deps_))); | |
6831 | |
6832 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; | |
6833 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; | |
6834 const char kSOCKS5OkRequest[] = { | |
6835 0x05, // Version | |
6836 0x01, // Command (CONNECT) | |
6837 0x00, // Reserved. | |
6838 0x03, // Address type (DOMAINNAME). | |
6839 0x0E, // Length of domain (14) | |
6840 // Domain string: | |
6841 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', | |
6842 0x00, 0x50, // 16-bit port (80) | |
6843 }; | |
6844 const char kSOCKS5OkResponse[] = | |
6845 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | |
6846 | |
6847 MockWrite data_writes[] = { | |
6848 MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), | |
6849 MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), | |
6850 MockWrite("GET / HTTP/1.1\r\n" | |
6851 "Host: www.google.com\r\n" | |
6852 "Connection: keep-alive\r\n\r\n") | |
6853 }; | |
6854 | |
6855 MockRead data_reads[] = { | |
6856 MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), | |
6857 MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), | |
6858 MockRead("HTTP/1.0 200 OK\r\n"), | |
6859 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), | |
6860 MockRead("Payload"), | |
6861 MockRead(SYNCHRONOUS, OK) | |
6862 }; | |
6863 | |
6864 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6865 data_writes, arraysize(data_writes)); | |
6866 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6867 | |
6868 TestCompletionCallback callback; | |
6869 | |
6870 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6871 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6872 | |
6873 rv = callback.WaitForResult(); | |
6874 EXPECT_EQ(OK, rv); | |
6875 | |
6876 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6877 ASSERT_TRUE(response != NULL); | |
6878 | |
6879 LoadTimingInfo load_timing_info; | |
6880 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
6881 TestLoadTimingNotReusedWithPac(load_timing_info, | |
6882 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
6883 | |
6884 std::string response_text; | |
6885 rv = ReadTransaction(trans.get(), &response_text); | |
6886 EXPECT_EQ(OK, rv); | |
6887 EXPECT_EQ("Payload", response_text); | |
6888 } | |
6889 | |
6890 TEST_F(HttpNetworkTransactionSpdy3Test, SOCKS5_SSL_GET) { | |
6891 HttpRequestInfo request; | |
6892 request.method = "GET"; | |
6893 request.url = GURL("https://www.google.com/"); | |
6894 request.load_flags = 0; | |
6895 | |
6896 session_deps_.proxy_service.reset( | |
6897 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); | |
6898 CapturingNetLog net_log; | |
6899 session_deps_.net_log = &net_log; | |
6900 | |
6901 scoped_ptr<HttpTransaction> trans( | |
6902 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
6903 CreateSession(&session_deps_))); | |
6904 | |
6905 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; | |
6906 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; | |
6907 const unsigned char kSOCKS5OkRequest[] = { | |
6908 0x05, // Version | |
6909 0x01, // Command (CONNECT) | |
6910 0x00, // Reserved. | |
6911 0x03, // Address type (DOMAINNAME). | |
6912 0x0E, // Length of domain (14) | |
6913 // Domain string: | |
6914 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', | |
6915 0x01, 0xBB, // 16-bit port (443) | |
6916 }; | |
6917 | |
6918 const char kSOCKS5OkResponse[] = | |
6919 { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; | |
6920 | |
6921 MockWrite data_writes[] = { | |
6922 MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), | |
6923 MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), | |
6924 arraysize(kSOCKS5OkRequest)), | |
6925 MockWrite("GET / HTTP/1.1\r\n" | |
6926 "Host: www.google.com\r\n" | |
6927 "Connection: keep-alive\r\n\r\n") | |
6928 }; | |
6929 | |
6930 MockRead data_reads[] = { | |
6931 MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), | |
6932 MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), | |
6933 MockRead("HTTP/1.0 200 OK\r\n"), | |
6934 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), | |
6935 MockRead("Payload"), | |
6936 MockRead(SYNCHRONOUS, OK) | |
6937 }; | |
6938 | |
6939 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
6940 data_writes, arraysize(data_writes)); | |
6941 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
6942 | |
6943 SSLSocketDataProvider ssl(ASYNC, OK); | |
6944 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
6945 | |
6946 TestCompletionCallback callback; | |
6947 | |
6948 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
6949 EXPECT_EQ(ERR_IO_PENDING, rv); | |
6950 | |
6951 rv = callback.WaitForResult(); | |
6952 EXPECT_EQ(OK, rv); | |
6953 | |
6954 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
6955 ASSERT_TRUE(response != NULL); | |
6956 | |
6957 LoadTimingInfo load_timing_info; | |
6958 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
6959 TestLoadTimingNotReusedWithPac(load_timing_info, | |
6960 CONNECT_TIMING_HAS_SSL_TIMES); | |
6961 | |
6962 std::string response_text; | |
6963 rv = ReadTransaction(trans.get(), &response_text); | |
6964 EXPECT_EQ(OK, rv); | |
6965 EXPECT_EQ("Payload", response_text); | |
6966 } | |
6967 | |
6968 namespace { | |
6969 | |
6970 // Tests that for connection endpoints the group names are correctly set. | |
6971 | |
6972 struct GroupNameTest { | |
6973 std::string proxy_server; | |
6974 std::string url; | |
6975 std::string expected_group_name; | |
6976 bool ssl; | |
6977 }; | |
6978 | |
6979 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( | |
6980 SpdySessionDependencies* session_deps_) { | |
6981 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); | |
6982 | |
6983 HttpServerProperties* http_server_properties = | |
6984 session->http_server_properties(); | |
6985 http_server_properties->SetAlternateProtocol( | |
6986 HostPortPair("host.with.alternate", 80), 443, | |
6987 NPN_SPDY_3); | |
6988 | |
6989 return session; | |
6990 } | |
6991 | |
6992 int GroupNameTransactionHelper( | |
6993 const std::string& url, | |
6994 const scoped_refptr<HttpNetworkSession>& session) { | |
6995 HttpRequestInfo request; | |
6996 request.method = "GET"; | |
6997 request.url = GURL(url); | |
6998 request.load_flags = 0; | |
6999 | |
7000 scoped_ptr<HttpTransaction> trans( | |
7001 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
7002 | |
7003 TestCompletionCallback callback; | |
7004 | |
7005 // We do not complete this request, the dtor will clean the transaction up. | |
7006 return trans->Start(&request, callback.callback(), BoundNetLog()); | |
7007 } | |
7008 | |
7009 } // namespace | |
7010 | |
7011 TEST_F(HttpNetworkTransactionSpdy3Test, GroupNameForDirectConnections) { | |
7012 const GroupNameTest tests[] = { | |
7013 { | |
7014 "", // unused | |
7015 "http://www.google.com/direct", | |
7016 "www.google.com:80", | |
7017 false, | |
7018 }, | |
7019 { | |
7020 "", // unused | |
7021 "http://[2001:1418:13:1::25]/direct", | |
7022 "[2001:1418:13:1::25]:80", | |
7023 false, | |
7024 }, | |
7025 | |
7026 // SSL Tests | |
7027 { | |
7028 "", // unused | |
7029 "https://www.google.com/direct_ssl", | |
7030 "ssl/www.google.com:443", | |
7031 true, | |
7032 }, | |
7033 { | |
7034 "", // unused | |
7035 "https://[2001:1418:13:1::25]/direct", | |
7036 "ssl/[2001:1418:13:1::25]:443", | |
7037 true, | |
7038 }, | |
7039 { | |
7040 "", // unused | |
7041 "http://host.with.alternate/direct", | |
7042 "ssl/host.with.alternate:443", | |
7043 true, | |
7044 }, | |
7045 }; | |
7046 | |
7047 HttpStreamFactory::set_use_alternate_protocols(true); | |
7048 | |
7049 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | |
7050 session_deps_.proxy_service.reset( | |
7051 ProxyService::CreateFixed(tests[i].proxy_server)); | |
7052 scoped_refptr<HttpNetworkSession> session( | |
7053 SetupSessionForGroupNameTests(&session_deps_)); | |
7054 | |
7055 HttpNetworkSessionPeer peer(session); | |
7056 CaptureGroupNameTransportSocketPool* transport_conn_pool = | |
7057 new CaptureGroupNameTransportSocketPool(NULL, NULL); | |
7058 CaptureGroupNameSSLSocketPool* ssl_conn_pool = | |
7059 new CaptureGroupNameSSLSocketPool(NULL, NULL); | |
7060 MockClientSocketPoolManager* mock_pool_manager = | |
7061 new MockClientSocketPoolManager; | |
7062 mock_pool_manager->SetTransportSocketPool(transport_conn_pool); | |
7063 mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); | |
7064 peer.SetClientSocketPoolManager(mock_pool_manager); | |
7065 | |
7066 EXPECT_EQ(ERR_IO_PENDING, | |
7067 GroupNameTransactionHelper(tests[i].url, session)); | |
7068 if (tests[i].ssl) | |
7069 EXPECT_EQ(tests[i].expected_group_name, | |
7070 ssl_conn_pool->last_group_name_received()); | |
7071 else | |
7072 EXPECT_EQ(tests[i].expected_group_name, | |
7073 transport_conn_pool->last_group_name_received()); | |
7074 } | |
7075 | |
7076 } | |
7077 | |
7078 TEST_F(HttpNetworkTransactionSpdy3Test, GroupNameForHTTPProxyConnections) { | |
7079 const GroupNameTest tests[] = { | |
7080 { | |
7081 "http_proxy", | |
7082 "http://www.google.com/http_proxy_normal", | |
7083 "www.google.com:80", | |
7084 false, | |
7085 }, | |
7086 | |
7087 // SSL Tests | |
7088 { | |
7089 "http_proxy", | |
7090 "https://www.google.com/http_connect_ssl", | |
7091 "ssl/www.google.com:443", | |
7092 true, | |
7093 }, | |
7094 | |
7095 { | |
7096 "http_proxy", | |
7097 "http://host.with.alternate/direct", | |
7098 "ssl/host.with.alternate:443", | |
7099 true, | |
7100 }, | |
7101 | |
7102 { | |
7103 "http_proxy", | |
7104 "ftp://ftp.google.com/http_proxy_normal", | |
7105 "ftp/ftp.google.com:21", | |
7106 false, | |
7107 }, | |
7108 }; | |
7109 | |
7110 HttpStreamFactory::set_use_alternate_protocols(true); | |
7111 | |
7112 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | |
7113 session_deps_.proxy_service.reset( | |
7114 ProxyService::CreateFixed(tests[i].proxy_server)); | |
7115 scoped_refptr<HttpNetworkSession> session( | |
7116 SetupSessionForGroupNameTests(&session_deps_)); | |
7117 | |
7118 HttpNetworkSessionPeer peer(session); | |
7119 | |
7120 HostPortPair proxy_host("http_proxy", 80); | |
7121 CaptureGroupNameHttpProxySocketPool* http_proxy_pool = | |
7122 new CaptureGroupNameHttpProxySocketPool(NULL, NULL); | |
7123 CaptureGroupNameSSLSocketPool* ssl_conn_pool = | |
7124 new CaptureGroupNameSSLSocketPool(NULL, NULL); | |
7125 | |
7126 MockClientSocketPoolManager* mock_pool_manager = | |
7127 new MockClientSocketPoolManager; | |
7128 mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); | |
7129 mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); | |
7130 peer.SetClientSocketPoolManager(mock_pool_manager); | |
7131 | |
7132 EXPECT_EQ(ERR_IO_PENDING, | |
7133 GroupNameTransactionHelper(tests[i].url, session)); | |
7134 if (tests[i].ssl) | |
7135 EXPECT_EQ(tests[i].expected_group_name, | |
7136 ssl_conn_pool->last_group_name_received()); | |
7137 else | |
7138 EXPECT_EQ(tests[i].expected_group_name, | |
7139 http_proxy_pool->last_group_name_received()); | |
7140 } | |
7141 } | |
7142 | |
7143 TEST_F(HttpNetworkTransactionSpdy3Test, GroupNameForSOCKSConnections) { | |
7144 const GroupNameTest tests[] = { | |
7145 { | |
7146 "socks4://socks_proxy:1080", | |
7147 "http://www.google.com/socks4_direct", | |
7148 "socks4/www.google.com:80", | |
7149 false, | |
7150 }, | |
7151 { | |
7152 "socks5://socks_proxy:1080", | |
7153 "http://www.google.com/socks5_direct", | |
7154 "socks5/www.google.com:80", | |
7155 false, | |
7156 }, | |
7157 | |
7158 // SSL Tests | |
7159 { | |
7160 "socks4://socks_proxy:1080", | |
7161 "https://www.google.com/socks4_ssl", | |
7162 "socks4/ssl/www.google.com:443", | |
7163 true, | |
7164 }, | |
7165 { | |
7166 "socks5://socks_proxy:1080", | |
7167 "https://www.google.com/socks5_ssl", | |
7168 "socks5/ssl/www.google.com:443", | |
7169 true, | |
7170 }, | |
7171 | |
7172 { | |
7173 "socks4://socks_proxy:1080", | |
7174 "http://host.with.alternate/direct", | |
7175 "socks4/ssl/host.with.alternate:443", | |
7176 true, | |
7177 }, | |
7178 }; | |
7179 | |
7180 HttpStreamFactory::set_use_alternate_protocols(true); | |
7181 | |
7182 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | |
7183 session_deps_.proxy_service.reset( | |
7184 ProxyService::CreateFixed(tests[i].proxy_server)); | |
7185 scoped_refptr<HttpNetworkSession> session( | |
7186 SetupSessionForGroupNameTests(&session_deps_)); | |
7187 | |
7188 HttpNetworkSessionPeer peer(session); | |
7189 | |
7190 HostPortPair proxy_host("socks_proxy", 1080); | |
7191 CaptureGroupNameSOCKSSocketPool* socks_conn_pool = | |
7192 new CaptureGroupNameSOCKSSocketPool(NULL, NULL); | |
7193 CaptureGroupNameSSLSocketPool* ssl_conn_pool = | |
7194 new CaptureGroupNameSSLSocketPool(NULL, NULL); | |
7195 | |
7196 MockClientSocketPoolManager* mock_pool_manager = | |
7197 new MockClientSocketPoolManager; | |
7198 mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); | |
7199 mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); | |
7200 peer.SetClientSocketPoolManager(mock_pool_manager); | |
7201 | |
7202 scoped_ptr<HttpTransaction> trans( | |
7203 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
7204 | |
7205 EXPECT_EQ(ERR_IO_PENDING, | |
7206 GroupNameTransactionHelper(tests[i].url, session)); | |
7207 if (tests[i].ssl) | |
7208 EXPECT_EQ(tests[i].expected_group_name, | |
7209 ssl_conn_pool->last_group_name_received()); | |
7210 else | |
7211 EXPECT_EQ(tests[i].expected_group_name, | |
7212 socks_conn_pool->last_group_name_received()); | |
7213 } | |
7214 } | |
7215 | |
7216 TEST_F(HttpNetworkTransactionSpdy3Test, ReconsiderProxyAfterFailedConnection) { | |
7217 HttpRequestInfo request; | |
7218 request.method = "GET"; | |
7219 request.url = GURL("http://www.google.com/"); | |
7220 | |
7221 session_deps_.proxy_service.reset( | |
7222 ProxyService::CreateFixed("myproxy:70;foobar:80")); | |
7223 | |
7224 // This simulates failure resolving all hostnames; that means we will fail | |
7225 // connecting to both proxies (myproxy:70 and foobar:80). | |
7226 session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); | |
7227 | |
7228 scoped_ptr<HttpTransaction> trans( | |
7229 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7230 CreateSession(&session_deps_))); | |
7231 | |
7232 TestCompletionCallback callback; | |
7233 | |
7234 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7235 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7236 | |
7237 rv = callback.WaitForResult(); | |
7238 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); | |
7239 } | |
7240 | |
7241 // Base test to make sure that when the load flags for a request specify to | |
7242 // bypass the cache, the DNS cache is not used. | |
7243 void HttpNetworkTransactionSpdy3Test::BypassHostCacheOnRefreshHelper( | |
7244 int load_flags) { | |
7245 // Issue a request, asking to bypass the cache(s). | |
7246 HttpRequestInfo request; | |
7247 request.method = "GET"; | |
7248 request.load_flags = load_flags; | |
7249 request.url = GURL("http://www.google.com/"); | |
7250 | |
7251 | |
7252 // Select a host resolver that does caching. | |
7253 session_deps_.host_resolver.reset(new MockCachingHostResolver); | |
7254 | |
7255 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7256 CreateSession(&session_deps_))); | |
7257 | |
7258 // Warm up the host cache so it has an entry for "www.google.com". | |
7259 AddressList addrlist; | |
7260 TestCompletionCallback callback; | |
7261 int rv = session_deps_.host_resolver->Resolve( | |
7262 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), &addrlist, | |
7263 callback.callback(), NULL, BoundNetLog()); | |
7264 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7265 rv = callback.WaitForResult(); | |
7266 EXPECT_EQ(OK, rv); | |
7267 | |
7268 // Verify that it was added to host cache, by doing a subsequent async lookup | |
7269 // and confirming it completes synchronously. | |
7270 rv = session_deps_.host_resolver->Resolve( | |
7271 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), &addrlist, | |
7272 callback.callback(), NULL, BoundNetLog()); | |
7273 ASSERT_EQ(OK, rv); | |
7274 | |
7275 // Inject a failure the next time that "www.google.com" is resolved. This way | |
7276 // we can tell if the next lookup hit the cache, or the "network". | |
7277 // (cache --> success, "network" --> failure). | |
7278 session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); | |
7279 | |
7280 // Connect up a mock socket which will fail with ERR_UNEXPECTED during the | |
7281 // first read -- this won't be reached as the host resolution will fail first. | |
7282 MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; | |
7283 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
7284 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7285 | |
7286 // Run the request. | |
7287 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7288 ASSERT_EQ(ERR_IO_PENDING, rv); | |
7289 rv = callback.WaitForResult(); | |
7290 | |
7291 // If we bypassed the cache, we would have gotten a failure while resolving | |
7292 // "www.google.com". | |
7293 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); | |
7294 } | |
7295 | |
7296 // There are multiple load flags that should trigger the host cache bypass. | |
7297 // Test each in isolation: | |
7298 TEST_F(HttpNetworkTransactionSpdy3Test, BypassHostCacheOnRefresh1) { | |
7299 BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); | |
7300 } | |
7301 | |
7302 TEST_F(HttpNetworkTransactionSpdy3Test, BypassHostCacheOnRefresh2) { | |
7303 BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); | |
7304 } | |
7305 | |
7306 TEST_F(HttpNetworkTransactionSpdy3Test, BypassHostCacheOnRefresh3) { | |
7307 BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); | |
7308 } | |
7309 | |
7310 // Make sure we can handle an error when writing the request. | |
7311 TEST_F(HttpNetworkTransactionSpdy3Test, RequestWriteError) { | |
7312 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
7313 | |
7314 HttpRequestInfo request; | |
7315 request.method = "GET"; | |
7316 request.url = GURL("http://www.foo.com/"); | |
7317 request.load_flags = 0; | |
7318 | |
7319 MockWrite write_failure[] = { | |
7320 MockWrite(ASYNC, ERR_CONNECTION_RESET), | |
7321 }; | |
7322 StaticSocketDataProvider data(NULL, 0, | |
7323 write_failure, arraysize(write_failure)); | |
7324 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7325 | |
7326 TestCompletionCallback callback; | |
7327 | |
7328 scoped_ptr<HttpTransaction> trans( | |
7329 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7330 CreateSession(&session_deps_))); | |
7331 | |
7332 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7333 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7334 | |
7335 rv = callback.WaitForResult(); | |
7336 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | |
7337 } | |
7338 | |
7339 // Check that a connection closed after the start of the headers finishes ok. | |
7340 TEST_F(HttpNetworkTransactionSpdy3Test, ConnectionClosedAfterStartOfHeaders) { | |
7341 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
7342 | |
7343 HttpRequestInfo request; | |
7344 request.method = "GET"; | |
7345 request.url = GURL("http://www.foo.com/"); | |
7346 request.load_flags = 0; | |
7347 | |
7348 MockRead data_reads[] = { | |
7349 MockRead("HTTP/1."), | |
7350 MockRead(SYNCHRONOUS, OK), | |
7351 }; | |
7352 | |
7353 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
7354 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7355 | |
7356 TestCompletionCallback callback; | |
7357 | |
7358 scoped_ptr<HttpTransaction> trans( | |
7359 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7360 CreateSession(&session_deps_))); | |
7361 | |
7362 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7363 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7364 | |
7365 rv = callback.WaitForResult(); | |
7366 EXPECT_EQ(OK, rv); | |
7367 | |
7368 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7369 ASSERT_TRUE(response != NULL); | |
7370 | |
7371 EXPECT_TRUE(response->headers.get() != NULL); | |
7372 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); | |
7373 | |
7374 std::string response_data; | |
7375 rv = ReadTransaction(trans.get(), &response_data); | |
7376 EXPECT_EQ(OK, rv); | |
7377 EXPECT_EQ("", response_data); | |
7378 } | |
7379 | |
7380 // Make sure that a dropped connection while draining the body for auth | |
7381 // restart does the right thing. | |
7382 TEST_F(HttpNetworkTransactionSpdy3Test, DrainResetOK) { | |
7383 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
7384 | |
7385 HttpRequestInfo request; | |
7386 request.method = "GET"; | |
7387 request.url = GURL("http://www.google.com/"); | |
7388 request.load_flags = 0; | |
7389 | |
7390 MockWrite data_writes1[] = { | |
7391 MockWrite("GET / HTTP/1.1\r\n" | |
7392 "Host: www.google.com\r\n" | |
7393 "Connection: keep-alive\r\n\r\n"), | |
7394 }; | |
7395 | |
7396 MockRead data_reads1[] = { | |
7397 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | |
7398 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
7399 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
7400 MockRead("Content-Length: 14\r\n\r\n"), | |
7401 MockRead("Unauth"), | |
7402 MockRead(ASYNC, ERR_CONNECTION_RESET), | |
7403 }; | |
7404 | |
7405 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
7406 data_writes1, arraysize(data_writes1)); | |
7407 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
7408 | |
7409 // After calling trans->RestartWithAuth(), this is the request we should | |
7410 // be issuing -- the final header line contains the credentials. | |
7411 MockWrite data_writes2[] = { | |
7412 MockWrite("GET / HTTP/1.1\r\n" | |
7413 "Host: www.google.com\r\n" | |
7414 "Connection: keep-alive\r\n" | |
7415 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
7416 }; | |
7417 | |
7418 // Lastly, the server responds with the actual content. | |
7419 MockRead data_reads2[] = { | |
7420 MockRead("HTTP/1.1 200 OK\r\n"), | |
7421 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
7422 MockRead("Content-Length: 100\r\n\r\n"), | |
7423 MockRead(SYNCHRONOUS, OK), | |
7424 }; | |
7425 | |
7426 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
7427 data_writes2, arraysize(data_writes2)); | |
7428 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
7429 | |
7430 TestCompletionCallback callback1; | |
7431 | |
7432 scoped_ptr<HttpTransaction> trans( | |
7433 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
7434 | |
7435 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
7436 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7437 | |
7438 rv = callback1.WaitForResult(); | |
7439 EXPECT_EQ(OK, rv); | |
7440 | |
7441 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7442 ASSERT_TRUE(response != NULL); | |
7443 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
7444 | |
7445 TestCompletionCallback callback2; | |
7446 | |
7447 rv = trans->RestartWithAuth( | |
7448 AuthCredentials(kFoo, kBar), callback2.callback()); | |
7449 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7450 | |
7451 rv = callback2.WaitForResult(); | |
7452 EXPECT_EQ(OK, rv); | |
7453 | |
7454 response = trans->GetResponseInfo(); | |
7455 ASSERT_TRUE(response != NULL); | |
7456 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
7457 EXPECT_EQ(100, response->headers->GetContentLength()); | |
7458 } | |
7459 | |
7460 // Test HTTPS connections going through a proxy that sends extra data. | |
7461 TEST_F(HttpNetworkTransactionSpdy3Test, HTTPSViaProxyWithExtraData) { | |
7462 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
7463 | |
7464 HttpRequestInfo request; | |
7465 request.method = "GET"; | |
7466 request.url = GURL("https://www.google.com/"); | |
7467 request.load_flags = 0; | |
7468 | |
7469 MockRead proxy_reads[] = { | |
7470 MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), | |
7471 MockRead(SYNCHRONOUS, OK) | |
7472 }; | |
7473 | |
7474 StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); | |
7475 SSLSocketDataProvider ssl(ASYNC, OK); | |
7476 | |
7477 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7478 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
7479 | |
7480 TestCompletionCallback callback; | |
7481 | |
7482 session_deps_.socket_factory->ResetNextMockIndexes(); | |
7483 | |
7484 scoped_ptr<HttpTransaction> trans( | |
7485 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7486 CreateSession(&session_deps_))); | |
7487 | |
7488 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7489 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7490 | |
7491 rv = callback.WaitForResult(); | |
7492 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
7493 } | |
7494 | |
7495 TEST_F(HttpNetworkTransactionSpdy3Test, LargeContentLengthThenClose) { | |
7496 HttpRequestInfo request; | |
7497 request.method = "GET"; | |
7498 request.url = GURL("http://www.google.com/"); | |
7499 request.load_flags = 0; | |
7500 | |
7501 scoped_ptr<HttpTransaction> trans( | |
7502 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7503 CreateSession(&session_deps_))); | |
7504 | |
7505 MockRead data_reads[] = { | |
7506 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"), | |
7507 MockRead(SYNCHRONOUS, OK), | |
7508 }; | |
7509 | |
7510 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
7511 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7512 | |
7513 TestCompletionCallback callback; | |
7514 | |
7515 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7516 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7517 | |
7518 EXPECT_EQ(OK, callback.WaitForResult()); | |
7519 | |
7520 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7521 ASSERT_TRUE(response != NULL); | |
7522 | |
7523 EXPECT_TRUE(response->headers.get() != NULL); | |
7524 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); | |
7525 | |
7526 std::string response_data; | |
7527 rv = ReadTransaction(trans.get(), &response_data); | |
7528 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); | |
7529 } | |
7530 | |
7531 TEST_F(HttpNetworkTransactionSpdy3Test, UploadFileSmallerThanLength) { | |
7532 base::FilePath temp_file_path; | |
7533 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); | |
7534 const uint64 kFakeSize = 100000; // file is actually blank | |
7535 UploadFileElementReader::ScopedOverridingContentLengthForTests | |
7536 overriding_content_length(kFakeSize); | |
7537 | |
7538 ScopedVector<UploadElementReader> element_readers; | |
7539 element_readers.push_back( | |
7540 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | |
7541 temp_file_path, | |
7542 0, | |
7543 kuint64max, | |
7544 base::Time())); | |
7545 UploadDataStream upload_data_stream(&element_readers, 0); | |
7546 | |
7547 HttpRequestInfo request; | |
7548 request.method = "POST"; | |
7549 request.url = GURL("http://www.google.com/upload"); | |
7550 request.upload_data_stream = &upload_data_stream; | |
7551 request.load_flags = 0; | |
7552 | |
7553 scoped_ptr<HttpTransaction> trans( | |
7554 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7555 CreateSession(&session_deps_))); | |
7556 | |
7557 MockRead data_reads[] = { | |
7558 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
7559 MockRead("hello world"), | |
7560 MockRead(SYNCHRONOUS, OK), | |
7561 }; | |
7562 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
7563 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7564 | |
7565 TestCompletionCallback callback; | |
7566 | |
7567 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7568 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7569 | |
7570 rv = callback.WaitForResult(); | |
7571 EXPECT_EQ(OK, rv); | |
7572 | |
7573 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7574 ASSERT_TRUE(response != NULL); | |
7575 | |
7576 EXPECT_TRUE(response->headers.get() != NULL); | |
7577 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); | |
7578 | |
7579 std::string response_data; | |
7580 rv = ReadTransaction(trans.get(), &response_data); | |
7581 EXPECT_EQ(OK, rv); | |
7582 EXPECT_EQ("hello world", response_data); | |
7583 | |
7584 file_util::Delete(temp_file_path, false); | |
7585 } | |
7586 | |
7587 TEST_F(HttpNetworkTransactionSpdy3Test, UploadUnreadableFile) { | |
7588 base::FilePath temp_file; | |
7589 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); | |
7590 std::string temp_file_content("Unreadable file."); | |
7591 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_content.c_str(), | |
7592 temp_file_content.length())); | |
7593 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); | |
7594 | |
7595 ScopedVector<UploadElementReader> element_readers; | |
7596 element_readers.push_back( | |
7597 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | |
7598 temp_file, | |
7599 0, | |
7600 kuint64max, | |
7601 base::Time())); | |
7602 UploadDataStream upload_data_stream(&element_readers, 0); | |
7603 | |
7604 HttpRequestInfo request; | |
7605 request.method = "POST"; | |
7606 request.url = GURL("http://www.google.com/upload"); | |
7607 request.upload_data_stream = &upload_data_stream; | |
7608 request.load_flags = 0; | |
7609 | |
7610 // If we try to upload an unreadable file, the network stack should report | |
7611 // the file size as zero and upload zero bytes for that file. | |
7612 scoped_ptr<HttpTransaction> trans( | |
7613 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7614 CreateSession(&session_deps_))); | |
7615 | |
7616 MockRead data_reads[] = { | |
7617 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
7618 MockRead(SYNCHRONOUS, OK), | |
7619 }; | |
7620 MockWrite data_writes[] = { | |
7621 MockWrite("POST /upload HTTP/1.1\r\n" | |
7622 "Host: www.google.com\r\n" | |
7623 "Connection: keep-alive\r\n" | |
7624 "Content-Length: 0\r\n\r\n"), | |
7625 MockWrite(SYNCHRONOUS, OK), | |
7626 }; | |
7627 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | |
7628 arraysize(data_writes)); | |
7629 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7630 | |
7631 TestCompletionCallback callback; | |
7632 | |
7633 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7634 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7635 | |
7636 rv = callback.WaitForResult(); | |
7637 EXPECT_EQ(OK, rv); | |
7638 | |
7639 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7640 ASSERT_TRUE(response != NULL); | |
7641 EXPECT_TRUE(response->headers.get() != NULL); | |
7642 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); | |
7643 | |
7644 file_util::Delete(temp_file, false); | |
7645 } | |
7646 | |
7647 TEST_F(HttpNetworkTransactionSpdy3Test, UnreadableUploadFileAfterAuthRestart) { | |
7648 base::FilePath temp_file; | |
7649 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); | |
7650 std::string temp_file_contents("Unreadable file."); | |
7651 std::string unreadable_contents(temp_file_contents.length(), '\0'); | |
7652 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), | |
7653 temp_file_contents.length())); | |
7654 | |
7655 ScopedVector<UploadElementReader> element_readers; | |
7656 element_readers.push_back( | |
7657 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | |
7658 temp_file, | |
7659 0, | |
7660 kuint64max, | |
7661 base::Time())); | |
7662 UploadDataStream upload_data_stream(&element_readers, 0); | |
7663 | |
7664 HttpRequestInfo request; | |
7665 request.method = "POST"; | |
7666 request.url = GURL("http://www.google.com/upload"); | |
7667 request.upload_data_stream = &upload_data_stream; | |
7668 request.load_flags = 0; | |
7669 | |
7670 scoped_ptr<HttpTransaction> trans( | |
7671 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7672 CreateSession(&session_deps_))); | |
7673 | |
7674 MockRead data_reads[] = { | |
7675 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | |
7676 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
7677 MockRead("Content-Length: 0\r\n\r\n"), // No response body. | |
7678 | |
7679 MockRead("HTTP/1.1 200 OK\r\n"), | |
7680 MockRead("Content-Length: 0\r\n\r\n"), | |
7681 MockRead(SYNCHRONOUS, OK), | |
7682 }; | |
7683 MockWrite data_writes[] = { | |
7684 MockWrite("POST /upload HTTP/1.1\r\n" | |
7685 "Host: www.google.com\r\n" | |
7686 "Connection: keep-alive\r\n" | |
7687 "Content-Length: 16\r\n\r\n"), | |
7688 MockWrite(SYNCHRONOUS, temp_file_contents.c_str()), | |
7689 | |
7690 MockWrite("POST /upload HTTP/1.1\r\n" | |
7691 "Host: www.google.com\r\n" | |
7692 "Connection: keep-alive\r\n" | |
7693 "Content-Length: 0\r\n" | |
7694 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | |
7695 MockWrite(SYNCHRONOUS, unreadable_contents.c_str(), | |
7696 temp_file_contents.length()), | |
7697 MockWrite(SYNCHRONOUS, OK), | |
7698 }; | |
7699 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | |
7700 arraysize(data_writes)); | |
7701 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7702 | |
7703 TestCompletionCallback callback1; | |
7704 | |
7705 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
7706 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7707 | |
7708 rv = callback1.WaitForResult(); | |
7709 EXPECT_EQ(OK, rv); | |
7710 | |
7711 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7712 ASSERT_TRUE(response != NULL); | |
7713 ASSERT_TRUE(response->headers.get() != NULL); | |
7714 EXPECT_EQ("HTTP/1.1 401 Unauthorized", response->headers->GetStatusLine()); | |
7715 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
7716 | |
7717 // Now make the file unreadable and try again. | |
7718 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); | |
7719 | |
7720 TestCompletionCallback callback2; | |
7721 | |
7722 rv = trans->RestartWithAuth( | |
7723 AuthCredentials(kFoo, kBar), callback2.callback()); | |
7724 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7725 | |
7726 rv = callback2.WaitForResult(); | |
7727 EXPECT_EQ(OK, rv); | |
7728 | |
7729 response = trans->GetResponseInfo(); | |
7730 ASSERT_TRUE(response != NULL); | |
7731 EXPECT_TRUE(response->headers.get() != NULL); | |
7732 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
7733 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
7734 | |
7735 file_util::Delete(temp_file, false); | |
7736 } | |
7737 | |
7738 // Tests that changes to Auth realms are treated like auth rejections. | |
7739 TEST_F(HttpNetworkTransactionSpdy3Test, ChangeAuthRealms) { | |
7740 | |
7741 HttpRequestInfo request; | |
7742 request.method = "GET"; | |
7743 request.url = GURL("http://www.google.com/"); | |
7744 request.load_flags = 0; | |
7745 | |
7746 // First transaction will request a resource and receive a Basic challenge | |
7747 // with realm="first_realm". | |
7748 MockWrite data_writes1[] = { | |
7749 MockWrite("GET / HTTP/1.1\r\n" | |
7750 "Host: www.google.com\r\n" | |
7751 "Connection: keep-alive\r\n" | |
7752 "\r\n"), | |
7753 }; | |
7754 MockRead data_reads1[] = { | |
7755 MockRead("HTTP/1.1 401 Unauthorized\r\n" | |
7756 "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" | |
7757 "\r\n"), | |
7758 }; | |
7759 | |
7760 // After calling trans->RestartWithAuth(), provide an Authentication header | |
7761 // for first_realm. The server will reject and provide a challenge with | |
7762 // second_realm. | |
7763 MockWrite data_writes2[] = { | |
7764 MockWrite("GET / HTTP/1.1\r\n" | |
7765 "Host: www.google.com\r\n" | |
7766 "Connection: keep-alive\r\n" | |
7767 "Authorization: Basic Zmlyc3Q6YmF6\r\n" | |
7768 "\r\n"), | |
7769 }; | |
7770 MockRead data_reads2[] = { | |
7771 MockRead("HTTP/1.1 401 Unauthorized\r\n" | |
7772 "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" | |
7773 "\r\n"), | |
7774 }; | |
7775 | |
7776 // This again fails, and goes back to first_realm. Make sure that the | |
7777 // entry is removed from cache. | |
7778 MockWrite data_writes3[] = { | |
7779 MockWrite("GET / HTTP/1.1\r\n" | |
7780 "Host: www.google.com\r\n" | |
7781 "Connection: keep-alive\r\n" | |
7782 "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" | |
7783 "\r\n"), | |
7784 }; | |
7785 MockRead data_reads3[] = { | |
7786 MockRead("HTTP/1.1 401 Unauthorized\r\n" | |
7787 "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" | |
7788 "\r\n"), | |
7789 }; | |
7790 | |
7791 // Try one last time (with the correct password) and get the resource. | |
7792 MockWrite data_writes4[] = { | |
7793 MockWrite("GET / HTTP/1.1\r\n" | |
7794 "Host: www.google.com\r\n" | |
7795 "Connection: keep-alive\r\n" | |
7796 "Authorization: Basic Zmlyc3Q6YmFy\r\n" | |
7797 "\r\n"), | |
7798 }; | |
7799 MockRead data_reads4[] = { | |
7800 MockRead("HTTP/1.1 200 OK\r\n" | |
7801 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
7802 "Content-Length: 5\r\n" | |
7803 "\r\n" | |
7804 "hello"), | |
7805 }; | |
7806 | |
7807 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
7808 data_writes1, arraysize(data_writes1)); | |
7809 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
7810 data_writes2, arraysize(data_writes2)); | |
7811 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), | |
7812 data_writes3, arraysize(data_writes3)); | |
7813 StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), | |
7814 data_writes4, arraysize(data_writes4)); | |
7815 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
7816 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
7817 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
7818 session_deps_.socket_factory->AddSocketDataProvider(&data4); | |
7819 | |
7820 TestCompletionCallback callback1; | |
7821 | |
7822 scoped_ptr<HttpTransaction> trans( | |
7823 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
7824 CreateSession(&session_deps_))); | |
7825 | |
7826 // Issue the first request with Authorize headers. There should be a | |
7827 // password prompt for first_realm waiting to be filled in after the | |
7828 // transaction completes. | |
7829 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
7830 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7831 rv = callback1.WaitForResult(); | |
7832 EXPECT_EQ(OK, rv); | |
7833 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7834 ASSERT_TRUE(response != NULL); | |
7835 const AuthChallengeInfo* challenge = response->auth_challenge.get(); | |
7836 ASSERT_FALSE(challenge == NULL); | |
7837 EXPECT_FALSE(challenge->is_proxy); | |
7838 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); | |
7839 EXPECT_EQ("first_realm", challenge->realm); | |
7840 EXPECT_EQ("basic", challenge->scheme); | |
7841 | |
7842 // Issue the second request with an incorrect password. There should be a | |
7843 // password prompt for second_realm waiting to be filled in after the | |
7844 // transaction completes. | |
7845 TestCompletionCallback callback2; | |
7846 rv = trans->RestartWithAuth( | |
7847 AuthCredentials(kFirst, kBaz), callback2.callback()); | |
7848 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7849 rv = callback2.WaitForResult(); | |
7850 EXPECT_EQ(OK, rv); | |
7851 response = trans->GetResponseInfo(); | |
7852 ASSERT_TRUE(response != NULL); | |
7853 challenge = response->auth_challenge.get(); | |
7854 ASSERT_FALSE(challenge == NULL); | |
7855 EXPECT_FALSE(challenge->is_proxy); | |
7856 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); | |
7857 EXPECT_EQ("second_realm", challenge->realm); | |
7858 EXPECT_EQ("basic", challenge->scheme); | |
7859 | |
7860 // Issue the third request with another incorrect password. There should be | |
7861 // a password prompt for first_realm waiting to be filled in. If the password | |
7862 // prompt is not present, it indicates that the HttpAuthCacheEntry for | |
7863 // first_realm was not correctly removed. | |
7864 TestCompletionCallback callback3; | |
7865 rv = trans->RestartWithAuth( | |
7866 AuthCredentials(kSecond, kFou), callback3.callback()); | |
7867 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7868 rv = callback3.WaitForResult(); | |
7869 EXPECT_EQ(OK, rv); | |
7870 response = trans->GetResponseInfo(); | |
7871 ASSERT_TRUE(response != NULL); | |
7872 challenge = response->auth_challenge.get(); | |
7873 ASSERT_FALSE(challenge == NULL); | |
7874 EXPECT_FALSE(challenge->is_proxy); | |
7875 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); | |
7876 EXPECT_EQ("first_realm", challenge->realm); | |
7877 EXPECT_EQ("basic", challenge->scheme); | |
7878 | |
7879 // Issue the fourth request with the correct password and username. | |
7880 TestCompletionCallback callback4; | |
7881 rv = trans->RestartWithAuth( | |
7882 AuthCredentials(kFirst, kBar), callback4.callback()); | |
7883 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7884 rv = callback4.WaitForResult(); | |
7885 EXPECT_EQ(OK, rv); | |
7886 response = trans->GetResponseInfo(); | |
7887 ASSERT_TRUE(response != NULL); | |
7888 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
7889 } | |
7890 | |
7891 TEST_F(HttpNetworkTransactionSpdy3Test, HonorAlternateProtocolHeader) { | |
7892 HttpStreamFactory::set_use_alternate_protocols(true); | |
7893 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
7894 | |
7895 | |
7896 MockRead data_reads[] = { | |
7897 MockRead("HTTP/1.1 200 OK\r\n"), | |
7898 MockRead(kAlternateProtocolHttpHeader), | |
7899 MockRead("hello world"), | |
7900 MockRead(SYNCHRONOUS, OK), | |
7901 }; | |
7902 | |
7903 HttpRequestInfo request; | |
7904 request.method = "GET"; | |
7905 request.url = GURL("http://www.google.com/"); | |
7906 request.load_flags = 0; | |
7907 | |
7908 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
7909 | |
7910 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
7911 | |
7912 TestCompletionCallback callback; | |
7913 | |
7914 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
7915 scoped_ptr<HttpTransaction> trans( | |
7916 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
7917 | |
7918 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7919 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7920 | |
7921 HostPortPair http_host_port_pair("www.google.com", 80); | |
7922 const HttpServerProperties& http_server_properties = | |
7923 *session->http_server_properties(); | |
7924 EXPECT_FALSE( | |
7925 http_server_properties.HasAlternateProtocol(http_host_port_pair)); | |
7926 | |
7927 EXPECT_EQ(OK, callback.WaitForResult()); | |
7928 | |
7929 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7930 ASSERT_TRUE(response != NULL); | |
7931 ASSERT_TRUE(response->headers.get() != NULL); | |
7932 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
7933 EXPECT_FALSE(response->was_fetched_via_spdy); | |
7934 EXPECT_FALSE(response->was_npn_negotiated); | |
7935 | |
7936 std::string response_data; | |
7937 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
7938 EXPECT_EQ("hello world", response_data); | |
7939 | |
7940 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); | |
7941 const PortAlternateProtocolPair alternate = | |
7942 http_server_properties.GetAlternateProtocol(http_host_port_pair); | |
7943 PortAlternateProtocolPair expected_alternate; | |
7944 expected_alternate.port = 443; | |
7945 expected_alternate.protocol = NPN_SPDY_3; | |
7946 EXPECT_TRUE(expected_alternate.Equals(alternate)); | |
7947 | |
7948 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); | |
7949 } | |
7950 | |
7951 TEST_F(HttpNetworkTransactionSpdy3Test, | |
7952 MarkBrokenAlternateProtocolAndFallback) { | |
7953 HttpStreamFactory::set_use_alternate_protocols(true); | |
7954 | |
7955 HttpRequestInfo request; | |
7956 request.method = "GET"; | |
7957 request.url = GURL("http://www.google.com/"); | |
7958 request.load_flags = 0; | |
7959 | |
7960 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); | |
7961 StaticSocketDataProvider first_data; | |
7962 first_data.set_connect_data(mock_connect); | |
7963 session_deps_.socket_factory->AddSocketDataProvider(&first_data); | |
7964 | |
7965 MockRead data_reads[] = { | |
7966 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
7967 MockRead("hello world"), | |
7968 MockRead(ASYNC, OK), | |
7969 }; | |
7970 StaticSocketDataProvider second_data( | |
7971 data_reads, arraysize(data_reads), NULL, 0); | |
7972 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | |
7973 | |
7974 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
7975 | |
7976 HttpServerProperties* http_server_properties = | |
7977 session->http_server_properties(); | |
7978 // Port must be < 1024, or the header will be ignored (since initial port was | |
7979 // port 80 (another restricted port). | |
7980 http_server_properties->SetAlternateProtocol( | |
7981 HostPortPair::FromURL(request.url), | |
7982 666 /* port is ignored by MockConnect anyway */, | |
7983 NPN_SPDY_3); | |
7984 | |
7985 scoped_ptr<HttpTransaction> trans( | |
7986 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
7987 TestCompletionCallback callback; | |
7988 | |
7989 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
7990 EXPECT_EQ(ERR_IO_PENDING, rv); | |
7991 EXPECT_EQ(OK, callback.WaitForResult()); | |
7992 | |
7993 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
7994 ASSERT_TRUE(response != NULL); | |
7995 ASSERT_TRUE(response->headers.get() != NULL); | |
7996 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
7997 | |
7998 std::string response_data; | |
7999 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8000 EXPECT_EQ("hello world", response_data); | |
8001 | |
8002 ASSERT_TRUE(http_server_properties->HasAlternateProtocol( | |
8003 HostPortPair::FromURL(request.url))); | |
8004 const PortAlternateProtocolPair alternate = | |
8005 http_server_properties->GetAlternateProtocol( | |
8006 HostPortPair::FromURL(request.url)); | |
8007 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | |
8008 } | |
8009 | |
8010 TEST_F(HttpNetworkTransactionSpdy3Test, | |
8011 AlternateProtocolPortRestrictedBlocked) { | |
8012 // Ensure that we're not allowed to redirect traffic via an alternate | |
8013 // protocol to an unrestricted (port >= 1024) when the original traffic was | |
8014 // on a restricted port (port < 1024). Ensure that we can redirect in all | |
8015 // other cases. | |
8016 HttpStreamFactory::set_use_alternate_protocols(true); | |
8017 | |
8018 HttpRequestInfo restricted_port_request; | |
8019 restricted_port_request.method = "GET"; | |
8020 restricted_port_request.url = GURL("http://www.google.com:1023/"); | |
8021 restricted_port_request.load_flags = 0; | |
8022 | |
8023 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); | |
8024 StaticSocketDataProvider first_data; | |
8025 first_data.set_connect_data(mock_connect); | |
8026 session_deps_.socket_factory->AddSocketDataProvider(&first_data); | |
8027 | |
8028 MockRead data_reads[] = { | |
8029 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
8030 MockRead("hello world"), | |
8031 MockRead(ASYNC, OK), | |
8032 }; | |
8033 StaticSocketDataProvider second_data( | |
8034 data_reads, arraysize(data_reads), NULL, 0); | |
8035 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | |
8036 | |
8037 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8038 | |
8039 HttpServerProperties* http_server_properties = | |
8040 session->http_server_properties(); | |
8041 const int kUnrestrictedAlternatePort = 1024; | |
8042 http_server_properties->SetAlternateProtocol( | |
8043 HostPortPair::FromURL(restricted_port_request.url), | |
8044 kUnrestrictedAlternatePort, | |
8045 NPN_SPDY_3); | |
8046 | |
8047 scoped_ptr<HttpTransaction> trans( | |
8048 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8049 TestCompletionCallback callback; | |
8050 | |
8051 int rv = trans->Start( | |
8052 &restricted_port_request, callback.callback(), BoundNetLog()); | |
8053 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8054 // Invalid change to unrestricted port should fail. | |
8055 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | |
8056 } | |
8057 | |
8058 TEST_F(HttpNetworkTransactionSpdy3Test, | |
8059 AlternateProtocolPortRestrictedPermitted) { | |
8060 // Ensure that we're allowed to redirect traffic via an alternate | |
8061 // protocol to an unrestricted (port >= 1024) when the original traffic was | |
8062 // on a restricted port (port < 1024) if we set | |
8063 // enable_user_alternate_protocol_ports. | |
8064 | |
8065 HttpStreamFactory::set_use_alternate_protocols(true); | |
8066 session_deps_.enable_user_alternate_protocol_ports = true; | |
8067 | |
8068 HttpRequestInfo restricted_port_request; | |
8069 restricted_port_request.method = "GET"; | |
8070 restricted_port_request.url = GURL("http://www.google.com:1023/"); | |
8071 restricted_port_request.load_flags = 0; | |
8072 | |
8073 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); | |
8074 StaticSocketDataProvider first_data; | |
8075 first_data.set_connect_data(mock_connect); | |
8076 session_deps_.socket_factory->AddSocketDataProvider(&first_data); | |
8077 | |
8078 MockRead data_reads[] = { | |
8079 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
8080 MockRead("hello world"), | |
8081 MockRead(ASYNC, OK), | |
8082 }; | |
8083 StaticSocketDataProvider second_data( | |
8084 data_reads, arraysize(data_reads), NULL, 0); | |
8085 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | |
8086 | |
8087 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8088 | |
8089 HttpServerProperties* http_server_properties = | |
8090 session->http_server_properties(); | |
8091 const int kUnrestrictedAlternatePort = 1024; | |
8092 http_server_properties->SetAlternateProtocol( | |
8093 HostPortPair::FromURL(restricted_port_request.url), | |
8094 kUnrestrictedAlternatePort, | |
8095 NPN_SPDY_3); | |
8096 | |
8097 scoped_ptr<HttpTransaction> trans( | |
8098 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8099 TestCompletionCallback callback; | |
8100 | |
8101 EXPECT_EQ(ERR_IO_PENDING, trans->Start( | |
8102 &restricted_port_request, callback.callback(), BoundNetLog())); | |
8103 // Change to unrestricted port should succeed. | |
8104 EXPECT_EQ(OK, callback.WaitForResult()); | |
8105 } | |
8106 | |
8107 TEST_F(HttpNetworkTransactionSpdy3Test, | |
8108 AlternateProtocolPortRestrictedAllowed) { | |
8109 // Ensure that we're not allowed to redirect traffic via an alternate | |
8110 // protocol to an unrestricted (port >= 1024) when the original traffic was | |
8111 // on a restricted port (port < 1024). Ensure that we can redirect in all | |
8112 // other cases. | |
8113 HttpStreamFactory::set_use_alternate_protocols(true); | |
8114 | |
8115 HttpRequestInfo restricted_port_request; | |
8116 restricted_port_request.method = "GET"; | |
8117 restricted_port_request.url = GURL("http://www.google.com:1023/"); | |
8118 restricted_port_request.load_flags = 0; | |
8119 | |
8120 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); | |
8121 StaticSocketDataProvider first_data; | |
8122 first_data.set_connect_data(mock_connect); | |
8123 session_deps_.socket_factory->AddSocketDataProvider(&first_data); | |
8124 | |
8125 MockRead data_reads[] = { | |
8126 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
8127 MockRead("hello world"), | |
8128 MockRead(ASYNC, OK), | |
8129 }; | |
8130 StaticSocketDataProvider second_data( | |
8131 data_reads, arraysize(data_reads), NULL, 0); | |
8132 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | |
8133 | |
8134 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8135 | |
8136 HttpServerProperties* http_server_properties = | |
8137 session->http_server_properties(); | |
8138 const int kRestrictedAlternatePort = 80; | |
8139 http_server_properties->SetAlternateProtocol( | |
8140 HostPortPair::FromURL(restricted_port_request.url), | |
8141 kRestrictedAlternatePort, | |
8142 NPN_SPDY_3); | |
8143 | |
8144 scoped_ptr<HttpTransaction> trans( | |
8145 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8146 TestCompletionCallback callback; | |
8147 | |
8148 int rv = trans->Start( | |
8149 &restricted_port_request, callback.callback(), BoundNetLog()); | |
8150 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8151 // Valid change to restricted port should pass. | |
8152 EXPECT_EQ(OK, callback.WaitForResult()); | |
8153 } | |
8154 | |
8155 TEST_F(HttpNetworkTransactionSpdy3Test, | |
8156 AlternateProtocolPortUnrestrictedAllowed1) { | |
8157 // Ensure that we're not allowed to redirect traffic via an alternate | |
8158 // protocol to an unrestricted (port >= 1024) when the original traffic was | |
8159 // on a restricted port (port < 1024). Ensure that we can redirect in all | |
8160 // other cases. | |
8161 HttpStreamFactory::set_use_alternate_protocols(true); | |
8162 | |
8163 HttpRequestInfo unrestricted_port_request; | |
8164 unrestricted_port_request.method = "GET"; | |
8165 unrestricted_port_request.url = GURL("http://www.google.com:1024/"); | |
8166 unrestricted_port_request.load_flags = 0; | |
8167 | |
8168 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); | |
8169 StaticSocketDataProvider first_data; | |
8170 first_data.set_connect_data(mock_connect); | |
8171 session_deps_.socket_factory->AddSocketDataProvider(&first_data); | |
8172 | |
8173 MockRead data_reads[] = { | |
8174 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
8175 MockRead("hello world"), | |
8176 MockRead(ASYNC, OK), | |
8177 }; | |
8178 StaticSocketDataProvider second_data( | |
8179 data_reads, arraysize(data_reads), NULL, 0); | |
8180 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | |
8181 | |
8182 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8183 | |
8184 HttpServerProperties* http_server_properties = | |
8185 session->http_server_properties(); | |
8186 const int kRestrictedAlternatePort = 80; | |
8187 http_server_properties->SetAlternateProtocol( | |
8188 HostPortPair::FromURL(unrestricted_port_request.url), | |
8189 kRestrictedAlternatePort, | |
8190 NPN_SPDY_3); | |
8191 | |
8192 scoped_ptr<HttpTransaction> trans( | |
8193 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8194 TestCompletionCallback callback; | |
8195 | |
8196 int rv = trans->Start( | |
8197 &unrestricted_port_request, callback.callback(), BoundNetLog()); | |
8198 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8199 // Valid change to restricted port should pass. | |
8200 EXPECT_EQ(OK, callback.WaitForResult()); | |
8201 } | |
8202 | |
8203 TEST_F(HttpNetworkTransactionSpdy3Test, | |
8204 AlternateProtocolPortUnrestrictedAllowed2) { | |
8205 // Ensure that we're not allowed to redirect traffic via an alternate | |
8206 // protocol to an unrestricted (port >= 1024) when the original traffic was | |
8207 // on a restricted port (port < 1024). Ensure that we can redirect in all | |
8208 // other cases. | |
8209 HttpStreamFactory::set_use_alternate_protocols(true); | |
8210 | |
8211 HttpRequestInfo unrestricted_port_request; | |
8212 unrestricted_port_request.method = "GET"; | |
8213 unrestricted_port_request.url = GURL("http://www.google.com:1024/"); | |
8214 unrestricted_port_request.load_flags = 0; | |
8215 | |
8216 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); | |
8217 StaticSocketDataProvider first_data; | |
8218 first_data.set_connect_data(mock_connect); | |
8219 session_deps_.socket_factory->AddSocketDataProvider(&first_data); | |
8220 | |
8221 MockRead data_reads[] = { | |
8222 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
8223 MockRead("hello world"), | |
8224 MockRead(ASYNC, OK), | |
8225 }; | |
8226 StaticSocketDataProvider second_data( | |
8227 data_reads, arraysize(data_reads), NULL, 0); | |
8228 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | |
8229 | |
8230 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8231 | |
8232 HttpServerProperties* http_server_properties = | |
8233 session->http_server_properties(); | |
8234 const int kUnrestrictedAlternatePort = 1024; | |
8235 http_server_properties->SetAlternateProtocol( | |
8236 HostPortPair::FromURL(unrestricted_port_request.url), | |
8237 kUnrestrictedAlternatePort, | |
8238 NPN_SPDY_3); | |
8239 | |
8240 scoped_ptr<HttpTransaction> trans( | |
8241 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8242 TestCompletionCallback callback; | |
8243 | |
8244 int rv = trans->Start( | |
8245 &unrestricted_port_request, callback.callback(), BoundNetLog()); | |
8246 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8247 // Valid change to an unrestricted port should pass. | |
8248 EXPECT_EQ(OK, callback.WaitForResult()); | |
8249 } | |
8250 | |
8251 TEST_F(HttpNetworkTransactionSpdy3Test, AlternateProtocolUnsafeBlocked) { | |
8252 // Ensure that we're not allowed to redirect traffic via an alternate | |
8253 // protocol to an unsafe port, and that we resume the second | |
8254 // HttpStreamFactoryImpl::Job once the alternate protocol request fails. | |
8255 HttpStreamFactory::set_use_alternate_protocols(true); | |
8256 | |
8257 HttpRequestInfo request; | |
8258 request.method = "GET"; | |
8259 request.url = GURL("http://www.google.com/"); | |
8260 request.load_flags = 0; | |
8261 | |
8262 // The alternate protocol request will error out before we attempt to connect, | |
8263 // so only the standard HTTP request will try to connect. | |
8264 MockRead data_reads[] = { | |
8265 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
8266 MockRead("hello world"), | |
8267 MockRead(ASYNC, OK), | |
8268 }; | |
8269 StaticSocketDataProvider data( | |
8270 data_reads, arraysize(data_reads), NULL, 0); | |
8271 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
8272 | |
8273 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8274 | |
8275 HttpServerProperties* http_server_properties = | |
8276 session->http_server_properties(); | |
8277 const int kUnsafePort = 7; | |
8278 http_server_properties->SetAlternateProtocol( | |
8279 HostPortPair::FromURL(request.url), | |
8280 kUnsafePort, | |
8281 NPN_SPDY_3); | |
8282 | |
8283 scoped_ptr<HttpTransaction> trans( | |
8284 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8285 TestCompletionCallback callback; | |
8286 | |
8287 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8288 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8289 // The HTTP request should succeed. | |
8290 EXPECT_EQ(OK, callback.WaitForResult()); | |
8291 | |
8292 // Disable alternate protocol before the asserts. | |
8293 HttpStreamFactory::set_use_alternate_protocols(false); | |
8294 | |
8295 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
8296 ASSERT_TRUE(response != NULL); | |
8297 ASSERT_TRUE(response->headers.get() != NULL); | |
8298 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8299 | |
8300 std::string response_data; | |
8301 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8302 EXPECT_EQ("hello world", response_data); | |
8303 } | |
8304 | |
8305 TEST_F(HttpNetworkTransactionSpdy3Test, UseAlternateProtocolForNpnSpdy) { | |
8306 HttpStreamFactory::set_use_alternate_protocols(true); | |
8307 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
8308 | |
8309 HttpRequestInfo request; | |
8310 request.method = "GET"; | |
8311 request.url = GURL("http://www.google.com/"); | |
8312 request.load_flags = 0; | |
8313 | |
8314 MockRead data_reads[] = { | |
8315 MockRead("HTTP/1.1 200 OK\r\n"), | |
8316 MockRead(kAlternateProtocolHttpHeader), | |
8317 MockRead("hello world"), | |
8318 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
8319 MockRead(ASYNC, OK), | |
8320 }; | |
8321 | |
8322 StaticSocketDataProvider first_transaction( | |
8323 data_reads, arraysize(data_reads), NULL, 0); | |
8324 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); | |
8325 | |
8326 SSLSocketDataProvider ssl(ASYNC, OK); | |
8327 ssl.SetNextProto(kProtoSPDY3); | |
8328 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
8329 | |
8330 scoped_ptr<SpdyFrame> req( | |
8331 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
8332 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; | |
8333 | |
8334 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
8335 scoped_ptr<SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | |
8336 MockRead spdy_reads[] = { | |
8337 CreateMockRead(*resp), | |
8338 CreateMockRead(*data), | |
8339 MockRead(ASYNC, 0, 0), | |
8340 }; | |
8341 | |
8342 DelayedSocketData spdy_data( | |
8343 1, // wait for one write to finish before reading. | |
8344 spdy_reads, arraysize(spdy_reads), | |
8345 spdy_writes, arraysize(spdy_writes)); | |
8346 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
8347 | |
8348 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | |
8349 StaticSocketDataProvider hanging_non_alternate_protocol_socket( | |
8350 NULL, 0, NULL, 0); | |
8351 hanging_non_alternate_protocol_socket.set_connect_data( | |
8352 never_finishing_connect); | |
8353 session_deps_.socket_factory->AddSocketDataProvider( | |
8354 &hanging_non_alternate_protocol_socket); | |
8355 | |
8356 TestCompletionCallback callback; | |
8357 | |
8358 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8359 scoped_ptr<HttpTransaction> trans( | |
8360 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8361 | |
8362 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8363 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8364 EXPECT_EQ(OK, callback.WaitForResult()); | |
8365 | |
8366 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
8367 ASSERT_TRUE(response != NULL); | |
8368 ASSERT_TRUE(response->headers.get() != NULL); | |
8369 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8370 | |
8371 std::string response_data; | |
8372 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8373 EXPECT_EQ("hello world", response_data); | |
8374 | |
8375 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8376 | |
8377 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8378 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8379 EXPECT_EQ(OK, callback.WaitForResult()); | |
8380 | |
8381 response = trans->GetResponseInfo(); | |
8382 ASSERT_TRUE(response != NULL); | |
8383 ASSERT_TRUE(response->headers.get() != NULL); | |
8384 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8385 EXPECT_TRUE(response->was_fetched_via_spdy); | |
8386 EXPECT_TRUE(response->was_npn_negotiated); | |
8387 | |
8388 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8389 EXPECT_EQ("hello!", response_data); | |
8390 } | |
8391 | |
8392 TEST_F(HttpNetworkTransactionSpdy3Test, AlternateProtocolWithSpdyLateBinding) { | |
8393 HttpStreamFactory::set_use_alternate_protocols(true); | |
8394 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
8395 | |
8396 HttpRequestInfo request; | |
8397 request.method = "GET"; | |
8398 request.url = GURL("http://www.google.com/"); | |
8399 request.load_flags = 0; | |
8400 | |
8401 MockRead data_reads[] = { | |
8402 MockRead("HTTP/1.1 200 OK\r\n"), | |
8403 MockRead(kAlternateProtocolHttpHeader), | |
8404 MockRead("hello world"), | |
8405 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
8406 MockRead(ASYNC, OK), | |
8407 }; | |
8408 | |
8409 StaticSocketDataProvider first_transaction( | |
8410 data_reads, arraysize(data_reads), NULL, 0); | |
8411 // Socket 1 is the HTTP transaction with the Alternate-Protocol header. | |
8412 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); | |
8413 | |
8414 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | |
8415 StaticSocketDataProvider hanging_socket( | |
8416 NULL, 0, NULL, 0); | |
8417 hanging_socket.set_connect_data(never_finishing_connect); | |
8418 // Socket 2 and 3 are the hanging Alternate-Protocol and | |
8419 // non-Alternate-Protocol jobs from the 2nd transaction. | |
8420 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); | |
8421 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); | |
8422 | |
8423 SSLSocketDataProvider ssl(ASYNC, OK); | |
8424 ssl.SetNextProto(kProtoSPDY3); | |
8425 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
8426 | |
8427 scoped_ptr<SpdyFrame> req1( | |
8428 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
8429 scoped_ptr<SpdyFrame> req2( | |
8430 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | |
8431 MockWrite spdy_writes[] = { | |
8432 CreateMockWrite(*req1), | |
8433 CreateMockWrite(*req2), | |
8434 }; | |
8435 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
8436 scoped_ptr<SpdyFrame> data1(ConstructSpdyBodyFrame(1, true)); | |
8437 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
8438 scoped_ptr<SpdyFrame> data2(ConstructSpdyBodyFrame(3, true)); | |
8439 MockRead spdy_reads[] = { | |
8440 CreateMockRead(*resp1), | |
8441 CreateMockRead(*data1), | |
8442 CreateMockRead(*resp2), | |
8443 CreateMockRead(*data2), | |
8444 MockRead(ASYNC, 0, 0), | |
8445 }; | |
8446 | |
8447 DelayedSocketData spdy_data( | |
8448 2, // wait for writes to finish before reading. | |
8449 spdy_reads, arraysize(spdy_reads), | |
8450 spdy_writes, arraysize(spdy_writes)); | |
8451 // Socket 4 is the successful Alternate-Protocol for transaction 3. | |
8452 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
8453 | |
8454 // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. | |
8455 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); | |
8456 | |
8457 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8458 TestCompletionCallback callback1; | |
8459 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); | |
8460 | |
8461 int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); | |
8462 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8463 EXPECT_EQ(OK, callback1.WaitForResult()); | |
8464 | |
8465 const HttpResponseInfo* response = trans1.GetResponseInfo(); | |
8466 ASSERT_TRUE(response != NULL); | |
8467 ASSERT_TRUE(response->headers.get() != NULL); | |
8468 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8469 | |
8470 std::string response_data; | |
8471 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); | |
8472 EXPECT_EQ("hello world", response_data); | |
8473 | |
8474 TestCompletionCallback callback2; | |
8475 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); | |
8476 rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); | |
8477 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8478 | |
8479 TestCompletionCallback callback3; | |
8480 HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); | |
8481 rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); | |
8482 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8483 | |
8484 EXPECT_EQ(OK, callback2.WaitForResult()); | |
8485 EXPECT_EQ(OK, callback3.WaitForResult()); | |
8486 | |
8487 response = trans2.GetResponseInfo(); | |
8488 ASSERT_TRUE(response != NULL); | |
8489 ASSERT_TRUE(response->headers.get() != NULL); | |
8490 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8491 EXPECT_TRUE(response->was_fetched_via_spdy); | |
8492 EXPECT_TRUE(response->was_npn_negotiated); | |
8493 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | |
8494 EXPECT_EQ("hello!", response_data); | |
8495 | |
8496 response = trans3.GetResponseInfo(); | |
8497 ASSERT_TRUE(response != NULL); | |
8498 ASSERT_TRUE(response->headers.get() != NULL); | |
8499 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8500 EXPECT_TRUE(response->was_fetched_via_spdy); | |
8501 EXPECT_TRUE(response->was_npn_negotiated); | |
8502 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); | |
8503 EXPECT_EQ("hello!", response_data); | |
8504 } | |
8505 | |
8506 TEST_F(HttpNetworkTransactionSpdy3Test, StallAlternateProtocolForNpnSpdy) { | |
8507 HttpStreamFactory::set_use_alternate_protocols(true); | |
8508 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
8509 | |
8510 HttpRequestInfo request; | |
8511 request.method = "GET"; | |
8512 request.url = GURL("http://www.google.com/"); | |
8513 request.load_flags = 0; | |
8514 | |
8515 MockRead data_reads[] = { | |
8516 MockRead("HTTP/1.1 200 OK\r\n"), | |
8517 MockRead(kAlternateProtocolHttpHeader), | |
8518 MockRead("hello world"), | |
8519 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
8520 MockRead(ASYNC, OK), | |
8521 }; | |
8522 | |
8523 StaticSocketDataProvider first_transaction( | |
8524 data_reads, arraysize(data_reads), NULL, 0); | |
8525 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); | |
8526 | |
8527 SSLSocketDataProvider ssl(ASYNC, OK); | |
8528 ssl.SetNextProto(kProtoSPDY3); | |
8529 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
8530 | |
8531 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | |
8532 StaticSocketDataProvider hanging_alternate_protocol_socket( | |
8533 NULL, 0, NULL, 0); | |
8534 hanging_alternate_protocol_socket.set_connect_data( | |
8535 never_finishing_connect); | |
8536 session_deps_.socket_factory->AddSocketDataProvider( | |
8537 &hanging_alternate_protocol_socket); | |
8538 | |
8539 // 2nd request is just a copy of the first one, over HTTP again. | |
8540 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); | |
8541 | |
8542 TestCompletionCallback callback; | |
8543 | |
8544 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8545 scoped_ptr<HttpTransaction> trans( | |
8546 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8547 | |
8548 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8549 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8550 EXPECT_EQ(OK, callback.WaitForResult()); | |
8551 | |
8552 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
8553 ASSERT_TRUE(response != NULL); | |
8554 ASSERT_TRUE(response->headers.get() != NULL); | |
8555 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8556 | |
8557 std::string response_data; | |
8558 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8559 EXPECT_EQ("hello world", response_data); | |
8560 | |
8561 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8562 | |
8563 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8564 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8565 EXPECT_EQ(OK, callback.WaitForResult()); | |
8566 | |
8567 response = trans->GetResponseInfo(); | |
8568 ASSERT_TRUE(response != NULL); | |
8569 ASSERT_TRUE(response->headers.get() != NULL); | |
8570 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8571 EXPECT_FALSE(response->was_fetched_via_spdy); | |
8572 EXPECT_FALSE(response->was_npn_negotiated); | |
8573 | |
8574 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8575 EXPECT_EQ("hello world", response_data); | |
8576 } | |
8577 | |
8578 class CapturingProxyResolver : public ProxyResolver { | |
8579 public: | |
8580 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} | |
8581 virtual ~CapturingProxyResolver() {} | |
8582 | |
8583 virtual int GetProxyForURL(const GURL& url, | |
8584 ProxyInfo* results, | |
8585 const CompletionCallback& callback, | |
8586 RequestHandle* request, | |
8587 const BoundNetLog& net_log) OVERRIDE { | |
8588 ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, | |
8589 HostPortPair("myproxy", 80)); | |
8590 results->UseProxyServer(proxy_server); | |
8591 resolved_.push_back(url); | |
8592 return OK; | |
8593 } | |
8594 | |
8595 virtual void CancelRequest(RequestHandle request) OVERRIDE { | |
8596 NOTREACHED(); | |
8597 } | |
8598 | |
8599 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { | |
8600 NOTREACHED(); | |
8601 return LOAD_STATE_IDLE; | |
8602 } | |
8603 | |
8604 virtual void CancelSetPacScript() OVERRIDE { | |
8605 NOTREACHED(); | |
8606 } | |
8607 | |
8608 virtual int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, | |
8609 const CompletionCallback& /*callback*/) OVERRIDE { | |
8610 return OK; | |
8611 } | |
8612 | |
8613 const std::vector<GURL>& resolved() const { return resolved_; } | |
8614 | |
8615 private: | |
8616 std::vector<GURL> resolved_; | |
8617 | |
8618 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); | |
8619 }; | |
8620 | |
8621 TEST_F(HttpNetworkTransactionSpdy3Test, | |
8622 UseAlternateProtocolForTunneledNpnSpdy) { | |
8623 HttpStreamFactory::set_use_alternate_protocols(true); | |
8624 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
8625 | |
8626 ProxyConfig proxy_config; | |
8627 proxy_config.set_auto_detect(true); | |
8628 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | |
8629 | |
8630 CapturingProxyResolver* capturing_proxy_resolver = | |
8631 new CapturingProxyResolver(); | |
8632 session_deps_.proxy_service.reset(new ProxyService( | |
8633 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, | |
8634 NULL)); | |
8635 CapturingNetLog net_log; | |
8636 session_deps_.net_log = &net_log; | |
8637 | |
8638 HttpRequestInfo request; | |
8639 request.method = "GET"; | |
8640 request.url = GURL("http://www.google.com/"); | |
8641 request.load_flags = 0; | |
8642 | |
8643 MockRead data_reads[] = { | |
8644 MockRead("HTTP/1.1 200 OK\r\n"), | |
8645 MockRead(kAlternateProtocolHttpHeader), | |
8646 MockRead("hello world"), | |
8647 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
8648 MockRead(ASYNC, OK), | |
8649 }; | |
8650 | |
8651 StaticSocketDataProvider first_transaction( | |
8652 data_reads, arraysize(data_reads), NULL, 0); | |
8653 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); | |
8654 | |
8655 SSLSocketDataProvider ssl(ASYNC, OK); | |
8656 ssl.SetNextProto(kProtoSPDY3); | |
8657 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
8658 | |
8659 scoped_ptr<SpdyFrame> req( | |
8660 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
8661 MockWrite spdy_writes[] = { | |
8662 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
8663 "Host: www.google.com\r\n" | |
8664 "Proxy-Connection: keep-alive\r\n\r\n"), // 0 | |
8665 CreateMockWrite(*req), // 3 | |
8666 }; | |
8667 | |
8668 const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; | |
8669 | |
8670 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
8671 scoped_ptr<SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | |
8672 MockRead spdy_reads[] = { | |
8673 MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 | |
8674 CreateMockRead(*resp.get(), 4), // 2, 4 | |
8675 CreateMockRead(*data.get(), 4), // 5 | |
8676 MockRead(ASYNC, 0, 0, 4), // 6 | |
8677 }; | |
8678 | |
8679 OrderedSocketData spdy_data( | |
8680 spdy_reads, arraysize(spdy_reads), | |
8681 spdy_writes, arraysize(spdy_writes)); | |
8682 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
8683 | |
8684 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | |
8685 StaticSocketDataProvider hanging_non_alternate_protocol_socket( | |
8686 NULL, 0, NULL, 0); | |
8687 hanging_non_alternate_protocol_socket.set_connect_data( | |
8688 never_finishing_connect); | |
8689 session_deps_.socket_factory->AddSocketDataProvider( | |
8690 &hanging_non_alternate_protocol_socket); | |
8691 | |
8692 TestCompletionCallback callback; | |
8693 | |
8694 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8695 scoped_ptr<HttpTransaction> trans( | |
8696 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8697 | |
8698 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8699 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8700 EXPECT_EQ(OK, callback.WaitForResult()); | |
8701 | |
8702 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
8703 ASSERT_TRUE(response != NULL); | |
8704 ASSERT_TRUE(response->headers.get() != NULL); | |
8705 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8706 EXPECT_FALSE(response->was_fetched_via_spdy); | |
8707 EXPECT_FALSE(response->was_npn_negotiated); | |
8708 | |
8709 std::string response_data; | |
8710 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8711 EXPECT_EQ("hello world", response_data); | |
8712 | |
8713 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8714 | |
8715 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8716 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8717 EXPECT_EQ(OK, callback.WaitForResult()); | |
8718 | |
8719 response = trans->GetResponseInfo(); | |
8720 ASSERT_TRUE(response != NULL); | |
8721 ASSERT_TRUE(response->headers.get() != NULL); | |
8722 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8723 EXPECT_TRUE(response->was_fetched_via_spdy); | |
8724 EXPECT_TRUE(response->was_npn_negotiated); | |
8725 | |
8726 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8727 EXPECT_EQ("hello!", response_data); | |
8728 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); | |
8729 EXPECT_EQ("http://www.google.com/", | |
8730 capturing_proxy_resolver->resolved()[0].spec()); | |
8731 EXPECT_EQ("https://www.google.com/", | |
8732 capturing_proxy_resolver->resolved()[1].spec()); | |
8733 | |
8734 LoadTimingInfo load_timing_info; | |
8735 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
8736 TestLoadTimingNotReusedWithPac(load_timing_info, | |
8737 CONNECT_TIMING_HAS_SSL_TIMES); | |
8738 } | |
8739 | |
8740 TEST_F(HttpNetworkTransactionSpdy3Test, | |
8741 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { | |
8742 HttpStreamFactory::set_use_alternate_protocols(true); | |
8743 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
8744 | |
8745 HttpRequestInfo request; | |
8746 request.method = "GET"; | |
8747 request.url = GURL("http://www.google.com/"); | |
8748 request.load_flags = 0; | |
8749 | |
8750 MockRead data_reads[] = { | |
8751 MockRead("HTTP/1.1 200 OK\r\n"), | |
8752 MockRead(kAlternateProtocolHttpHeader), | |
8753 MockRead("hello world"), | |
8754 MockRead(ASYNC, OK), | |
8755 }; | |
8756 | |
8757 StaticSocketDataProvider first_transaction( | |
8758 data_reads, arraysize(data_reads), NULL, 0); | |
8759 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); | |
8760 | |
8761 SSLSocketDataProvider ssl(ASYNC, OK); | |
8762 ssl.SetNextProto(kProtoSPDY3); | |
8763 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
8764 | |
8765 scoped_ptr<SpdyFrame> req( | |
8766 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
8767 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; | |
8768 | |
8769 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
8770 scoped_ptr<SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | |
8771 MockRead spdy_reads[] = { | |
8772 CreateMockRead(*resp), | |
8773 CreateMockRead(*data), | |
8774 MockRead(ASYNC, 0, 0), | |
8775 }; | |
8776 | |
8777 DelayedSocketData spdy_data( | |
8778 1, // wait for one write to finish before reading. | |
8779 spdy_reads, arraysize(spdy_reads), | |
8780 spdy_writes, arraysize(spdy_writes)); | |
8781 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
8782 | |
8783 TestCompletionCallback callback; | |
8784 | |
8785 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
8786 | |
8787 scoped_ptr<HttpTransaction> trans( | |
8788 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8789 | |
8790 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8791 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8792 EXPECT_EQ(OK, callback.WaitForResult()); | |
8793 | |
8794 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
8795 ASSERT_TRUE(response != NULL); | |
8796 ASSERT_TRUE(response->headers.get() != NULL); | |
8797 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8798 | |
8799 std::string response_data; | |
8800 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8801 EXPECT_EQ("hello world", response_data); | |
8802 | |
8803 // Set up an initial SpdySession in the pool to reuse. | |
8804 HostPortPair host_port_pair("www.google.com", 443); | |
8805 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
8806 kPrivacyModeDisabled); | |
8807 scoped_refptr<SpdySession> spdy_session = | |
8808 session->spdy_session_pool()->Get(key, BoundNetLog()); | |
8809 scoped_refptr<TransportSocketParams> transport_params( | |
8810 new TransportSocketParams(host_port_pair, MEDIUM, false, false, | |
8811 OnHostResolutionCallback())); | |
8812 | |
8813 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
8814 EXPECT_EQ(ERR_IO_PENDING, | |
8815 connection->Init(host_port_pair.ToString(), | |
8816 transport_params, | |
8817 LOWEST, | |
8818 callback.callback(), | |
8819 session->GetTransportSocketPool( | |
8820 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
8821 BoundNetLog())); | |
8822 EXPECT_EQ(OK, callback.WaitForResult()); | |
8823 | |
8824 SSLConfig ssl_config; | |
8825 session->ssl_config_service()->GetSSLConfig(&ssl_config); | |
8826 scoped_ptr<ClientSocketHandle> ssl_connection(new ClientSocketHandle); | |
8827 SSLClientSocketContext context; | |
8828 context.cert_verifier = session_deps_.cert_verifier.get(); | |
8829 context.transport_security_state = | |
8830 session_deps_.transport_security_state.get(); | |
8831 ssl_connection->set_socket( | |
8832 session_deps_.socket_factory->CreateSSLClientSocket( | |
8833 connection.release(), | |
8834 HostPortPair(std::string(), 443), | |
8835 ssl_config, | |
8836 context)); | |
8837 EXPECT_EQ(ERR_IO_PENDING, | |
8838 ssl_connection->socket()->Connect(callback.callback())); | |
8839 EXPECT_EQ(OK, callback.WaitForResult()); | |
8840 | |
8841 EXPECT_EQ(OK, spdy_session->InitializeWithSocket(ssl_connection.release(), | |
8842 true, OK)); | |
8843 | |
8844 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
8845 | |
8846 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
8847 EXPECT_EQ(ERR_IO_PENDING, rv); | |
8848 EXPECT_EQ(OK, callback.WaitForResult()); | |
8849 | |
8850 response = trans->GetResponseInfo(); | |
8851 ASSERT_TRUE(response != NULL); | |
8852 ASSERT_TRUE(response->headers.get() != NULL); | |
8853 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
8854 EXPECT_TRUE(response->was_fetched_via_spdy); | |
8855 EXPECT_TRUE(response->was_npn_negotiated); | |
8856 | |
8857 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
8858 EXPECT_EQ("hello!", response_data); | |
8859 } | |
8860 | |
8861 // GenerateAuthToken is a mighty big test. | |
8862 // It tests all permutation of GenerateAuthToken behavior: | |
8863 // - Synchronous and Asynchronous completion. | |
8864 // - OK or error on completion. | |
8865 // - Direct connection, non-authenticating proxy, and authenticating proxy. | |
8866 // - HTTP or HTTPS backend (to include proxy tunneling). | |
8867 // - Non-authenticating and authenticating backend. | |
8868 // | |
8869 // In all, there are 44 reasonable permuations (for example, if there are | |
8870 // problems generating an auth token for an authenticating proxy, we don't | |
8871 // need to test all permutations of the backend server). | |
8872 // | |
8873 // The test proceeds by going over each of the configuration cases, and | |
8874 // potentially running up to three rounds in each of the tests. The TestConfig | |
8875 // specifies both the configuration for the test as well as the expectations | |
8876 // for the results. | |
8877 TEST_F(HttpNetworkTransactionSpdy3Test, GenerateAuthToken) { | |
8878 static const char kServer[] = "http://www.example.com"; | |
8879 static const char kSecureServer[] = "https://www.example.com"; | |
8880 static const char kProxy[] = "myproxy:70"; | |
8881 const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; | |
8882 | |
8883 enum AuthTiming { | |
8884 AUTH_NONE, | |
8885 AUTH_SYNC, | |
8886 AUTH_ASYNC, | |
8887 }; | |
8888 | |
8889 const MockWrite kGet( | |
8890 "GET / HTTP/1.1\r\n" | |
8891 "Host: www.example.com\r\n" | |
8892 "Connection: keep-alive\r\n\r\n"); | |
8893 const MockWrite kGetProxy( | |
8894 "GET http://www.example.com/ HTTP/1.1\r\n" | |
8895 "Host: www.example.com\r\n" | |
8896 "Proxy-Connection: keep-alive\r\n\r\n"); | |
8897 const MockWrite kGetAuth( | |
8898 "GET / HTTP/1.1\r\n" | |
8899 "Host: www.example.com\r\n" | |
8900 "Connection: keep-alive\r\n" | |
8901 "Authorization: auth_token\r\n\r\n"); | |
8902 const MockWrite kGetProxyAuth( | |
8903 "GET http://www.example.com/ HTTP/1.1\r\n" | |
8904 "Host: www.example.com\r\n" | |
8905 "Proxy-Connection: keep-alive\r\n" | |
8906 "Proxy-Authorization: auth_token\r\n\r\n"); | |
8907 const MockWrite kGetAuthThroughProxy( | |
8908 "GET http://www.example.com/ HTTP/1.1\r\n" | |
8909 "Host: www.example.com\r\n" | |
8910 "Proxy-Connection: keep-alive\r\n" | |
8911 "Authorization: auth_token\r\n\r\n"); | |
8912 const MockWrite kGetAuthWithProxyAuth( | |
8913 "GET http://www.example.com/ HTTP/1.1\r\n" | |
8914 "Host: www.example.com\r\n" | |
8915 "Proxy-Connection: keep-alive\r\n" | |
8916 "Proxy-Authorization: auth_token\r\n" | |
8917 "Authorization: auth_token\r\n\r\n"); | |
8918 const MockWrite kConnect( | |
8919 "CONNECT www.example.com:443 HTTP/1.1\r\n" | |
8920 "Host: www.example.com\r\n" | |
8921 "Proxy-Connection: keep-alive\r\n\r\n"); | |
8922 const MockWrite kConnectProxyAuth( | |
8923 "CONNECT www.example.com:443 HTTP/1.1\r\n" | |
8924 "Host: www.example.com\r\n" | |
8925 "Proxy-Connection: keep-alive\r\n" | |
8926 "Proxy-Authorization: auth_token\r\n\r\n"); | |
8927 | |
8928 const MockRead kSuccess( | |
8929 "HTTP/1.1 200 OK\r\n" | |
8930 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
8931 "Content-Length: 3\r\n\r\n" | |
8932 "Yes"); | |
8933 const MockRead kFailure( | |
8934 "Should not be called."); | |
8935 const MockRead kServerChallenge( | |
8936 "HTTP/1.1 401 Unauthorized\r\n" | |
8937 "WWW-Authenticate: Mock realm=server\r\n" | |
8938 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
8939 "Content-Length: 14\r\n\r\n" | |
8940 "Unauthorized\r\n"); | |
8941 const MockRead kProxyChallenge( | |
8942 "HTTP/1.1 407 Unauthorized\r\n" | |
8943 "Proxy-Authenticate: Mock realm=proxy\r\n" | |
8944 "Proxy-Connection: close\r\n" | |
8945 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
8946 "Content-Length: 14\r\n\r\n" | |
8947 "Unauthorized\r\n"); | |
8948 const MockRead kProxyConnected( | |
8949 "HTTP/1.1 200 Connection Established\r\n\r\n"); | |
8950 | |
8951 // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with | |
8952 // no constructors, but the C++ compiler on Windows warns about | |
8953 // unspecified data in compound literals. So, moved to using constructors, | |
8954 // and TestRound's created with the default constructor should not be used. | |
8955 struct TestRound { | |
8956 TestRound() | |
8957 : expected_rv(ERR_UNEXPECTED), | |
8958 extra_write(NULL), | |
8959 extra_read(NULL) { | |
8960 } | |
8961 TestRound(const MockWrite& write_arg, const MockRead& read_arg, | |
8962 int expected_rv_arg) | |
8963 : write(write_arg), | |
8964 read(read_arg), | |
8965 expected_rv(expected_rv_arg), | |
8966 extra_write(NULL), | |
8967 extra_read(NULL) { | |
8968 } | |
8969 TestRound(const MockWrite& write_arg, const MockRead& read_arg, | |
8970 int expected_rv_arg, const MockWrite* extra_write_arg, | |
8971 const MockRead* extra_read_arg) | |
8972 : write(write_arg), | |
8973 read(read_arg), | |
8974 expected_rv(expected_rv_arg), | |
8975 extra_write(extra_write_arg), | |
8976 extra_read(extra_read_arg) { | |
8977 } | |
8978 MockWrite write; | |
8979 MockRead read; | |
8980 int expected_rv; | |
8981 const MockWrite* extra_write; | |
8982 const MockRead* extra_read; | |
8983 }; | |
8984 | |
8985 static const int kNoSSL = 500; | |
8986 | |
8987 struct TestConfig { | |
8988 const char* proxy_url; | |
8989 AuthTiming proxy_auth_timing; | |
8990 int proxy_auth_rv; | |
8991 const char* server_url; | |
8992 AuthTiming server_auth_timing; | |
8993 int server_auth_rv; | |
8994 int num_auth_rounds; | |
8995 int first_ssl_round; | |
8996 TestRound rounds[3]; | |
8997 } test_configs[] = { | |
8998 // Non-authenticating HTTP server with a direct connection. | |
8999 { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, | |
9000 { TestRound(kGet, kSuccess, OK)}}, | |
9001 // Authenticating HTTP server with a direct connection. | |
9002 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, | |
9003 { TestRound(kGet, kServerChallenge, OK), | |
9004 TestRound(kGetAuth, kSuccess, OK)}}, | |
9005 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, | |
9006 { TestRound(kGet, kServerChallenge, OK), | |
9007 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9008 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, | |
9009 { TestRound(kGet, kServerChallenge, OK), | |
9010 TestRound(kGetAuth, kSuccess, OK)}}, | |
9011 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, | |
9012 { TestRound(kGet, kServerChallenge, OK), | |
9013 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9014 // Non-authenticating HTTP server through a non-authenticating proxy. | |
9015 { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, | |
9016 { TestRound(kGetProxy, kSuccess, OK)}}, | |
9017 // Authenticating HTTP server through a non-authenticating proxy. | |
9018 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, | |
9019 { TestRound(kGetProxy, kServerChallenge, OK), | |
9020 TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, | |
9021 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, | |
9022 { TestRound(kGetProxy, kServerChallenge, OK), | |
9023 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, | |
9024 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, | |
9025 { TestRound(kGetProxy, kServerChallenge, OK), | |
9026 TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, | |
9027 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, | |
9028 { TestRound(kGetProxy, kServerChallenge, OK), | |
9029 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, | |
9030 // Non-authenticating HTTP server through an authenticating proxy. | |
9031 { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, | |
9032 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9033 TestRound(kGetProxyAuth, kSuccess, OK)}}, | |
9034 { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, | |
9035 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9036 TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, | |
9037 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, | |
9038 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9039 TestRound(kGetProxyAuth, kSuccess, OK)}}, | |
9040 { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, | |
9041 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9042 TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, | |
9043 // Authenticating HTTP server through an authenticating proxy. | |
9044 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, | |
9045 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9046 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9047 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, | |
9048 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, | |
9049 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9050 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9051 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, | |
9052 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, | |
9053 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9054 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9055 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, | |
9056 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, | |
9057 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9058 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9059 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, | |
9060 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, | |
9061 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9062 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9063 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, | |
9064 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, | |
9065 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9066 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9067 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, | |
9068 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, | |
9069 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9070 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9071 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, | |
9072 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, | |
9073 { TestRound(kGetProxy, kProxyChallenge, OK), | |
9074 TestRound(kGetProxyAuth, kServerChallenge, OK), | |
9075 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, | |
9076 // Non-authenticating HTTPS server with a direct connection. | |
9077 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, | |
9078 { TestRound(kGet, kSuccess, OK)}}, | |
9079 // Authenticating HTTPS server with a direct connection. | |
9080 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, | |
9081 { TestRound(kGet, kServerChallenge, OK), | |
9082 TestRound(kGetAuth, kSuccess, OK)}}, | |
9083 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, | |
9084 { TestRound(kGet, kServerChallenge, OK), | |
9085 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9086 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, | |
9087 { TestRound(kGet, kServerChallenge, OK), | |
9088 TestRound(kGetAuth, kSuccess, OK)}}, | |
9089 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, | |
9090 { TestRound(kGet, kServerChallenge, OK), | |
9091 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9092 // Non-authenticating HTTPS server with a non-authenticating proxy. | |
9093 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, | |
9094 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, | |
9095 // Authenticating HTTPS server through a non-authenticating proxy. | |
9096 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, | |
9097 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), | |
9098 TestRound(kGetAuth, kSuccess, OK)}}, | |
9099 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, | |
9100 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), | |
9101 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9102 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, | |
9103 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), | |
9104 TestRound(kGetAuth, kSuccess, OK)}}, | |
9105 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, | |
9106 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), | |
9107 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9108 // Non-Authenticating HTTPS server through an authenticating proxy. | |
9109 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, | |
9110 { TestRound(kConnect, kProxyChallenge, OK), | |
9111 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, | |
9112 { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, | |
9113 { TestRound(kConnect, kProxyChallenge, OK), | |
9114 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, | |
9115 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, | |
9116 { TestRound(kConnect, kProxyChallenge, OK), | |
9117 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, | |
9118 { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, | |
9119 { TestRound(kConnect, kProxyChallenge, OK), | |
9120 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, | |
9121 // Authenticating HTTPS server through an authenticating proxy. | |
9122 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, | |
9123 { TestRound(kConnect, kProxyChallenge, OK), | |
9124 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9125 &kGet, &kServerChallenge), | |
9126 TestRound(kGetAuth, kSuccess, OK)}}, | |
9127 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, | |
9128 { TestRound(kConnect, kProxyChallenge, OK), | |
9129 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9130 &kGet, &kServerChallenge), | |
9131 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9132 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, | |
9133 { TestRound(kConnect, kProxyChallenge, OK), | |
9134 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9135 &kGet, &kServerChallenge), | |
9136 TestRound(kGetAuth, kSuccess, OK)}}, | |
9137 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, | |
9138 { TestRound(kConnect, kProxyChallenge, OK), | |
9139 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9140 &kGet, &kServerChallenge), | |
9141 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9142 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, | |
9143 { TestRound(kConnect, kProxyChallenge, OK), | |
9144 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9145 &kGet, &kServerChallenge), | |
9146 TestRound(kGetAuth, kSuccess, OK)}}, | |
9147 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, | |
9148 { TestRound(kConnect, kProxyChallenge, OK), | |
9149 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9150 &kGet, &kServerChallenge), | |
9151 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9152 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, | |
9153 { TestRound(kConnect, kProxyChallenge, OK), | |
9154 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9155 &kGet, &kServerChallenge), | |
9156 TestRound(kGetAuth, kSuccess, OK)}}, | |
9157 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, | |
9158 { TestRound(kConnect, kProxyChallenge, OK), | |
9159 TestRound(kConnectProxyAuth, kProxyConnected, OK, | |
9160 &kGet, &kServerChallenge), | |
9161 TestRound(kGetAuth, kFailure, kAuthErr)}}, | |
9162 }; | |
9163 | |
9164 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_configs); ++i) { | |
9165 HttpAuthHandlerMock::Factory* auth_factory( | |
9166 new HttpAuthHandlerMock::Factory()); | |
9167 session_deps_.http_auth_handler_factory.reset(auth_factory); | |
9168 const TestConfig& test_config = test_configs[i]; | |
9169 | |
9170 // Set up authentication handlers as necessary. | |
9171 if (test_config.proxy_auth_timing != AUTH_NONE) { | |
9172 for (int n = 0; n < 2; n++) { | |
9173 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | |
9174 std::string auth_challenge = "Mock realm=proxy"; | |
9175 GURL origin(test_config.proxy_url); | |
9176 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), | |
9177 auth_challenge.end()); | |
9178 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, | |
9179 origin, BoundNetLog()); | |
9180 auth_handler->SetGenerateExpectation( | |
9181 test_config.proxy_auth_timing == AUTH_ASYNC, | |
9182 test_config.proxy_auth_rv); | |
9183 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); | |
9184 } | |
9185 } | |
9186 if (test_config.server_auth_timing != AUTH_NONE) { | |
9187 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | |
9188 std::string auth_challenge = "Mock realm=server"; | |
9189 GURL origin(test_config.server_url); | |
9190 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), | |
9191 auth_challenge.end()); | |
9192 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, | |
9193 origin, BoundNetLog()); | |
9194 auth_handler->SetGenerateExpectation( | |
9195 test_config.server_auth_timing == AUTH_ASYNC, | |
9196 test_config.server_auth_rv); | |
9197 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); | |
9198 } | |
9199 if (test_config.proxy_url) { | |
9200 session_deps_.proxy_service.reset( | |
9201 ProxyService::CreateFixed(test_config.proxy_url)); | |
9202 } else { | |
9203 session_deps_.proxy_service.reset(ProxyService::CreateDirect()); | |
9204 } | |
9205 | |
9206 HttpRequestInfo request; | |
9207 request.method = "GET"; | |
9208 request.url = GURL(test_config.server_url); | |
9209 request.load_flags = 0; | |
9210 | |
9211 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9212 HttpNetworkTransaction trans( | |
9213 DEFAULT_PRIORITY, CreateSession(&session_deps_)); | |
9214 | |
9215 for (int round = 0; round < test_config.num_auth_rounds; ++round) { | |
9216 const TestRound& read_write_round = test_config.rounds[round]; | |
9217 | |
9218 // Set up expected reads and writes. | |
9219 MockRead reads[2]; | |
9220 reads[0] = read_write_round.read; | |
9221 size_t length_reads = 1; | |
9222 if (read_write_round.extra_read) { | |
9223 reads[1] = *read_write_round.extra_read; | |
9224 length_reads = 2; | |
9225 } | |
9226 | |
9227 MockWrite writes[2]; | |
9228 writes[0] = read_write_round.write; | |
9229 size_t length_writes = 1; | |
9230 if (read_write_round.extra_write) { | |
9231 writes[1] = *read_write_round.extra_write; | |
9232 length_writes = 2; | |
9233 } | |
9234 StaticSocketDataProvider data_provider( | |
9235 reads, length_reads, writes, length_writes); | |
9236 session_deps_.socket_factory->AddSocketDataProvider(&data_provider); | |
9237 | |
9238 // Add an SSL sequence if necessary. | |
9239 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); | |
9240 if (round >= test_config.first_ssl_round) | |
9241 session_deps_.socket_factory->AddSSLSocketDataProvider( | |
9242 &ssl_socket_data_provider); | |
9243 | |
9244 // Start or restart the transaction. | |
9245 TestCompletionCallback callback; | |
9246 int rv; | |
9247 if (round == 0) { | |
9248 rv = trans.Start(&request, callback.callback(), BoundNetLog()); | |
9249 } else { | |
9250 rv = trans.RestartWithAuth( | |
9251 AuthCredentials(kFoo, kBar), callback.callback()); | |
9252 } | |
9253 if (rv == ERR_IO_PENDING) | |
9254 rv = callback.WaitForResult(); | |
9255 | |
9256 // Compare results with expected data. | |
9257 EXPECT_EQ(read_write_round.expected_rv, rv); | |
9258 const HttpResponseInfo* response = trans.GetResponseInfo(); | |
9259 if (read_write_round.expected_rv == OK) { | |
9260 ASSERT_TRUE(response != NULL); | |
9261 } else { | |
9262 EXPECT_TRUE(response == NULL); | |
9263 EXPECT_EQ(round + 1, test_config.num_auth_rounds); | |
9264 continue; | |
9265 } | |
9266 if (round + 1 < test_config.num_auth_rounds) { | |
9267 EXPECT_FALSE(response->auth_challenge.get() == NULL); | |
9268 } else { | |
9269 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
9270 } | |
9271 } | |
9272 } | |
9273 } | |
9274 | |
9275 TEST_F(HttpNetworkTransactionSpdy3Test, MultiRoundAuth) { | |
9276 // Do multi-round authentication and make sure it works correctly. | |
9277 HttpAuthHandlerMock::Factory* auth_factory( | |
9278 new HttpAuthHandlerMock::Factory()); | |
9279 session_deps_.http_auth_handler_factory.reset(auth_factory); | |
9280 session_deps_.proxy_service.reset(ProxyService::CreateDirect()); | |
9281 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); | |
9282 session_deps_.host_resolver->set_synchronous_mode(true); | |
9283 | |
9284 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | |
9285 auth_handler->set_connection_based(true); | |
9286 std::string auth_challenge = "Mock realm=server"; | |
9287 GURL origin("http://www.example.com"); | |
9288 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), | |
9289 auth_challenge.end()); | |
9290 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, | |
9291 origin, BoundNetLog()); | |
9292 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); | |
9293 | |
9294 int rv = OK; | |
9295 const HttpResponseInfo* response = NULL; | |
9296 HttpRequestInfo request; | |
9297 request.method = "GET"; | |
9298 request.url = origin; | |
9299 request.load_flags = 0; | |
9300 | |
9301 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9302 | |
9303 // Use a TCP Socket Pool with only one connection per group. This is used | |
9304 // to validate that the TCP socket is not released to the pool between | |
9305 // each round of multi-round authentication. | |
9306 HttpNetworkSessionPeer session_peer(session); | |
9307 ClientSocketPoolHistograms transport_pool_histograms("SmallTCP"); | |
9308 TransportClientSocketPool* transport_pool = new TransportClientSocketPool( | |
9309 50, // Max sockets for pool | |
9310 1, // Max sockets per group | |
9311 &transport_pool_histograms, | |
9312 session_deps_.host_resolver.get(), | |
9313 session_deps_.socket_factory.get(), | |
9314 session_deps_.net_log); | |
9315 MockClientSocketPoolManager* mock_pool_manager = | |
9316 new MockClientSocketPoolManager; | |
9317 mock_pool_manager->SetTransportSocketPool(transport_pool); | |
9318 session_peer.SetClientSocketPoolManager(mock_pool_manager); | |
9319 | |
9320 scoped_ptr<HttpTransaction> trans( | |
9321 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9322 TestCompletionCallback callback; | |
9323 | |
9324 const MockWrite kGet( | |
9325 "GET / HTTP/1.1\r\n" | |
9326 "Host: www.example.com\r\n" | |
9327 "Connection: keep-alive\r\n\r\n"); | |
9328 const MockWrite kGetAuth( | |
9329 "GET / HTTP/1.1\r\n" | |
9330 "Host: www.example.com\r\n" | |
9331 "Connection: keep-alive\r\n" | |
9332 "Authorization: auth_token\r\n\r\n"); | |
9333 | |
9334 const MockRead kServerChallenge( | |
9335 "HTTP/1.1 401 Unauthorized\r\n" | |
9336 "WWW-Authenticate: Mock realm=server\r\n" | |
9337 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
9338 "Content-Length: 14\r\n\r\n" | |
9339 "Unauthorized\r\n"); | |
9340 const MockRead kSuccess( | |
9341 "HTTP/1.1 200 OK\r\n" | |
9342 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
9343 "Content-Length: 3\r\n\r\n" | |
9344 "Yes"); | |
9345 | |
9346 MockWrite writes[] = { | |
9347 // First round | |
9348 kGet, | |
9349 // Second round | |
9350 kGetAuth, | |
9351 // Third round | |
9352 kGetAuth, | |
9353 // Fourth round | |
9354 kGetAuth, | |
9355 // Competing request | |
9356 kGet, | |
9357 }; | |
9358 MockRead reads[] = { | |
9359 // First round | |
9360 kServerChallenge, | |
9361 // Second round | |
9362 kServerChallenge, | |
9363 // Third round | |
9364 kServerChallenge, | |
9365 // Fourth round | |
9366 kSuccess, | |
9367 // Competing response | |
9368 kSuccess, | |
9369 }; | |
9370 StaticSocketDataProvider data_provider(reads, arraysize(reads), | |
9371 writes, arraysize(writes)); | |
9372 session_deps_.socket_factory->AddSocketDataProvider(&data_provider); | |
9373 | |
9374 const char* const kSocketGroup = "www.example.com:80"; | |
9375 | |
9376 // First round of authentication. | |
9377 auth_handler->SetGenerateExpectation(false, OK); | |
9378 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
9379 if (rv == ERR_IO_PENDING) | |
9380 rv = callback.WaitForResult(); | |
9381 EXPECT_EQ(OK, rv); | |
9382 response = trans->GetResponseInfo(); | |
9383 ASSERT_TRUE(response != NULL); | |
9384 EXPECT_FALSE(response->auth_challenge.get() == NULL); | |
9385 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | |
9386 | |
9387 // In between rounds, another request comes in for the same domain. | |
9388 // It should not be able to grab the TCP socket that trans has already | |
9389 // claimed. | |
9390 scoped_ptr<HttpTransaction> trans_compete( | |
9391 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9392 TestCompletionCallback callback_compete; | |
9393 rv = trans_compete->Start( | |
9394 &request, callback_compete.callback(), BoundNetLog()); | |
9395 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9396 // callback_compete.WaitForResult at this point would stall forever, | |
9397 // since the HttpNetworkTransaction does not release the request back to | |
9398 // the pool until after authentication completes. | |
9399 | |
9400 // Second round of authentication. | |
9401 auth_handler->SetGenerateExpectation(false, OK); | |
9402 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); | |
9403 if (rv == ERR_IO_PENDING) | |
9404 rv = callback.WaitForResult(); | |
9405 EXPECT_EQ(OK, rv); | |
9406 response = trans->GetResponseInfo(); | |
9407 ASSERT_TRUE(response != NULL); | |
9408 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
9409 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | |
9410 | |
9411 // Third round of authentication. | |
9412 auth_handler->SetGenerateExpectation(false, OK); | |
9413 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); | |
9414 if (rv == ERR_IO_PENDING) | |
9415 rv = callback.WaitForResult(); | |
9416 EXPECT_EQ(OK, rv); | |
9417 response = trans->GetResponseInfo(); | |
9418 ASSERT_TRUE(response != NULL); | |
9419 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
9420 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | |
9421 | |
9422 // Fourth round of authentication, which completes successfully. | |
9423 auth_handler->SetGenerateExpectation(false, OK); | |
9424 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); | |
9425 if (rv == ERR_IO_PENDING) | |
9426 rv = callback.WaitForResult(); | |
9427 EXPECT_EQ(OK, rv); | |
9428 response = trans->GetResponseInfo(); | |
9429 ASSERT_TRUE(response != NULL); | |
9430 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
9431 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | |
9432 | |
9433 // Read the body since the fourth round was successful. This will also | |
9434 // release the socket back to the pool. | |
9435 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); | |
9436 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
9437 if (rv == ERR_IO_PENDING) | |
9438 rv = callback.WaitForResult(); | |
9439 EXPECT_EQ(3, rv); | |
9440 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
9441 EXPECT_EQ(0, rv); | |
9442 // There are still 0 idle sockets, since the trans_compete transaction | |
9443 // will be handed it immediately after trans releases it to the group. | |
9444 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | |
9445 | |
9446 // The competing request can now finish. Wait for the headers and then | |
9447 // read the body. | |
9448 rv = callback_compete.WaitForResult(); | |
9449 EXPECT_EQ(OK, rv); | |
9450 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
9451 if (rv == ERR_IO_PENDING) | |
9452 rv = callback.WaitForResult(); | |
9453 EXPECT_EQ(3, rv); | |
9454 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
9455 EXPECT_EQ(0, rv); | |
9456 | |
9457 // Finally, the socket is released to the group. | |
9458 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | |
9459 } | |
9460 | |
9461 // This tests the case that a request is issued via http instead of spdy after | |
9462 // npn is negotiated. | |
9463 TEST_F(HttpNetworkTransactionSpdy3Test, NpnWithHttpOverSSL) { | |
9464 HttpStreamFactory::set_use_alternate_protocols(true); | |
9465 HttpStreamFactory::SetNextProtos( | |
9466 MakeNextProtos("http/1.1", "http1.1", NULL)); | |
9467 HttpRequestInfo request; | |
9468 request.method = "GET"; | |
9469 request.url = GURL("https://www.google.com/"); | |
9470 request.load_flags = 0; | |
9471 | |
9472 MockWrite data_writes[] = { | |
9473 MockWrite("GET / HTTP/1.1\r\n" | |
9474 "Host: www.google.com\r\n" | |
9475 "Connection: keep-alive\r\n\r\n"), | |
9476 }; | |
9477 | |
9478 MockRead data_reads[] = { | |
9479 MockRead("HTTP/1.1 200 OK\r\n"), | |
9480 MockRead(kAlternateProtocolHttpHeader), | |
9481 MockRead("hello world"), | |
9482 MockRead(SYNCHRONOUS, OK), | |
9483 }; | |
9484 | |
9485 SSLSocketDataProvider ssl(ASYNC, OK); | |
9486 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | |
9487 ssl.next_proto = "http/1.1"; | |
9488 ssl.protocol_negotiated = kProtoHTTP11; | |
9489 | |
9490 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
9491 | |
9492 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
9493 data_writes, arraysize(data_writes)); | |
9494 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
9495 | |
9496 TestCompletionCallback callback; | |
9497 | |
9498 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9499 scoped_ptr<HttpTransaction> trans( | |
9500 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9501 | |
9502 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
9503 | |
9504 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9505 EXPECT_EQ(OK, callback.WaitForResult()); | |
9506 | |
9507 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
9508 ASSERT_TRUE(response != NULL); | |
9509 ASSERT_TRUE(response->headers.get() != NULL); | |
9510 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
9511 | |
9512 std::string response_data; | |
9513 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
9514 EXPECT_EQ("hello world", response_data); | |
9515 | |
9516 EXPECT_FALSE(response->was_fetched_via_spdy); | |
9517 EXPECT_TRUE(response->was_npn_negotiated); | |
9518 } | |
9519 | |
9520 TEST_F(HttpNetworkTransactionSpdy3Test, SpdyPostNPNServerHangup) { | |
9521 // Simulate the SSL handshake completing with an NPN negotiation | |
9522 // followed by an immediate server closing of the socket. | |
9523 // Fix crash: http://crbug.com/46369 | |
9524 HttpStreamFactory::set_use_alternate_protocols(true); | |
9525 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
9526 | |
9527 HttpRequestInfo request; | |
9528 request.method = "GET"; | |
9529 request.url = GURL("https://www.google.com/"); | |
9530 request.load_flags = 0; | |
9531 | |
9532 SSLSocketDataProvider ssl(ASYNC, OK); | |
9533 ssl.SetNextProto(kProtoSPDY3); | |
9534 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
9535 | |
9536 scoped_ptr<SpdyFrame> req( | |
9537 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
9538 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; | |
9539 | |
9540 MockRead spdy_reads[] = { | |
9541 MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. | |
9542 }; | |
9543 | |
9544 DelayedSocketData spdy_data( | |
9545 0, // don't wait in this case, immediate hangup. | |
9546 spdy_reads, arraysize(spdy_reads), | |
9547 spdy_writes, arraysize(spdy_writes)); | |
9548 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
9549 | |
9550 TestCompletionCallback callback; | |
9551 | |
9552 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9553 scoped_ptr<HttpTransaction> trans( | |
9554 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9555 | |
9556 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
9557 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9558 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); | |
9559 } | |
9560 | |
9561 TEST_F(HttpNetworkTransactionSpdy3Test, SpdyAlternateProtocolThroughProxy) { | |
9562 // This test ensures that the URL passed into the proxy is upgraded | |
9563 // to https when doing an Alternate Protocol upgrade. | |
9564 HttpStreamFactory::set_use_alternate_protocols(true); | |
9565 HttpStreamFactory::SetNextProtos( | |
9566 MakeNextProtos( | |
9567 "http/1.1", "http1.1", "spdy/2", "spdy/3", "spdy/3.1", | |
9568 "spdy/4a1", "spdy", NULL)); | |
9569 | |
9570 session_deps_.proxy_service.reset( | |
9571 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | |
9572 CapturingNetLog net_log; | |
9573 session_deps_.net_log = &net_log; | |
9574 HttpAuthHandlerMock::Factory* auth_factory = | |
9575 new HttpAuthHandlerMock::Factory(); | |
9576 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); | |
9577 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); | |
9578 auth_factory->set_do_init_from_challenge(true); | |
9579 session_deps_.http_auth_handler_factory.reset(auth_factory); | |
9580 | |
9581 HttpRequestInfo request; | |
9582 request.method = "GET"; | |
9583 request.url = GURL("http://www.google.com"); | |
9584 request.load_flags = 0; | |
9585 | |
9586 // First round goes unauthenticated through the proxy. | |
9587 MockWrite data_writes_1[] = { | |
9588 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
9589 "Host: www.google.com\r\n" | |
9590 "Proxy-Connection: keep-alive\r\n" | |
9591 "\r\n"), | |
9592 }; | |
9593 MockRead data_reads_1[] = { | |
9594 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
9595 MockRead("HTTP/1.1 200 OK\r\n" | |
9596 "Alternate-Protocol: 443:npn-spdy/3\r\n" | |
9597 "Proxy-Connection: close\r\n" | |
9598 "\r\n"), | |
9599 }; | |
9600 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), | |
9601 data_writes_1, arraysize(data_writes_1)); | |
9602 | |
9603 // Second round tries to tunnel to www.google.com due to the | |
9604 // Alternate-Protocol announcement in the first round. It fails due | |
9605 // to a proxy authentication challenge. | |
9606 // After the failure, a tunnel is established to www.google.com using | |
9607 // Proxy-Authorization headers. There is then a SPDY request round. | |
9608 // | |
9609 // NOTE: Despite the "Proxy-Connection: Close", these are done on the | |
9610 // same MockTCPClientSocket since the underlying HttpNetworkClientSocket | |
9611 // does a Disconnect and Connect on the same socket, rather than trying | |
9612 // to obtain a new one. | |
9613 // | |
9614 // NOTE: Originally, the proxy response to the second CONNECT request | |
9615 // simply returned another 407 so the unit test could skip the SSL connection | |
9616 // establishment and SPDY framing issues. Alas, the | |
9617 // retry-http-when-alternate-protocol fails logic kicks in, which was more | |
9618 // complicated to set up expectations for than the SPDY session. | |
9619 | |
9620 scoped_ptr<SpdyFrame> req( | |
9621 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
9622 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
9623 scoped_ptr<SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | |
9624 | |
9625 MockWrite data_writes_2[] = { | |
9626 // First connection attempt without Proxy-Authorization. | |
9627 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
9628 "Host: www.google.com\r\n" | |
9629 "Proxy-Connection: keep-alive\r\n" | |
9630 "\r\n"), | |
9631 | |
9632 // Second connection attempt with Proxy-Authorization. | |
9633 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
9634 "Host: www.google.com\r\n" | |
9635 "Proxy-Connection: keep-alive\r\n" | |
9636 "Proxy-Authorization: auth_token\r\n" | |
9637 "\r\n"), | |
9638 | |
9639 // SPDY request | |
9640 CreateMockWrite(*req), | |
9641 }; | |
9642 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" | |
9643 "Proxy-Authenticate: Mock\r\n" | |
9644 "Proxy-Connection: close\r\n" | |
9645 "\r\n"); | |
9646 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; | |
9647 MockRead data_reads_2[] = { | |
9648 // First connection attempt fails | |
9649 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), | |
9650 MockRead(ASYNC, kRejectConnectResponse, | |
9651 arraysize(kRejectConnectResponse) - 1, 1), | |
9652 | |
9653 // Second connection attempt passes | |
9654 MockRead(ASYNC, kAcceptConnectResponse, | |
9655 arraysize(kAcceptConnectResponse) -1, 4), | |
9656 | |
9657 // SPDY response | |
9658 CreateMockRead(*resp.get(), 6), | |
9659 CreateMockRead(*data.get(), 6), | |
9660 MockRead(ASYNC, 0, 0, 6), | |
9661 }; | |
9662 OrderedSocketData data_2( | |
9663 data_reads_2, arraysize(data_reads_2), | |
9664 data_writes_2, arraysize(data_writes_2)); | |
9665 | |
9666 SSLSocketDataProvider ssl(ASYNC, OK); | |
9667 ssl.SetNextProto(kProtoSPDY3); | |
9668 | |
9669 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | |
9670 StaticSocketDataProvider hanging_non_alternate_protocol_socket( | |
9671 NULL, 0, NULL, 0); | |
9672 hanging_non_alternate_protocol_socket.set_connect_data( | |
9673 never_finishing_connect); | |
9674 | |
9675 session_deps_.socket_factory->AddSocketDataProvider(&data_1); | |
9676 session_deps_.socket_factory->AddSocketDataProvider(&data_2); | |
9677 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
9678 session_deps_.socket_factory->AddSocketDataProvider( | |
9679 &hanging_non_alternate_protocol_socket); | |
9680 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9681 | |
9682 // First round should work and provide the Alternate-Protocol state. | |
9683 TestCompletionCallback callback_1; | |
9684 scoped_ptr<HttpTransaction> trans_1( | |
9685 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9686 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); | |
9687 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9688 EXPECT_EQ(OK, callback_1.WaitForResult()); | |
9689 | |
9690 // Second round should attempt a tunnel connect and get an auth challenge. | |
9691 TestCompletionCallback callback_2; | |
9692 scoped_ptr<HttpTransaction> trans_2( | |
9693 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9694 rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); | |
9695 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9696 EXPECT_EQ(OK, callback_2.WaitForResult()); | |
9697 const HttpResponseInfo* response = trans_2->GetResponseInfo(); | |
9698 ASSERT_TRUE(response != NULL); | |
9699 ASSERT_FALSE(response->auth_challenge.get() == NULL); | |
9700 | |
9701 // Restart with auth. Tunnel should work and response received. | |
9702 TestCompletionCallback callback_3; | |
9703 rv = trans_2->RestartWithAuth( | |
9704 AuthCredentials(kFoo, kBar), callback_3.callback()); | |
9705 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9706 EXPECT_EQ(OK, callback_3.WaitForResult()); | |
9707 | |
9708 // After all that work, these two lines (or actually, just the scheme) are | |
9709 // what this test is all about. Make sure it happens correctly. | |
9710 const GURL& request_url = auth_handler->request_url(); | |
9711 EXPECT_EQ("https", request_url.scheme()); | |
9712 EXPECT_EQ("www.google.com", request_url.host()); | |
9713 | |
9714 LoadTimingInfo load_timing_info; | |
9715 EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); | |
9716 TestLoadTimingNotReusedWithPac(load_timing_info, | |
9717 CONNECT_TIMING_HAS_SSL_TIMES); | |
9718 } | |
9719 | |
9720 // Test that if we cancel the transaction as the connection is completing, that | |
9721 // everything tears down correctly. | |
9722 TEST_F(HttpNetworkTransactionSpdy3Test, SimpleCancel) { | |
9723 // Setup everything about the connection to complete synchronously, so that | |
9724 // after calling HttpNetworkTransaction::Start, the only thing we're waiting | |
9725 // for is the callback from the HttpStreamRequest. | |
9726 // Then cancel the transaction. | |
9727 // Verify that we don't crash. | |
9728 MockConnect mock_connect(SYNCHRONOUS, OK); | |
9729 MockRead data_reads[] = { | |
9730 MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), | |
9731 MockRead(SYNCHRONOUS, "hello world"), | |
9732 MockRead(SYNCHRONOUS, OK), | |
9733 }; | |
9734 | |
9735 HttpRequestInfo request; | |
9736 request.method = "GET"; | |
9737 request.url = GURL("http://www.google.com/"); | |
9738 request.load_flags = 0; | |
9739 | |
9740 session_deps_.host_resolver->set_synchronous_mode(true); | |
9741 scoped_ptr<HttpTransaction> trans( | |
9742 new HttpNetworkTransaction(DEFAULT_PRIORITY, | |
9743 CreateSession(&session_deps_))); | |
9744 | |
9745 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
9746 data.set_connect_data(mock_connect); | |
9747 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
9748 | |
9749 TestCompletionCallback callback; | |
9750 | |
9751 CapturingBoundNetLog log; | |
9752 int rv = trans->Start(&request, callback.callback(), log.bound()); | |
9753 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9754 trans.reset(); // Cancel the transaction here. | |
9755 | |
9756 base::MessageLoop::current()->RunUntilIdle(); | |
9757 } | |
9758 | |
9759 // Test a basic GET request through a proxy. | |
9760 TEST_F(HttpNetworkTransactionSpdy3Test, ProxyGet) { | |
9761 session_deps_.proxy_service.reset( | |
9762 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | |
9763 CapturingBoundNetLog log; | |
9764 session_deps_.net_log = log.bound().net_log(); | |
9765 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9766 | |
9767 HttpRequestInfo request; | |
9768 request.method = "GET"; | |
9769 request.url = GURL("http://www.google.com/"); | |
9770 | |
9771 MockWrite data_writes1[] = { | |
9772 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | |
9773 "Host: www.google.com\r\n" | |
9774 "Proxy-Connection: keep-alive\r\n\r\n"), | |
9775 }; | |
9776 | |
9777 MockRead data_reads1[] = { | |
9778 MockRead("HTTP/1.1 200 OK\r\n"), | |
9779 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
9780 MockRead("Content-Length: 100\r\n\r\n"), | |
9781 MockRead(SYNCHRONOUS, OK), | |
9782 }; | |
9783 | |
9784 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
9785 data_writes1, arraysize(data_writes1)); | |
9786 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
9787 | |
9788 TestCompletionCallback callback1; | |
9789 | |
9790 scoped_ptr<HttpTransaction> trans( | |
9791 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9792 | |
9793 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
9794 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9795 | |
9796 rv = callback1.WaitForResult(); | |
9797 EXPECT_EQ(OK, rv); | |
9798 | |
9799 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
9800 ASSERT_TRUE(response != NULL); | |
9801 | |
9802 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
9803 EXPECT_EQ(200, response->headers->response_code()); | |
9804 EXPECT_EQ(100, response->headers->GetContentLength()); | |
9805 EXPECT_TRUE(response->was_fetched_via_proxy); | |
9806 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
9807 | |
9808 LoadTimingInfo load_timing_info; | |
9809 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
9810 TestLoadTimingNotReusedWithPac(load_timing_info, | |
9811 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | |
9812 } | |
9813 | |
9814 // Test a basic HTTPS GET request through a proxy. | |
9815 TEST_F(HttpNetworkTransactionSpdy3Test, ProxyTunnelGet) { | |
9816 session_deps_.proxy_service.reset( | |
9817 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | |
9818 CapturingBoundNetLog log; | |
9819 session_deps_.net_log = log.bound().net_log(); | |
9820 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9821 | |
9822 HttpRequestInfo request; | |
9823 request.method = "GET"; | |
9824 request.url = GURL("https://www.google.com/"); | |
9825 | |
9826 // Since we have proxy, should try to establish tunnel. | |
9827 MockWrite data_writes1[] = { | |
9828 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
9829 "Host: www.google.com\r\n" | |
9830 "Proxy-Connection: keep-alive\r\n\r\n"), | |
9831 | |
9832 MockWrite("GET / HTTP/1.1\r\n" | |
9833 "Host: www.google.com\r\n" | |
9834 "Connection: keep-alive\r\n\r\n"), | |
9835 }; | |
9836 | |
9837 MockRead data_reads1[] = { | |
9838 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), | |
9839 | |
9840 MockRead("HTTP/1.1 200 OK\r\n"), | |
9841 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
9842 MockRead("Content-Length: 100\r\n\r\n"), | |
9843 MockRead(SYNCHRONOUS, OK), | |
9844 }; | |
9845 | |
9846 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
9847 data_writes1, arraysize(data_writes1)); | |
9848 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
9849 SSLSocketDataProvider ssl(ASYNC, OK); | |
9850 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
9851 | |
9852 TestCompletionCallback callback1; | |
9853 | |
9854 scoped_ptr<HttpTransaction> trans( | |
9855 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9856 | |
9857 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
9858 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9859 | |
9860 rv = callback1.WaitForResult(); | |
9861 EXPECT_EQ(OK, rv); | |
9862 CapturingNetLog::CapturedEntryList entries; | |
9863 log.GetEntries(&entries); | |
9864 size_t pos = ExpectLogContainsSomewhere( | |
9865 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | |
9866 NetLog::PHASE_NONE); | |
9867 ExpectLogContainsSomewhere( | |
9868 entries, pos, | |
9869 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | |
9870 NetLog::PHASE_NONE); | |
9871 | |
9872 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
9873 ASSERT_TRUE(response != NULL); | |
9874 | |
9875 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
9876 EXPECT_EQ(200, response->headers->response_code()); | |
9877 EXPECT_EQ(100, response->headers->GetContentLength()); | |
9878 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
9879 EXPECT_TRUE(response->was_fetched_via_proxy); | |
9880 | |
9881 LoadTimingInfo load_timing_info; | |
9882 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
9883 TestLoadTimingNotReusedWithPac(load_timing_info, | |
9884 CONNECT_TIMING_HAS_SSL_TIMES); | |
9885 } | |
9886 | |
9887 // Test a basic HTTPS GET request through a proxy, but the server hangs up | |
9888 // while establishing the tunnel. | |
9889 TEST_F(HttpNetworkTransactionSpdy3Test, ProxyTunnelGetHangup) { | |
9890 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
9891 CapturingBoundNetLog log; | |
9892 session_deps_.net_log = log.bound().net_log(); | |
9893 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9894 | |
9895 HttpRequestInfo request; | |
9896 request.method = "GET"; | |
9897 request.url = GURL("https://www.google.com/"); | |
9898 | |
9899 // Since we have proxy, should try to establish tunnel. | |
9900 MockWrite data_writes1[] = { | |
9901 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
9902 "Host: www.google.com\r\n" | |
9903 "Proxy-Connection: keep-alive\r\n\r\n"), | |
9904 | |
9905 MockWrite("GET / HTTP/1.1\r\n" | |
9906 "Host: www.google.com\r\n" | |
9907 "Connection: keep-alive\r\n\r\n"), | |
9908 }; | |
9909 | |
9910 MockRead data_reads1[] = { | |
9911 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
9912 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), | |
9913 MockRead(ASYNC, 0, 0), // EOF | |
9914 }; | |
9915 | |
9916 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | |
9917 data_writes1, arraysize(data_writes1)); | |
9918 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
9919 SSLSocketDataProvider ssl(ASYNC, OK); | |
9920 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
9921 | |
9922 TestCompletionCallback callback1; | |
9923 | |
9924 scoped_ptr<HttpTransaction> trans( | |
9925 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
9926 | |
9927 int rv = trans->Start(&request, callback1.callback(), log.bound()); | |
9928 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9929 | |
9930 rv = callback1.WaitForResult(); | |
9931 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); | |
9932 CapturingNetLog::CapturedEntryList entries; | |
9933 log.GetEntries(&entries); | |
9934 size_t pos = ExpectLogContainsSomewhere( | |
9935 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | |
9936 NetLog::PHASE_NONE); | |
9937 ExpectLogContainsSomewhere( | |
9938 entries, pos, | |
9939 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | |
9940 NetLog::PHASE_NONE); | |
9941 } | |
9942 | |
9943 // Test for crbug.com/55424. | |
9944 TEST_F(HttpNetworkTransactionSpdy3Test, PreconnectWithExistingSpdySession) { | |
9945 | |
9946 scoped_ptr<SpdyFrame> req( | |
9947 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); | |
9948 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; | |
9949 | |
9950 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
9951 scoped_ptr<SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); | |
9952 MockRead spdy_reads[] = { | |
9953 CreateMockRead(*resp), | |
9954 CreateMockRead(*data), | |
9955 MockRead(ASYNC, 0, 0), | |
9956 }; | |
9957 | |
9958 DelayedSocketData spdy_data( | |
9959 1, // wait for one write to finish before reading. | |
9960 spdy_reads, arraysize(spdy_reads), | |
9961 spdy_writes, arraysize(spdy_writes)); | |
9962 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
9963 | |
9964 SSLSocketDataProvider ssl(ASYNC, OK); | |
9965 ssl.SetNextProto(kProtoSPDY3); | |
9966 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
9967 | |
9968 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
9969 | |
9970 // Set up an initial SpdySession in the pool to reuse. | |
9971 HostPortPair host_port_pair("www.google.com", 443); | |
9972 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
9973 kPrivacyModeDisabled); | |
9974 scoped_refptr<SpdySession> spdy_session = | |
9975 session->spdy_session_pool()->Get(key, BoundNetLog()); | |
9976 scoped_refptr<TransportSocketParams> transport_params( | |
9977 new TransportSocketParams(host_port_pair, MEDIUM, false, false, | |
9978 OnHostResolutionCallback())); | |
9979 TestCompletionCallback callback; | |
9980 | |
9981 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
9982 EXPECT_EQ(ERR_IO_PENDING, | |
9983 connection->Init(host_port_pair.ToString(), | |
9984 transport_params, | |
9985 LOWEST, | |
9986 callback.callback(), | |
9987 session->GetTransportSocketPool( | |
9988 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
9989 BoundNetLog())); | |
9990 EXPECT_EQ(OK, callback.WaitForResult()); | |
9991 spdy_session->InitializeWithSocket(connection.release(), false, OK); | |
9992 | |
9993 HttpRequestInfo request; | |
9994 request.method = "GET"; | |
9995 request.url = GURL("https://www.google.com/"); | |
9996 request.load_flags = 0; | |
9997 | |
9998 // This is the important line that marks this as a preconnect. | |
9999 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; | |
10000 | |
10001 scoped_ptr<HttpTransaction> trans( | |
10002 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
10003 | |
10004 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
10005 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10006 EXPECT_EQ(OK, callback.WaitForResult()); | |
10007 } | |
10008 | |
10009 // Given a net error, cause that error to be returned from the first Write() | |
10010 // call and verify that the HttpTransaction fails with that error. | |
10011 void HttpNetworkTransactionSpdy3Test::CheckErrorIsPassedBack( | |
10012 int error, IoMode mode) { | |
10013 net::HttpRequestInfo request_info; | |
10014 request_info.url = GURL("https://www.example.com/"); | |
10015 request_info.method = "GET"; | |
10016 request_info.load_flags = net::LOAD_NORMAL; | |
10017 | |
10018 | |
10019 SSLSocketDataProvider ssl_data(mode, OK); | |
10020 net::MockWrite data_writes[] = { | |
10021 net::MockWrite(mode, error), | |
10022 }; | |
10023 net::StaticSocketDataProvider data(NULL, 0, | |
10024 data_writes, arraysize(data_writes)); | |
10025 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
10026 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); | |
10027 | |
10028 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10029 scoped_ptr<HttpTransaction> trans( | |
10030 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
10031 | |
10032 TestCompletionCallback callback; | |
10033 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); | |
10034 if (rv == net::ERR_IO_PENDING) | |
10035 rv = callback.WaitForResult(); | |
10036 ASSERT_EQ(error, rv); | |
10037 } | |
10038 | |
10039 TEST_F(HttpNetworkTransactionSpdy3Test, SSLWriteCertError) { | |
10040 // Just check a grab bag of cert errors. | |
10041 static const int kErrors[] = { | |
10042 ERR_CERT_COMMON_NAME_INVALID, | |
10043 ERR_CERT_AUTHORITY_INVALID, | |
10044 ERR_CERT_DATE_INVALID, | |
10045 }; | |
10046 for (size_t i = 0; i < arraysize(kErrors); i++) { | |
10047 CheckErrorIsPassedBack(kErrors[i], ASYNC); | |
10048 CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); | |
10049 } | |
10050 } | |
10051 | |
10052 // Ensure that a client certificate is removed from the SSL client auth | |
10053 // cache when: | |
10054 // 1) No proxy is involved. | |
10055 // 2) TLS False Start is disabled. | |
10056 // 3) The initial TLS handshake requests a client certificate. | |
10057 // 4) The client supplies an invalid/unacceptable certificate. | |
10058 TEST_F(HttpNetworkTransactionSpdy3Test, | |
10059 ClientAuthCertCache_Direct_NoFalseStart) { | |
10060 net::HttpRequestInfo request_info; | |
10061 request_info.url = GURL("https://www.example.com/"); | |
10062 request_info.method = "GET"; | |
10063 request_info.load_flags = net::LOAD_NORMAL; | |
10064 | |
10065 | |
10066 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); | |
10067 cert_request->host_and_port = "www.example.com:443"; | |
10068 | |
10069 // [ssl_]data1 contains the data for the first SSL handshake. When a | |
10070 // CertificateRequest is received for the first time, the handshake will | |
10071 // be aborted to allow the caller to provide a certificate. | |
10072 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
10073 ssl_data1.cert_request_info = cert_request.get(); | |
10074 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); | |
10075 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); | |
10076 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
10077 | |
10078 // [ssl_]data2 contains the data for the second SSL handshake. When TLS | |
10079 // False Start is not being used, the result of the SSL handshake will be | |
10080 // returned as part of the SSLClientSocket::Connect() call. This test | |
10081 // matches the result of a server sending a handshake_failure alert, | |
10082 // rather than a Finished message, because it requires a client | |
10083 // certificate and none was supplied. | |
10084 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); | |
10085 ssl_data2.cert_request_info = cert_request.get(); | |
10086 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); | |
10087 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); | |
10088 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
10089 | |
10090 // [ssl_]data3 contains the data for the third SSL handshake. When a | |
10091 // connection to a server fails during an SSL handshake, | |
10092 // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous | |
10093 // connection was attempted with TLSv1.1. This is transparent to the caller | |
10094 // of the HttpNetworkTransaction. Because this test failure is due to | |
10095 // requiring a client certificate, this fallback handshake should also | |
10096 // fail. | |
10097 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); | |
10098 ssl_data3.cert_request_info = cert_request.get(); | |
10099 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); | |
10100 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); | |
10101 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
10102 | |
10103 // [ssl_]data4 contains the data for the fourth SSL handshake. When a | |
10104 // connection to a server fails during an SSL handshake, | |
10105 // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous | |
10106 // connection was attempted with TLSv1. This is transparent to the caller | |
10107 // of the HttpNetworkTransaction. Because this test failure is due to | |
10108 // requiring a client certificate, this fallback handshake should also | |
10109 // fail. | |
10110 SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); | |
10111 ssl_data4.cert_request_info = cert_request.get(); | |
10112 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); | |
10113 net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); | |
10114 session_deps_.socket_factory->AddSocketDataProvider(&data4); | |
10115 | |
10116 // Need one more if TLSv1.2 is enabled. | |
10117 SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); | |
10118 ssl_data5.cert_request_info = cert_request.get(); | |
10119 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); | |
10120 net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); | |
10121 session_deps_.socket_factory->AddSocketDataProvider(&data5); | |
10122 | |
10123 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10124 scoped_ptr<HttpTransaction> trans( | |
10125 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
10126 | |
10127 // Begin the SSL handshake with the peer. This consumes ssl_data1. | |
10128 TestCompletionCallback callback; | |
10129 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); | |
10130 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
10131 | |
10132 // Complete the SSL handshake, which should abort due to requiring a | |
10133 // client certificate. | |
10134 rv = callback.WaitForResult(); | |
10135 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); | |
10136 | |
10137 // Indicate that no certificate should be supplied. From the perspective | |
10138 // of SSLClientCertCache, NULL is just as meaningful as a real | |
10139 // certificate, so this is the same as supply a | |
10140 // legitimate-but-unacceptable certificate. | |
10141 rv = trans->RestartWithCertificate(NULL, callback.callback()); | |
10142 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
10143 | |
10144 // Ensure the certificate was added to the client auth cache before | |
10145 // allowing the connection to continue restarting. | |
10146 scoped_refptr<X509Certificate> client_cert; | |
10147 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
10148 &client_cert)); | |
10149 ASSERT_EQ(NULL, client_cert.get()); | |
10150 | |
10151 // Restart the handshake. This will consume ssl_data2, which fails, and | |
10152 // then consume ssl_data3 and ssl_data4, both of which should also fail. | |
10153 // The result code is checked against what ssl_data4 should return. | |
10154 rv = callback.WaitForResult(); | |
10155 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | |
10156 | |
10157 // Ensure that the client certificate is removed from the cache on a | |
10158 // handshake failure. | |
10159 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
10160 &client_cert)); | |
10161 } | |
10162 | |
10163 // Ensure that a client certificate is removed from the SSL client auth | |
10164 // cache when: | |
10165 // 1) No proxy is involved. | |
10166 // 2) TLS False Start is enabled. | |
10167 // 3) The initial TLS handshake requests a client certificate. | |
10168 // 4) The client supplies an invalid/unacceptable certificate. | |
10169 TEST_F(HttpNetworkTransactionSpdy3Test, ClientAuthCertCache_Direct_FalseStart) { | |
10170 net::HttpRequestInfo request_info; | |
10171 request_info.url = GURL("https://www.example.com/"); | |
10172 request_info.method = "GET"; | |
10173 request_info.load_flags = net::LOAD_NORMAL; | |
10174 | |
10175 | |
10176 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); | |
10177 cert_request->host_and_port = "www.example.com:443"; | |
10178 | |
10179 // When TLS False Start is used, SSLClientSocket::Connect() calls will | |
10180 // return successfully after reading up to the peer's Certificate message. | |
10181 // This is to allow the caller to call SSLClientSocket::Write(), which can | |
10182 // enqueue application data to be sent in the same packet as the | |
10183 // ChangeCipherSpec and Finished messages. | |
10184 // The actual handshake will be finished when SSLClientSocket::Read() is | |
10185 // called, which expects to process the peer's ChangeCipherSpec and | |
10186 // Finished messages. If there was an error negotiating with the peer, | |
10187 // such as due to the peer requiring a client certificate when none was | |
10188 // supplied, the alert sent by the peer won't be processed until Read() is | |
10189 // called. | |
10190 | |
10191 // Like the non-False Start case, when a client certificate is requested by | |
10192 // the peer, the handshake is aborted during the Connect() call. | |
10193 // [ssl_]data1 represents the initial SSL handshake with the peer. | |
10194 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
10195 ssl_data1.cert_request_info = cert_request.get(); | |
10196 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); | |
10197 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); | |
10198 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
10199 | |
10200 // When a client certificate is supplied, Connect() will not be aborted | |
10201 // when the peer requests the certificate. Instead, the handshake will | |
10202 // artificially succeed, allowing the caller to write the HTTP request to | |
10203 // the socket. The handshake messages are not processed until Read() is | |
10204 // called, which then detects that the handshake was aborted, due to the | |
10205 // peer sending a handshake_failure because it requires a client | |
10206 // certificate. | |
10207 SSLSocketDataProvider ssl_data2(ASYNC, net::OK); | |
10208 ssl_data2.cert_request_info = cert_request.get(); | |
10209 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); | |
10210 net::MockRead data2_reads[] = { | |
10211 net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), | |
10212 }; | |
10213 net::StaticSocketDataProvider data2( | |
10214 data2_reads, arraysize(data2_reads), NULL, 0); | |
10215 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
10216 | |
10217 // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is | |
10218 // the data for the SSL handshake once the TLSv1.1 connection falls back to | |
10219 // TLSv1. It has the same behaviour as [ssl_]data2. | |
10220 SSLSocketDataProvider ssl_data3(ASYNC, net::OK); | |
10221 ssl_data3.cert_request_info = cert_request.get(); | |
10222 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); | |
10223 net::StaticSocketDataProvider data3( | |
10224 data2_reads, arraysize(data2_reads), NULL, 0); | |
10225 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
10226 | |
10227 // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection | |
10228 // falls back to SSLv3. It has the same behaviour as [ssl_]data2. | |
10229 SSLSocketDataProvider ssl_data4(ASYNC, net::OK); | |
10230 ssl_data4.cert_request_info = cert_request.get(); | |
10231 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); | |
10232 net::StaticSocketDataProvider data4( | |
10233 data2_reads, arraysize(data2_reads), NULL, 0); | |
10234 session_deps_.socket_factory->AddSocketDataProvider(&data4); | |
10235 | |
10236 // Need one more if TLSv1.2 is enabled. | |
10237 SSLSocketDataProvider ssl_data5(ASYNC, net::OK); | |
10238 ssl_data5.cert_request_info = cert_request.get(); | |
10239 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); | |
10240 net::StaticSocketDataProvider data5( | |
10241 data2_reads, arraysize(data2_reads), NULL, 0); | |
10242 session_deps_.socket_factory->AddSocketDataProvider(&data5); | |
10243 | |
10244 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10245 scoped_ptr<HttpTransaction> trans( | |
10246 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
10247 | |
10248 // Begin the initial SSL handshake. | |
10249 TestCompletionCallback callback; | |
10250 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); | |
10251 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
10252 | |
10253 // Complete the SSL handshake, which should abort due to requiring a | |
10254 // client certificate. | |
10255 rv = callback.WaitForResult(); | |
10256 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); | |
10257 | |
10258 // Indicate that no certificate should be supplied. From the perspective | |
10259 // of SSLClientCertCache, NULL is just as meaningful as a real | |
10260 // certificate, so this is the same as supply a | |
10261 // legitimate-but-unacceptable certificate. | |
10262 rv = trans->RestartWithCertificate(NULL, callback.callback()); | |
10263 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
10264 | |
10265 // Ensure the certificate was added to the client auth cache before | |
10266 // allowing the connection to continue restarting. | |
10267 scoped_refptr<X509Certificate> client_cert; | |
10268 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
10269 &client_cert)); | |
10270 ASSERT_EQ(NULL, client_cert.get()); | |
10271 | |
10272 | |
10273 // Restart the handshake. This will consume ssl_data2, which fails, and | |
10274 // then consume ssl_data3 and ssl_data4, both of which should also fail. | |
10275 // The result code is checked against what ssl_data4 should return. | |
10276 rv = callback.WaitForResult(); | |
10277 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | |
10278 | |
10279 // Ensure that the client certificate is removed from the cache on a | |
10280 // handshake failure. | |
10281 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
10282 &client_cert)); | |
10283 } | |
10284 | |
10285 // Ensure that a client certificate is removed from the SSL client auth | |
10286 // cache when: | |
10287 // 1) An HTTPS proxy is involved. | |
10288 // 3) The HTTPS proxy requests a client certificate. | |
10289 // 4) The client supplies an invalid/unacceptable certificate for the | |
10290 // proxy. | |
10291 // The test is repeated twice, first for connecting to an HTTPS endpoint, | |
10292 // then for connecting to an HTTP endpoint. | |
10293 TEST_F(HttpNetworkTransactionSpdy3Test, ClientAuthCertCache_Proxy_Fail) { | |
10294 session_deps_.proxy_service.reset( | |
10295 ProxyService::CreateFixed("https://proxy:70")); | |
10296 CapturingBoundNetLog log; | |
10297 session_deps_.net_log = log.bound().net_log(); | |
10298 | |
10299 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); | |
10300 cert_request->host_and_port = "proxy:70"; | |
10301 | |
10302 // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of | |
10303 // [ssl_]data[1-3]. Rather than represending the endpoint | |
10304 // (www.example.com:443), they represent failures with the HTTPS proxy | |
10305 // (proxy:70). | |
10306 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
10307 ssl_data1.cert_request_info = cert_request.get(); | |
10308 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); | |
10309 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); | |
10310 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
10311 | |
10312 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); | |
10313 ssl_data2.cert_request_info = cert_request.get(); | |
10314 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); | |
10315 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); | |
10316 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
10317 | |
10318 // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. | |
10319 #if 0 | |
10320 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); | |
10321 ssl_data3.cert_request_info = cert_request.get(); | |
10322 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); | |
10323 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); | |
10324 session_deps_.socket_factory->AddSocketDataProvider(&data3); | |
10325 #endif | |
10326 | |
10327 net::HttpRequestInfo requests[2]; | |
10328 requests[0].url = GURL("https://www.example.com/"); | |
10329 requests[0].method = "GET"; | |
10330 requests[0].load_flags = net::LOAD_NORMAL; | |
10331 | |
10332 requests[1].url = GURL("http://www.example.com/"); | |
10333 requests[1].method = "GET"; | |
10334 requests[1].load_flags = net::LOAD_NORMAL; | |
10335 | |
10336 for (size_t i = 0; i < arraysize(requests); ++i) { | |
10337 session_deps_.socket_factory->ResetNextMockIndexes(); | |
10338 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10339 scoped_ptr<HttpNetworkTransaction> trans( | |
10340 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
10341 | |
10342 // Begin the SSL handshake with the proxy. | |
10343 TestCompletionCallback callback; | |
10344 int rv = trans->Start( | |
10345 &requests[i], callback.callback(), net::BoundNetLog()); | |
10346 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
10347 | |
10348 // Complete the SSL handshake, which should abort due to requiring a | |
10349 // client certificate. | |
10350 rv = callback.WaitForResult(); | |
10351 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); | |
10352 | |
10353 // Indicate that no certificate should be supplied. From the perspective | |
10354 // of SSLClientCertCache, NULL is just as meaningful as a real | |
10355 // certificate, so this is the same as supply a | |
10356 // legitimate-but-unacceptable certificate. | |
10357 rv = trans->RestartWithCertificate(NULL, callback.callback()); | |
10358 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
10359 | |
10360 // Ensure the certificate was added to the client auth cache before | |
10361 // allowing the connection to continue restarting. | |
10362 scoped_refptr<X509Certificate> client_cert; | |
10363 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("proxy:70", | |
10364 &client_cert)); | |
10365 ASSERT_EQ(NULL, client_cert.get()); | |
10366 // Ensure the certificate was NOT cached for the endpoint. This only | |
10367 // applies to HTTPS requests, but is fine to check for HTTP requests. | |
10368 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
10369 &client_cert)); | |
10370 | |
10371 // Restart the handshake. This will consume ssl_data2, which fails, and | |
10372 // then consume ssl_data3, which should also fail. The result code is | |
10373 // checked against what ssl_data3 should return. | |
10374 rv = callback.WaitForResult(); | |
10375 ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); | |
10376 | |
10377 // Now that the new handshake has failed, ensure that the client | |
10378 // certificate was removed from the client auth cache. | |
10379 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70", | |
10380 &client_cert)); | |
10381 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
10382 &client_cert)); | |
10383 } | |
10384 } | |
10385 | |
10386 TEST_F(HttpNetworkTransactionSpdy3Test, UseIPConnectionPooling) { | |
10387 HttpStreamFactory::set_use_alternate_protocols(true); | |
10388 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
10389 | |
10390 // Set up a special HttpNetworkSession with a MockCachingHostResolver. | |
10391 session_deps_.host_resolver.reset(new MockCachingHostResolver()); | |
10392 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10393 SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); | |
10394 pool_peer.DisableDomainAuthenticationVerification(); | |
10395 | |
10396 SSLSocketDataProvider ssl(ASYNC, OK); | |
10397 ssl.SetNextProto(kProtoSPDY3); | |
10398 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
10399 | |
10400 scoped_ptr<SpdyFrame> host1_req( | |
10401 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); | |
10402 scoped_ptr<SpdyFrame> host2_req( | |
10403 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); | |
10404 MockWrite spdy_writes[] = { | |
10405 CreateMockWrite(*host1_req, 1), | |
10406 CreateMockWrite(*host2_req, 4), | |
10407 }; | |
10408 scoped_ptr<SpdyFrame> host1_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10409 scoped_ptr<SpdyFrame> host1_resp_body(ConstructSpdyBodyFrame(1, true)); | |
10410 scoped_ptr<SpdyFrame> host2_resp(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
10411 scoped_ptr<SpdyFrame> host2_resp_body(ConstructSpdyBodyFrame(3, true)); | |
10412 MockRead spdy_reads[] = { | |
10413 CreateMockRead(*host1_resp, 2), | |
10414 CreateMockRead(*host1_resp_body, 3), | |
10415 CreateMockRead(*host2_resp, 5), | |
10416 CreateMockRead(*host2_resp_body, 6), | |
10417 MockRead(ASYNC, 0, 7), | |
10418 }; | |
10419 | |
10420 IPAddressNumber ip; | |
10421 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); | |
10422 IPEndPoint peer_addr = IPEndPoint(ip, 443); | |
10423 MockConnect connect(ASYNC, OK, peer_addr); | |
10424 OrderedSocketData spdy_data( | |
10425 connect, | |
10426 spdy_reads, arraysize(spdy_reads), | |
10427 spdy_writes, arraysize(spdy_writes)); | |
10428 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
10429 | |
10430 TestCompletionCallback callback; | |
10431 HttpRequestInfo request1; | |
10432 request1.method = "GET"; | |
10433 request1.url = GURL("https://www.google.com/"); | |
10434 request1.load_flags = 0; | |
10435 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); | |
10436 | |
10437 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); | |
10438 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10439 EXPECT_EQ(OK, callback.WaitForResult()); | |
10440 | |
10441 const HttpResponseInfo* response = trans1.GetResponseInfo(); | |
10442 ASSERT_TRUE(response != NULL); | |
10443 ASSERT_TRUE(response->headers.get() != NULL); | |
10444 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
10445 | |
10446 std::string response_data; | |
10447 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); | |
10448 EXPECT_EQ("hello!", response_data); | |
10449 | |
10450 // Preload www.gmail.com into HostCache. | |
10451 HostPortPair host_port("www.gmail.com", 443); | |
10452 HostResolver::RequestInfo resolve_info(host_port); | |
10453 AddressList ignored; | |
10454 rv = session_deps_.host_resolver->Resolve(resolve_info, &ignored, | |
10455 callback.callback(), NULL, | |
10456 BoundNetLog()); | |
10457 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10458 rv = callback.WaitForResult(); | |
10459 EXPECT_EQ(OK, rv); | |
10460 | |
10461 HttpRequestInfo request2; | |
10462 request2.method = "GET"; | |
10463 request2.url = GURL("https://www.gmail.com/"); | |
10464 request2.load_flags = 0; | |
10465 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); | |
10466 | |
10467 rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); | |
10468 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10469 EXPECT_EQ(OK, callback.WaitForResult()); | |
10470 | |
10471 response = trans2.GetResponseInfo(); | |
10472 ASSERT_TRUE(response != NULL); | |
10473 ASSERT_TRUE(response->headers.get() != NULL); | |
10474 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
10475 EXPECT_TRUE(response->was_fetched_via_spdy); | |
10476 EXPECT_TRUE(response->was_npn_negotiated); | |
10477 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | |
10478 EXPECT_EQ("hello!", response_data); | |
10479 } | |
10480 | |
10481 TEST_F(HttpNetworkTransactionSpdy3Test, UseIPConnectionPoolingAfterResolution) { | |
10482 HttpStreamFactory::set_use_alternate_protocols(true); | |
10483 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
10484 | |
10485 // Set up a special HttpNetworkSession with a MockCachingHostResolver. | |
10486 session_deps_.host_resolver.reset(new MockCachingHostResolver()); | |
10487 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10488 SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); | |
10489 pool_peer.DisableDomainAuthenticationVerification(); | |
10490 | |
10491 SSLSocketDataProvider ssl(ASYNC, OK); | |
10492 ssl.SetNextProto(kProtoSPDY3); | |
10493 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
10494 | |
10495 scoped_ptr<SpdyFrame> host1_req( | |
10496 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); | |
10497 scoped_ptr<SpdyFrame> host2_req( | |
10498 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); | |
10499 MockWrite spdy_writes[] = { | |
10500 CreateMockWrite(*host1_req, 1), | |
10501 CreateMockWrite(*host2_req, 4), | |
10502 }; | |
10503 scoped_ptr<SpdyFrame> host1_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10504 scoped_ptr<SpdyFrame> host1_resp_body(ConstructSpdyBodyFrame(1, true)); | |
10505 scoped_ptr<SpdyFrame> host2_resp(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
10506 scoped_ptr<SpdyFrame> host2_resp_body(ConstructSpdyBodyFrame(3, true)); | |
10507 MockRead spdy_reads[] = { | |
10508 CreateMockRead(*host1_resp, 2), | |
10509 CreateMockRead(*host1_resp_body, 3), | |
10510 CreateMockRead(*host2_resp, 5), | |
10511 CreateMockRead(*host2_resp_body, 6), | |
10512 MockRead(ASYNC, 0, 7), | |
10513 }; | |
10514 | |
10515 IPAddressNumber ip; | |
10516 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); | |
10517 IPEndPoint peer_addr = IPEndPoint(ip, 443); | |
10518 MockConnect connect(ASYNC, OK, peer_addr); | |
10519 OrderedSocketData spdy_data( | |
10520 connect, | |
10521 spdy_reads, arraysize(spdy_reads), | |
10522 spdy_writes, arraysize(spdy_writes)); | |
10523 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
10524 | |
10525 TestCompletionCallback callback; | |
10526 HttpRequestInfo request1; | |
10527 request1.method = "GET"; | |
10528 request1.url = GURL("https://www.google.com/"); | |
10529 request1.load_flags = 0; | |
10530 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); | |
10531 | |
10532 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); | |
10533 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10534 EXPECT_EQ(OK, callback.WaitForResult()); | |
10535 | |
10536 const HttpResponseInfo* response = trans1.GetResponseInfo(); | |
10537 ASSERT_TRUE(response != NULL); | |
10538 ASSERT_TRUE(response->headers.get() != NULL); | |
10539 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
10540 | |
10541 std::string response_data; | |
10542 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); | |
10543 EXPECT_EQ("hello!", response_data); | |
10544 | |
10545 HttpRequestInfo request2; | |
10546 request2.method = "GET"; | |
10547 request2.url = GURL("https://www.gmail.com/"); | |
10548 request2.load_flags = 0; | |
10549 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); | |
10550 | |
10551 rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); | |
10552 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10553 EXPECT_EQ(OK, callback.WaitForResult()); | |
10554 | |
10555 response = trans2.GetResponseInfo(); | |
10556 ASSERT_TRUE(response != NULL); | |
10557 ASSERT_TRUE(response->headers.get() != NULL); | |
10558 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
10559 EXPECT_TRUE(response->was_fetched_via_spdy); | |
10560 EXPECT_TRUE(response->was_npn_negotiated); | |
10561 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | |
10562 EXPECT_EQ("hello!", response_data); | |
10563 } | |
10564 | |
10565 class OneTimeCachingHostResolver : public net::HostResolver { | |
10566 public: | |
10567 explicit OneTimeCachingHostResolver(const HostPortPair& host_port) | |
10568 : host_port_(host_port) {} | |
10569 virtual ~OneTimeCachingHostResolver() {} | |
10570 | |
10571 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } | |
10572 | |
10573 // HostResolver methods: | |
10574 virtual int Resolve(const RequestInfo& info, | |
10575 AddressList* addresses, | |
10576 const CompletionCallback& callback, | |
10577 RequestHandle* out_req, | |
10578 const BoundNetLog& net_log) OVERRIDE { | |
10579 return host_resolver_.Resolve( | |
10580 info, addresses, callback, out_req, net_log); | |
10581 } | |
10582 | |
10583 virtual int ResolveFromCache(const RequestInfo& info, | |
10584 AddressList* addresses, | |
10585 const BoundNetLog& net_log) OVERRIDE { | |
10586 int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); | |
10587 if (rv == OK && info.host_port_pair().Equals(host_port_)) | |
10588 host_resolver_.GetHostCache()->clear(); | |
10589 return rv; | |
10590 } | |
10591 | |
10592 virtual void CancelRequest(RequestHandle req) OVERRIDE { | |
10593 host_resolver_.CancelRequest(req); | |
10594 } | |
10595 | |
10596 MockCachingHostResolver* GetMockHostResolver() { | |
10597 return &host_resolver_; | |
10598 } | |
10599 | |
10600 private: | |
10601 MockCachingHostResolver host_resolver_; | |
10602 const HostPortPair host_port_; | |
10603 }; | |
10604 | |
10605 TEST_F(HttpNetworkTransactionSpdy3Test, | |
10606 UseIPConnectionPoolingWithHostCacheExpiration) { | |
10607 HttpStreamFactory::set_use_alternate_protocols(true); | |
10608 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
10609 | |
10610 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. | |
10611 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); | |
10612 HttpNetworkSession::Params params = | |
10613 SpdySessionDependencies::CreateSessionParams(&session_deps_); | |
10614 params.host_resolver = &host_resolver; | |
10615 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10616 SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); | |
10617 pool_peer.DisableDomainAuthenticationVerification(); | |
10618 | |
10619 SSLSocketDataProvider ssl(ASYNC, OK); | |
10620 ssl.SetNextProto(kProtoSPDY3); | |
10621 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
10622 | |
10623 scoped_ptr<SpdyFrame> host1_req( | |
10624 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); | |
10625 scoped_ptr<SpdyFrame> host2_req( | |
10626 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); | |
10627 MockWrite spdy_writes[] = { | |
10628 CreateMockWrite(*host1_req, 1), | |
10629 CreateMockWrite(*host2_req, 4), | |
10630 }; | |
10631 scoped_ptr<SpdyFrame> host1_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10632 scoped_ptr<SpdyFrame> host1_resp_body(ConstructSpdyBodyFrame(1, true)); | |
10633 scoped_ptr<SpdyFrame> host2_resp(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
10634 scoped_ptr<SpdyFrame> host2_resp_body(ConstructSpdyBodyFrame(3, true)); | |
10635 MockRead spdy_reads[] = { | |
10636 CreateMockRead(*host1_resp, 2), | |
10637 CreateMockRead(*host1_resp_body, 3), | |
10638 CreateMockRead(*host2_resp, 5), | |
10639 CreateMockRead(*host2_resp_body, 6), | |
10640 MockRead(ASYNC, 0, 7), | |
10641 }; | |
10642 | |
10643 IPAddressNumber ip; | |
10644 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); | |
10645 IPEndPoint peer_addr = IPEndPoint(ip, 443); | |
10646 MockConnect connect(ASYNC, OK, peer_addr); | |
10647 OrderedSocketData spdy_data( | |
10648 connect, | |
10649 spdy_reads, arraysize(spdy_reads), | |
10650 spdy_writes, arraysize(spdy_writes)); | |
10651 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); | |
10652 | |
10653 TestCompletionCallback callback; | |
10654 HttpRequestInfo request1; | |
10655 request1.method = "GET"; | |
10656 request1.url = GURL("https://www.google.com/"); | |
10657 request1.load_flags = 0; | |
10658 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); | |
10659 | |
10660 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); | |
10661 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10662 EXPECT_EQ(OK, callback.WaitForResult()); | |
10663 | |
10664 const HttpResponseInfo* response = trans1.GetResponseInfo(); | |
10665 ASSERT_TRUE(response != NULL); | |
10666 ASSERT_TRUE(response->headers.get() != NULL); | |
10667 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
10668 | |
10669 std::string response_data; | |
10670 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); | |
10671 EXPECT_EQ("hello!", response_data); | |
10672 | |
10673 // Preload cache entries into HostCache. | |
10674 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); | |
10675 AddressList ignored; | |
10676 rv = host_resolver.Resolve(resolve_info, &ignored, callback.callback(), NULL, | |
10677 BoundNetLog()); | |
10678 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10679 rv = callback.WaitForResult(); | |
10680 EXPECT_EQ(OK, rv); | |
10681 | |
10682 HttpRequestInfo request2; | |
10683 request2.method = "GET"; | |
10684 request2.url = GURL("https://www.gmail.com/"); | |
10685 request2.load_flags = 0; | |
10686 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); | |
10687 | |
10688 rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); | |
10689 EXPECT_EQ(ERR_IO_PENDING, rv); | |
10690 EXPECT_EQ(OK, callback.WaitForResult()); | |
10691 | |
10692 response = trans2.GetResponseInfo(); | |
10693 ASSERT_TRUE(response != NULL); | |
10694 ASSERT_TRUE(response->headers.get() != NULL); | |
10695 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
10696 EXPECT_TRUE(response->was_fetched_via_spdy); | |
10697 EXPECT_TRUE(response->was_npn_negotiated); | |
10698 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | |
10699 EXPECT_EQ("hello!", response_data); | |
10700 } | |
10701 | |
10702 TEST_F(HttpNetworkTransactionSpdy3Test, ReadPipelineEvictionFallback) { | |
10703 MockRead data_reads1[] = { | |
10704 MockRead(SYNCHRONOUS, ERR_PIPELINE_EVICTION), | |
10705 }; | |
10706 MockRead data_reads2[] = { | |
10707 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
10708 MockRead("hello world"), | |
10709 MockRead(SYNCHRONOUS, OK), | |
10710 }; | |
10711 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), NULL, 0); | |
10712 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), NULL, 0); | |
10713 StaticSocketDataProvider* data[] = { &data1, &data2 }; | |
10714 | |
10715 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | |
10716 | |
10717 EXPECT_EQ(OK, out.rv); | |
10718 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | |
10719 EXPECT_EQ("hello world", out.response_data); | |
10720 } | |
10721 | |
10722 TEST_F(HttpNetworkTransactionSpdy3Test, SendPipelineEvictionFallback) { | |
10723 MockWrite data_writes1[] = { | |
10724 MockWrite(SYNCHRONOUS, ERR_PIPELINE_EVICTION), | |
10725 }; | |
10726 MockWrite data_writes2[] = { | |
10727 MockWrite("GET / HTTP/1.1\r\n" | |
10728 "Host: www.google.com\r\n" | |
10729 "Connection: keep-alive\r\n\r\n"), | |
10730 }; | |
10731 MockRead data_reads2[] = { | |
10732 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
10733 MockRead("hello world"), | |
10734 MockRead(SYNCHRONOUS, OK), | |
10735 }; | |
10736 StaticSocketDataProvider data1(NULL, 0, | |
10737 data_writes1, arraysize(data_writes1)); | |
10738 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
10739 data_writes2, arraysize(data_writes2)); | |
10740 StaticSocketDataProvider* data[] = { &data1, &data2 }; | |
10741 | |
10742 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | |
10743 | |
10744 EXPECT_EQ(OK, out.rv); | |
10745 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | |
10746 EXPECT_EQ("hello world", out.response_data); | |
10747 } | |
10748 | |
10749 TEST_F(HttpNetworkTransactionSpdy3Test, DoNotUseSpdySessionForHttp) { | |
10750 const std::string https_url = "https://www.google.com/"; | |
10751 const std::string httpUrl = "http://www.google.com:443/"; | |
10752 | |
10753 // SPDY GET for HTTPS URL | |
10754 scoped_ptr<SpdyFrame> req1( | |
10755 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | |
10756 | |
10757 MockWrite writes1[] = { | |
10758 CreateMockWrite(*req1, 0), | |
10759 }; | |
10760 | |
10761 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10762 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); | |
10763 MockRead reads1[] = { | |
10764 CreateMockRead(*resp1, 1), | |
10765 CreateMockRead(*body1, 2), | |
10766 MockRead(ASYNC, ERR_IO_PENDING, 3) | |
10767 }; | |
10768 | |
10769 DelayedSocketData data1( | |
10770 1, reads1, arraysize(reads1), | |
10771 writes1, arraysize(writes1)); | |
10772 MockConnect connect_data1(ASYNC, OK); | |
10773 data1.set_connect_data(connect_data1); | |
10774 | |
10775 // HTTP GET for the HTTP URL | |
10776 MockWrite writes2[] = { | |
10777 MockWrite(ASYNC, 4, | |
10778 "GET / HTTP/1.1\r\n" | |
10779 "Host: www.google.com:443\r\n" | |
10780 "Connection: keep-alive\r\n\r\n"), | |
10781 }; | |
10782 | |
10783 MockRead reads2[] = { | |
10784 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
10785 MockRead(ASYNC, 6, "hello"), | |
10786 MockRead(ASYNC, 7, OK), | |
10787 }; | |
10788 | |
10789 DelayedSocketData data2( | |
10790 1, reads2, arraysize(reads2), | |
10791 writes2, arraysize(writes2)); | |
10792 | |
10793 SSLSocketDataProvider ssl(ASYNC, OK); | |
10794 ssl.SetNextProto(kProtoSPDY3); | |
10795 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
10796 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
10797 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
10798 | |
10799 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10800 | |
10801 // Start the first transaction to set up the SpdySession | |
10802 HttpRequestInfo request1; | |
10803 request1.method = "GET"; | |
10804 request1.url = GURL(https_url); | |
10805 request1.load_flags = 0; | |
10806 HttpNetworkTransaction trans1(LOWEST, session.get()); | |
10807 TestCompletionCallback callback1; | |
10808 EXPECT_EQ(ERR_IO_PENDING, | |
10809 trans1.Start(&request1, callback1.callback(), BoundNetLog())); | |
10810 base::MessageLoop::current()->RunUntilIdle(); | |
10811 | |
10812 EXPECT_EQ(OK, callback1.WaitForResult()); | |
10813 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); | |
10814 | |
10815 // Now, start the HTTP request | |
10816 HttpRequestInfo request2; | |
10817 request2.method = "GET"; | |
10818 request2.url = GURL(httpUrl); | |
10819 request2.load_flags = 0; | |
10820 HttpNetworkTransaction trans2(MEDIUM, session.get()); | |
10821 TestCompletionCallback callback2; | |
10822 EXPECT_EQ(ERR_IO_PENDING, | |
10823 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | |
10824 base::MessageLoop::current()->RunUntilIdle(); | |
10825 | |
10826 EXPECT_EQ(OK, callback2.WaitForResult()); | |
10827 EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); | |
10828 } | |
10829 | |
10830 TEST_F(HttpNetworkTransactionSpdy3Test, DoNotUseSpdySessionForHttpOverTunnel) { | |
10831 const std::string https_url = "https://www.google.com/"; | |
10832 const std::string httpUrl = "http://www.google.com:443/"; | |
10833 | |
10834 // SPDY GET for HTTPS URL (through CONNECT tunnel) | |
10835 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); | |
10836 scoped_ptr<SpdyFrame> req1( | |
10837 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | |
10838 | |
10839 scoped_ptr<SpdyFrame> wrapped_req1(ConstructWrappedSpdyFrame(req1, 1)); | |
10840 // SPDY GET for HTTP URL (through the proxy, but not the tunnel) | |
10841 scoped_ptr<SpdyFrame> req2( | |
10842 spdy_util_.ConstructSpdyGet(httpUrl.c_str(), false, 3, MEDIUM)); | |
10843 | |
10844 MockWrite writes1[] = { | |
10845 CreateMockWrite(*connect, 0), | |
10846 CreateMockWrite(*wrapped_req1, 2), | |
10847 CreateMockWrite(*req2, 5), | |
10848 }; | |
10849 | |
10850 scoped_ptr<SpdyFrame> conn_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10851 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10852 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); | |
10853 scoped_ptr<SpdyFrame> wrapped_resp1(ConstructWrappedSpdyFrame(resp1, 1)); | |
10854 scoped_ptr<SpdyFrame> wrapped_body1(ConstructWrappedSpdyFrame(body1, 1)); | |
10855 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
10856 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); | |
10857 MockRead reads1[] = { | |
10858 CreateMockRead(*conn_resp, 1), | |
10859 CreateMockRead(*wrapped_resp1, 3), | |
10860 CreateMockRead(*wrapped_body1, 4), | |
10861 CreateMockRead(*resp2, 6), | |
10862 CreateMockRead(*body2, 7), | |
10863 MockRead(ASYNC, ERR_IO_PENDING, 8) | |
10864 }; | |
10865 | |
10866 DeterministicSocketData data1(reads1, arraysize(reads1), | |
10867 writes1, arraysize(writes1)); | |
10868 MockConnect connect_data1(ASYNC, OK); | |
10869 data1.set_connect_data(connect_data1); | |
10870 | |
10871 session_deps_.proxy_service.reset( | |
10872 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); | |
10873 CapturingNetLog log; | |
10874 session_deps_.net_log = &log; | |
10875 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy | |
10876 ssl1.SetNextProto(kProtoSPDY3); | |
10877 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); | |
10878 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server | |
10879 ssl2.SetNextProto(kProtoSPDY3); | |
10880 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); | |
10881 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); | |
10882 | |
10883 scoped_refptr<HttpNetworkSession> session( | |
10884 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); | |
10885 | |
10886 // Start the first transaction to set up the SpdySession | |
10887 HttpRequestInfo request1; | |
10888 request1.method = "GET"; | |
10889 request1.url = GURL(https_url); | |
10890 request1.load_flags = 0; | |
10891 HttpNetworkTransaction trans1(LOWEST, session.get()); | |
10892 TestCompletionCallback callback1; | |
10893 EXPECT_EQ(ERR_IO_PENDING, | |
10894 trans1.Start(&request1, callback1.callback(), BoundNetLog())); | |
10895 base::MessageLoop::current()->RunUntilIdle(); | |
10896 data1.RunFor(4); | |
10897 | |
10898 EXPECT_EQ(OK, callback1.WaitForResult()); | |
10899 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); | |
10900 | |
10901 LoadTimingInfo load_timing_info1; | |
10902 EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); | |
10903 TestLoadTimingNotReusedWithPac(load_timing_info1, | |
10904 CONNECT_TIMING_HAS_SSL_TIMES); | |
10905 | |
10906 // Now, start the HTTP request | |
10907 HttpRequestInfo request2; | |
10908 request2.method = "GET"; | |
10909 request2.url = GURL(httpUrl); | |
10910 request2.load_flags = 0; | |
10911 HttpNetworkTransaction trans2(MEDIUM, session.get()); | |
10912 TestCompletionCallback callback2; | |
10913 EXPECT_EQ(ERR_IO_PENDING, | |
10914 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | |
10915 base::MessageLoop::current()->RunUntilIdle(); | |
10916 data1.RunFor(3); | |
10917 | |
10918 EXPECT_EQ(OK, callback2.WaitForResult()); | |
10919 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | |
10920 | |
10921 // HTTP requests over a SPDY session should have a different connection | |
10922 // socket_log_id than requests over a tunnel. | |
10923 LoadTimingInfo load_timing_info2; | |
10924 EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); | |
10925 TestLoadTimingReusedWithPac(load_timing_info2); | |
10926 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | |
10927 } | |
10928 | |
10929 TEST_F(HttpNetworkTransactionSpdy3Test, UseSpdySessionForHttpWhenForced) { | |
10930 HttpStreamFactory::set_force_spdy_always(true); | |
10931 const std::string https_url = "https://www.google.com/"; | |
10932 const std::string http_url = "http://www.google.com:443/"; | |
10933 | |
10934 // SPDY GET for HTTPS URL | |
10935 scoped_ptr<SpdyFrame> req1( | |
10936 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | |
10937 // SPDY GET for the HTTP URL | |
10938 scoped_ptr<SpdyFrame> req2( | |
10939 spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM)); | |
10940 | |
10941 MockWrite writes[] = { | |
10942 CreateMockWrite(*req1, 1), | |
10943 CreateMockWrite(*req2, 4), | |
10944 }; | |
10945 | |
10946 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10947 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); | |
10948 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | |
10949 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); | |
10950 MockRead reads[] = { | |
10951 CreateMockRead(*resp1, 2), | |
10952 CreateMockRead(*body1, 3), | |
10953 CreateMockRead(*resp2, 5), | |
10954 CreateMockRead(*body2, 6), | |
10955 MockRead(ASYNC, ERR_IO_PENDING, 7) | |
10956 }; | |
10957 | |
10958 OrderedSocketData data(reads, arraysize(reads), | |
10959 writes, arraysize(writes)); | |
10960 | |
10961 SSLSocketDataProvider ssl(ASYNC, OK); | |
10962 ssl.SetNextProto(kProtoSPDY3); | |
10963 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
10964 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
10965 | |
10966 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
10967 | |
10968 // Start the first transaction to set up the SpdySession | |
10969 HttpRequestInfo request1; | |
10970 request1.method = "GET"; | |
10971 request1.url = GURL(https_url); | |
10972 request1.load_flags = 0; | |
10973 HttpNetworkTransaction trans1(LOWEST, session.get()); | |
10974 TestCompletionCallback callback1; | |
10975 EXPECT_EQ(ERR_IO_PENDING, | |
10976 trans1.Start(&request1, callback1.callback(), BoundNetLog())); | |
10977 base::MessageLoop::current()->RunUntilIdle(); | |
10978 | |
10979 EXPECT_EQ(OK, callback1.WaitForResult()); | |
10980 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); | |
10981 | |
10982 // Now, start the HTTP request | |
10983 HttpRequestInfo request2; | |
10984 request2.method = "GET"; | |
10985 request2.url = GURL(http_url); | |
10986 request2.load_flags = 0; | |
10987 HttpNetworkTransaction trans2(MEDIUM, session.get()); | |
10988 TestCompletionCallback callback2; | |
10989 EXPECT_EQ(ERR_IO_PENDING, | |
10990 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | |
10991 base::MessageLoop::current()->RunUntilIdle(); | |
10992 | |
10993 EXPECT_EQ(OK, callback2.WaitForResult()); | |
10994 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | |
10995 } | |
10996 | |
10997 // Test that in the case where we have a SPDY session to a SPDY proxy | |
10998 // that we do not pool other origins that resolve to the same IP when | |
10999 // the certificate does not match the new origin. | |
11000 // http://crbug.com/134690 | |
11001 TEST_F(HttpNetworkTransactionSpdy3Test, DoNotUseSpdySessionIfCertDoesNotMatch) { | |
11002 const std::string url1 = "http://www.google.com/"; | |
11003 const std::string url2 = "https://mail.google.com/"; | |
11004 const std::string ip_addr = "1.2.3.4"; | |
11005 | |
11006 scoped_ptr<SpdyFrame> req1( | |
11007 spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); | |
11008 | |
11009 MockWrite writes1[] = { | |
11010 CreateMockWrite(*req1, 0), | |
11011 }; | |
11012 | |
11013 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
11014 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); | |
11015 MockRead reads1[] = { | |
11016 CreateMockRead(*resp1, 1), | |
11017 CreateMockRead(*body1, 2), | |
11018 MockRead(ASYNC, OK, 3) // EOF | |
11019 }; | |
11020 | |
11021 scoped_ptr<DeterministicSocketData> data1( | |
11022 new DeterministicSocketData(reads1, arraysize(reads1), | |
11023 writes1, arraysize(writes1))); | |
11024 IPAddressNumber ip; | |
11025 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); | |
11026 IPEndPoint peer_addr = IPEndPoint(ip, 443); | |
11027 MockConnect connect_data1(ASYNC, OK, peer_addr); | |
11028 data1->set_connect_data(connect_data1); | |
11029 | |
11030 // SPDY GET for HTTPS URL (direct) | |
11031 scoped_ptr<SpdyFrame> req2( | |
11032 spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); | |
11033 | |
11034 MockWrite writes2[] = { | |
11035 CreateMockWrite(*req2, 0), | |
11036 }; | |
11037 | |
11038 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
11039 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); | |
11040 MockRead reads2[] = { | |
11041 CreateMockRead(*resp2, 1), | |
11042 CreateMockRead(*body2, 2), | |
11043 MockRead(ASYNC, OK, 3) // EOF | |
11044 }; | |
11045 | |
11046 scoped_ptr<DeterministicSocketData> data2( | |
11047 new DeterministicSocketData(reads2, arraysize(reads2), | |
11048 writes2, arraysize(writes2))); | |
11049 MockConnect connect_data2(ASYNC, OK); | |
11050 data2->set_connect_data(connect_data2); | |
11051 | |
11052 // Set up a proxy config that sends HTTP requests to a proxy, and | |
11053 // all others direct. | |
11054 ProxyConfig proxy_config; | |
11055 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); | |
11056 CapturingProxyResolver* capturing_proxy_resolver = | |
11057 new CapturingProxyResolver(); | |
11058 session_deps_.proxy_service.reset(new ProxyService( | |
11059 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, | |
11060 NULL)); | |
11061 | |
11062 // Load a valid cert. Note, that this does not need to | |
11063 // be valid for proxy because the MockSSLClientSocket does | |
11064 // not actually verify it. But SpdySession will use this | |
11065 // to see if it is valid for the new origin | |
11066 base::FilePath certs_dir = GetTestCertsDirectory(); | |
11067 scoped_refptr<X509Certificate> server_cert( | |
11068 ImportCertFromFile(certs_dir, "ok_cert.pem")); | |
11069 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | |
11070 | |
11071 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy | |
11072 ssl1.SetNextProto(kProtoSPDY3); | |
11073 ssl1.cert = server_cert; | |
11074 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); | |
11075 session_deps_.deterministic_socket_factory->AddSocketDataProvider( | |
11076 data1.get()); | |
11077 | |
11078 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server | |
11079 ssl2.SetNextProto(kProtoSPDY3); | |
11080 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); | |
11081 session_deps_.deterministic_socket_factory->AddSocketDataProvider( | |
11082 data2.get()); | |
11083 | |
11084 session_deps_.host_resolver.reset(new MockCachingHostResolver()); | |
11085 session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); | |
11086 session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); | |
11087 | |
11088 scoped_refptr<HttpNetworkSession> session( | |
11089 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); | |
11090 | |
11091 // Start the first transaction to set up the SpdySession | |
11092 HttpRequestInfo request1; | |
11093 request1.method = "GET"; | |
11094 request1.url = GURL(url1); | |
11095 request1.load_flags = 0; | |
11096 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); | |
11097 TestCompletionCallback callback1; | |
11098 ASSERT_EQ(ERR_IO_PENDING, | |
11099 trans1.Start(&request1, callback1.callback(), BoundNetLog())); | |
11100 data1->RunFor(3); | |
11101 | |
11102 ASSERT_TRUE(callback1.have_result()); | |
11103 EXPECT_EQ(OK, callback1.WaitForResult()); | |
11104 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); | |
11105 | |
11106 // Now, start the HTTP request | |
11107 HttpRequestInfo request2; | |
11108 request2.method = "GET"; | |
11109 request2.url = GURL(url2); | |
11110 request2.load_flags = 0; | |
11111 HttpNetworkTransaction trans2(MEDIUM, session.get()); | |
11112 TestCompletionCallback callback2; | |
11113 EXPECT_EQ(ERR_IO_PENDING, | |
11114 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | |
11115 base::MessageLoop::current()->RunUntilIdle(); | |
11116 data2->RunFor(3); | |
11117 | |
11118 ASSERT_TRUE(callback2.have_result()); | |
11119 EXPECT_EQ(OK, callback2.WaitForResult()); | |
11120 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | |
11121 } | |
11122 | |
11123 // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED | |
11124 // error) in SPDY session, removes the socket from pool and closes the SPDY | |
11125 // session. Verify that new url's from the same HttpNetworkSession (and a new | |
11126 // SpdySession) do work. http://crbug.com/224701 | |
11127 TEST_F(HttpNetworkTransactionSpdy3Test, ErrorSocketNotConnected) { | |
11128 const std::string https_url = "https://www.google.com/"; | |
11129 | |
11130 MockRead reads1[] = { | |
11131 MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) | |
11132 }; | |
11133 | |
11134 scoped_ptr<DeterministicSocketData> data1( | |
11135 new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); | |
11136 data1->SetStop(1); | |
11137 | |
11138 scoped_ptr<SpdyFrame> req2( | |
11139 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); | |
11140 MockWrite writes2[] = { | |
11141 CreateMockWrite(*req2, 0), | |
11142 }; | |
11143 | |
11144 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
11145 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); | |
11146 MockRead reads2[] = { | |
11147 CreateMockRead(*resp2, 1), | |
11148 CreateMockRead(*body2, 2), | |
11149 MockRead(ASYNC, OK, 3) // EOF | |
11150 }; | |
11151 | |
11152 scoped_ptr<DeterministicSocketData> data2( | |
11153 new DeterministicSocketData(reads2, arraysize(reads2), | |
11154 writes2, arraysize(writes2))); | |
11155 | |
11156 SSLSocketDataProvider ssl1(ASYNC, OK); | |
11157 ssl1.SetNextProto(kProtoSPDY3); | |
11158 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); | |
11159 session_deps_.deterministic_socket_factory->AddSocketDataProvider( | |
11160 data1.get()); | |
11161 | |
11162 SSLSocketDataProvider ssl2(ASYNC, OK); | |
11163 ssl2.SetNextProto(kProtoSPDY3); | |
11164 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); | |
11165 session_deps_.deterministic_socket_factory->AddSocketDataProvider( | |
11166 data2.get()); | |
11167 | |
11168 scoped_refptr<HttpNetworkSession> session( | |
11169 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); | |
11170 | |
11171 // Start the first transaction to set up the SpdySession and verify that | |
11172 // connection was closed. | |
11173 HttpRequestInfo request1; | |
11174 request1.method = "GET"; | |
11175 request1.url = GURL(https_url); | |
11176 request1.load_flags = 0; | |
11177 HttpNetworkTransaction trans1(MEDIUM, session.get()); | |
11178 TestCompletionCallback callback1; | |
11179 EXPECT_EQ(ERR_IO_PENDING, | |
11180 trans1.Start(&request1, callback1.callback(), BoundNetLog())); | |
11181 base::MessageLoop::current()->RunUntilIdle(); | |
11182 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); | |
11183 | |
11184 // Now, start the second request and make sure it succeeds. | |
11185 HttpRequestInfo request2; | |
11186 request2.method = "GET"; | |
11187 request2.url = GURL(https_url); | |
11188 request2.load_flags = 0; | |
11189 HttpNetworkTransaction trans2(MEDIUM, session.get()); | |
11190 TestCompletionCallback callback2; | |
11191 EXPECT_EQ(ERR_IO_PENDING, | |
11192 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | |
11193 base::MessageLoop::current()->RunUntilIdle(); | |
11194 data2->RunFor(3); | |
11195 | |
11196 ASSERT_TRUE(callback2.have_result()); | |
11197 EXPECT_EQ(OK, callback2.WaitForResult()); | |
11198 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | |
11199 } | |
11200 | |
11201 TEST_F(HttpNetworkTransactionSpdy3Test, CloseIdleSpdySessionToOpenNewOne) { | |
11202 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
11203 ClientSocketPoolManager::set_max_sockets_per_group( | |
11204 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
11205 ClientSocketPoolManager::set_max_sockets_per_pool( | |
11206 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
11207 | |
11208 // Use two different hosts with different IPs so they don't get pooled. | |
11209 session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); | |
11210 session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); | |
11211 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
11212 | |
11213 SSLSocketDataProvider ssl1(ASYNC, OK); | |
11214 ssl1.SetNextProto(kProtoSPDY3); | |
11215 SSLSocketDataProvider ssl2(ASYNC, OK); | |
11216 ssl2.SetNextProto(kProtoSPDY3); | |
11217 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); | |
11218 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); | |
11219 | |
11220 scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( | |
11221 "https://www.a.com", false, 1, DEFAULT_PRIORITY)); | |
11222 MockWrite spdy1_writes[] = { | |
11223 CreateMockWrite(*host1_req, 1), | |
11224 }; | |
11225 scoped_ptr<SpdyFrame> host1_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
11226 scoped_ptr<SpdyFrame> host1_resp_body(ConstructSpdyBodyFrame(1, true)); | |
11227 MockRead spdy1_reads[] = { | |
11228 CreateMockRead(*host1_resp, 2), | |
11229 CreateMockRead(*host1_resp_body, 3), | |
11230 MockRead(ASYNC, ERR_IO_PENDING, 4), | |
11231 }; | |
11232 | |
11233 scoped_ptr<OrderedSocketData> spdy1_data( | |
11234 new OrderedSocketData( | |
11235 spdy1_reads, arraysize(spdy1_reads), | |
11236 spdy1_writes, arraysize(spdy1_writes))); | |
11237 session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); | |
11238 | |
11239 scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( | |
11240 "https://www.b.com", false, 1, DEFAULT_PRIORITY)); | |
11241 MockWrite spdy2_writes[] = { | |
11242 CreateMockWrite(*host2_req, 1), | |
11243 }; | |
11244 scoped_ptr<SpdyFrame> host2_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
11245 scoped_ptr<SpdyFrame> host2_resp_body(ConstructSpdyBodyFrame(1, true)); | |
11246 MockRead spdy2_reads[] = { | |
11247 CreateMockRead(*host2_resp, 2), | |
11248 CreateMockRead(*host2_resp_body, 3), | |
11249 MockRead(ASYNC, ERR_IO_PENDING, 4), | |
11250 }; | |
11251 | |
11252 scoped_ptr<OrderedSocketData> spdy2_data( | |
11253 new OrderedSocketData( | |
11254 spdy2_reads, arraysize(spdy2_reads), | |
11255 spdy2_writes, arraysize(spdy2_writes))); | |
11256 session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); | |
11257 | |
11258 MockWrite http_write[] = { | |
11259 MockWrite("GET / HTTP/1.1\r\n" | |
11260 "Host: www.a.com\r\n" | |
11261 "Connection: keep-alive\r\n\r\n"), | |
11262 }; | |
11263 | |
11264 MockRead http_read[] = { | |
11265 MockRead("HTTP/1.1 200 OK\r\n"), | |
11266 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
11267 MockRead("Content-Length: 6\r\n\r\n"), | |
11268 MockRead("hello!"), | |
11269 }; | |
11270 StaticSocketDataProvider http_data(http_read, arraysize(http_read), | |
11271 http_write, arraysize(http_write)); | |
11272 session_deps_.socket_factory->AddSocketDataProvider(&http_data); | |
11273 | |
11274 HostPortPair host_port_pair_a("www.a.com", 443); | |
11275 SpdySessionKey spdy_session_key_a( | |
11276 host_port_pair_a, ProxyServer::Direct(), kPrivacyModeDisabled); | |
11277 EXPECT_FALSE( | |
11278 session->spdy_session_pool()->HasSession(spdy_session_key_a)); | |
11279 | |
11280 TestCompletionCallback callback; | |
11281 HttpRequestInfo request1; | |
11282 request1.method = "GET"; | |
11283 request1.url = GURL("https://www.a.com/"); | |
11284 request1.load_flags = 0; | |
11285 scoped_ptr<HttpNetworkTransaction> trans( | |
11286 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
11287 | |
11288 int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); | |
11289 EXPECT_EQ(ERR_IO_PENDING, rv); | |
11290 EXPECT_EQ(OK, callback.WaitForResult()); | |
11291 | |
11292 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
11293 ASSERT_TRUE(response != NULL); | |
11294 ASSERT_TRUE(response->headers.get() != NULL); | |
11295 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
11296 EXPECT_TRUE(response->was_fetched_via_spdy); | |
11297 EXPECT_TRUE(response->was_npn_negotiated); | |
11298 | |
11299 std::string response_data; | |
11300 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
11301 EXPECT_EQ("hello!", response_data); | |
11302 trans.reset(); | |
11303 EXPECT_TRUE( | |
11304 session->spdy_session_pool()->HasSession(spdy_session_key_a)); | |
11305 | |
11306 HostPortPair host_port_pair_b("www.b.com", 443); | |
11307 SpdySessionKey spdy_session_key_b( | |
11308 host_port_pair_b, ProxyServer::Direct(), kPrivacyModeDisabled); | |
11309 EXPECT_FALSE( | |
11310 session->spdy_session_pool()->HasSession(spdy_session_key_b)); | |
11311 HttpRequestInfo request2; | |
11312 request2.method = "GET"; | |
11313 request2.url = GURL("https://www.b.com/"); | |
11314 request2.load_flags = 0; | |
11315 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
11316 | |
11317 rv = trans->Start(&request2, callback.callback(), BoundNetLog()); | |
11318 EXPECT_EQ(ERR_IO_PENDING, rv); | |
11319 EXPECT_EQ(OK, callback.WaitForResult()); | |
11320 | |
11321 response = trans->GetResponseInfo(); | |
11322 ASSERT_TRUE(response != NULL); | |
11323 ASSERT_TRUE(response->headers.get() != NULL); | |
11324 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
11325 EXPECT_TRUE(response->was_fetched_via_spdy); | |
11326 EXPECT_TRUE(response->was_npn_negotiated); | |
11327 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
11328 EXPECT_EQ("hello!", response_data); | |
11329 EXPECT_FALSE( | |
11330 session->spdy_session_pool()->HasSession(spdy_session_key_a)); | |
11331 EXPECT_TRUE( | |
11332 session->spdy_session_pool()->HasSession(spdy_session_key_b)); | |
11333 | |
11334 HostPortPair host_port_pair_a1("www.a.com", 80); | |
11335 SpdySessionKey spdy_session_key_a1( | |
11336 host_port_pair_a1, ProxyServer::Direct(), kPrivacyModeDisabled); | |
11337 EXPECT_FALSE( | |
11338 session->spdy_session_pool()->HasSession(spdy_session_key_a1)); | |
11339 HttpRequestInfo request3; | |
11340 request3.method = "GET"; | |
11341 request3.url = GURL("http://www.a.com/"); | |
11342 request3.load_flags = 0; | |
11343 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
11344 | |
11345 rv = trans->Start(&request3, callback.callback(), BoundNetLog()); | |
11346 EXPECT_EQ(ERR_IO_PENDING, rv); | |
11347 EXPECT_EQ(OK, callback.WaitForResult()); | |
11348 | |
11349 response = trans->GetResponseInfo(); | |
11350 ASSERT_TRUE(response != NULL); | |
11351 ASSERT_TRUE(response->headers.get() != NULL); | |
11352 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
11353 EXPECT_FALSE(response->was_fetched_via_spdy); | |
11354 EXPECT_FALSE(response->was_npn_negotiated); | |
11355 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
11356 EXPECT_EQ("hello!", response_data); | |
11357 EXPECT_FALSE( | |
11358 session->spdy_session_pool()->HasSession(spdy_session_key_a)); | |
11359 EXPECT_FALSE( | |
11360 session->spdy_session_pool()->HasSession(spdy_session_key_b)); | |
11361 | |
11362 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); | |
11363 } | |
11364 | |
11365 } // namespace net | |
OLD | NEW |