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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #elif defined(USE_NSS) | 10 #elif defined(USE_NSS) |
11 #include "base/nss_util.h" | 11 #include "base/nss_util.h" |
| 12 #include <sslproto.h> |
12 #endif | 13 #endif |
13 | 14 |
14 #include <algorithm> | 15 #include <algorithm> |
15 #include <string> | 16 #include <string> |
16 | 17 |
17 #include "base/file_util.h" | 18 #include "base/file_util.h" |
18 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
19 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/process_util.h" | 22 #include "base/process_util.h" |
22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
23 #include "base/string_piece.h" | 24 #include "base/string_piece.h" |
24 #include "base/string_util.h" | 25 #include "base/string_util.h" |
25 #include "base/stringprintf.h" | 26 #include "base/stringprintf.h" |
26 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
27 #include "net/base/cookie_monster.h" | 28 #include "net/base/cookie_monster.h" |
28 #include "net/base/cookie_policy.h" | 29 #include "net/base/cookie_policy.h" |
29 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
30 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
31 #include "net/base/net_log.h" | 32 #include "net/base/net_log.h" |
32 #include "net/base/net_log_unittest.h" | 33 #include "net/base/net_log_unittest.h" |
33 #include "net/base/net_module.h" | 34 #include "net/base/net_module.h" |
34 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
35 #include "net/base/ssl_connection_status_flags.h" | 36 #include "net/base/ssl_connection_status_flags.h" |
| 37 #include "net/base/cert_status_flags.h" |
36 #include "net/base/upload_data.h" | 38 #include "net/base/upload_data.h" |
37 #include "net/disk_cache/disk_cache.h" | 39 #include "net/disk_cache/disk_cache.h" |
38 #include "net/ftp/ftp_network_layer.h" | 40 #include "net/ftp/ftp_network_layer.h" |
39 #include "net/http/http_cache.h" | 41 #include "net/http/http_cache.h" |
40 #include "net/http/http_network_layer.h" | 42 #include "net/http/http_network_layer.h" |
41 #include "net/http/http_request_headers.h" | 43 #include "net/http/http_request_headers.h" |
42 #include "net/http/http_response_headers.h" | 44 #include "net/http/http_response_headers.h" |
43 #include "net/proxy/proxy_service.h" | 45 #include "net/proxy/proxy_service.h" |
44 #include "net/test/test_server.h" | 46 #include "net/test/test_server.h" |
45 #include "net/url_request/url_request.h" | 47 #include "net/url_request/url_request.h" |
46 #include "net/url_request/url_request_file_dir_job.h" | 48 #include "net/url_request/url_request_file_dir_job.h" |
47 #include "net/url_request/url_request_http_job.h" | 49 #include "net/url_request/url_request_http_job.h" |
48 #include "net/url_request/url_request_test_job.h" | 50 #include "net/url_request/url_request_test_job.h" |
49 #include "net/url_request/url_request_test_util.h" | 51 #include "net/url_request/url_request_test_util.h" |
50 #include "testing/gtest/include/gtest/gtest.h" | 52 #include "testing/gtest/include/gtest/gtest.h" |
51 #include "testing/platform_test.h" | 53 #include "testing/platform_test.h" |
52 | 54 |
53 using base::Time; | 55 using base::Time; |
54 | 56 |
55 namespace { | 57 namespace { |
56 | 58 |
57 const string16 kChrome(ASCIIToUTF16("chrome")); | 59 const string16 kChrome(ASCIIToUTF16("chrome")); |
58 const string16 kSecret(ASCIIToUTF16("secret")); | 60 const string16 kSecret(ASCIIToUTF16("secret")); |
| 61 const string16 kWrongSecret(ASCIIToUTF16("wrongsecret")); |
59 const string16 kUser(ASCIIToUTF16("user")); | 62 const string16 kUser(ASCIIToUTF16("user")); |
| 63 const string16 kWrongUser(ASCIIToUTF16("wronguser")); |
60 | 64 |
61 base::StringPiece TestNetResourceProvider(int key) { | 65 base::StringPiece TestNetResourceProvider(int key) { |
62 return "header"; | 66 return "header"; |
63 } | 67 } |
64 | 68 |
65 // Do a case-insensitive search through |haystack| for |needle|. | 69 // Do a case-insensitive search through |haystack| for |needle|. |
66 bool ContainsString(const std::string& haystack, const char* needle) { | 70 bool ContainsString(const std::string& haystack, const char* needle) { |
67 std::string::const_iterator it = | 71 std::string::const_iterator it = |
68 std::search(haystack.begin(), | 72 std::search(haystack.begin(), |
69 haystack.end(), | 73 haystack.end(), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 110 |
107 // -1 means unknown. 0 means no encryption. | 111 // -1 means unknown. 0 means no encryption. |
108 EXPECT_GT(ssl_info.security_bits, 0); | 112 EXPECT_GT(ssl_info.security_bits, 0); |
109 | 113 |
110 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. | 114 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. |
111 int cipher_suite = net::SSLConnectionStatusToCipherSuite( | 115 int cipher_suite = net::SSLConnectionStatusToCipherSuite( |
112 ssl_info.connection_status); | 116 ssl_info.connection_status); |
113 EXPECT_NE(0, cipher_suite); | 117 EXPECT_NE(0, cipher_suite); |
114 } | 118 } |
115 | 119 |
| 120 // Verify that the AuthChallengeInfo for TLS-SRP has valid values. |
| 121 void CheckTLSAuthChallengeInfo(net::AuthChallengeInfo* login_request, |
| 122 GURL& request_url) { |
| 123 EXPECT_EQ(WideToUTF8(login_request->host_and_port), |
| 124 net::GetHostAndPort(request_url)); |
| 125 EXPECT_EQ(net::kTLSSRPScheme, WideToUTF8(login_request->scheme)); |
| 126 EXPECT_EQ("", WideToUTF8(login_request->realm)); |
| 127 EXPECT_EQ(net::AUTH_OVER_TLS, login_request->over_protocol); |
| 128 } |
| 129 |
116 } // namespace | 130 } // namespace |
117 | 131 |
118 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 132 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
119 class URLRequestTest : public PlatformTest { | 133 class URLRequestTest : public PlatformTest { |
120 public: | 134 public: |
121 static void SetUpTestCase() { | 135 static void SetUpTestCase() { |
122 net::URLRequest::AllowFileAccess(); | 136 net::URLRequest::AllowFileAccess(); |
123 } | 137 } |
124 }; | 138 }; |
125 | 139 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 on_certificate_requested_count_++; | 430 on_certificate_requested_count_++; |
417 MessageLoop::current()->Quit(); | 431 MessageLoop::current()->Quit(); |
418 } | 432 } |
419 int on_certificate_requested_count() { | 433 int on_certificate_requested_count() { |
420 return on_certificate_requested_count_; | 434 return on_certificate_requested_count_; |
421 } | 435 } |
422 private: | 436 private: |
423 int on_certificate_requested_count_; | 437 int on_certificate_requested_count_; |
424 }; | 438 }; |
425 | 439 |
| 440 class HTTPSVClientSRPLoginTestDelegate : public TestDelegate { |
| 441 public: |
| 442 HTTPSVClientSRPLoginTestDelegate() : |
| 443 on_tls_login_required_count_(0), |
| 444 last_login_request_info_(NULL) { |
| 445 } |
| 446 virtual void OnTLSLoginRequired( |
| 447 net::URLRequest* request, |
| 448 net::AuthChallengeInfo* login_request_info) { |
| 449 on_tls_login_required_count_++; |
| 450 last_login_request_info_ = login_request_info; |
| 451 MessageLoop::current()->Quit(); |
| 452 } |
| 453 int on_tls_login_required_count() { |
| 454 return on_tls_login_required_count_; |
| 455 }; |
| 456 net::AuthChallengeInfo* last_login_request_info() { |
| 457 return last_login_request_info_; |
| 458 } |
| 459 private: |
| 460 int on_tls_login_required_count_; |
| 461 net::AuthChallengeInfo* last_login_request_info_; |
| 462 }; |
| 463 |
426 } // namespace | 464 } // namespace |
427 | 465 |
428 // TODO(davidben): Test the rest of the code. Specifically, | 466 // TODO(davidben): Test the rest of the code. Specifically, |
429 // - Filtering which certificates to select. | 467 // - Filtering which certificates to select. |
430 // - Sending a certificate back. | 468 // - Sending a certificate back. |
431 // - Getting a certificate request in an SSL renegotiation sending the | 469 // - Getting a certificate request in an SSL renegotiation sending the |
432 // HTTP request. | 470 // HTTP request. |
433 TEST_F(HTTPSRequestTest, ClientAuthTest) { | 471 TEST_F(HTTPSRequestTest, ClientAuthTest) { |
434 net::TestServer::HTTPSOptions https_options; | 472 net::TestServer::HTTPSOptions https_options; |
435 https_options.request_client_certificate = true; | 473 https_options.request_client_certificate = true; |
(...skipping 20 matching lines...) Expand all Loading... |
456 r.ContinueWithCertificate(NULL); | 494 r.ContinueWithCertificate(NULL); |
457 | 495 |
458 MessageLoop::current()->Run(); | 496 MessageLoop::current()->Run(); |
459 | 497 |
460 EXPECT_EQ(1, d.response_started_count()); | 498 EXPECT_EQ(1, d.response_started_count()); |
461 EXPECT_FALSE(d.received_data_before_response()); | 499 EXPECT_FALSE(d.received_data_before_response()); |
462 EXPECT_NE(0, d.bytes_received()); | 500 EXPECT_NE(0, d.bytes_received()); |
463 } | 501 } |
464 } | 502 } |
465 | 503 |
| 504 TEST_F(HTTPSRequestTest, HTTPSSRPLoginTest) { |
| 505 bool only_tls_srp = false; |
| 506 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) { |
| 507 net::TestServer::HTTPSOptions https_options; |
| 508 https_options.use_tls_srp = true; |
| 509 https_options.only_tls_srp = only_tls_srp; |
| 510 net::TestServer test_server(https_options, FilePath()); |
| 511 ASSERT_TRUE(test_server.Start()); |
| 512 |
| 513 TestDelegate d; |
| 514 { |
| 515 TestURLRequest r(test_server.GetURL("tlslogininfo"), &d); |
| 516 r.SetTLSLogin(kUser, kSecret); |
| 517 |
| 518 r.Start(); |
| 519 EXPECT_TRUE(r.is_pending()); |
| 520 |
| 521 MessageLoop::current()->Run(); |
| 522 |
| 523 EXPECT_NE(0, d.bytes_received()); |
| 524 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 525 std::string::npos); |
| 526 EXPECT_FALSE(d.received_data_before_response()); |
| 527 } |
| 528 } |
| 529 } |
| 530 |
| 531 // Provide no TLS login credentials at first; wait to be prompted by the |
| 532 // server, and then provide them. |
| 533 TEST_F(HTTPSRequestTest, HTTPSSRPLoginContinueTest) { |
| 534 bool only_tls_srp = false; |
| 535 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) { |
| 536 net::TestServer::HTTPSOptions https_options; |
| 537 https_options.use_tls_srp = true; |
| 538 https_options.only_tls_srp = only_tls_srp; |
| 539 net::TestServer test_server(https_options, FilePath()); |
| 540 ASSERT_TRUE(test_server.Start()); |
| 541 |
| 542 HTTPSVClientSRPLoginTestDelegate d; |
| 543 { |
| 544 GURL https_url = test_server.GetURL("tlslogininfo"); |
| 545 TestURLRequest r(https_url, &d); |
| 546 |
| 547 r.Start(); |
| 548 EXPECT_TRUE(r.is_pending()); |
| 549 MessageLoop::current()->Run(); |
| 550 EXPECT_EQ(0, d.bytes_received()); |
| 551 EXPECT_FALSE(d.received_data_before_response()); |
| 552 EXPECT_EQ(1, d.on_tls_login_required_count()); |
| 553 CheckTLSAuthChallengeInfo(d.last_login_request_info(), https_url); |
| 554 |
| 555 r.SetTLSLogin(kUser, kSecret); |
| 556 r.ContinueWithTLSLogin(); |
| 557 MessageLoop::current()->Run(); |
| 558 |
| 559 EXPECT_NE(0, d.bytes_received()); |
| 560 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 561 std::string::npos); |
| 562 EXPECT_FALSE(d.received_data_before_response()); |
| 563 } |
| 564 } |
| 565 } |
| 566 |
| 567 // Open a connection to the same host using SSL certificate auth, and then open |
| 568 // a connection to the same host requesting TLS-SRP auth. |
| 569 // TODO(sqs): disabled - see todo below. |
| 570 // |
| 571 // TODO(sqs): This happens on, e.g., GnuTLS/mod_gnutls. If the Client Hello has |
| 572 // no "srp" extension but has SRP cipher suites, GnuTLS will choose a non-SRP |
| 573 // ciphersuite. Other implementations (OpenSSL, TLS Lite) will send |
| 574 // "unknown_psk_identity". |
| 575 TEST_F(HTTPSRequestTest, DISABLED_SSLCertThenWantUpgradeToSRP) { |
| 576 net::TestServer::HTTPSOptions https_options; |
| 577 https_options.use_tls_srp = true; |
| 578 https_options.only_tls_srp = false; |
| 579 net::TestServer test_server(https_options, FilePath()); |
| 580 ASSERT_TRUE(test_server.Start()); |
| 581 |
| 582 GURL https_url = test_server.GetURL("tlslogininfo"); |
| 583 GURL::Replacements replacements; |
| 584 replacements.SetSchemeStr("httpsv"); |
| 585 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 586 |
| 587 { |
| 588 TestDelegate d_https; |
| 589 d_https.set_allow_certificate_errors(true); |
| 590 TestURLRequest r_https(https_url, &d_https); |
| 591 // TODO(sqs): need to force this connection to use certificate auth. Right |
| 592 // now, TLS Lite sends unknown_psk_identity if the client lists SRP cipher |
| 593 // suites even if no srp username is sent in the client hello. One way to |
| 594 // force this is to set all of the SRP cipher suites as disabled in the |
| 595 // URLRequest's ssl_config, but it's not accessible (ssl_config is actually |
| 596 // much deeper than URLRequest). |
| 597 |
| 598 r_https.Start(); |
| 599 EXPECT_TRUE(r_https.is_pending()); |
| 600 MessageLoop::current()->Run(); |
| 601 EXPECT_EQ(1, d_https.response_started_count()); |
| 602 EXPECT_NE(0, d_https.bytes_received()); |
| 603 CheckSSLInfo(r_https.ssl_info()); |
| 604 |
| 605 HTTPSVClientSRPLoginTestDelegate d; |
| 606 TestURLRequest r(httpsv_url, &d); |
| 607 r.Start(); |
| 608 EXPECT_TRUE(r.is_pending()); |
| 609 |
| 610 MessageLoop::current()->Run(); |
| 611 EXPECT_EQ(0, d.bytes_received()); |
| 612 EXPECT_FALSE(d.received_data_before_response()); |
| 613 EXPECT_EQ(1, d.on_tls_login_required_count()); |
| 614 CheckTLSAuthChallengeInfo(d.last_login_request_info(), httpsv_url); |
| 615 |
| 616 r.SetTLSLogin(kUser, kSecret); |
| 617 r.ContinueWithTLSLogin(); |
| 618 |
| 619 MessageLoop::current()->Run(); |
| 620 EXPECT_NE(0, d.bytes_received()); |
| 621 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 622 std::string::npos); |
| 623 EXPECT_FALSE(d.received_data_before_response()); |
| 624 } |
| 625 } |
| 626 |
| 627 TEST_F(HTTPSRequestTest, TLSLoginCredentialsRemainCached) { |
| 628 net::TestServer::HTTPSOptions https_options; |
| 629 https_options.use_tls_srp = true; |
| 630 net::TestServer test_server(https_options, FilePath()); |
| 631 ASSERT_TRUE(test_server.Start()); |
| 632 |
| 633 GURL https_url = test_server.GetURL(""); |
| 634 GURL::Replacements replacements; |
| 635 replacements.SetSchemeStr("httpsv"); |
| 636 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 637 |
| 638 GURL::Replacements replacements2; |
| 639 replacements2.SetPathStr("tlslogininfo"); |
| 640 GURL https_url2 = https_url.ReplaceComponents(replacements2); |
| 641 |
| 642 { |
| 643 HTTPSVClientSRPLoginTestDelegate d; |
| 644 TestURLRequest r(httpsv_url, &d); |
| 645 r.Start(); |
| 646 EXPECT_TRUE(r.is_pending()); |
| 647 |
| 648 MessageLoop::current()->Run(); |
| 649 EXPECT_EQ(0, d.bytes_received()); |
| 650 EXPECT_FALSE(d.received_data_before_response()); |
| 651 EXPECT_EQ(1, d.on_tls_login_required_count()); |
| 652 CheckTLSAuthChallengeInfo(d.last_login_request_info(), httpsv_url); |
| 653 |
| 654 r.SetTLSLogin(kUser, kSecret); |
| 655 r.ContinueWithTLSLogin(); |
| 656 |
| 657 MessageLoop::current()->Run(); |
| 658 EXPECT_NE(0, d.bytes_received()); |
| 659 EXPECT_FALSE(d.received_data_before_response()); |
| 660 |
| 661 // Don't specify credentials for this request. |
| 662 HTTPSVClientSRPLoginTestDelegate d2; |
| 663 TestURLRequest r2(https_url2, &d2); |
| 664 r2.Start(); |
| 665 EXPECT_TRUE(r2.is_pending()); |
| 666 MessageLoop::current()->Run(); |
| 667 EXPECT_NE(0, d2.bytes_received()); |
| 668 EXPECT_FALSE(d2.received_data_before_response()); |
| 669 LOG(INFO) << "GOT '" << d2.data_received() << "'"; |
| 670 EXPECT_TRUE(d2.data_received().find(UTF16ToUTF8(kUser)) != |
| 671 std::string::npos); |
| 672 } |
| 673 } |
| 674 |
| 675 TEST_F(HTTPSRequestTest, HTTPSVLoginTest) { |
| 676 bool only_tls_srp = false; |
| 677 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) { |
| 678 net::TestServer::HTTPSOptions https_options; |
| 679 https_options.use_tls_srp = true; |
| 680 https_options.only_tls_srp = only_tls_srp; |
| 681 net::TestServer test_server(https_options, FilePath()); |
| 682 ASSERT_TRUE(test_server.Start()); |
| 683 |
| 684 GURL https_url = test_server.GetURL("tlslogininfo"); |
| 685 GURL::Replacements replacements; |
| 686 replacements.SetSchemeStr("httpsv"); |
| 687 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 688 |
| 689 { |
| 690 HTTPSVClientSRPLoginTestDelegate d; |
| 691 TestURLRequest r(httpsv_url, &d); |
| 692 r.Start(); |
| 693 EXPECT_TRUE(r.is_pending()); |
| 694 |
| 695 MessageLoop::current()->Run(); |
| 696 EXPECT_EQ(0, d.bytes_received()); |
| 697 EXPECT_FALSE(d.received_data_before_response()); |
| 698 EXPECT_EQ(1, d.on_tls_login_required_count()); |
| 699 CheckTLSAuthChallengeInfo(d.last_login_request_info(), httpsv_url); |
| 700 |
| 701 r.SetTLSLogin(kUser, kSecret); |
| 702 r.ContinueWithTLSLogin(); |
| 703 |
| 704 MessageLoop::current()->Run(); |
| 705 EXPECT_NE(0, d.bytes_received()); |
| 706 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 707 std::string::npos); |
| 708 EXPECT_FALSE(d.received_data_before_response()); |
| 709 } |
| 710 } |
| 711 } |
| 712 |
| 713 TEST_F(HTTPSRequestTest, HTTPSVSRPLoginWithCertTest) { |
| 714 net::TestServer::HTTPSOptions https_options( |
| 715 net::TestServer::HTTPSOptions::CERT_OK); |
| 716 https_options.use_tls_srp = true; |
| 717 net::TestServer test_server(https_options, |
| 718 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 719 ASSERT_TRUE(test_server.Start()); |
| 720 |
| 721 GURL https_url = test_server.GetURL("tlslogininfo"); |
| 722 GURL::Replacements replacements; |
| 723 replacements.SetSchemeStr("httpsv"); |
| 724 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 725 |
| 726 TestDelegate d; |
| 727 { |
| 728 TestURLRequest r(httpsv_url, &d); |
| 729 r.SetTLSLogin(kUser, kSecret); |
| 730 |
| 731 r.Start(); |
| 732 EXPECT_TRUE(r.is_pending()); |
| 733 |
| 734 MessageLoop::current()->Run(); |
| 735 |
| 736 EXPECT_EQ(1, d.response_started_count()); |
| 737 EXPECT_FALSE(d.received_data_before_response()); |
| 738 EXPECT_NE(0, d.bytes_received()); |
| 739 CheckSSLInfo(r.ssl_info()); |
| 740 EXPECT_FALSE(net::IsCertStatusError(r.ssl_info().cert_status)); |
| 741 EXPECT_TRUE(r.ssl_info().cert.get()); |
| 742 EXPECT_EQ(kUser, r.ssl_info().tls_username); |
| 743 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 744 std::string::npos); |
| 745 } |
| 746 } |
| 747 |
| 748 // Check that we still validate certs on SRP cipher suites that use certs. |
| 749 TEST_F(HTTPSRequestTest, HTTPSVSRPBadCertFailureTest) { |
| 750 bool cert_err_allowed = false; |
| 751 for (int i = 0; i < 2; i++, cert_err_allowed = !cert_err_allowed) { |
| 752 net::TestServer::HTTPSOptions https_options( |
| 753 net::TestServer::HTTPSOptions::CERT_EXPIRED); |
| 754 https_options.use_tls_srp = true; |
| 755 net::TestServer test_server(https_options, |
| 756 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 757 ASSERT_TRUE(test_server.Start()); |
| 758 |
| 759 GURL https_url = test_server.GetURL("tlslogininfo"); |
| 760 GURL::Replacements replacements; |
| 761 replacements.SetSchemeStr("httpsv"); |
| 762 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 763 |
| 764 TestDelegate d; |
| 765 { |
| 766 d.set_allow_certificate_errors(cert_err_allowed); |
| 767 TestURLRequest r(httpsv_url, &d); |
| 768 r.SetTLSLogin(kUser, kSecret); |
| 769 |
| 770 r.Start(); |
| 771 EXPECT_TRUE(r.is_pending()); |
| 772 MessageLoop::current()->Run(); |
| 773 |
| 774 EXPECT_EQ(1, d.response_started_count()); |
| 775 EXPECT_FALSE(d.received_data_before_response()); |
| 776 EXPECT_TRUE(d.have_certificate_errors()); |
| 777 |
| 778 if (cert_err_allowed) { |
| 779 EXPECT_NE(0, d.bytes_received()); |
| 780 CheckSSLInfo(r.ssl_info()); |
| 781 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 782 std::string::npos); |
| 783 } else { |
| 784 EXPECT_EQ(0, d.bytes_received()); |
| 785 } |
| 786 } |
| 787 } |
| 788 } |
| 789 |
| 790 TEST_F(HTTPSRequestTest, HTTPSVBadSecretFailureTest) { |
| 791 bool only_tls_srp = false; |
| 792 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) { |
| 793 net::TestServer::HTTPSOptions https_options; |
| 794 https_options.use_tls_srp = true; |
| 795 https_options.only_tls_srp = only_tls_srp; |
| 796 net::TestServer test_server(https_options, FilePath()); |
| 797 ASSERT_TRUE(test_server.Start()); |
| 798 |
| 799 GURL https_url = test_server.GetURL("tlslogininfo"); |
| 800 GURL::Replacements replacements; |
| 801 replacements.SetSchemeStr("httpsv"); |
| 802 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 803 |
| 804 { |
| 805 HTTPSVClientSRPLoginTestDelegate d; |
| 806 |
| 807 TestURLRequest r(httpsv_url, &d); |
| 808 // Try wrong password. Since this is an httpsv URL, even when the server |
| 809 // also offers certificate-based cipher suites, we will fail to connect. |
| 810 r.SetTLSLogin(kUser, kWrongSecret); |
| 811 r.Start(); |
| 812 EXPECT_TRUE(r.is_pending()); |
| 813 MessageLoop::current()->Run(); |
| 814 EXPECT_EQ(0, d.bytes_received()); |
| 815 EXPECT_EQ(1, d.on_tls_login_required_count()); |
| 816 EXPECT_FALSE(d.received_data_before_response()); |
| 817 |
| 818 // Now continue with the correct password. |
| 819 r.SetTLSLogin(kUser, kSecret); |
| 820 r.ContinueWithTLSLogin(); |
| 821 |
| 822 MessageLoop::current()->Run(); |
| 823 EXPECT_NE(0, d.bytes_received()); |
| 824 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 825 std::string::npos); |
| 826 EXPECT_FALSE(d.received_data_before_response()); |
| 827 } |
| 828 } |
| 829 } |
| 830 |
| 831 TEST_F(HTTPSRequestTest, HTTPSVBadUsernameTest) { |
| 832 bool only_tls_srp = false; |
| 833 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) { |
| 834 net::TestServer::HTTPSOptions https_options; |
| 835 https_options.use_tls_srp = true; |
| 836 https_options.only_tls_srp = only_tls_srp; |
| 837 net::TestServer test_server(https_options, FilePath()); |
| 838 ASSERT_TRUE(test_server.Start()); |
| 839 |
| 840 GURL https_url = test_server.GetURL("tlslogininfo"); |
| 841 GURL::Replacements replacements; |
| 842 replacements.SetSchemeStr("httpsv"); |
| 843 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 844 |
| 845 { |
| 846 HTTPSVClientSRPLoginTestDelegate d; |
| 847 |
| 848 TestURLRequest r(httpsv_url, &d); |
| 849 // Try wrong password. Since this is an httpsv URL, even when the server |
| 850 // also offers certificate-based cipher suites, we will fail to connect. |
| 851 r.SetTLSLogin(kWrongUser, kSecret); |
| 852 r.Start(); |
| 853 EXPECT_TRUE(r.is_pending()); |
| 854 MessageLoop::current()->Run(); |
| 855 EXPECT_EQ(0, d.bytes_received()); |
| 856 EXPECT_FALSE(d.received_data_before_response()); |
| 857 EXPECT_EQ(1, d.on_tls_login_required_count()); |
| 858 CheckTLSAuthChallengeInfo(d.last_login_request_info(), httpsv_url); |
| 859 |
| 860 // Now continue with the correct password. |
| 861 r.SetTLSLogin(kUser, kSecret); |
| 862 r.ContinueWithTLSLogin(); |
| 863 |
| 864 MessageLoop::current()->Run(); |
| 865 EXPECT_NE(0, d.bytes_received()); |
| 866 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) != |
| 867 std::string::npos); |
| 868 EXPECT_FALSE(d.received_data_before_response()); |
| 869 } |
| 870 } |
| 871 } |
| 872 |
| 873 TEST_F(HTTPSRequestTest, HTTPSVCancelLoginTest) { |
| 874 net::TestServer::HTTPSOptions https_options; |
| 875 https_options.use_tls_srp = true; |
| 876 https_options.only_tls_srp = true; |
| 877 net::TestServer test_server(https_options, FilePath()); |
| 878 ASSERT_TRUE(test_server.Start()); |
| 879 |
| 880 GURL https_url = test_server.GetURL(""); |
| 881 GURL::Replacements replacements; |
| 882 replacements.SetSchemeStr("httpsv"); |
| 883 GURL httpsv_url = https_url.ReplaceComponents(replacements); |
| 884 |
| 885 { |
| 886 HTTPSVClientSRPLoginTestDelegate d; |
| 887 |
| 888 TestURLRequest r(httpsv_url, &d); |
| 889 r.Start(); |
| 890 EXPECT_TRUE(r.is_pending()); |
| 891 MessageLoop::current()->Run(); |
| 892 |
| 893 EXPECT_EQ(0, d.bytes_received()); |
| 894 EXPECT_EQ(1, d.on_tls_login_required_count()); |
| 895 EXPECT_FALSE(d.received_data_before_response()); |
| 896 |
| 897 r.CancelTLSLogin(); |
| 898 |
| 899 MessageLoop::current()->Run(); |
| 900 EXPECT_EQ(0, d.bytes_received()); |
| 901 EXPECT_FALSE(d.received_data_before_response()); |
| 902 } |
| 903 } |
| 904 |
466 TEST_F(URLRequestTestHTTP, CancelTest) { | 905 TEST_F(URLRequestTestHTTP, CancelTest) { |
467 TestDelegate d; | 906 TestDelegate d; |
468 { | 907 { |
469 TestURLRequest r(GURL("http://www.google.com/"), &d); | 908 TestURLRequest r(GURL("http://www.google.com/"), &d); |
470 | 909 |
471 r.Start(); | 910 r.Start(); |
472 EXPECT_TRUE(r.is_pending()); | 911 EXPECT_TRUE(r.is_pending()); |
473 | 912 |
474 r.Cancel(); | 913 r.Cancel(); |
475 | 914 |
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2729 net::HttpRequestHeaders headers; | 3168 net::HttpRequestHeaders headers; |
2730 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 3169 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
2731 req.SetExtraRequestHeaders(headers); | 3170 req.SetExtraRequestHeaders(headers); |
2732 req.Start(); | 3171 req.Start(); |
2733 MessageLoop::current()->Run(); | 3172 MessageLoop::current()->Run(); |
2734 // If the net tests are being run with ChromeFrame then we need to allow for | 3173 // If the net tests are being run with ChromeFrame then we need to allow for |
2735 // the 'chromeframe' suffix which is added to the user agent before the | 3174 // the 'chromeframe' suffix which is added to the user agent before the |
2736 // closing parentheses. | 3175 // closing parentheses. |
2737 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3176 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
2738 } | 3177 } |
OLD | NEW |