| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 net::GetWebSocketTestDataDirectory()) { | 318 net::GetWebSocketTestDataDirectory()) { |
| 319 https_server_.AddDefaultHandlers(base::FilePath(kDocRoot)); | 319 https_server_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 320 | 320 |
| 321 https_server_expired_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); | 321 https_server_expired_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 322 https_server_expired_.AddDefaultHandlers(base::FilePath(kDocRoot)); | 322 https_server_expired_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 323 | 323 |
| 324 https_server_mismatched_.SetSSLConfig( | 324 https_server_mismatched_.SetSSLConfig( |
| 325 net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | 325 net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 326 https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot)); | 326 https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 327 | 327 |
| 328 // TODO(estark): once http://crbug.com/634171 is fixed and certificate | 328 // Sometimes favicons load before tests check the authentication |
| 329 // errors for subresources don't generate DISPLAYED_INSECURE_CONTENT remove | 329 // state, and sometimes they load after. This is problematic on |
| 330 // these filters. | 330 // tests that load pages with certificate errors, because the page |
| 331 // will be marked as having displayed subresources with certificate |
| 332 // errors only if the favicon loads before the test checks the |
| 333 // authentication state. To avoid this non-determinism, add an |
| 334 // interceptor to hang all favicon requests. |
| 331 std::unique_ptr<net::URLRequestInterceptor> interceptor(new FaviconFilter); | 335 std::unique_ptr<net::URLRequestInterceptor> interceptor(new FaviconFilter); |
| 332 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 336 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 333 "https", "127.0.0.1", std::move(interceptor)); | 337 "https", "127.0.0.1", std::move(interceptor)); |
| 334 interceptor.reset(new FaviconFilter); | 338 interceptor.reset(new FaviconFilter); |
| 335 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 339 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 336 "https", "localhost", std::move(interceptor)); | 340 "https", "localhost", std::move(interceptor)); |
| 337 } | 341 } |
| 338 | 342 |
| 339 void SetUpCommandLine(base::CommandLine* command_line) override { | 343 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 340 // Browser will both run and display insecure content. | 344 // Browser will both run and display insecure content. |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 GURL url = https_server_.GetURL("/ssl/page_with_subresource.html"); | 937 GURL url = https_server_.GetURL("/ssl/page_with_subresource.html"); |
| 934 GURL::Replacements replacements; | 938 GURL::Replacements replacements; |
| 935 std::string new_host("localhost"); | 939 std::string new_host("localhost"); |
| 936 replacements.SetHostStr(new_host); | 940 replacements.SetHostStr(new_host); |
| 937 url = url.ReplaceComponents(replacements); | 941 url = url.ReplaceComponents(replacements); |
| 938 | 942 |
| 939 ui_test_utils::NavigateToURL(browser(), url); | 943 ui_test_utils::NavigateToURL(browser(), url); |
| 940 | 944 |
| 941 // We should see no interstitial, but we should have an error | 945 // We should see no interstitial, but we should have an error |
| 942 // (red-crossed-out-https) in the URL bar. | 946 // (red-crossed-out-https) in the URL bar. |
| 943 // TODO(estark): once http://crbug.com/634171 is fixed and certificate | |
| 944 // errors for subresources don't generate | |
| 945 // DISPLAYED/RAN_INSECURE_CONTENT switch this back to AuthState::NONE. | |
| 946 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 947 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 947 AuthState::RAN_INSECURE_CONTENT); | 948 AuthState::NONE); |
| 948 | 949 |
| 949 // We should see that the script tag in the page loaded and ran (and | 950 // We should see that the script tag in the page loaded and ran (and |
| 950 // wasn't blocked by the certificate error). | 951 // wasn't blocked by the certificate error). |
| 951 base::string16 title; | 952 base::string16 title; |
| 952 base::string16 expected_title = base::ASCIIToUTF16("This script has loaded"); | 953 base::string16 expected_title = base::ASCIIToUTF16("This script has loaded"); |
| 953 ui_test_utils::GetCurrentTabTitle(browser(), &title); | 954 ui_test_utils::GetCurrentTabTitle(browser(), &title); |
| 954 EXPECT_EQ(title, expected_title); | 955 EXPECT_EQ(title, expected_title); |
| 955 } | 956 } |
| 956 | 957 |
| 957 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSErrorCausedByClockUsingBuildTime) { | 958 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSErrorCausedByClockUsingBuildTime) { |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2224 content::NOTIFICATION_LOAD_STOP, | 2225 content::NOTIFICATION_LOAD_STOP, |
| 2225 content::Source<NavigationController>(&tab->GetController())); | 2226 content::Source<NavigationController>(&tab->GetController())); |
| 2226 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 2227 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2227 tab, | 2228 tab, |
| 2228 "window.domAutomationController.send(clickLink('goodHTTPSLink'));", | 2229 "window.domAutomationController.send(clickLink('goodHTTPSLink'));", |
| 2229 &success)); | 2230 &success)); |
| 2230 ASSERT_TRUE(success); | 2231 ASSERT_TRUE(success); |
| 2231 observer.Wait(); | 2232 observer.Wait(); |
| 2232 | 2233 |
| 2233 // We should still be authentication broken. | 2234 // We should still be authentication broken. |
| 2234 // TODO(estark): once http://crbug.com/634171 is fixed and certificate | |
| 2235 // errors for subresources don't generate | |
| 2236 // DISPLAYED/RAN_INSECURE_CONTENT switch this back to AuthState::NONE. | |
| 2237 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, | 2235 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, |
| 2238 AuthState::RAN_INSECURE_CONTENT); | 2236 AuthState::NONE); |
| 2239 } | 2237 } |
| 2240 | 2238 |
| 2241 // From an HTTP top frame, navigate to good and bad HTTPS (security state should | 2239 // From an HTTP top frame, navigate to good and bad HTTPS (security state should |
| 2242 // stay unauthenticated). | 2240 // stay unauthenticated). |
| 2243 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) { | 2241 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) { |
| 2244 ASSERT_TRUE(embedded_test_server()->Start()); | 2242 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2245 ASSERT_TRUE(https_server_.Start()); | 2243 ASSERT_TRUE(https_server_.Start()); |
| 2246 ASSERT_TRUE(https_server_expired_.Start()); | 2244 ASSERT_TRUE(https_server_expired_.Start()); |
| 2247 | 2245 |
| 2248 std::string top_frame_path; | 2246 std::string top_frame_path; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 // the user approves the bad certificate. | 2332 // the user approves the bad certificate. |
| 2335 ui_test_utils::NavigateToURL( | 2333 ui_test_utils::NavigateToURL( |
| 2336 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); | 2334 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); |
| 2337 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2335 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2338 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2336 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2339 AuthState::SHOWING_INTERSTITIAL); | 2337 AuthState::SHOWING_INTERSTITIAL); |
| 2340 ProceedThroughInterstitial(tab); | 2338 ProceedThroughInterstitial(tab); |
| 2341 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2339 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2342 AuthState::NONE); | 2340 AuthState::NONE); |
| 2343 | 2341 |
| 2342 ChromeSecurityStateModelClient* client = |
| 2343 ChromeSecurityStateModelClient::FromWebContents(tab); |
| 2344 ASSERT_TRUE(client); |
| 2345 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, |
| 2346 client->GetSecurityInfo().mixed_content_status); |
| 2347 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, |
| 2348 client->GetSecurityInfo().content_with_cert_errors_status); |
| 2349 |
| 2344 // Navigate to safe page that has Worker loading unsafe content. | 2350 // Navigate to safe page that has Worker loading unsafe content. |
| 2345 // Expect content to load but be marked as auth broken due to running insecure | 2351 // Expect content to load but be marked as auth broken due to running insecure |
| 2346 // content. | 2352 // content. |
| 2347 std::string page_with_unsafe_worker_path; | 2353 std::string page_with_unsafe_worker_path; |
| 2348 GetPageWithUnsafeWorkerPath(https_server_mismatched_, | 2354 GetPageWithUnsafeWorkerPath(https_server_mismatched_, |
| 2349 &page_with_unsafe_worker_path); | 2355 &page_with_unsafe_worker_path); |
| 2350 ui_test_utils::NavigateToURL( | 2356 ui_test_utils::NavigateToURL( |
| 2351 browser(), https_server_.GetURL(page_with_unsafe_worker_path)); | 2357 browser(), https_server_.GetURL(page_with_unsafe_worker_path)); |
| 2352 CheckWorkerLoadResult(tab, true); // Worker loads insecure content | 2358 CheckWorkerLoadResult(tab, true); // Worker loads insecure content |
| 2353 CheckAuthenticationBrokenState(tab, CertError::NONE, | 2359 CheckAuthenticationBrokenState(tab, CertError::NONE, AuthState::NONE); |
| 2354 AuthState::RAN_INSECURE_CONTENT); | 2360 |
| 2361 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, |
| 2362 client->GetSecurityInfo().mixed_content_status); |
| 2363 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_RAN, |
| 2364 client->GetSecurityInfo().content_with_cert_errors_status); |
| 2355 } | 2365 } |
| 2356 | 2366 |
| 2357 // Visits a page with unsafe content and makes sure that if a user exception to | 2367 // Visits a page with unsafe content and makes sure that if a user exception to |
| 2358 // the certificate error is present, the image is loaded and script executes. | 2368 // the certificate error is present, the image is loaded and script executes. |
| 2359 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) { | 2369 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) { |
| 2360 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2370 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2361 ASSERT_NO_FATAL_FAILURE(SetUpUnsafeContentsWithUserException( | 2371 ASSERT_NO_FATAL_FAILURE(SetUpUnsafeContentsWithUserException( |
| 2362 "/ssl/page_with_unsafe_contents.html")); | 2372 "/ssl/page_with_unsafe_contents.html")); |
| 2363 CheckAuthenticationBrokenState( | 2373 CheckAuthenticationBrokenState(tab, CertError::NONE, AuthState::NONE); |
| 2364 tab, CertError::NONE, | 2374 |
| 2365 AuthState::RAN_INSECURE_CONTENT | AuthState::DISPLAYED_INSECURE_CONTENT); | 2375 ChromeSecurityStateModelClient* client = |
| 2376 ChromeSecurityStateModelClient::FromWebContents(tab); |
| 2377 ASSERT_TRUE(client); |
| 2378 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, |
| 2379 client->GetSecurityInfo().mixed_content_status); |
| 2380 EXPECT_EQ( |
| 2381 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, |
| 2382 client->GetSecurityInfo().content_with_cert_errors_status); |
| 2366 | 2383 |
| 2367 int img_width; | 2384 int img_width; |
| 2368 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | 2385 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
| 2369 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); | 2386 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); |
| 2370 // In order to check that the image was loaded, we check its width. | 2387 // In order to check that the image was loaded, we check its width. |
| 2371 // The actual image (Google logo) is 114 pixels wide, so we assume a good | 2388 // The actual image (Google logo) is 114 pixels wide, so we assume a good |
| 2372 // image is greater than 100. | 2389 // image is greater than 100. |
| 2373 EXPECT_GT(img_width, 100); | 2390 EXPECT_GT(img_width, 100); |
| 2374 | 2391 |
| 2375 bool js_result = false; | 2392 bool js_result = false; |
| 2376 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 2393 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2377 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); | 2394 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); |
| 2378 EXPECT_TRUE(js_result); | 2395 EXPECT_TRUE(js_result); |
| 2379 | 2396 |
| 2380 // Test that active subresources with the same certificate errors as | 2397 // Test that active subresources with the same certificate errors as |
| 2381 // the main resources don't cause mixed content UI downgrades. (Such | 2398 // the main resources also get noted in |content_with_cert_errors_status|. |
| 2382 // errors would be confusing and duplicative.) | |
| 2383 std::string replacement_path; | 2399 std::string replacement_path; |
| 2384 GetFilePathWithHostAndPortReplacement( | 2400 GetFilePathWithHostAndPortReplacement( |
| 2385 "/ssl/page_with_unsafe_contents.html", | 2401 "/ssl/page_with_unsafe_contents.html", |
| 2386 https_server_mismatched_.host_port_pair(), &replacement_path); | 2402 https_server_mismatched_.host_port_pair(), &replacement_path); |
| 2387 ui_test_utils::NavigateToURL( | 2403 ui_test_utils::NavigateToURL( |
| 2388 browser(), https_server_mismatched_.GetURL(replacement_path)); | 2404 browser(), https_server_mismatched_.GetURL(replacement_path)); |
| 2389 js_result = false; | 2405 js_result = false; |
| 2390 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 2406 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2391 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); | 2407 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); |
| 2392 EXPECT_TRUE(js_result); | 2408 EXPECT_TRUE(js_result); |
| 2393 // TODO(estark): once http://crbug.com/634171 is fixed and certificate | 2409 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2394 // errors for subresources don't generate | 2410 AuthState::NONE); |
| 2395 // DISPLAYED/RAN_INSECURE_CONTENT switch this back to AuthState::NONE. | 2411 |
| 2396 CheckAuthenticationBrokenState( | 2412 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, |
| 2397 tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2413 client->GetSecurityInfo().mixed_content_status); |
| 2398 AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT); | 2414 EXPECT_EQ( |
| 2415 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, |
| 2416 client->GetSecurityInfo().content_with_cert_errors_status); |
| 2399 } | 2417 } |
| 2400 | 2418 |
| 2401 // Like the test above, but only displaying inactive content (an image). | 2419 // Like the test above, but only displaying inactive content (an image). |
| 2402 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeImageWithUserException) { | 2420 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeImageWithUserException) { |
| 2403 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2421 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2404 ASSERT_NO_FATAL_FAILURE( | 2422 ASSERT_NO_FATAL_FAILURE( |
| 2405 SetUpUnsafeContentsWithUserException("/ssl/page_with_unsafe_image.html")); | 2423 SetUpUnsafeContentsWithUserException("/ssl/page_with_unsafe_image.html")); |
| 2406 CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT); | 2424 CheckAuthenticatedState(tab, AuthState::NONE); |
| 2425 |
| 2426 ChromeSecurityStateModelClient* client = |
| 2427 ChromeSecurityStateModelClient::FromWebContents(tab); |
| 2428 ASSERT_TRUE(client); |
| 2429 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, |
| 2430 client->GetSecurityInfo().mixed_content_status); |
| 2431 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED, |
| 2432 client->GetSecurityInfo().content_with_cert_errors_status); |
| 2407 | 2433 |
| 2408 int img_width; | 2434 int img_width; |
| 2409 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | 2435 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
| 2410 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); | 2436 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); |
| 2411 // In order to check that the image was loaded, we check its width. | 2437 // In order to check that the image was loaded, we check its width. |
| 2412 // The actual image (Google logo) is 114 pixels wide, so we assume a good | 2438 // The actual image (Google logo) is 114 pixels wide, so we assume a good |
| 2413 // image is greater than 100. | 2439 // image is greater than 100. |
| 2414 EXPECT_GT(img_width, 100); | 2440 EXPECT_GT(img_width, 100); |
| 2415 } | 2441 } |
| 2416 | 2442 |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3070 | 3096 |
| 3071 // Visit a page over https that contains a frame with a redirect. | 3097 // Visit a page over https that contains a frame with a redirect. |
| 3072 | 3098 |
| 3073 // XMLHttpRequest insecure content in synchronous mode. | 3099 // XMLHttpRequest insecure content in synchronous mode. |
| 3074 | 3100 |
| 3075 // XMLHttpRequest insecure content in asynchronous mode. | 3101 // XMLHttpRequest insecure content in asynchronous mode. |
| 3076 | 3102 |
| 3077 // XMLHttpRequest over bad ssl in synchronous mode. | 3103 // XMLHttpRequest over bad ssl in synchronous mode. |
| 3078 | 3104 |
| 3079 // XMLHttpRequest over OK ssl in synchronous mode. | 3105 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |