OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/url_request/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 ASSERT_TRUE(url_request.is_pending()); | 235 ASSERT_TRUE(url_request.is_pending()); |
236 socket_data(0)->RunFor(4); | 236 socket_data(0)->RunFor(4); |
237 | 237 |
238 EXPECT_TRUE(url_request.status().is_success()); | 238 EXPECT_TRUE(url_request.status().is_success()); |
239 EXPECT_EQ(1, network_delegate()->completed_requests()); | 239 EXPECT_EQ(1, network_delegate()->completed_requests()); |
240 EXPECT_EQ(0, network_delegate()->error_count()); | 240 EXPECT_EQ(0, network_delegate()->error_count()); |
241 EXPECT_FALSE(request_delegate.auth_required_called()); | 241 EXPECT_FALSE(request_delegate.auth_required_called()); |
242 EXPECT_EQ("test.html", request_delegate.data_received()); | 242 EXPECT_EQ("test.html", request_delegate.data_received()); |
243 } | 243 } |
244 | 244 |
245 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedAuth) { | 245 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthNoCredentials) { |
246 MockWrite writes[] = { | 246 MockWrite writes[] = { |
247 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 247 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
248 "Host: ftp.example.com\r\n" | 248 "Host: ftp.example.com\r\n" |
249 "Proxy-Connection: keep-alive\r\n\r\n"), | 249 "Proxy-Connection: keep-alive\r\n\r\n"), |
250 }; | 250 }; |
251 MockRead reads[] = { | 251 MockRead reads[] = { |
252 // No credentials. | 252 // No credentials. |
253 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | 253 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), |
254 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " | 254 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " |
255 "realm=\"MyRealm1\"\r\n"), | 255 "realm=\"MyRealm1\"\r\n"), |
256 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 256 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
257 MockRead(ASYNC, 4, "test.html"), | 257 MockRead(ASYNC, 4, "test.html"), |
258 }; | 258 }; |
259 | 259 |
260 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 260 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
261 | 261 |
262 TestDelegate request_delegate; | 262 TestDelegate request_delegate; |
263 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 263 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
264 &request_delegate, | 264 &request_delegate, |
265 request_context(), | 265 request_context(), |
266 network_delegate()); | 266 network_delegate()); |
267 url_request.Start(); | 267 url_request.Start(); |
268 ASSERT_TRUE(url_request.is_pending()); | 268 ASSERT_TRUE(url_request.is_pending()); |
269 socket_data(0)->RunFor(5); | 269 socket_data(0)->RunFor(5); |
270 | 270 |
271 EXPECT_TRUE(url_request.status().is_success()); | 271 EXPECT_TRUE(url_request.status().is_success()); |
272 EXPECT_EQ(1, network_delegate()->completed_requests()); | 272 EXPECT_EQ(1, network_delegate()->completed_requests()); |
273 EXPECT_EQ(0, network_delegate()->error_count()); | 273 EXPECT_EQ(0, network_delegate()->error_count()); |
274 EXPECT_FALSE(request_delegate.auth_required_called()); | 274 EXPECT_TRUE(request_delegate.auth_required_called()); |
275 EXPECT_EQ("test.html", request_delegate.data_received()); | 275 EXPECT_EQ("test.html", request_delegate.data_received()); |
276 } | 276 } |
277 | 277 |
mmenke
2013/03/28 18:34:52
Other test suggestions:
1) After authenticating
| |
278 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthWithCredentials) { | |
279 MockWrite writes[] = { | |
280 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
281 "Host: ftp.example.com\r\n" | |
282 "Proxy-Connection: keep-alive\r\n\r\n"), | |
283 MockWrite(ASYNC, 5, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
284 "Host: ftp.example.com\r\n" | |
285 "Proxy-Connection: keep-alive\r\n" | |
286 "Proxy-Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), | |
287 }; | |
288 MockRead reads[] = { | |
289 // No credentials. | |
290 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
291 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " | |
292 "realm=\"MyRealm1\"\r\n"), | |
293 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | |
294 MockRead(ASYNC, 4, "test.html"), | |
295 | |
296 // Second response. | |
297 MockRead(ASYNC, 6, "HTTP/1.1 200 OK\r\n"), | |
298 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), | |
299 MockRead(ASYNC, 8, "test2.html"), | |
300 }; | |
301 | |
302 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | |
303 | |
304 TestDelegate request_delegate; | |
305 request_delegate.set_credentials( | |
306 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | |
307 URLRequest url_request(GURL("ftp://ftp.example.com/"), | |
308 &request_delegate, | |
309 request_context(), | |
310 network_delegate()); | |
311 url_request.Start(); | |
312 ASSERT_TRUE(url_request.is_pending()); | |
313 socket_data(0)->RunFor(9); | |
314 | |
315 EXPECT_TRUE(url_request.status().is_success()); | |
316 EXPECT_EQ(1, network_delegate()->completed_requests()); | |
317 EXPECT_EQ(0, network_delegate()->error_count()); | |
318 EXPECT_TRUE(request_delegate.auth_required_called()); | |
319 EXPECT_EQ("test2.html", request_delegate.data_received()); | |
320 } | |
321 | |
322 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthNoCredentials) { | |
323 MockWrite writes[] = { | |
324 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
325 "Host: ftp.example.com\r\n" | |
326 "Proxy-Connection: keep-alive\r\n\r\n"), | |
327 }; | |
328 MockRead reads[] = { | |
329 // No credentials. | |
330 MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), | |
331 MockRead(ASYNC, 2, "WWW-Authenticate: Basic " | |
332 "realm=\"MyRealm1\"\r\n"), | |
333 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | |
334 MockRead(ASYNC, 4, "test.html"), | |
335 }; | |
336 | |
337 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | |
338 | |
339 TestDelegate request_delegate; | |
340 URLRequest url_request(GURL("ftp://ftp.example.com/"), | |
341 &request_delegate, | |
342 request_context(), | |
343 network_delegate()); | |
344 url_request.Start(); | |
345 ASSERT_TRUE(url_request.is_pending()); | |
346 socket_data(0)->RunFor(5); | |
347 | |
348 EXPECT_TRUE(url_request.status().is_success()); | |
349 EXPECT_EQ(1, network_delegate()->completed_requests()); | |
350 EXPECT_EQ(0, network_delegate()->error_count()); | |
351 EXPECT_TRUE(request_delegate.auth_required_called()); | |
352 EXPECT_EQ("test.html", request_delegate.data_received()); | |
353 } | |
354 | |
355 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthWithCredentials) { | |
356 MockWrite writes[] = { | |
357 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
358 "Host: ftp.example.com\r\n" | |
359 "Proxy-Connection: keep-alive\r\n\r\n"), | |
360 MockWrite(ASYNC, 5, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
361 "Host: ftp.example.com\r\n" | |
362 "Proxy-Connection: keep-alive\r\n" | |
363 "Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), | |
364 }; | |
365 MockRead reads[] = { | |
366 // No credentials. | |
367 MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), | |
368 MockRead(ASYNC, 2, "WWW-Authenticate: Basic " | |
369 "realm=\"MyRealm1\"\r\n"), | |
370 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | |
371 MockRead(ASYNC, 4, "test.html"), | |
372 | |
373 // Second response. | |
374 MockRead(ASYNC, 6, "HTTP/1.1 200 OK\r\n"), | |
375 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), | |
376 MockRead(ASYNC, 8, "test2.html"), | |
377 }; | |
378 | |
379 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | |
380 | |
381 TestDelegate request_delegate; | |
382 request_delegate.set_credentials( | |
383 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | |
384 URLRequest url_request(GURL("ftp://ftp.example.com/"), | |
385 &request_delegate, | |
386 request_context(), | |
387 network_delegate()); | |
388 url_request.Start(); | |
389 ASSERT_TRUE(url_request.is_pending()); | |
390 socket_data(0)->RunFor(9); | |
391 | |
392 EXPECT_TRUE(url_request.status().is_success()); | |
393 EXPECT_EQ(1, network_delegate()->completed_requests()); | |
394 EXPECT_EQ(0, network_delegate()->error_count()); | |
395 EXPECT_TRUE(request_delegate.auth_required_called()); | |
396 EXPECT_EQ("test2.html", request_delegate.data_received()); | |
397 } | |
398 | |
399 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAndServerAuth) { | |
400 MockWrite writes[] = { | |
401 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
402 "Host: ftp.example.com\r\n" | |
403 "Proxy-Connection: keep-alive\r\n\r\n"), | |
404 MockWrite(ASYNC, 5, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
405 "Host: ftp.example.com\r\n" | |
406 "Proxy-Connection: keep-alive\r\n" | |
407 "Proxy-Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), | |
408 MockWrite(ASYNC, 10, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | |
409 "Host: ftp.example.com\r\n" | |
410 "Proxy-Connection: keep-alive\r\n" | |
411 "Proxy-Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n" | |
412 "Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), | |
413 }; | |
414 MockRead reads[] = { | |
415 // No credentials. | |
416 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
417 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " | |
418 "realm=\"MyRealm1\"\r\n"), | |
419 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | |
420 MockRead(ASYNC, 4, "test.html"), | |
421 | |
422 // Second response. | |
423 MockRead(ASYNC, 6, "HTTP/1.1 401 Unauthorized\r\n"), | |
424 MockRead(ASYNC, 7, "WWW-Authenticate: Basic " | |
425 "realm=\"MyRealm1\"\r\n"), | |
mmenke
2013/03/28 18:34:52
I'd like to see a different password for the secon
| |
426 MockRead(ASYNC, 8, "Content-Length: 9\r\n\r\n"), | |
427 MockRead(ASYNC, 9, "test.html"), | |
428 | |
429 // Third response. | |
430 MockRead(ASYNC, 11, "HTTP/1.1 200 OK\r\n"), | |
431 MockRead(ASYNC, 12, "Content-Length: 10\r\n\r\n"), | |
432 MockRead(ASYNC, 13, "test2.html"), | |
433 }; | |
434 | |
435 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | |
436 | |
437 TestDelegate request_delegate; | |
438 request_delegate.set_credentials( | |
439 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | |
440 URLRequest url_request(GURL("ftp://ftp.example.com/"), | |
441 &request_delegate, | |
442 request_context(), | |
443 network_delegate()); | |
444 url_request.Start(); | |
445 ASSERT_TRUE(url_request.is_pending()); | |
446 socket_data(0)->RunFor(14); | |
447 | |
448 EXPECT_TRUE(url_request.status().is_success()); | |
449 EXPECT_EQ(1, network_delegate()->completed_requests()); | |
450 EXPECT_EQ(0, network_delegate()->error_count()); | |
451 EXPECT_TRUE(request_delegate.auth_required_called()); | |
452 EXPECT_EQ("test2.html", request_delegate.data_received()); | |
453 } | |
454 | |
278 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { | 455 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { |
279 MockWrite writes[] = { | 456 MockWrite writes[] = { |
280 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 457 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
281 "Host: ftp.example.com\r\n" | 458 "Host: ftp.example.com\r\n" |
282 "Proxy-Connection: keep-alive\r\n\r\n"), | 459 "Proxy-Connection: keep-alive\r\n\r\n"), |
283 }; | 460 }; |
284 MockRead reads[] = { | 461 MockRead reads[] = { |
285 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 462 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
286 MockRead(ASYNC, 2, "Content-Length: 9\r\n"), | 463 MockRead(ASYNC, 2, "Content-Length: 9\r\n"), |
287 MockRead(ASYNC, 3, "Set-Cookie: name=value\r\n\r\n"), | 464 MockRead(ASYNC, 3, "Set-Cookie: name=value\r\n\r\n"), |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 EXPECT_TRUE(url_request2.status().is_success()); | 633 EXPECT_TRUE(url_request2.status().is_success()); |
457 EXPECT_EQ(2, network_delegate()->completed_requests()); | 634 EXPECT_EQ(2, network_delegate()->completed_requests()); |
458 EXPECT_EQ(0, network_delegate()->error_count()); | 635 EXPECT_EQ(0, network_delegate()->error_count()); |
459 EXPECT_FALSE(request_delegate2.auth_required_called()); | 636 EXPECT_FALSE(request_delegate2.auth_required_called()); |
460 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 637 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
461 } | 638 } |
462 | 639 |
463 } // namespace | 640 } // namespace |
464 | 641 |
465 } // namespace net | 642 } // namespace net |
OLD | NEW |