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