OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 5 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 // worth of browsing history and verify that the exception has been deleted. | 618 // worth of browsing history and verify that the exception has been deleted. |
619 state->AllowCert( | 619 state->AllowCert( |
620 kGoogleHost, *google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 620 kGoogleHost, *google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
621 RemoveAndWait(profile); | 621 RemoveAndWait(profile); |
622 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, | 622 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
623 state->QueryPolicy(kGoogleHost, | 623 state->QueryPolicy(kGoogleHost, |
624 *google_cert.get(), | 624 *google_cert.get(), |
625 net::CERT_STATUS_DATE_INVALID, | 625 net::CERT_STATUS_DATE_INVALID, |
626 &unused_value)); | 626 &unused_value)); |
627 } | 627 } |
628 | |
629 // Tests to make sure that localhost certificate errors are ignored or | |
630 // treated as normal errors, depending on whether the | |
631 // kAllowInsecureLocalhost flag is set. | |
632 | |
633 // When the flag isn't set, requests to localhost with invalid | |
634 // certificates should be denied. | |
635 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, | |
636 LocalhostErrorWithoutFlag) { | |
637 // Serve the Google cert for localhost to generate an error. | |
638 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | |
Ryan Sleevi
2015/02/04 19:34:41
Not your fault, other than I never noticed until t
estark
2015/02/05 03:02:38
Done. Just to make sure I understand:
* The pain o
| |
639 content::WebContents* tab = | |
640 browser()->tab_strip_model()->GetActiveWebContents(); | |
641 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | |
642 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | |
643 bool unused_value; | |
644 | |
645 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, | |
646 state->QueryPolicy("localhost", | |
647 *google_cert.get(), | |
648 net::CERT_STATUS_COMMON_NAME_INVALID, | |
649 &unused_value)); | |
650 } | |
651 | |
652 // When the flag is set, requests to localhost with invalid certificates | |
653 // should be allowed. | |
654 class AllowLocalhostErrorsSSLHostStateDelegateTest | |
655 : public ChromeSSLHostStateDelegateTest { | |
656 protected: | |
657 void SetUpCommandLine(base::CommandLine* command_line) override { | |
658 ChromeSSLHostStateDelegateTest::SetUpCommandLine(command_line); | |
659 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); | |
660 } | |
661 }; | |
662 | |
663 IN_PROC_BROWSER_TEST_F(AllowLocalhostErrorsSSLHostStateDelegateTest, | |
664 LocalhostErrorWithFlag) { | |
665 // Serve the Google cert for localhost to generate an error. | |
666 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | |
667 content::WebContents* tab = | |
668 browser()->tab_strip_model()->GetActiveWebContents(); | |
669 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | |
670 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | |
671 bool unused_value; | |
672 | |
673 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, | |
674 state->QueryPolicy("localhost", | |
675 *google_cert.get(), | |
676 net::CERT_STATUS_COMMON_NAME_INVALID, | |
677 &unused_value)); | |
678 } | |
OLD | NEW |