Chromium Code Reviews| 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 EXPECT_TRUE(cert1 && cert2); | 270 EXPECT_TRUE(cert1 && cert2); |
| 271 EXPECT_TRUE(cert1->Equals(cert2.get())); | 271 EXPECT_TRUE(cert1->Equals(cert2.get())); |
| 272 | 272 |
| 273 SSLStatus one_without_cert_id = one; | 273 SSLStatus one_without_cert_id = one; |
| 274 one_without_cert_id.cert_id = 0; | 274 one_without_cert_id.cert_id = 0; |
| 275 SSLStatus two_without_cert_id = two; | 275 SSLStatus two_without_cert_id = two; |
| 276 two_without_cert_id.cert_id = 0; | 276 two_without_cert_id.cert_id = 0; |
| 277 EXPECT_TRUE(one_without_cert_id.Equals(two_without_cert_id)); | 277 EXPECT_TRUE(one_without_cert_id.Equals(two_without_cert_id)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Sometimes favicons load before tests check the authentication state, | |
| 281 // and sometimes they load after. This is problematic on tests that load | |
| 282 // pages with certificate errors, because the page will be marked as | |
| 283 // having displayed subresources with certificate errors only if the | |
| 284 // favicon loads before the test checks the authentication | |
| 285 // state. HungJob and FaviconFilter are used to hang favicon requests to | |
| 286 // avoid this nondeterminism. | |
| 280 class HungJob : public net::URLRequestJob { | 287 class HungJob : public net::URLRequestJob { |
| 281 public: | 288 public: |
| 282 HungJob(net::URLRequest* request, net::NetworkDelegate* network_delegate) | 289 HungJob(net::URLRequest* request, net::NetworkDelegate* network_delegate) |
| 283 : net::URLRequestJob(request, network_delegate) {} | 290 : net::URLRequestJob(request, network_delegate) {} |
| 284 | 291 |
| 285 void Start() override { | 292 void Start() override { |
| 286 } | 293 } |
| 287 }; | 294 }; |
| 288 | 295 |
| 289 class FaviconFilter : public net::URLRequestInterceptor { | 296 class FaviconFilter : public net::URLRequestInterceptor { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 318 net::GetWebSocketTestDataDirectory()) { | 325 net::GetWebSocketTestDataDirectory()) { |
| 319 https_server_.AddDefaultHandlers(base::FilePath(kDocRoot)); | 326 https_server_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 320 | 327 |
| 321 https_server_expired_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); | 328 https_server_expired_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 322 https_server_expired_.AddDefaultHandlers(base::FilePath(kDocRoot)); | 329 https_server_expired_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 323 | 330 |
| 324 https_server_mismatched_.SetSSLConfig( | 331 https_server_mismatched_.SetSSLConfig( |
| 325 net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | 332 net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 326 https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot)); | 333 https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 327 | 334 |
| 328 // TODO(estark): once http://crbug.com/634171 is fixed and certificate | 335 // Sometimes favicons load before tests check the authentication |
| 329 // errors for subresources don't generate DISPLAYED_INSECURE_CONTENT remove | 336 // state, and sometimes they load after. This is problematic on |
| 330 // these filters. | 337 // tests that load pages with certificate errors, because the page |
| 338 // will be marked as having displayed subresources with certificate | |
| 339 // errors only if the favicon loads before the test checks the | |
| 340 // authentication state. To avoid this non-determinism, add an | |
| 341 // interceptor to hang all favicon requests. | |
|
jam
2016/08/11 19:53:20
nit: did you mean to have nearly the same comment
estark
2016/08/12 04:56:02
Done.
| |
| 331 std::unique_ptr<net::URLRequestInterceptor> interceptor(new FaviconFilter); | 342 std::unique_ptr<net::URLRequestInterceptor> interceptor(new FaviconFilter); |
| 332 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 343 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 333 "https", "127.0.0.1", std::move(interceptor)); | 344 "https", "127.0.0.1", std::move(interceptor)); |
| 334 interceptor.reset(new FaviconFilter); | 345 interceptor.reset(new FaviconFilter); |
| 335 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 346 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 336 "https", "localhost", std::move(interceptor)); | 347 "https", "localhost", std::move(interceptor)); |
| 337 } | 348 } |
| 338 | 349 |
| 339 void SetUpCommandLine(base::CommandLine* command_line) override { | 350 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 340 // Browser will both run and display insecure content. | 351 // Browser will both run and display insecure content. |
| (...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2305 // the user approves the bad certificate. | 2316 // the user approves the bad certificate. |
| 2306 ui_test_utils::NavigateToURL( | 2317 ui_test_utils::NavigateToURL( |
| 2307 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); | 2318 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); |
| 2308 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2319 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2309 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2320 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2310 AuthState::SHOWING_INTERSTITIAL); | 2321 AuthState::SHOWING_INTERSTITIAL); |
| 2311 ProceedThroughInterstitial(tab); | 2322 ProceedThroughInterstitial(tab); |
| 2312 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2323 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2313 AuthState::NONE); | 2324 AuthState::NONE); |
| 2314 | 2325 |
| 2326 ChromeSecurityStateModelClient* client = | |
| 2327 ChromeSecurityStateModelClient::FromWebContents(tab); | |
| 2328 ASSERT_TRUE(client); | |
| 2329 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, | |
| 2330 client->GetSecurityInfo().mixed_content_status); | |
| 2331 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, | |
| 2332 client->GetSecurityInfo().content_with_cert_errors_status); | |
| 2333 | |
| 2315 // Navigate to safe page that has Worker loading unsafe content. | 2334 // Navigate to safe page that has Worker loading unsafe content. |
| 2316 // Expect content to load but be marked as auth broken due to running insecure | 2335 // Expect content to load but be marked as auth broken due to running insecure |
| 2317 // content. | 2336 // content. |
| 2318 std::string page_with_unsafe_worker_path; | 2337 std::string page_with_unsafe_worker_path; |
| 2319 GetPageWithUnsafeWorkerPath(https_server_mismatched_, | 2338 GetPageWithUnsafeWorkerPath(https_server_mismatched_, |
| 2320 &page_with_unsafe_worker_path); | 2339 &page_with_unsafe_worker_path); |
| 2321 ui_test_utils::NavigateToURL( | 2340 ui_test_utils::NavigateToURL( |
| 2322 browser(), https_server_.GetURL(page_with_unsafe_worker_path)); | 2341 browser(), https_server_.GetURL(page_with_unsafe_worker_path)); |
| 2323 CheckWorkerLoadResult(tab, true); // Worker loads insecure content | 2342 CheckWorkerLoadResult(tab, true); // Worker loads insecure content |
| 2324 CheckAuthenticationBrokenState(tab, CertError::NONE, | 2343 CheckAuthenticationBrokenState(tab, CertError::NONE, AuthState::NONE); |
| 2325 AuthState::RAN_INSECURE_CONTENT); | 2344 |
| 2345 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, | |
| 2346 client->GetSecurityInfo().mixed_content_status); | |
| 2347 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_RAN, | |
| 2348 client->GetSecurityInfo().content_with_cert_errors_status); | |
| 2326 } | 2349 } |
| 2327 | 2350 |
| 2328 // Visits a page with unsafe content and makes sure that if a user exception to | 2351 // Visits a page with unsafe content and makes sure that if a user exception to |
| 2329 // the certificate error is present, the image is loaded and script executes. | 2352 // the certificate error is present, the image is loaded and script executes. |
| 2330 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) { | 2353 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) { |
| 2331 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2354 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2332 ASSERT_NO_FATAL_FAILURE(SetUpUnsafeContentsWithUserException( | 2355 ASSERT_NO_FATAL_FAILURE(SetUpUnsafeContentsWithUserException( |
| 2333 "/ssl/page_with_unsafe_contents.html")); | 2356 "/ssl/page_with_unsafe_contents.html")); |
| 2334 CheckAuthenticationBrokenState( | 2357 CheckAuthenticationBrokenState(tab, CertError::NONE, AuthState::NONE); |
| 2335 tab, CertError::NONE, | 2358 |
| 2336 AuthState::RAN_INSECURE_CONTENT | AuthState::DISPLAYED_INSECURE_CONTENT); | 2359 ChromeSecurityStateModelClient* client = |
| 2360 ChromeSecurityStateModelClient::FromWebContents(tab); | |
| 2361 ASSERT_TRUE(client); | |
| 2362 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, | |
| 2363 client->GetSecurityInfo().mixed_content_status); | |
| 2364 EXPECT_EQ( | |
| 2365 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, | |
| 2366 client->GetSecurityInfo().content_with_cert_errors_status); | |
| 2337 | 2367 |
| 2338 int img_width; | 2368 int img_width; |
| 2339 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | 2369 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
| 2340 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); | 2370 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); |
| 2341 // In order to check that the image was loaded, we check its width. | 2371 // In order to check that the image was loaded, we check its width. |
| 2342 // The actual image (Google logo) is 114 pixels wide, so we assume a good | 2372 // The actual image (Google logo) is 114 pixels wide, so we assume a good |
| 2343 // image is greater than 100. | 2373 // image is greater than 100. |
| 2344 EXPECT_GT(img_width, 100); | 2374 EXPECT_GT(img_width, 100); |
| 2345 | 2375 |
| 2346 bool js_result = false; | 2376 bool js_result = false; |
| 2347 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 2377 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2348 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); | 2378 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); |
| 2349 EXPECT_TRUE(js_result); | 2379 EXPECT_TRUE(js_result); |
| 2350 | 2380 |
| 2351 // Test that active subresources with the same certificate errors as | 2381 // Test that active subresources with the same certificate errors as |
| 2352 // the main resources don't cause mixed content UI downgrades. (Such | 2382 // the main resources also get noted in |content_with_cert_errors_status|. |
| 2353 // errors would be confusing and duplicative.) | |
| 2354 std::string replacement_path; | 2383 std::string replacement_path; |
| 2355 GetFilePathWithHostAndPortReplacement( | 2384 GetFilePathWithHostAndPortReplacement( |
| 2356 "/ssl/page_with_unsafe_contents.html", | 2385 "/ssl/page_with_unsafe_contents.html", |
| 2357 https_server_mismatched_.host_port_pair(), &replacement_path); | 2386 https_server_mismatched_.host_port_pair(), &replacement_path); |
| 2358 ui_test_utils::NavigateToURL( | 2387 ui_test_utils::NavigateToURL( |
| 2359 browser(), https_server_mismatched_.GetURL(replacement_path)); | 2388 browser(), https_server_mismatched_.GetURL(replacement_path)); |
| 2360 js_result = false; | 2389 js_result = false; |
| 2361 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 2390 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2362 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); | 2391 tab, "window.domAutomationController.send(IsFooSet());", &js_result)); |
| 2363 EXPECT_TRUE(js_result); | 2392 EXPECT_TRUE(js_result); |
| 2364 // TODO(estark): once http://crbug.com/634171 is fixed and certificate errors | |
| 2365 // for subresources don't generate DISPLAYED_INSECURE_CONTENT switch this back | |
| 2366 // to AuthState::NONE. | |
| 2367 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 2393 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2368 AuthState::DISPLAYED_INSECURE_CONTENT); | 2394 AuthState::NONE); |
| 2395 | |
| 2396 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, | |
| 2397 client->GetSecurityInfo().mixed_content_status); | |
| 2398 EXPECT_EQ( | |
| 2399 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, | |
| 2400 client->GetSecurityInfo().content_with_cert_errors_status); | |
| 2369 } | 2401 } |
| 2370 | 2402 |
| 2371 // Like the test above, but only displaying inactive content (an image). | 2403 // Like the test above, but only displaying inactive content (an image). |
| 2372 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeImageWithUserException) { | 2404 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeImageWithUserException) { |
| 2373 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2405 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2374 ASSERT_NO_FATAL_FAILURE( | 2406 ASSERT_NO_FATAL_FAILURE( |
| 2375 SetUpUnsafeContentsWithUserException("/ssl/page_with_unsafe_image.html")); | 2407 SetUpUnsafeContentsWithUserException("/ssl/page_with_unsafe_image.html")); |
| 2376 CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT); | 2408 CheckAuthenticatedState(tab, AuthState::NONE); |
| 2409 | |
| 2410 ChromeSecurityStateModelClient* client = | |
| 2411 ChromeSecurityStateModelClient::FromWebContents(tab); | |
| 2412 ASSERT_TRUE(client); | |
| 2413 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE, | |
| 2414 client->GetSecurityInfo().mixed_content_status); | |
| 2415 EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED, | |
| 2416 client->GetSecurityInfo().content_with_cert_errors_status); | |
| 2377 | 2417 |
| 2378 int img_width; | 2418 int img_width; |
| 2379 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | 2419 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
| 2380 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); | 2420 tab, "window.domAutomationController.send(ImageWidth());", &img_width)); |
| 2381 // In order to check that the image was loaded, we check its width. | 2421 // In order to check that the image was loaded, we check its width. |
| 2382 // The actual image (Google logo) is 114 pixels wide, so we assume a good | 2422 // The actual image (Google logo) is 114 pixels wide, so we assume a good |
| 2383 // image is greater than 100. | 2423 // image is greater than 100. |
| 2384 EXPECT_GT(img_width, 100); | 2424 EXPECT_GT(img_width, 100); |
| 2385 } | 2425 } |
| 2386 | 2426 |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3039 | 3079 |
| 3040 // Visit a page over https that contains a frame with a redirect. | 3080 // Visit a page over https that contains a frame with a redirect. |
| 3041 | 3081 |
| 3042 // XMLHttpRequest insecure content in synchronous mode. | 3082 // XMLHttpRequest insecure content in synchronous mode. |
| 3043 | 3083 |
| 3044 // XMLHttpRequest insecure content in asynchronous mode. | 3084 // XMLHttpRequest insecure content in asynchronous mode. |
| 3045 | 3085 |
| 3046 // XMLHttpRequest over bad ssl in synchronous mode. | 3086 // XMLHttpRequest over bad ssl in synchronous mode. |
| 3047 | 3087 |
| 3048 // XMLHttpRequest over OK ssl in synchronous mode. | 3088 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |