OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // Create the SPDY Stream | 192 // Create the SPDY Stream |
193 ASSERT_EQ( | 193 ASSERT_EQ( |
194 OK, | 194 OK, |
195 spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(), | 195 spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(), |
196 CompletionCallback())); | 196 CompletionCallback())); |
197 | 197 |
198 // Create the SpdyProxyClientSocket | 198 // Create the SpdyProxyClientSocket |
199 sock_.reset( | 199 sock_.reset( |
200 new SpdyProxyClientSocket(spdy_stream_, user_agent_, | 200 new SpdyProxyClientSocket(spdy_stream_, user_agent_, |
201 endpoint_host_port_pair_, url_, | 201 endpoint_host_port_pair_, url_, |
202 proxy_host_port_, session_->http_auth_cache(), | 202 proxy_host_port_, |
203 session_->http_auth_handler_factory())); | 203 new HttpAuthController( |
| 204 HttpAuth::AUTH_PROXY, |
| 205 GURL(kProxyUrl), |
| 206 session_->http_auth_cache(), |
| 207 session_->http_auth_handler_factory()))); |
204 } | 208 } |
205 | 209 |
206 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( | 210 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( |
207 const char* data, int size) { | 211 const char* data, int size) { |
208 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); | 212 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); |
209 memcpy(buf->data(), data, size); | 213 memcpy(buf->data(), data, size); |
210 return buf; | 214 return buf; |
211 } | 215 } |
212 | 216 |
213 void SpdyProxyClientSocketTest::AssertConnectSucceeds() { | 217 void SpdyProxyClientSocketTest::AssertConnectSucceeds() { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 }; | 447 }; |
444 | 448 |
445 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); | 449 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
446 MockRead reads[] = { | 450 MockRead reads[] = { |
447 CreateMockRead(*resp, 1, true), | 451 CreateMockRead(*resp, 1, true), |
448 MockRead(true, 0, 3), // EOF | 452 MockRead(true, 0, 3), // EOF |
449 }; | 453 }; |
450 | 454 |
451 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 455 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
452 | 456 |
453 AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED); | 457 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
454 | 458 |
455 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); | 459 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
456 ASSERT_TRUE(response != NULL); | 460 ASSERT_TRUE(response != NULL); |
457 ASSERT_EQ(407, response->headers->response_code()); | 461 ASSERT_EQ(407, response->headers->response_code()); |
458 ASSERT_EQ("Proxy Authentication Required", | 462 ASSERT_EQ("Proxy Authentication Required", |
459 response->headers->GetStatusText()); | 463 response->headers->GetStatusText()); |
460 } | 464 } |
461 | 465 |
462 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { | 466 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { |
463 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); | 467 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); |
464 MockWrite writes[] = { | 468 MockWrite writes[] = { |
465 CreateMockWrite(*conn, 0, false), | 469 CreateMockWrite(*conn, 0, false), |
466 }; | 470 }; |
467 | 471 |
468 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 472 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
469 MockRead reads[] = { | 473 MockRead reads[] = { |
470 CreateMockRead(*resp, 1, true), | 474 CreateMockRead(*resp, 1, true), |
471 MockRead(true, 0, 3), // EOF | 475 MockRead(true, 0, 3), // EOF |
472 }; | 476 }; |
473 | 477 |
474 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 478 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
475 AddAuthToCache(); | 479 AddAuthToCache(); |
476 | 480 |
477 AssertConnectSucceeds(); | 481 AssertConnectSucceeds(); |
478 | 482 |
479 AssertConnectionEstablished(); | 483 AssertConnectionEstablished(); |
480 } | 484 } |
481 | 485 |
| 486 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRestart) { |
| 487 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 488 scoped_ptr<spdy::SpdyFrame> auth(ConstructConnectAuthRequestFrame()); |
| 489 MockWrite writes[] = { |
| 490 CreateMockWrite(*conn, 0, false), |
| 491 }; |
| 492 |
| 493 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
| 494 scoped_ptr<spdy::SpdyFrame> auth_resp(ConstructConnectReplyFrame()); |
| 495 MockRead reads[] = { |
| 496 CreateMockRead(*resp, 1, true), |
| 497 MockRead(true, 0, 3), // EOF |
| 498 }; |
| 499 |
| 500 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 501 |
| 502 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
| 503 |
| 504 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
| 505 ASSERT_TRUE(response != NULL); |
| 506 ASSERT_EQ(407, response->headers->response_code()); |
| 507 ASSERT_EQ("Proxy Authentication Required", |
| 508 response->headers->GetStatusText()); |
| 509 |
| 510 AddAuthToCache(); |
| 511 |
| 512 ASSERT_EQ(OK, sock_->RestartWithAuth(read_callback_.callback())); |
| 513 // A SpdyProxyClientSocket sits on a single SPDY stream which can |
| 514 // only be used for a single request/response. |
| 515 ASSERT_FALSE(sock_->IsConnectedAndIdle()); |
| 516 } |
| 517 |
482 TEST_F(SpdyProxyClientSocketTest, ConnectFails) { | 518 TEST_F(SpdyProxyClientSocketTest, ConnectFails) { |
483 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 519 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
484 MockWrite writes[] = { | 520 MockWrite writes[] = { |
485 CreateMockWrite(*conn, 0, false), | 521 CreateMockWrite(*conn, 0, false), |
486 }; | 522 }; |
487 | 523 |
488 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 524 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
489 MockRead reads[] = { | 525 MockRead reads[] = { |
490 MockRead(true, 0, 1), // EOF | 526 MockRead(true, 0, 1), // EOF |
491 }; | 527 }; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 860 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
825 MockRead reads[] = { | 861 MockRead reads[] = { |
826 CreateMockRead(*resp, 1, true), | 862 CreateMockRead(*resp, 1, true), |
827 CreateMockRead(*msg1, 2, true), | 863 CreateMockRead(*msg1, 2, true), |
828 CreateMockRead(*msg2, 3, true), | 864 CreateMockRead(*msg2, 3, true), |
829 MockRead(true, 0, 4), // EOF | 865 MockRead(true, 0, 4), // EOF |
830 }; | 866 }; |
831 | 867 |
832 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 868 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
833 | 869 |
834 AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED); | 870 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
835 | 871 |
836 Run(2); // SpdySession consumes the next two reads and sends then to | 872 Run(2); // SpdySession consumes the next two reads and sends then to |
837 // sock_ to be buffered. | 873 // sock_ to be buffered. |
838 AssertSyncReadEquals(kMsg1, kLen1); | 874 AssertSyncReadEquals(kMsg1, kLen1); |
839 AssertSyncReadEquals(kMsg2, kLen2); | 875 AssertSyncReadEquals(kMsg2, kLen2); |
840 } | 876 } |
841 | 877 |
842 TEST_F(SpdyProxyClientSocketTest, ReadErrorResponseBody) { | 878 TEST_F(SpdyProxyClientSocketTest, ReadErrorResponseBody) { |
843 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 879 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
844 MockWrite writes[] = { | 880 MockWrite writes[] = { |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 write_callback_.callback())); | 1327 write_callback_.callback())); |
1292 | 1328 |
1293 Run(2); | 1329 Run(2); |
1294 | 1330 |
1295 EXPECT_FALSE(sock_.get()); | 1331 EXPECT_FALSE(sock_.get()); |
1296 EXPECT_TRUE(read_callback.have_result()); | 1332 EXPECT_TRUE(read_callback.have_result()); |
1297 EXPECT_FALSE(write_callback_.have_result()); | 1333 EXPECT_FALSE(write_callback_.have_result()); |
1298 } | 1334 } |
1299 | 1335 |
1300 } // namespace net | 1336 } // namespace net |
OLD | NEW |