| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 MockRead(true, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | 251 MockRead(true, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 252 MockRead(true, 3, "Content-Length: 10\r\n\r\n"), | 252 MockRead(true, 3, "Content-Length: 10\r\n\r\n"), |
| 253 MockRead(true, 4, "0123456789"), | 253 MockRead(true, 4, "0123456789"), |
| 254 }; | 254 }; |
| 255 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyConnect(NULL, 0, 1)); | 255 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyConnect(NULL, 0, 1)); |
| 256 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); | 256 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); |
| 257 MockWrite spdy_writes[] = { | 257 MockWrite spdy_writes[] = { |
| 258 CreateMockWrite(*req, 0, true), | 258 CreateMockWrite(*req, 0, true), |
| 259 CreateMockWrite(*rst, 2, true), | 259 CreateMockWrite(*rst, 2, true), |
| 260 }; | 260 }; |
| 261 static const char* const kAuthChallenge[] = { | |
| 262 "status", "407 Proxy Authentication Required", | |
| 263 "version", "HTTP/1.1", | |
| 264 "proxy-authenticate", "Basic realm=\"MyRealm1\"", | |
| 265 }; | |
| 266 | |
| 267 scoped_ptr<spdy::SpdyFrame> resp( | 261 scoped_ptr<spdy::SpdyFrame> resp( |
| 268 ConstructSpdyControlFrame(NULL, | 262 ConstructSpdySynReplyError( |
| 269 0, | 263 "407 Proxy Authentication Required", NULL, 0, 1)); |
| 270 false, | |
| 271 1, | |
| 272 LOWEST, | |
| 273 spdy::SYN_REPLY, | |
| 274 spdy::CONTROL_FLAG_NONE, | |
| 275 kAuthChallenge, | |
| 276 arraysize(kAuthChallenge))); | |
| 277 MockRead spdy_reads[] = { | 264 MockRead spdy_reads[] = { |
| 278 CreateMockWrite(*resp, 1, true), | 265 CreateMockWrite(*resp, 1, true), |
| 279 MockRead(true, 0, 3) | 266 MockRead(true, 0, 3) |
| 280 }; | 267 }; |
| 281 | 268 |
| 282 Initialize(false, reads, arraysize(reads), writes, arraysize(writes), | 269 Initialize(false, reads, arraysize(reads), writes, arraysize(writes), |
| 283 spdy_reads, arraysize(spdy_reads), spdy_writes, | 270 spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 284 arraysize(spdy_writes)); | 271 arraysize(spdy_writes)); |
| 285 | 272 |
| 286 data_->StopAfter(4); | 273 data_->StopAfter(4); |
| 287 int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, | 274 int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, |
| 288 BoundNetLog()); | 275 BoundNetLog()); |
| 289 EXPECT_EQ(ERR_IO_PENDING, rv); | 276 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 290 EXPECT_FALSE(handle_.is_initialized()); | 277 EXPECT_FALSE(handle_.is_initialized()); |
| 291 EXPECT_FALSE(handle_.socket()); | 278 EXPECT_FALSE(handle_.socket()); |
| 292 | 279 |
| 293 data_->RunFor(GetParam() == SPDY ? 2 : 4); | 280 data_->RunFor(4); |
| 294 rv = callback_.WaitForResult(); | 281 rv = callback_.WaitForResult(); |
| 295 EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, rv); | |
| 296 EXPECT_TRUE(handle_.is_initialized()); | |
| 297 ASSERT_TRUE(handle_.socket()); | |
| 298 if (GetParam() != SPDY) { | 282 if (GetParam() != SPDY) { |
| 283 EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, rv); |
| 284 EXPECT_TRUE(handle_.is_initialized()); |
| 285 ASSERT_TRUE(handle_.socket()); |
| 299 HttpProxyClientSocket* tunnel_socket = | 286 HttpProxyClientSocket* tunnel_socket = |
| 300 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 287 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
| 301 EXPECT_FALSE(tunnel_socket->IsConnected()); | 288 EXPECT_FALSE(tunnel_socket->IsConnected()); |
| 302 EXPECT_FALSE(tunnel_socket->using_spdy()); | 289 EXPECT_FALSE(tunnel_socket->using_spdy()); |
| 290 } else { |
| 291 // Proxy auth is not really implemented for SPDY yet |
| 292 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 293 EXPECT_FALSE(handle_.is_initialized()); |
| 294 EXPECT_FALSE(handle_.socket()); |
| 303 } | 295 } |
| 304 } | 296 } |
| 305 | 297 |
| 306 TEST_P(HttpProxyClientSocketPoolTest, HaveAuth) { | 298 TEST_P(HttpProxyClientSocketPoolTest, HaveAuth) { |
| 307 // It's pretty much impossible to make the SPDY case becave synchronously | 299 // It's pretty much impossible to make the SPDY case becave synchronously |
| 308 // so we skip this test for SPDY | 300 // so we skip this test for SPDY |
| 309 if (GetParam() == SPDY) | 301 if (GetParam() == SPDY) |
| 310 return; | 302 return; |
| 311 MockWrite writes[] = { | 303 MockWrite writes[] = { |
| 312 MockWrite(false, 0, | 304 MockWrite(false, 0, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // HTTPS or SPDY Proxy CONNECT responses are trustworthy | 521 // HTTPS or SPDY Proxy CONNECT responses are trustworthy |
| 530 EXPECT_EQ(ERR_HTTPS_PROXY_TUNNEL_RESPONSE, rv); | 522 EXPECT_EQ(ERR_HTTPS_PROXY_TUNNEL_RESPONSE, rv); |
| 531 EXPECT_TRUE(handle_.is_initialized()); | 523 EXPECT_TRUE(handle_.is_initialized()); |
| 532 EXPECT_TRUE(handle_.socket()); | 524 EXPECT_TRUE(handle_.socket()); |
| 533 } | 525 } |
| 534 } | 526 } |
| 535 | 527 |
| 536 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 528 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
| 537 | 529 |
| 538 } // namespace net | 530 } // namespace net |
| OLD | NEW |