Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 6804032: Add TLS-SRP (RFC 5054) support Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 on_certificate_requested_count_++; 420 on_certificate_requested_count_++;
417 MessageLoop::current()->Quit(); 421 MessageLoop::current()->Quit();
418 } 422 }
419 int on_certificate_requested_count() { 423 int on_certificate_requested_count() {
420 return on_certificate_requested_count_; 424 return on_certificate_requested_count_;
421 } 425 }
422 private: 426 private:
423 int on_certificate_requested_count_; 427 int on_certificate_requested_count_;
424 }; 428 };
425 429
430 class HTTPSVClientSRPLoginTestDelegate : public TestDelegate {
431 public:
432 HTTPSVClientSRPLoginTestDelegate() :
433 on_tls_login_required_count_(0),
434 last_login_request_info_(NULL) {
435 }
436 virtual void OnTLSLoginRequired(
437 net::URLRequest* request,
438 net::AuthChallengeInfo* login_request_info) {
439 on_tls_login_required_count_++;
440 last_login_request_info_ = login_request_info;
441 MessageLoop::current()->Quit();
442 }
443 int on_tls_login_required_count() {
444 return on_tls_login_required_count_;
445 };
446 net::AuthChallengeInfo* last_login_request_info() {
447 return last_login_request_info_;
448 }
449 private:
450 int on_tls_login_required_count_;
451 net::AuthChallengeInfo* last_login_request_info_;
452 };
453
426 } // namespace 454 } // namespace
427 455
428 // TODO(davidben): Test the rest of the code. Specifically, 456 // TODO(davidben): Test the rest of the code. Specifically,
429 // - Filtering which certificates to select. 457 // - Filtering which certificates to select.
430 // - Sending a certificate back. 458 // - Sending a certificate back.
431 // - Getting a certificate request in an SSL renegotiation sending the 459 // - Getting a certificate request in an SSL renegotiation sending the
432 // HTTP request. 460 // HTTP request.
433 TEST_F(HTTPSRequestTest, ClientAuthTest) { 461 TEST_F(HTTPSRequestTest, ClientAuthTest) {
434 net::TestServer::HTTPSOptions https_options; 462 net::TestServer::HTTPSOptions https_options;
435 https_options.request_client_certificate = true; 463 https_options.request_client_certificate = true;
(...skipping 20 matching lines...) Expand all
456 r.ContinueWithCertificate(NULL); 484 r.ContinueWithCertificate(NULL);
457 485
458 MessageLoop::current()->Run(); 486 MessageLoop::current()->Run();
459 487
460 EXPECT_EQ(1, d.response_started_count()); 488 EXPECT_EQ(1, d.response_started_count());
461 EXPECT_FALSE(d.received_data_before_response()); 489 EXPECT_FALSE(d.received_data_before_response());
462 EXPECT_NE(0, d.bytes_received()); 490 EXPECT_NE(0, d.bytes_received());
463 } 491 }
464 } 492 }
465 493
494 TEST_F(HTTPSRequestTest, HTTPSSRPLoginTest) {
495 bool only_tls_srp = false;
496 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) {
497 net::TestServer::HTTPSOptions https_options;
498 https_options.use_tls_srp = true;
499 https_options.only_tls_srp = only_tls_srp;
500 net::TestServer test_server(https_options, FilePath());
501 ASSERT_TRUE(test_server.Start());
502
503 TestDelegate d;
504 {
505 TestURLRequest r(test_server.GetURL("tlslogininfo"), &d);
506 r.SetTLSLogin(kUser, kSecret);
507
508 r.Start();
509 EXPECT_TRUE(r.is_pending());
510
511 MessageLoop::current()->Run();
512
513 EXPECT_NE(0, d.bytes_received());
514 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) !=
515 std::string::npos);
516 EXPECT_FALSE(d.received_data_before_response());
517 }
518 }
519 }
520
521 // Provide no TLS login credentials at first; wait to be prompted by the
522 // server, and then provide them.
523 TEST_F(HTTPSRequestTest, HTTPSSRPLoginContinueTest) {
524 bool only_tls_srp = false;
525 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) {
526 net::TestServer::HTTPSOptions https_options;
527 https_options.use_tls_srp = true;
528 https_options.only_tls_srp = only_tls_srp;
529 net::TestServer test_server(https_options, FilePath());
530 ASSERT_TRUE(test_server.Start());
531
532 HTTPSVClientSRPLoginTestDelegate d;
533 {
534 GURL https_url = test_server.GetURL("tlslogininfo");
535 TestURLRequest r(https_url, &d);
536
537 r.Start();
538 EXPECT_TRUE(r.is_pending());
539 MessageLoop::current()->Run();
540 EXPECT_EQ(0, d.bytes_received());
541 EXPECT_FALSE(d.received_data_before_response());
542 EXPECT_EQ(1, d.on_tls_login_required_count());
543 EXPECT_EQ("TLS-SRP", WideToUTF8(d.last_login_request_info()->scheme));
544 std::string host_and_port =
545 WideToUTF8(d.last_login_request_info()->host_and_port);
546 EXPECT_TRUE(host_and_port.find(https_url.host()) != std::string::npos);
547 EXPECT_TRUE(host_and_port.find(https_url.port()) != std::string::npos);
548 EXPECT_EQ("", WideToUTF8(d.last_login_request_info()->realm));
549
550 r.SetTLSLogin(kUser, kSecret);
551 r.ContinueWithTLSLogin();
552 MessageLoop::current()->Run();
553
554 EXPECT_NE(0, d.bytes_received());
555 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) !=
556 std::string::npos);
557 EXPECT_FALSE(d.received_data_before_response());
558 }
559 }
560 }
561
562 // Open a connection to the same host using SSL certificate auth, and then open
563 // a connection to the same host requesting TLS-SRP auth.
564 // TODO(sqs): disabled - see todo below.
565 //
566 // TODO(sqs): This happens on, e.g., GnuTLS/mod_gnutls. If the Client Hello has
567 // no "srp" extension but has SRP cipher suites, GnuTLS will choose a non-SRP
568 // ciphersuite. Other implementations (OpenSSL, TLS Lite) will send
569 // "unknown_psk_identity".
570 TEST_F(HTTPSRequestTest, DISABLED_SSLCertThenWantUpgradeToSRP) {
571 net::TestServer::HTTPSOptions https_options;
572 https_options.use_tls_srp = true;
573 https_options.only_tls_srp = false;
574 net::TestServer test_server(https_options, FilePath());
575 ASSERT_TRUE(test_server.Start());
576
577 GURL https_url = test_server.GetURL("tlslogininfo");
578 GURL::Replacements replacements;
579 replacements.SetSchemeStr("httpsv");
580 GURL httpsv_url = https_url.ReplaceComponents(replacements);
581
582 {
583 TestDelegate d_https;
584 d_https.set_allow_certificate_errors(true);
585 TestURLRequest r_https(https_url, &d_https);
586 // TODO(sqs): need to force this connection to use certificate auth. Right
587 // now, TLS Lite sends unknown_psk_identity if the client lists SRP cipher
588 // suites even if no srp username is sent in the client hello. One way to
589 // force this is to set all of the SRP cipher suites as disabled in the
590 // URLRequest's ssl_config, but it's not accessible (ssl_config is actually
591 // much deeper than URLRequest).
592
593 r_https.Start();
594 EXPECT_TRUE(r_https.is_pending());
595 MessageLoop::current()->Run();
596 EXPECT_EQ(1, d_https.response_started_count());
597 EXPECT_NE(0, d_https.bytes_received());
598 CheckSSLInfo(r_https.ssl_info());
599
600 HTTPSVClientSRPLoginTestDelegate d;
601 TestURLRequest r(httpsv_url, &d);
602 r.Start();
603 EXPECT_TRUE(r.is_pending());
604
605 MessageLoop::current()->Run();
606 EXPECT_EQ(0, d.bytes_received());
607 EXPECT_FALSE(d.received_data_before_response());
608 EXPECT_EQ(1, d.on_tls_login_required_count());
609 EXPECT_EQ("TLS-SRP", WideToUTF8(d.last_login_request_info()->scheme));
610 std::string host_and_port =
611 WideToUTF8(d.last_login_request_info()->host_and_port);
612 EXPECT_TRUE(host_and_port.find(httpsv_url.host()) != std::string::npos);
613 EXPECT_TRUE(host_and_port.find(httpsv_url.port()) != std::string::npos);
614 EXPECT_EQ("", WideToUTF8(d.last_login_request_info()->realm));
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 EXPECT_EQ("TLS-SRP", WideToUTF8(d.last_login_request_info()->scheme));
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 EXPECT_EQ("TLS-SRP", WideToUTF8(d.last_login_request_info()->scheme));
700 std::string host_and_port =
701 WideToUTF8(d.last_login_request_info()->host_and_port);
702 EXPECT_TRUE(host_and_port.find(httpsv_url.host()) != std::string::npos);
703 EXPECT_TRUE(host_and_port.find(httpsv_url.port()) != std::string::npos);
704 EXPECT_EQ("", WideToUTF8(d.last_login_request_info()->realm));
705
706 r.SetTLSLogin(kUser, kSecret);
707 r.ContinueWithTLSLogin();
708
709 MessageLoop::current()->Run();
710 EXPECT_NE(0, d.bytes_received());
711 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) !=
712 std::string::npos);
713 EXPECT_FALSE(d.received_data_before_response());
714 }
715 }
716 }
717
718 TEST_F(HTTPSRequestTest, HTTPSVSRPLoginWithCertTest) {
719 net::TestServer::HTTPSOptions https_options(
720 net::TestServer::HTTPSOptions::CERT_OK);
721 https_options.use_tls_srp = true;
722 net::TestServer test_server(https_options,
723 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
724 ASSERT_TRUE(test_server.Start());
725
726 GURL https_url = test_server.GetURL("tlslogininfo");
727 GURL::Replacements replacements;
728 replacements.SetSchemeStr("httpsv");
729 GURL httpsv_url = https_url.ReplaceComponents(replacements);
730
731 TestDelegate d;
732 {
733 TestURLRequest r(httpsv_url, &d);
734 r.SetTLSLogin(kUser, kSecret);
735
736 r.Start();
737 EXPECT_TRUE(r.is_pending());
738
739 MessageLoop::current()->Run();
740
741 EXPECT_EQ(1, d.response_started_count());
742 EXPECT_FALSE(d.received_data_before_response());
743 EXPECT_NE(0, d.bytes_received());
744 CheckSSLInfo(r.ssl_info());
745 EXPECT_FALSE(net::IsCertStatusError(r.ssl_info().cert_status));
746 EXPECT_TRUE(r.ssl_info().cert.get());
747 EXPECT_EQ(kUser, r.ssl_info().tls_username);
748 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) !=
749 std::string::npos);
750 }
751 }
752
753 // Check that we still validate certs on SRP cipher suites that use certs.
754 TEST_F(HTTPSRequestTest, HTTPSVSRPBadCertFailureTest) {
755 bool cert_err_allowed = false;
756 for (int i = 0; i < 2; i++, cert_err_allowed = !cert_err_allowed) {
757 net::TestServer::HTTPSOptions https_options(
758 net::TestServer::HTTPSOptions::CERT_EXPIRED);
759 https_options.use_tls_srp = true;
760 net::TestServer test_server(https_options,
761 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
762 ASSERT_TRUE(test_server.Start());
763
764 GURL https_url = test_server.GetURL("tlslogininfo");
765 GURL::Replacements replacements;
766 replacements.SetSchemeStr("httpsv");
767 GURL httpsv_url = https_url.ReplaceComponents(replacements);
768
769 TestDelegate d;
770 {
771 d.set_allow_certificate_errors(cert_err_allowed);
772 TestURLRequest r(httpsv_url, &d);
773 r.SetTLSLogin(kUser, kSecret);
774
775 r.Start();
776 EXPECT_TRUE(r.is_pending());
777 MessageLoop::current()->Run();
778
779 EXPECT_EQ(1, d.response_started_count());
780 EXPECT_FALSE(d.received_data_before_response());
781 EXPECT_TRUE(d.have_certificate_errors());
782
783 if (cert_err_allowed) {
784 EXPECT_NE(0, d.bytes_received());
785 CheckSSLInfo(r.ssl_info());
786 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) !=
787 std::string::npos);
788 } else {
789 EXPECT_EQ(0, d.bytes_received());
790 }
791 }
792 }
793 }
794
795 TEST_F(HTTPSRequestTest, HTTPSVBadSecretFailureTest) {
796 bool only_tls_srp = false;
797 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) {
798 net::TestServer::HTTPSOptions https_options;
799 https_options.use_tls_srp = true;
800 https_options.only_tls_srp = only_tls_srp;
801 net::TestServer test_server(https_options, FilePath());
802 ASSERT_TRUE(test_server.Start());
803
804 GURL https_url = test_server.GetURL("tlslogininfo");
805 GURL::Replacements replacements;
806 replacements.SetSchemeStr("httpsv");
807 GURL httpsv_url = https_url.ReplaceComponents(replacements);
808
809 {
810 HTTPSVClientSRPLoginTestDelegate d;
811
812 TestURLRequest r(httpsv_url, &d);
813 // Try wrong password. Since this is an httpsv URL, even when the server
814 // also offers certificate-based cipher suites, we will fail to connect.
815 r.SetTLSLogin(kUser, kWrongSecret);
816 r.Start();
817 EXPECT_TRUE(r.is_pending());
818 MessageLoop::current()->Run();
819 EXPECT_EQ(0, d.bytes_received());
820 EXPECT_EQ(1, d.on_tls_login_required_count());
821 EXPECT_FALSE(d.received_data_before_response());
822
823 // Now continue with the correct password.
824 r.SetTLSLogin(kUser, kSecret);
825 r.ContinueWithTLSLogin();
826
827 MessageLoop::current()->Run();
828 EXPECT_NE(0, d.bytes_received());
829 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) !=
830 std::string::npos);
831 EXPECT_FALSE(d.received_data_before_response());
832 }
833 }
834 }
835
836 TEST_F(HTTPSRequestTest, HTTPSVBadUsernameTest) {
837 bool only_tls_srp = false;
838 for (int i = 0; i < 2; i++, only_tls_srp = !only_tls_srp) {
839 net::TestServer::HTTPSOptions https_options;
840 https_options.use_tls_srp = true;
841 https_options.only_tls_srp = only_tls_srp;
842 net::TestServer test_server(https_options, FilePath());
843 ASSERT_TRUE(test_server.Start());
844
845 GURL https_url = test_server.GetURL("tlslogininfo");
846 GURL::Replacements replacements;
847 replacements.SetSchemeStr("httpsv");
848 GURL httpsv_url = https_url.ReplaceComponents(replacements);
849
850 {
851 HTTPSVClientSRPLoginTestDelegate d;
852
853 TestURLRequest r(httpsv_url, &d);
854 // Try wrong password. Since this is an httpsv URL, even when the server
855 // also offers certificate-based cipher suites, we will fail to connect.
856 r.SetTLSLogin(kWrongUser, kSecret);
857 r.Start();
858 EXPECT_TRUE(r.is_pending());
859 MessageLoop::current()->Run();
860 EXPECT_EQ(0, d.bytes_received());
861 EXPECT_FALSE(d.received_data_before_response());
862 EXPECT_EQ(1, d.on_tls_login_required_count());
863 ASSERT_TRUE(d.last_login_request_info() != NULL);
864 EXPECT_EQ("TLS-SRP", WideToUTF8(d.last_login_request_info()->scheme));
865 std::string host_and_port =
866 WideToUTF8(d.last_login_request_info()->host_and_port);
867 EXPECT_TRUE(host_and_port.find(httpsv_url.host()) != std::string::npos);
868 EXPECT_TRUE(host_and_port.find(httpsv_url.port()) != std::string::npos);
869 EXPECT_EQ("", WideToUTF8(d.last_login_request_info()->realm));
870
871 // Now continue with the correct password.
872 r.SetTLSLogin(kUser, kSecret);
873 r.ContinueWithTLSLogin();
874
875 MessageLoop::current()->Run();
876 EXPECT_NE(0, d.bytes_received());
877 EXPECT_TRUE(d.data_received().find(UTF16ToUTF8(kUser)) !=
878 std::string::npos);
879 EXPECT_FALSE(d.received_data_before_response());
880 }
881 }
882 }
883
884 TEST_F(HTTPSRequestTest, HTTPSVCancelLoginTest) {
885 net::TestServer::HTTPSOptions https_options;
886 https_options.use_tls_srp = true;
887 https_options.only_tls_srp = true;
888 net::TestServer test_server(https_options, FilePath());
889 ASSERT_TRUE(test_server.Start());
890
891 GURL https_url = test_server.GetURL("");
892 GURL::Replacements replacements;
893 replacements.SetSchemeStr("httpsv");
894 GURL httpsv_url = https_url.ReplaceComponents(replacements);
895
896 {
897 HTTPSVClientSRPLoginTestDelegate d;
898
899 TestURLRequest r(httpsv_url, &d);
900 r.Start();
901 EXPECT_TRUE(r.is_pending());
902 MessageLoop::current()->Run();
903
904 EXPECT_EQ(0, d.bytes_received());
905 EXPECT_EQ(1, d.on_tls_login_required_count());
906 EXPECT_FALSE(d.received_data_before_response());
907
908 r.CancelTLSLogin();
909
910 MessageLoop::current()->Run();
911 EXPECT_EQ(0, d.bytes_received());
912 EXPECT_FALSE(d.received_data_before_response());
913 }
914 }
915
466 TEST_F(URLRequestTestHTTP, CancelTest) { 916 TEST_F(URLRequestTestHTTP, CancelTest) {
467 TestDelegate d; 917 TestDelegate d;
468 { 918 {
469 TestURLRequest r(GURL("http://www.google.com/"), &d); 919 TestURLRequest r(GURL("http://www.google.com/"), &d);
470 920
471 r.Start(); 921 r.Start();
472 EXPECT_TRUE(r.is_pending()); 922 EXPECT_TRUE(r.is_pending());
473 923
474 r.Cancel(); 924 r.Cancel();
475 925
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 net::HttpRequestHeaders headers; 3179 net::HttpRequestHeaders headers;
2730 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 3180 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
2731 req.SetExtraRequestHeaders(headers); 3181 req.SetExtraRequestHeaders(headers);
2732 req.Start(); 3182 req.Start();
2733 MessageLoop::current()->Run(); 3183 MessageLoop::current()->Run();
2734 // If the net tests are being run with ChromeFrame then we need to allow for 3184 // 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 3185 // the 'chromeframe' suffix which is added to the user agent before the
2736 // closing parentheses. 3186 // closing parentheses.
2737 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 3187 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
2738 } 3188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698