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