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

Side by Side Diff: chrome/browser/ssl/security_state_tab_helper_browser_tests.cc

Issue 2917873004: Implement 'Not secure' warning for non-secure pages in Incognito mode (Closed)
Patch Set: Ensure sensitive fields trigger warnings outside of Incognito Created 3 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/security_state_tab_helper.h" 5 #include "chrome/browser/ssl/security_state_tab_helper.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/scoped_command_line.h"
12 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
13 #include "chrome/browser/ssl/cert_verifier_browser_test.h" 14 #include "chrome/browser/ssl/cert_verifier_browser_test.h"
14 #include "chrome/browser/ssl/ssl_blocking_page.h" 15 #include "chrome/browser/ssl/ssl_blocking_page.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 17 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 366 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
366 } 367 }
367 } 368 }
368 369
369 net::EmbeddedTestServer https_server_; 370 net::EmbeddedTestServer https_server_;
370 371
371 private: 372 private:
372 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest); 373 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest);
373 }; 374 };
374 375
376 // Same as SecurityStateTabHelperTest, but with Incognito enabled.
377 class SecurityStateTabHelperIncognitoTest : public SecurityStateTabHelperTest {
378 public:
379 SecurityStateTabHelperIncognitoTest() : SecurityStateTabHelperTest() {}
380
381 void SetUpCommandLine(base::CommandLine* command_line) override {
382 SecurityStateTabHelperTest::SetUpCommandLine(command_line);
383 // Test should run Incognito.
384 command_line->AppendSwitch(switches::kIncognito);
385 }
386
387 private:
388 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperIncognitoTest);
389 };
390
375 class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest { 391 class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest {
376 public: 392 public:
377 DidChangeVisibleSecurityStateTest() 393 DidChangeVisibleSecurityStateTest()
378 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { 394 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
379 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); 395 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
380 } 396 }
381 397
382 void SetUpCommandLine(base::CommandLine* command_line) override { 398 void SetUpCommandLine(base::CommandLine* command_line) override {
383 // Browser will both run and display insecure content. 399 // Browser will both run and display insecure content.
384 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); 400 command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 protected: 942 protected:
927 void SetUpOnMainThread() override { 943 void SetUpOnMainThread() override {
928 ASSERT_TRUE(embedded_test_server()->Start()); 944 ASSERT_TRUE(embedded_test_server()->Start());
929 945
930 content::BrowserThread::PostTask( 946 content::BrowserThread::PostTask(
931 content::BrowserThread::IO, FROM_HERE, 947 content::BrowserThread::IO, FROM_HERE,
932 base::Bind(&InstallLoadingInterceptor, 948 base::Bind(&InstallLoadingInterceptor,
933 embedded_test_server()->GetURL("/title1.html").host())); 949 embedded_test_server()->GetURL("/title1.html").host()));
934 } 950 }
935 951
952 private:
elawrence 2017/06/07 21:05:05 git cl lint demands this.
936 DISALLOW_COPY_AND_ASSIGN(SecurityStateLoadingTest); 953 DISALLOW_COPY_AND_ASSIGN(SecurityStateLoadingTest);
937 }; 954 };
938 955
939 // Tests that navigation state changes cause the security state to be 956 // Tests that navigation state changes cause the security state to be
940 // updated. 957 // updated.
941 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) { 958 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) {
942 ASSERT_TRUE(https_server_.Start()); 959 ASSERT_TRUE(https_server_.Start());
943 SetUpMockCertVerifierForHttpsServer(0, net::OK); 960 SetUpMockCertVerifierForHttpsServer(0, net::OK);
944 961
945 // Navigate to an HTTPS page. 962 // Navigate to an HTTPS page.
(...skipping 30 matching lines...) Expand all
976 "/password/simple_password.html")); 993 "/password/simple_password.html"));
977 InjectScript(contents); 994 InjectScript(contents);
978 security_state::SecurityInfo security_info; 995 security_state::SecurityInfo security_info;
979 helper->GetSecurityInfo(&security_info); 996 helper->GetSecurityInfo(&security_info);
980 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 997 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
981 998
982 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 999 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
983 ASSERT_TRUE(entry); 1000 ASSERT_TRUE(entry);
984 EXPECT_TRUE(entry->GetSSL().content_status & 1001 EXPECT_TRUE(entry->GetSSL().content_status &
985 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 1002 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1003
1004 {
1005 // Ensure the warning is still present when HTTPBad Phase 2 flag is enabled.
1006 base::test::ScopedCommandLine scoped_command_line;
1007 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1008 security_state::switches::kMarkHttpAs,
1009 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1010
1011 helper->GetSecurityInfo(&security_info);
1012 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1013 }
986 } 1014 }
987 1015
988 // Tests that when a visible password field is detected on a blob URL, the 1016 // Tests that when a visible password field is detected on a blob URL, the
989 // security level is downgraded to HTTP_SHOW_WARNING. 1017 // security level is downgraded to HTTP_SHOW_WARNING.
990 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, 1018 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
991 PasswordSecurityLevelDowngradedOnBlobUrl) { 1019 PasswordSecurityLevelDowngradedOnBlobUrl) {
992 TestPasswordFieldOnBlobOrFilesystemURL( 1020 TestPasswordFieldOnBlobOrFilesystemURL(
993 "blob", 1021 "blob",
994 "var blob = new Blob(['<html><form><input type=password></form></html>']," 1022 "var blob = new Blob(['<html><form><input type=password></form></html>'],"
995 " {type: 'text/html'});" 1023 " {type: 'text/html'});"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 // already a console message logged for the current main-frame 1373 // already a console message logged for the current main-frame
1346 // navigation. 1374 // navigation.
1347 content::WindowedNotificationObserver subframe_observer( 1375 content::WindowedNotificationObserver subframe_observer(
1348 content::NOTIFICATION_LOAD_STOP, 1376 content::NOTIFICATION_LOAD_STOP,
1349 content::Source<content::NavigationController>( 1377 content::Source<content::NavigationController>(
1350 &contents->GetController())); 1378 &contents->GetController()));
1351 EXPECT_TRUE(content::ExecuteScript( 1379 EXPECT_TRUE(content::ExecuteScript(
1352 contents, "document.getElementById('navFrame').src = '/title2.html';")); 1380 contents, "document.getElementById('navFrame').src = '/title2.html';"));
1353 subframe_observer.Wait(); 1381 subframe_observer.Wait();
1354 contents->OnCreditCardInputShownOnHttp(); 1382 contents->OnCreditCardInputShownOnHttp();
1383 helper->GetSecurityInfo(&security_info);
elawrence 2017/06/07 21:05:05 Opportunistic fix.
1355 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1384 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1356 1385
1357 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING 1386 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
1358 // again. From the above subframe navigation and this main-frame 1387 // again. From the above subframe navigation and this main-frame
1359 // navigation, exactly one console message is expected. 1388 // navigation, exactly one console message is expected.
1360 GURL second_http_url = 1389 GURL second_http_url =
1361 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1390 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1362 ui_test_utils::NavigateToURL(delegate, second_http_url); 1391 ui_test_utils::NavigateToURL(delegate, second_http_url);
1363 entry = contents->GetController().GetVisibleEntry(); 1392 entry = contents->GetController().GetVisibleEntry();
1364 ASSERT_TRUE(entry); 1393 ASSERT_TRUE(entry);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 delegate->ClearConsoleMessages(); 1450 delegate->ClearConsoleMessages();
1422 1451
1423 // Navigate with pushState and trigger VisibleSecurityStateChanged 1452 // Navigate with pushState and trigger VisibleSecurityStateChanged
1424 // again. While the security level is still HTTP_SHOW_WARNING, an 1453 // again. While the security level is still HTTP_SHOW_WARNING, an
1425 // additional console message should not be logged because there was 1454 // additional console message should not be logged because there was
1426 // already a console message logged for the current main-frame 1455 // already a console message logged for the current main-frame
1427 // navigation. 1456 // navigation.
1428 EXPECT_TRUE(content::ExecuteScript( 1457 EXPECT_TRUE(content::ExecuteScript(
1429 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');")); 1458 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
1430 contents->OnCreditCardInputShownOnHttp(); 1459 contents->OnCreditCardInputShownOnHttp();
1460 helper->GetSecurityInfo(&security_info);
elawrence 2017/06/07 21:05:05 Opportunistic fix.
1431 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1461 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1432 1462
1433 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING 1463 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
1434 // again. From the above pushState navigation and this main-frame 1464 // again. From the above pushState navigation and this main-frame
1435 // navigation, exactly one console message is expected. 1465 // navigation, exactly one console message is expected.
1436 GURL second_http_url = 1466 GURL second_http_url =
1437 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1467 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1438 ui_test_utils::NavigateToURL(delegate, second_http_url); 1468 ui_test_utils::NavigateToURL(delegate, second_http_url);
1439 entry = contents->GetController().GetVisibleEntry(); 1469 entry = contents->GetController().GetVisibleEntry();
1440 ASSERT_TRUE(entry); 1470 ASSERT_TRUE(entry);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 INVALID_CERTIFICATE, browser(), 1637 INVALID_CERTIFICATE, browser(),
1608 https_test_server_expired.GetCertificate().get()); 1638 https_test_server_expired.GetCertificate().get());
1609 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic); 1639 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic);
1610 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed); 1640 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed);
1611 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty()); 1641 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty());
1612 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content); 1642 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content);
1613 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content); 1643 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content);
1614 EXPECT_TRUE(observer.latest_explanations().summary.empty()); 1644 EXPECT_TRUE(observer.latest_explanations().summary.empty());
1615 } 1645 }
1616 1646
1647 // Tests that the security level of a HTTP page in Incognito mode is downgraded
1648 // to HTTP_SHOW_WARNING when MarkHttpAsNonSecureWhileIncognito is enabled.
1649 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1650 SecurityLevelDowngradedForHTTPInIncognito) {
1651 // Set the mode using the command line flag rather than the field trial to
1652 // ensure that fieldtrial_testing_config.json does not interfere.
1653 base::test::ScopedCommandLine scoped_command_line;
1654 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1655 security_state::switches::kMarkHttpAs,
1656 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1657
1658 content::WebContents* contents =
1659 browser()->tab_strip_model()->GetActiveWebContents();
1660 ASSERT_TRUE(contents);
1661
1662 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1663
1664 SecurityStyleTestObserver observer(contents);
1665
1666 SecurityStateTabHelper* helper =
1667 SecurityStateTabHelper::FromWebContents(contents);
1668 ASSERT_TRUE(helper);
1669
1670 // Navigate to an HTTP page. Use a non-local hostname so that is it
1671 // not considered secure.
1672 GURL http_url =
1673 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1674 ui_test_utils::NavigateToURL(browser(), http_url);
1675
1676 security_state::SecurityInfo security_info;
1677 helper->GetSecurityInfo(&security_info);
1678 EXPECT_TRUE(security_info.is_incognito);
1679 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1680 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1681 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1682
1683 // Ensure that same-page pushstate does not add another notice.
1684 EXPECT_TRUE(content::ExecuteScript(
1685 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
1686 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1687 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1688 }
1689
1690 // Tests that the security level of a HTTP page is NEUTRAL when MarkHttpAs is
1691 // not set.
1692 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1693 SecurityLevelNeutralByDefaultForHTTP) {
1694 content::WebContents* contents =
1695 browser()->tab_strip_model()->GetActiveWebContents();
1696 ASSERT_TRUE(contents);
1697
1698 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1699
1700 SecurityStyleTestObserver observer(contents);
1701
1702 SecurityStateTabHelper* helper =
1703 SecurityStateTabHelper::FromWebContents(contents);
1704 ASSERT_TRUE(helper);
1705
1706 // Navigate to an HTTP page. Use a non-local hostname so that is it
1707 // not considered secure.
1708 GURL http_url =
1709 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1710 ui_test_utils::NavigateToURL(browser(), http_url);
1711
1712 security_state::SecurityInfo security_info;
1713 helper->GetSecurityInfo(&security_info);
1714 // The Incognito flag is unset to avoid incorrect logging in the console and
1715 // developer tools.
1716 EXPECT_FALSE(security_info.is_incognito);
1717 EXPECT_EQ(security_state::NONE, security_info.security_level);
1718 EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
1719 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1720 }
1721
1722 // Tests that the security level of a HTTP page is downgraded to DANGEROUS when
1723 // MarkHttpAsDangerous is enabled.
1724 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1725 SecurityLevelDangerousWhenMarkHttpAsDangerous) {
1726 base::test::ScopedCommandLine scoped_command_line;
1727 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1728 security_state::switches::kMarkHttpAs,
1729 security_state::switches::kMarkHttpAsDangerous);
1730
1731 content::WebContents* contents =
1732 browser()->tab_strip_model()->GetActiveWebContents();
1733 ASSERT_TRUE(contents);
1734
1735 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1736
1737 SecurityStyleTestObserver observer(contents);
1738
1739 SecurityStateTabHelper* helper =
1740 SecurityStateTabHelper::FromWebContents(contents);
1741 ASSERT_TRUE(helper);
1742
1743 // Navigate to an HTTP page. Use a non-local hostname so that is it
1744 // not considered secure.
1745 GURL http_url =
1746 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1747 ui_test_utils::NavigateToURL(browser(), http_url);
1748
1749 security_state::SecurityInfo security_info;
1750 helper->GetSecurityInfo(&security_info);
1751 // The Incognito flag is unset to avoid incorrect logging in the console and
1752 // developer tools.
1753 EXPECT_FALSE(security_info.is_incognito);
1754 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level);
1755 EXPECT_EQ(blink::kWebSecurityStyleInsecure, observer.latest_security_style());
1756 }
1757
1617 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back, 1758 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back,
1618 // and test that the observed security style matches. 1759 // and test that the observed security style matches.
1619 #if defined(OS_CHROMEOS) 1760 #if defined(OS_CHROMEOS)
1620 // Flaky on Chrome OS. See https://crbug.com/638576. 1761 // Flaky on Chrome OS. See https://crbug.com/638576.
1621 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \ 1762 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1622 DISABLED_DidChangeVisibleSecurityStateObserverGoBack 1763 DISABLED_DidChangeVisibleSecurityStateObserverGoBack
1623 #else 1764 #else
1624 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \ 1765 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1625 DidChangeVisibleSecurityStateObserverGoBack 1766 DidChangeVisibleSecurityStateObserverGoBack
1626 #endif 1767 #endif
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 base::string16 obsolete_description = l10n_util::GetStringFUTF16( 1998 base::string16 obsolete_description = l10n_util::GetStringFUTF16(
1858 IDS_OBSOLETE_SSL_DESCRIPTION, description_replacements, nullptr); 1999 IDS_OBSOLETE_SSL_DESCRIPTION, description_replacements, nullptr);
1859 2000
1860 EXPECT_EQ( 2001 EXPECT_EQ(
1861 obsolete_description, 2002 obsolete_description,
1862 base::ASCIIToUTF16( 2003 base::ASCIIToUTF16(
1863 observer.latest_explanations().info_explanations[0].description)); 2004 observer.latest_explanations().info_explanations[0].description));
1864 } 2005 }
1865 2006
1866 } // namespace 2007 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698