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 "base/base_switches.h" | 5 #include "base/base_switches.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 base::RunLoop().RunUntilIdle(); | 548 base::RunLoop().RunUntilIdle(); |
549 EXPECT_EQ(std::string(), GetLatestHostnameReported()); | 549 EXPECT_EQ(std::string(), GetLatestHostnameReported()); |
550 } | 550 } |
551 } | 551 } |
552 | 552 |
553 net::EmbeddedTestServer https_server_; | 553 net::EmbeddedTestServer https_server_; |
554 net::EmbeddedTestServer https_server_expired_; | 554 net::EmbeddedTestServer https_server_expired_; |
555 net::EmbeddedTestServer https_server_mismatched_; | 555 net::EmbeddedTestServer https_server_mismatched_; |
556 net::SpawnedTestServer wss_server_expired_; | 556 net::SpawnedTestServer wss_server_expired_; |
557 | 557 |
| 558 protected: |
| 559 // Navigates to an interstitial and clicks through the certificate |
| 560 // error; then navigates to a page at |path| that loads unsafe content. |
| 561 void SetUpUnsafeContentsWithUserException(const std::string& path) { |
| 562 ASSERT_TRUE(https_server_.Start()); |
| 563 // Note that it is necessary to user https_server_mismatched_ here over the |
| 564 // other invalid cert servers. This is because the test relies on the two |
| 565 // servers having different hosts since SSL exceptions are per-host, not per |
| 566 // origin, and https_server_mismatched_ uses 'localhost' rather than |
| 567 // '127.0.0.1'. |
| 568 ASSERT_TRUE(https_server_mismatched_.Start()); |
| 569 |
| 570 // Navigate to an unsafe site. Proceed with interstitial page to indicate |
| 571 // the user approves the bad certificate. |
| 572 ui_test_utils::NavigateToURL( |
| 573 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); |
| 574 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 575 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 576 AuthState::SHOWING_INTERSTITIAL); |
| 577 ProceedThroughInterstitial(tab); |
| 578 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 579 AuthState::NONE); |
| 580 |
| 581 std::string replacement_path; |
| 582 GetFilePathWithHostAndPortReplacement( |
| 583 path, https_server_mismatched_.host_port_pair(), &replacement_path); |
| 584 ui_test_utils::NavigateToURL(browser(), |
| 585 https_server_.GetURL(replacement_path)); |
| 586 } |
| 587 |
558 private: | 588 private: |
559 typedef net::SpawnedTestServer::SSLOptions SSLOptions; | 589 typedef net::SpawnedTestServer::SSLOptions SSLOptions; |
560 | 590 |
561 DISALLOW_COPY_AND_ASSIGN(SSLUITest); | 591 DISALLOW_COPY_AND_ASSIGN(SSLUITest); |
562 }; | 592 }; |
563 | 593 |
564 class SSLUITestBlock : public SSLUITest { | 594 class SSLUITestBlock : public SSLUITest { |
565 public: | 595 public: |
566 SSLUITestBlock() : SSLUITest() {} | 596 SSLUITestBlock() : SSLUITest() {} |
567 | 597 |
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 page_with_unsafe_worker_path)); | 2148 page_with_unsafe_worker_path)); |
2119 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2149 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
2120 // Expect Worker not to load insecure content. | 2150 // Expect Worker not to load insecure content. |
2121 CheckWorkerLoadResult(tab, false); | 2151 CheckWorkerLoadResult(tab, false); |
2122 // The bad content is filtered, expect the state to be authenticated. | 2152 // The bad content is filtered, expect the state to be authenticated. |
2123 CheckAuthenticatedState(tab, AuthState::NONE); | 2153 CheckAuthenticatedState(tab, AuthState::NONE); |
2124 } | 2154 } |
2125 | 2155 |
2126 // This test, and the related test TestUnsafeContentsWithUserException, verify | 2156 // This test, and the related test TestUnsafeContentsWithUserException, verify |
2127 // that if unsafe content is loaded but the host of that unsafe content has a | 2157 // that if unsafe content is loaded but the host of that unsafe content has a |
2128 // user exception, the content runs and the security style remains | 2158 // user exception, the content runs and the security style is downgraded. |
2129 // authenticated. This is not necessarily the behavior that should exist, but it | |
2130 // is verification that it does behave that way. See https://crbug.com/477868 | |
2131 // for more inforamtion on this. | |
2132 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerWithUserException) { | 2159 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerWithUserException) { |
2133 ASSERT_TRUE(https_server_.Start()); | 2160 ASSERT_TRUE(https_server_.Start()); |
2134 // Note that it is necessary to user https_server_mismatched_ here over the | 2161 // Note that it is necessary to user https_server_mismatched_ here over the |
2135 // other invalid cert servers. This is because the test relies on the two | 2162 // other invalid cert servers. This is because the test relies on the two |
2136 // servers having different hosts since SSL exceptions are per-host, not per | 2163 // servers having different hosts since SSL exceptions are per-host, not per |
2137 // origin, and https_server_mismatched_ uses 'localhost' rather than | 2164 // origin, and https_server_mismatched_ uses 'localhost' rather than |
2138 // '127.0.0.1'. | 2165 // '127.0.0.1'. |
2139 ASSERT_TRUE(https_server_mismatched_.Start()); | 2166 ASSERT_TRUE(https_server_mismatched_.Start()); |
2140 | 2167 |
2141 // Navigate to an unsafe site. Proceed with interstitial page to indicate | 2168 // Navigate to an unsafe site. Proceed with interstitial page to indicate |
2142 // the user approves the bad certificate. | 2169 // the user approves the bad certificate. |
2143 ui_test_utils::NavigateToURL( | 2170 ui_test_utils::NavigateToURL( |
2144 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); | 2171 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); |
2145 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2172 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
2146 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2173 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
2147 AuthState::SHOWING_INTERSTITIAL); | 2174 AuthState::SHOWING_INTERSTITIAL); |
2148 ProceedThroughInterstitial(tab); | 2175 ProceedThroughInterstitial(tab); |
2149 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2176 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
2150 AuthState::NONE); | 2177 AuthState::NONE); |
2151 | 2178 |
2152 // Navigate to safe page that has Worker loading unsafe content. | 2179 // Navigate to safe page that has Worker loading unsafe content. |
2153 // Expect content to load but be marked as auth broken due to running insecure | 2180 // Expect content to load but be marked as auth broken due to running insecure |
2154 // content. | 2181 // content. |
2155 std::string page_with_unsafe_worker_path; | 2182 std::string page_with_unsafe_worker_path; |
2156 GetPageWithUnsafeWorkerPath(https_server_mismatched_, | 2183 GetPageWithUnsafeWorkerPath(https_server_mismatched_, |
2157 &page_with_unsafe_worker_path); | 2184 &page_with_unsafe_worker_path); |
2158 ui_test_utils::NavigateToURL( | 2185 ui_test_utils::NavigateToURL( |
2159 browser(), https_server_.GetURL(page_with_unsafe_worker_path)); | 2186 browser(), https_server_.GetURL(page_with_unsafe_worker_path)); |
2160 CheckWorkerLoadResult(tab, true); // Worker loads insecure content | 2187 CheckWorkerLoadResult(tab, true); // Worker loads insecure content |
2161 CheckAuthenticatedState(tab, CertError::NONE); | 2188 CheckAuthenticationBrokenState(tab, CertError::NONE, |
| 2189 AuthState::RAN_INSECURE_CONTENT); |
2162 } | 2190 } |
2163 | 2191 |
2164 // Visits a page with unsafe content and makes sure that if a user exception to | 2192 // Visits a page with unsafe content and makes sure that if a user exception to |
2165 // the certificate error is present, the image is loaded and script executes. | 2193 // the certificate error is present, the image is loaded and script executes. |
2166 // | |
2167 // See the comment above SSLUITest.TestUnsafeContentsInWorkerWithUserException | |
2168 // for a discussion about the desired behavior. | |
2169 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) { | 2194 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) { |
2170 ASSERT_TRUE(https_server_.Start()); | 2195 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
2171 // Note that it is necessary to user https_server_mismatched_ here over the | 2196 ASSERT_NO_FATAL_FAILURE(SetUpUnsafeContentsWithUserException( |
2172 // other invalid cert servers. This is because the test relies on the two | 2197 "/ssl/page_with_unsafe_contents.html")); |
2173 // servers having different hosts since SSL exceptions are per-host, not per | 2198 CheckAuthenticationBrokenState( |
2174 // origin, and https_server_mismatched_ uses 'localhost' rather than | 2199 tab, CertError::NONE, |
2175 // '127.0.0.1'. | 2200 AuthState::RAN_INSECURE_CONTENT | AuthState::DISPLAYED_INSECURE_CONTENT); |
2176 ASSERT_TRUE(https_server_mismatched_.Start()); | |
2177 | 2201 |
2178 // Navigate to an unsafe site. Proceed with interstitial page to indicate | 2202 int img_width; |
2179 // the user approves the bad certificate. | 2203 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
2180 ui_test_utils::NavigateToURL( | 2204 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); |
2181 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); | 2205 // In order to check that the image was loaded, we check its width. |
2182 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2206 // The actual image (Google logo) is 114 pixels wide, so we assume a good |
2183 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2207 // image is greater than 100. |
2184 AuthState::SHOWING_INTERSTITIAL); | 2208 EXPECT_GT(img_width, 100); |
2185 ProceedThroughInterstitial(tab); | |
2186 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | |
2187 AuthState::NONE); | |
2188 | 2209 |
| 2210 bool js_result = false; |
| 2211 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2212 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); |
| 2213 EXPECT_TRUE(js_result); |
| 2214 |
| 2215 // Test that active subresources with the same certificate errors as |
| 2216 // the main resources don't cause mixed content UI downgrades. (Such |
| 2217 // errors would be confusing and duplicative.) |
2189 std::string replacement_path; | 2218 std::string replacement_path; |
2190 GetFilePathWithHostAndPortReplacement( | 2219 GetFilePathWithHostAndPortReplacement( |
2191 "/ssl/page_with_unsafe_contents.html", | 2220 "/ssl/page_with_unsafe_contents.html", |
2192 https_server_mismatched_.host_port_pair(), &replacement_path); | 2221 https_server_mismatched_.host_port_pair(), &replacement_path); |
2193 ui_test_utils::NavigateToURL(browser(), | 2222 ui_test_utils::NavigateToURL( |
2194 https_server_.GetURL(replacement_path)); | 2223 browser(), https_server_mismatched_.GetURL(replacement_path)); |
| 2224 js_result = false; |
| 2225 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2226 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); |
| 2227 EXPECT_TRUE(js_result); |
| 2228 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2229 AuthState::NONE); |
| 2230 } |
2195 | 2231 |
2196 // When the bad content is filtered, the state is expected to be | 2232 // Like the test above, but only displaying inactive content (an image). |
2197 // authenticated. | 2233 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeImageWithUserException) { |
2198 CheckAuthenticatedState(tab, AuthState::NONE); | 2234 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2235 ASSERT_NO_FATAL_FAILURE( |
| 2236 SetUpUnsafeContentsWithUserException("/ssl/page_with_unsafe_image.html")); |
| 2237 CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT); |
2199 | 2238 |
2200 int img_width; | 2239 int img_width; |
2201 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | 2240 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
2202 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); | 2241 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); |
2203 // In order to check that the image was loaded, we check its width. | 2242 // In order to check that the image was loaded, we check its width. |
2204 // The actual image (Google logo) is 114 pixels wide, so we assume a good | 2243 // The actual image (Google logo) is 114 pixels wide, so we assume a good |
2205 // image is greater than 100. | 2244 // image is greater than 100. |
2206 EXPECT_GT(img_width, 100); | 2245 EXPECT_GT(img_width, 100); |
2207 | |
2208 bool js_result = false; | |
2209 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
2210 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); | |
2211 EXPECT_TRUE(js_result); | |
2212 CheckAuthenticatedState(tab, CertError::NONE); | |
2213 } | 2246 } |
2214 | 2247 |
2215 // Test that when the browser blocks displaying insecure content (images), the | 2248 // Test that when the browser blocks displaying insecure content (images), the |
2216 // indicator shows a secure page, because the blocking made the otherwise | 2249 // indicator shows a secure page, because the blocking made the otherwise |
2217 // unsafe page safe (the notification of this state is handled by other means). | 2250 // unsafe page safe (the notification of this state is handled by other means). |
2218 IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockDisplayingInsecureImage) { | 2251 IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockDisplayingInsecureImage) { |
2219 ASSERT_TRUE(embedded_test_server()->Start()); | 2252 ASSERT_TRUE(embedded_test_server()->Start()); |
2220 ASSERT_TRUE(https_server_.Start()); | 2253 ASSERT_TRUE(https_server_.Start()); |
2221 | 2254 |
2222 std::string replacement_path; | 2255 std::string replacement_path; |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2884 | 2917 |
2885 // Visit a page over https that contains a frame with a redirect. | 2918 // Visit a page over https that contains a frame with a redirect. |
2886 | 2919 |
2887 // XMLHttpRequest insecure content in synchronous mode. | 2920 // XMLHttpRequest insecure content in synchronous mode. |
2888 | 2921 |
2889 // XMLHttpRequest insecure content in asynchronous mode. | 2922 // XMLHttpRequest insecure content in asynchronous mode. |
2890 | 2923 |
2891 // XMLHttpRequest over bad ssl in synchronous mode. | 2924 // XMLHttpRequest over bad ssl in synchronous mode. |
2892 | 2925 |
2893 // XMLHttpRequest over OK ssl in synchronous mode. | 2926 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |