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

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

Issue 2616553002: Remove obsolete SHA-1 UX elements (Closed)
Patch Set: Improve tests and simplify logic Created 3 years, 11 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"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 base::string16 secure_description = l10n_util::GetStringFUTF16( 198 base::string16 secure_description = l10n_util::GetStringFUTF16(
199 IDS_STRONG_SSL_DESCRIPTION, description_replacements, nullptr); 199 IDS_STRONG_SSL_DESCRIPTION, description_replacements, nullptr);
200 200
201 EXPECT_EQ(secure_description, 201 EXPECT_EQ(secure_description,
202 base::ASCIIToUTF16(secure_explanations.back().description)); 202 base::ASCIIToUTF16(secure_explanations.back().description));
203 } 203 }
204 204
205 void CheckSecurityInfoForSecure( 205 void CheckSecurityInfoForSecure(
206 content::WebContents* contents, 206 content::WebContents* contents,
207 security_state::SecurityLevel expect_security_level, 207 security_state::SecurityLevel expect_security_level,
208 security_state::SHA1DeprecationStatus expect_sha1_status, 208 bool expect_sha1_in_chain,
209 security_state::ContentStatus expect_mixed_content_status, 209 security_state::ContentStatus expect_mixed_content_status,
210 bool pkp_bypassed, 210 bool pkp_bypassed,
211 bool expect_cert_error) { 211 bool expect_cert_error) {
212 ASSERT_TRUE(contents); 212 ASSERT_TRUE(contents);
213 213
214 SecurityStateTabHelper* helper = 214 SecurityStateTabHelper* helper =
215 SecurityStateTabHelper::FromWebContents(contents); 215 SecurityStateTabHelper::FromWebContents(contents);
216 ASSERT_TRUE(helper); 216 ASSERT_TRUE(helper);
217 security_state::SecurityInfo security_info; 217 security_state::SecurityInfo security_info;
218 helper->GetSecurityInfo(&security_info); 218 helper->GetSecurityInfo(&security_info);
219 EXPECT_EQ(expect_security_level, security_info.security_level); 219 EXPECT_EQ(expect_security_level, security_info.security_level);
220 EXPECT_EQ(expect_sha1_status, security_info.sha1_deprecation_status); 220 EXPECT_EQ(expect_sha1_in_chain, security_info.sha1_in_chain);
221 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status); 221 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status);
222 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 222 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
223 EXPECT_TRUE(security_info.scheme_is_cryptographic); 223 EXPECT_TRUE(security_info.scheme_is_cryptographic);
224 EXPECT_EQ(pkp_bypassed, security_info.pkp_bypassed); 224 EXPECT_EQ(pkp_bypassed, security_info.pkp_bypassed);
225 EXPECT_EQ(expect_cert_error, 225 EXPECT_EQ(expect_cert_error,
226 net::IsCertStatusError(security_info.cert_status)); 226 net::IsCertStatusError(security_info.cert_status));
227 EXPECT_GT(security_info.security_bits, 0); 227 EXPECT_GT(security_info.security_bits, 0);
228 EXPECT_TRUE(!!security_info.certificate); 228 EXPECT_TRUE(!!security_info.certificate);
229 } 229 }
230 230
231 void CheckSecurityInfoForNonSecure(content::WebContents* contents) { 231 void CheckSecurityInfoForNonSecure(content::WebContents* contents) {
232 ASSERT_TRUE(contents); 232 ASSERT_TRUE(contents);
233 233
234 SecurityStateTabHelper* helper = 234 SecurityStateTabHelper* helper =
235 SecurityStateTabHelper::FromWebContents(contents); 235 SecurityStateTabHelper::FromWebContents(contents);
236 ASSERT_TRUE(helper); 236 ASSERT_TRUE(helper);
237 security_state::SecurityInfo security_info; 237 security_state::SecurityInfo security_info;
238 helper->GetSecurityInfo(&security_info); 238 helper->GetSecurityInfo(&security_info);
239 EXPECT_EQ(security_state::NONE, security_info.security_level); 239 EXPECT_EQ(security_state::NONE, security_info.security_level);
240 EXPECT_EQ(security_state::NO_DEPRECATED_SHA1, 240 EXPECT_FALSE(security_info.sha1_in_chain);
241 security_info.sha1_deprecation_status);
242 EXPECT_EQ(security_state::CONTENT_STATUS_NONE, 241 EXPECT_EQ(security_state::CONTENT_STATUS_NONE,
243 security_info.mixed_content_status); 242 security_info.mixed_content_status);
244 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 243 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
245 EXPECT_FALSE(security_info.scheme_is_cryptographic); 244 EXPECT_FALSE(security_info.scheme_is_cryptographic);
246 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 245 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
247 EXPECT_EQ(-1, security_info.security_bits); 246 EXPECT_EQ(-1, security_info.security_bits);
248 EXPECT_FALSE(!!security_info.certificate); 247 EXPECT_FALSE(!!security_info.certificate);
249 } 248 }
250 249
251 void ProceedThroughInterstitial(content::WebContents* tab) { 250 void ProceedThroughInterstitial(content::WebContents* tab) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 content::WebContents* contents = 361 content::WebContents* contents =
363 browser()->tab_strip_model()->GetActiveWebContents(); 362 browser()->tab_strip_model()->GetActiveWebContents();
364 ASSERT_TRUE(contents); 363 ASSERT_TRUE(contents);
365 364
366 SecurityStateTabHelper* helper = 365 SecurityStateTabHelper* helper =
367 SecurityStateTabHelper::FromWebContents(contents); 366 SecurityStateTabHelper::FromWebContents(contents);
368 ASSERT_TRUE(helper); 367 ASSERT_TRUE(helper);
369 security_state::SecurityInfo security_info; 368 security_state::SecurityInfo security_info;
370 helper->GetSecurityInfo(&security_info); 369 helper->GetSecurityInfo(&security_info);
371 EXPECT_EQ(security_state::NONE, security_info.security_level); 370 EXPECT_EQ(security_state::NONE, security_info.security_level);
372 EXPECT_EQ(security_state::NO_DEPRECATED_SHA1, 371 EXPECT_FALSE(security_info.sha1_in_chain);
373 security_info.sha1_deprecation_status);
374 EXPECT_EQ(security_state::CONTENT_STATUS_NONE, 372 EXPECT_EQ(security_state::CONTENT_STATUS_NONE,
375 security_info.mixed_content_status); 373 security_info.mixed_content_status);
376 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 374 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
377 EXPECT_FALSE(security_info.scheme_is_cryptographic); 375 EXPECT_FALSE(security_info.scheme_is_cryptographic);
378 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 376 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
379 EXPECT_FALSE(!!security_info.certificate); 377 EXPECT_FALSE(!!security_info.certificate);
380 EXPECT_EQ(-1, security_info.security_bits); 378 EXPECT_EQ(-1, security_info.security_bits);
381 EXPECT_EQ(0, security_info.connection_status); 379 EXPECT_EQ(0, security_info.connection_status);
382 } 380 }
383 381
384 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpsPage) { 382 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpsPage) {
385 ASSERT_TRUE(https_server_.Start()); 383 ASSERT_TRUE(https_server_.Start());
386 SetUpMockCertVerifierForHttpsServer(0, net::OK); 384 SetUpMockCertVerifierForHttpsServer(0, net::OK);
387 385
388 ui_test_utils::NavigateToURL(browser(), 386 ui_test_utils::NavigateToURL(browser(),
389 https_server_.GetURL("/ssl/google.html")); 387 https_server_.GetURL("/ssl/google.html"));
390 CheckSecurityInfoForSecure( 388 CheckSecurityInfoForSecure(
391 browser()->tab_strip_model()->GetActiveWebContents(), 389 browser()->tab_strip_model()->GetActiveWebContents(),
392 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 390 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
393 security_state::CONTENT_STATUS_NONE, false,
394 false /* expect cert status error */); 391 false /* expect cert status error */);
395 } 392 }
396 393
397 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1Certificate) { 394 // Test a SHA-1 certificate
estark 2017/01/09 23:00:21 Unfinished comment
395 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1CertificateBlocked) {
396 ASSERT_TRUE(https_server_.Start());
397 SetUpMockCertVerifierForHttpsServer(
398 net::CERT_STATUS_SHA1_SIGNATURE_PRESENT |
399 net::CERT_STATUS_WEAK_SIGNATURE_ALGORITHM,
400 net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM);
401
402 content::WebContents* web_contents =
403 browser()->tab_strip_model()->GetActiveWebContents();
404 SecurityStyleTestObserver observer(web_contents);
405 ui_test_utils::NavigateToURL(browser(),
406 https_server_.GetURL("/ssl/google.html"));
407 CheckSecurityInfoForSecure(
408 browser()->tab_strip_model()->GetActiveWebContents(),
409 security_state::DANGEROUS, true, security_state::CONTENT_STATUS_NONE,
410 false, true /* expect cert status error */);
411
412 const content::SecurityStyleExplanations& interstitial_explanation =
413 observer.latest_explanations();
414 ASSERT_EQ(1u, interstitial_explanation.broken_explanations.size());
415 ASSERT_EQ(1u, interstitial_explanation.unauthenticated_explanations.size());
416
417 ProceedThroughInterstitial(
418 browser()->tab_strip_model()->GetActiveWebContents());
419
420 CheckSecurityInfoForSecure(
421 browser()->tab_strip_model()->GetActiveWebContents(),
422 security_state::DANGEROUS, true, security_state::CONTENT_STATUS_NONE,
423 false, true /* expect cert status error */);
424
425 const content::SecurityStyleExplanations& page_explanation =
426 observer.latest_explanations();
427 ASSERT_EQ(1u, page_explanation.broken_explanations.size());
428 ASSERT_EQ(1u, page_explanation.unauthenticated_explanations.size());
estark 2017/01/09 23:00:21 Optional nit: other tests in this file check the a
429 }
430
431 // Test a SHA-1 certificate that is allowed by policy
432 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1CertificateWarning) {
398 ASSERT_TRUE(https_server_.Start()); 433 ASSERT_TRUE(https_server_.Start());
399 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 434 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
400 net::OK); 435 net::OK);
401 436
437 content::WebContents* web_contents =
438 browser()->tab_strip_model()->GetActiveWebContents();
439 SecurityStyleTestObserver observer(web_contents);
402 ui_test_utils::NavigateToURL(browser(), 440 ui_test_utils::NavigateToURL(browser(),
403 https_server_.GetURL("/ssl/google.html")); 441 https_server_.GetURL("/ssl/google.html"));
404 CheckSecurityInfoForSecure( 442 CheckSecurityInfoForSecure(
405 browser()->tab_strip_model()->GetActiveWebContents(), 443 browser()->tab_strip_model()->GetActiveWebContents(),
406 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 444 security_state::NONE, true, security_state::CONTENT_STATUS_NONE, false,
407 security_state::CONTENT_STATUS_NONE, false,
408 false /* expect cert status error */); 445 false /* expect cert status error */);
446
447 const content::SecurityStyleExplanations& explanation =
448 observer.latest_explanations();
449
450 ASSERT_EQ(0u, explanation.broken_explanations.size());
451 ASSERT_EQ(1u, explanation.unauthenticated_explanations.size());
409 } 452 }
410 453
411 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContent) { 454 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContent) {
412 ASSERT_TRUE(embedded_test_server()->Start()); 455 ASSERT_TRUE(embedded_test_server()->Start());
413 ASSERT_TRUE(https_server_.Start()); 456 ASSERT_TRUE(https_server_.Start());
414 SetUpMockCertVerifierForHttpsServer(0, net::OK); 457 SetUpMockCertVerifierForHttpsServer(0, net::OK);
415 host_resolver()->AddRule("example.test", 458 host_resolver()->AddRule("example.test",
416 https_server_.GetURL("/title1.html").host()); 459 https_server_.GetURL("/title1.html").host());
417 460
418 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 461 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
419 replacement_pair.set_host("example.test"); 462 replacement_pair.set_host("example.test");
420 463
421 // Navigate to an HTTPS page that displays mixed content. 464 // Navigate to an HTTPS page that displays mixed content.
422 std::string replacement_path; 465 std::string replacement_path;
423 GetFilePathWithHostAndPortReplacement( 466 GetFilePathWithHostAndPortReplacement(
424 "/ssl/page_displays_insecure_content.html", replacement_pair, 467 "/ssl/page_displays_insecure_content.html", replacement_pair,
425 &replacement_path); 468 &replacement_path);
426 ui_test_utils::NavigateToURL(browser(), 469 ui_test_utils::NavigateToURL(browser(),
427 https_server_.GetURL(replacement_path)); 470 https_server_.GetURL(replacement_path));
428 CheckSecurityInfoForSecure( 471 CheckSecurityInfoForSecure(
429 browser()->tab_strip_model()->GetActiveWebContents(), 472 browser()->tab_strip_model()->GetActiveWebContents(),
430 security_state::NONE, security_state::NO_DEPRECATED_SHA1, 473 security_state::NONE, false, security_state::CONTENT_STATUS_DISPLAYED,
431 security_state::CONTENT_STATUS_DISPLAYED, false, 474 false, false /* expect cert status error */);
432 false /* expect cert status error */);
433 475
434 // Navigate to an HTTPS page that displays mixed content dynamically. 476 // Navigate to an HTTPS page that displays mixed content dynamically.
435 GetFilePathWithHostAndPortReplacement( 477 GetFilePathWithHostAndPortReplacement(
436 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair, 478 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
437 &replacement_path); 479 &replacement_path);
438 ui_test_utils::NavigateToURL(browser(), 480 ui_test_utils::NavigateToURL(browser(),
439 https_server_.GetURL(replacement_path)); 481 https_server_.GetURL(replacement_path));
440 CheckSecurityInfoForSecure( 482 CheckSecurityInfoForSecure(
441 browser()->tab_strip_model()->GetActiveWebContents(), 483 browser()->tab_strip_model()->GetActiveWebContents(),
442 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 484 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
443 security_state::CONTENT_STATUS_NONE, false,
444 false /* expect cert status error */); 485 false /* expect cert status error */);
445 // Load the insecure image. 486 // Load the insecure image.
446 bool js_result = false; 487 bool js_result = false;
447 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 488 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
448 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 489 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
449 &js_result)); 490 &js_result));
450 EXPECT_TRUE(js_result); 491 EXPECT_TRUE(js_result);
451 CheckSecurityInfoForSecure( 492 CheckSecurityInfoForSecure(
452 browser()->tab_strip_model()->GetActiveWebContents(), 493 browser()->tab_strip_model()->GetActiveWebContents(),
453 security_state::NONE, security_state::NO_DEPRECATED_SHA1, 494 security_state::NONE, false, security_state::CONTENT_STATUS_DISPLAYED,
454 security_state::CONTENT_STATUS_DISPLAYED, false, 495 false, false /* expect cert status error */);
455 false /* expect cert status error */);
456 496
457 // Navigate to an HTTPS page that runs mixed content. 497 // Navigate to an HTTPS page that runs mixed content.
458 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html", 498 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
459 replacement_pair, &replacement_path); 499 replacement_pair, &replacement_path);
460 ui_test_utils::NavigateToURL(browser(), 500 ui_test_utils::NavigateToURL(browser(),
461 https_server_.GetURL(replacement_path)); 501 https_server_.GetURL(replacement_path));
462 CheckSecurityInfoForSecure( 502 CheckSecurityInfoForSecure(
463 browser()->tab_strip_model()->GetActiveWebContents(), 503 browser()->tab_strip_model()->GetActiveWebContents(),
464 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 504 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_RAN,
465 security_state::CONTENT_STATUS_RAN, false, 505 false, false /* expect cert status error */);
466 false /* expect cert status error */);
467 506
468 // Navigate to an HTTPS page that runs and displays mixed content. 507 // Navigate to an HTTPS page that runs and displays mixed content.
469 GetFilePathWithHostAndPortReplacement( 508 GetFilePathWithHostAndPortReplacement(
470 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair, 509 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
471 &replacement_path); 510 &replacement_path);
472 ui_test_utils::NavigateToURL(browser(), 511 ui_test_utils::NavigateToURL(browser(),
473 https_server_.GetURL(replacement_path)); 512 https_server_.GetURL(replacement_path));
474 CheckSecurityInfoForSecure( 513 CheckSecurityInfoForSecure(
475 browser()->tab_strip_model()->GetActiveWebContents(), 514 browser()->tab_strip_model()->GetActiveWebContents(),
476 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 515 security_state::DANGEROUS, false,
477 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 516 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
478 false /* expect cert status error */); 517 false /* expect cert status error */);
479 518
480 // Navigate to an HTTPS page that runs mixed content in an iframe. 519 // Navigate to an HTTPS page that runs mixed content in an iframe.
481 net::HostPortPair host_port_pair = 520 net::HostPortPair host_port_pair =
482 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 521 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
483 host_port_pair.set_host("different-host.test"); 522 host_port_pair.set_host("different-host.test");
484 host_resolver()->AddRule("different-host.test", 523 host_resolver()->AddRule("different-host.test",
485 https_server_.GetURL("/title1.html").host()); 524 https_server_.GetURL("/title1.html").host());
486 host_resolver()->AddRule( 525 host_resolver()->AddRule(
487 "different-http-host.test", 526 "different-http-host.test",
488 embedded_test_server()->GetURL("/title1.html").host()); 527 embedded_test_server()->GetURL("/title1.html").host());
489 GetFilePathWithHostAndPortReplacement( 528 GetFilePathWithHostAndPortReplacement(
490 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, 529 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair,
491 &replacement_path); 530 &replacement_path);
492 ui_test_utils::NavigateToURL(browser(), 531 ui_test_utils::NavigateToURL(browser(),
493 https_server_.GetURL(replacement_path)); 532 https_server_.GetURL(replacement_path));
494 CheckSecurityInfoForSecure( 533 CheckSecurityInfoForSecure(
495 browser()->tab_strip_model()->GetActiveWebContents(), 534 browser()->tab_strip_model()->GetActiveWebContents(),
496 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 535 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_RAN,
497 security_state::CONTENT_STATUS_RAN, false, 536 false, false /* expect cert status error */);
498 false /* expect cert status error */);
499 } 537 }
500 538
501 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, 539 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
502 ActiveContentWithCertErrors) { 540 ActiveContentWithCertErrors) {
503 ASSERT_TRUE(https_server_.Start()); 541 ASSERT_TRUE(https_server_.Start());
504 SetUpMockCertVerifierForHttpsServer(0, net::OK); 542 SetUpMockCertVerifierForHttpsServer(0, net::OK);
505 543
506 // Navigate to an HTTPS page and simulate active content with 544 // Navigate to an HTTPS page and simulate active content with
507 // certificate errors. 545 // certificate errors.
508 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); 546 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html"));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 ASSERT_TRUE(helper); 618 ASSERT_TRUE(helper);
581 security_state::SecurityInfo security_info; 619 security_state::SecurityInfo security_info;
582 helper->GetSecurityInfo(&security_info); 620 helper->GetSecurityInfo(&security_info);
583 621
584 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 622 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
585 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level); 623 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level);
586 EXPECT_EQ(security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, 624 EXPECT_EQ(security_state::CONTENT_STATUS_DISPLAYED_AND_RAN,
587 security_info.content_with_cert_errors_status); 625 security_info.content_with_cert_errors_status);
588 } 626 }
589 627
590 // Same as the test above but with a long-lived SHA1 cert. 628 // Same as SecurityStateTabHelperTest.ActiveAndPassiveContentWithCertErrors but
629 // with a SHA1 cert.
591 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentWithSHA1Cert) { 630 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentWithSHA1Cert) {
592 ASSERT_TRUE(embedded_test_server()->Start()); 631 ASSERT_TRUE(embedded_test_server()->Start());
593 ASSERT_TRUE(https_server_.Start()); 632 ASSERT_TRUE(https_server_.Start());
594 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 633 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
595 net::OK); 634 net::OK);
596 635
597 host_resolver()->AddRule("example.test", 636 host_resolver()->AddRule("example.test",
598 https_server_.GetURL("/title1.html").host()); 637 https_server_.GetURL("/title1.html").host());
599 638
600 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 639 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
601 replacement_pair.set_host("example.test"); 640 replacement_pair.set_host("example.test");
602 641
603 // Navigate to an HTTPS page that displays mixed content. 642 // Navigate to an HTTPS page that displays mixed content.
604 std::string replacement_path; 643 std::string replacement_path;
605 GetFilePathWithHostAndPortReplacement( 644 GetFilePathWithHostAndPortReplacement(
606 "/ssl/page_displays_insecure_content.html", replacement_pair, 645 "/ssl/page_displays_insecure_content.html", replacement_pair,
607 &replacement_path); 646 &replacement_path);
608 ui_test_utils::NavigateToURL(browser(), 647 ui_test_utils::NavigateToURL(browser(),
609 https_server_.GetURL(replacement_path)); 648 https_server_.GetURL(replacement_path));
610 CheckSecurityInfoForSecure( 649 CheckSecurityInfoForSecure(
611 browser()->tab_strip_model()->GetActiveWebContents(), 650 browser()->tab_strip_model()->GetActiveWebContents(),
612 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 651 security_state::NONE, true, security_state::CONTENT_STATUS_DISPLAYED,
613 security_state::CONTENT_STATUS_DISPLAYED, false, 652 false, false /* expect cert status error */);
614 false /* expect cert status error */);
615 653
616 // Navigate to an HTTPS page that displays mixed content dynamically. 654 // Navigate to an HTTPS page that displays mixed content dynamically.
617 GetFilePathWithHostAndPortReplacement( 655 GetFilePathWithHostAndPortReplacement(
618 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair, 656 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
619 &replacement_path); 657 &replacement_path);
620 ui_test_utils::NavigateToURL(browser(), 658 ui_test_utils::NavigateToURL(browser(),
621 https_server_.GetURL(replacement_path)); 659 https_server_.GetURL(replacement_path));
622 CheckSecurityInfoForSecure( 660 CheckSecurityInfoForSecure(
623 browser()->tab_strip_model()->GetActiveWebContents(), 661 browser()->tab_strip_model()->GetActiveWebContents(),
624 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 662 security_state::NONE, true, security_state::CONTENT_STATUS_NONE, false,
625 security_state::CONTENT_STATUS_NONE, false,
626 false /* expect cert status error */); 663 false /* expect cert status error */);
627 // Load the insecure image. 664 // Load the insecure image.
628 bool js_result = false; 665 bool js_result = false;
629 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 666 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
630 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 667 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
631 &js_result)); 668 &js_result));
632 EXPECT_TRUE(js_result); 669 EXPECT_TRUE(js_result);
633 CheckSecurityInfoForSecure( 670 CheckSecurityInfoForSecure(
634 browser()->tab_strip_model()->GetActiveWebContents(), 671 browser()->tab_strip_model()->GetActiveWebContents(),
635 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 672 security_state::NONE, true, security_state::CONTENT_STATUS_DISPLAYED,
636 security_state::CONTENT_STATUS_DISPLAYED, false, 673 false, false /* expect cert status error */);
637 false /* expect cert status error */);
638 674
639 // Navigate to an HTTPS page that runs mixed content. 675 // Navigate to an HTTPS page that runs mixed content.
640 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html", 676 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
641 replacement_pair, &replacement_path); 677 replacement_pair, &replacement_path);
642 ui_test_utils::NavigateToURL(browser(), 678 ui_test_utils::NavigateToURL(browser(),
643 https_server_.GetURL(replacement_path)); 679 https_server_.GetURL(replacement_path));
644 CheckSecurityInfoForSecure( 680 CheckSecurityInfoForSecure(
645 browser()->tab_strip_model()->GetActiveWebContents(), 681 browser()->tab_strip_model()->GetActiveWebContents(),
646 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 682 security_state::DANGEROUS, true, security_state::CONTENT_STATUS_RAN,
647 security_state::CONTENT_STATUS_RAN, false, 683 false, false /* expect cert status error */);
648 false /* expect cert status error */);
649 684
650 // Navigate to an HTTPS page that runs and displays mixed content. 685 // Navigate to an HTTPS page that runs and displays mixed content.
651 GetFilePathWithHostAndPortReplacement( 686 GetFilePathWithHostAndPortReplacement(
652 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair, 687 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
653 &replacement_path); 688 &replacement_path);
654 ui_test_utils::NavigateToURL(browser(), 689 ui_test_utils::NavigateToURL(browser(),
655 https_server_.GetURL(replacement_path)); 690 https_server_.GetURL(replacement_path));
656 CheckSecurityInfoForSecure( 691 CheckSecurityInfoForSecure(
657 browser()->tab_strip_model()->GetActiveWebContents(), 692 browser()->tab_strip_model()->GetActiveWebContents(),
658 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 693 security_state::DANGEROUS, true,
659 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 694 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
660 false /* expect cert status error */); 695 false /* expect cert status error */);
661 } 696 }
662 697
663 // Tests that the Content Security Policy block-all-mixed-content 698 // Tests that the Content Security Policy block-all-mixed-content
664 // directive stops mixed content from running. 699 // directive stops mixed content from running.
665 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentStrictBlocking) { 700 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentStrictBlocking) {
666 ASSERT_TRUE(https_server_.Start()); 701 ASSERT_TRUE(https_server_.Start());
667 SetUpMockCertVerifierForHttpsServer(0, net::OK); 702 SetUpMockCertVerifierForHttpsServer(0, net::OK);
668 703
669 // Navigate to an HTTPS page that tries to run mixed content in an 704 // Navigate to an HTTPS page that tries to run mixed content in an
670 // iframe, with strict mixed content blocking. 705 // iframe, with strict mixed content blocking.
671 std::string replacement_path; 706 std::string replacement_path;
672 net::HostPortPair host_port_pair = 707 net::HostPortPair host_port_pair =
673 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 708 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
674 host_port_pair.set_host("different-host.test"); 709 host_port_pair.set_host("different-host.test");
675 host_resolver()->AddRule("different-host.test", 710 host_resolver()->AddRule("different-host.test",
676 https_server_.GetURL("/title1.html").host()); 711 https_server_.GetURL("/title1.html").host());
677 GetFilePathWithHostAndPortReplacement( 712 GetFilePathWithHostAndPortReplacement(
678 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html", 713 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html",
679 host_port_pair, &replacement_path); 714 host_port_pair, &replacement_path);
680 ui_test_utils::NavigateToURL(browser(), 715 ui_test_utils::NavigateToURL(browser(),
681 https_server_.GetURL(replacement_path)); 716 https_server_.GetURL(replacement_path));
682 CheckSecurityInfoForSecure( 717 CheckSecurityInfoForSecure(
683 browser()->tab_strip_model()->GetActiveWebContents(), 718 browser()->tab_strip_model()->GetActiveWebContents(),
684 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 719 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
685 security_state::CONTENT_STATUS_NONE, false,
686 false /* expect cert status error */); 720 false /* expect cert status error */);
687 } 721 }
688 722
689 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, BrokenHTTPS) { 723 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, BrokenHTTPS) {
690 ASSERT_TRUE(embedded_test_server()->Start()); 724 ASSERT_TRUE(embedded_test_server()->Start());
691 ASSERT_TRUE(https_server_.Start()); 725 ASSERT_TRUE(https_server_.Start());
692 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, 726 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID,
693 net::ERR_CERT_DATE_INVALID); 727 net::ERR_CERT_DATE_INVALID);
694 728
695 ui_test_utils::NavigateToURL(browser(), 729 ui_test_utils::NavigateToURL(browser(),
696 https_server_.GetURL("/ssl/google.html")); 730 https_server_.GetURL("/ssl/google.html"));
697 CheckSecurityInfoForSecure( 731 CheckSecurityInfoForSecure(
698 browser()->tab_strip_model()->GetActiveWebContents(), 732 browser()->tab_strip_model()->GetActiveWebContents(),
699 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 733 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_NONE,
700 security_state::CONTENT_STATUS_NONE, false, 734 false, true /* expect cert status error */);
701 true /* expect cert status error */);
702 735
703 ProceedThroughInterstitial( 736 ProceedThroughInterstitial(
704 browser()->tab_strip_model()->GetActiveWebContents()); 737 browser()->tab_strip_model()->GetActiveWebContents());
705 738
706 CheckSecurityInfoForSecure( 739 CheckSecurityInfoForSecure(
707 browser()->tab_strip_model()->GetActiveWebContents(), 740 browser()->tab_strip_model()->GetActiveWebContents(),
708 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 741 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_NONE,
709 security_state::CONTENT_STATUS_NONE, false, 742 false, true /* expect cert status error */);
710 true /* expect cert status error */);
711 743
712 // Navigate to a broken HTTPS page that displays mixed content. 744 // Navigate to a broken HTTPS page that displays mixed content.
713 std::string replacement_path; 745 std::string replacement_path;
714 GetFilePathWithHostAndPortReplacement( 746 GetFilePathWithHostAndPortReplacement(
715 "/ssl/page_displays_insecure_content.html", 747 "/ssl/page_displays_insecure_content.html",
716 embedded_test_server()->host_port_pair(), &replacement_path); 748 embedded_test_server()->host_port_pair(), &replacement_path);
717 ui_test_utils::NavigateToURL(browser(), 749 ui_test_utils::NavigateToURL(browser(),
718 https_server_.GetURL(replacement_path)); 750 https_server_.GetURL(replacement_path));
719 CheckSecurityInfoForSecure( 751 CheckSecurityInfoForSecure(
720 browser()->tab_strip_model()->GetActiveWebContents(), 752 browser()->tab_strip_model()->GetActiveWebContents(),
721 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 753 security_state::DANGEROUS, false,
722 security_state::CONTENT_STATUS_DISPLAYED, false, 754 security_state::CONTENT_STATUS_DISPLAYED, false,
723 true /* expect cert status error */); 755 true /* expect cert status error */);
724 } 756 }
725 757
726 const char kReportURI[] = "https://report-hpkp.test"; 758 const char kReportURI[] = "https://report-hpkp.test";
727 759
728 class PKPModelClientTest : public SecurityStateTabHelperTest { 760 class PKPModelClientTest : public SecurityStateTabHelperTest {
729 public: 761 public:
730 void SetUpOnMainThread() override { 762 void SetUpOnMainThread() override {
731 ASSERT_TRUE(https_server_.Start()); 763 ASSERT_TRUE(https_server_.Start());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 memset(hash.data(), 1, hash.size()); 804 memset(hash.data(), 1, hash.size());
773 verify_result.public_key_hashes.push_back(hash); 805 verify_result.public_key_hashes.push_back(hash);
774 806
775 mock_cert_verifier()->AddResultForCert(cert, verify_result, net::OK); 807 mock_cert_verifier()->AddResultForCert(cert, verify_result, net::OK);
776 808
777 ui_test_utils::NavigateToURL(browser(), 809 ui_test_utils::NavigateToURL(browser(),
778 https_server_.GetURL("/ssl/google.html")); 810 https_server_.GetURL("/ssl/google.html"));
779 811
780 CheckSecurityInfoForSecure( 812 CheckSecurityInfoForSecure(
781 browser()->tab_strip_model()->GetActiveWebContents(), 813 browser()->tab_strip_model()->GetActiveWebContents(),
782 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 814 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, true,
783 security_state::CONTENT_STATUS_NONE, true, false); 815 false);
784 816
785 const content::SecurityStyleExplanations& explanation = 817 const content::SecurityStyleExplanations& explanation =
786 observer.latest_explanations(); 818 observer.latest_explanations();
787 EXPECT_TRUE(explanation.pkp_bypassed); 819 EXPECT_TRUE(explanation.pkp_bypassed);
788 EXPECT_FALSE(explanation.info_explanations.empty()); 820 EXPECT_FALSE(explanation.info_explanations.empty());
789 } 821 }
790 822
791 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) { 823 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) {
792 content::WebContents* web_contents = 824 content::WebContents* web_contents =
793 browser()->tab_strip_model()->GetActiveWebContents(); 825 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 // updated. 890 // updated.
859 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) { 891 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) {
860 ASSERT_TRUE(https_server_.Start()); 892 ASSERT_TRUE(https_server_.Start());
861 SetUpMockCertVerifierForHttpsServer(0, net::OK); 893 SetUpMockCertVerifierForHttpsServer(0, net::OK);
862 894
863 // Navigate to an HTTPS page. 895 // Navigate to an HTTPS page.
864 ui_test_utils::NavigateToURL(browser(), 896 ui_test_utils::NavigateToURL(browser(),
865 https_server_.GetURL("/ssl/google.html")); 897 https_server_.GetURL("/ssl/google.html"));
866 CheckSecurityInfoForSecure( 898 CheckSecurityInfoForSecure(
867 browser()->tab_strip_model()->GetActiveWebContents(), 899 browser()->tab_strip_model()->GetActiveWebContents(),
868 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 900 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
869 security_state::CONTENT_STATUS_NONE, false,
870 false /* expect cert status error */); 901 false /* expect cert status error */);
871 902
872 // Navigate to a page that doesn't finish loading. Test that the 903 // Navigate to a page that doesn't finish loading. Test that the
873 // security state is neutral while the page is loading. 904 // security state is neutral while the page is loading.
874 browser()->OpenURL(content::OpenURLParams( 905 browser()->OpenURL(content::OpenURLParams(
875 embedded_test_server()->GetURL("/title1.html"), content::Referrer(), 906 embedded_test_server()->GetURL("/title1.html"), content::Referrer(),
876 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); 907 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
877 CheckSecurityInfoForNonSecure( 908 CheckSecurityInfoForNonSecure(
878 browser()->tab_strip_model()->GetActiveWebContents()); 909 browser()->tab_strip_model()->GetActiveWebContents());
879 } 910 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 ASSERT_TRUE(tab); 1503 ASSERT_TRUE(tab);
1473 1504
1474 content::WebContents* new_contents = content::WebContents::Create( 1505 content::WebContents* new_contents = content::WebContents::Create(
1475 content::WebContents::CreateParams(tab->GetBrowserContext())); 1506 content::WebContents::CreateParams(tab->GetBrowserContext()));
1476 content::NavigationController& controller = new_contents->GetController(); 1507 content::NavigationController& controller = new_contents->GetController();
1477 SecurityStateTabHelper::CreateForWebContents(new_contents); 1508 SecurityStateTabHelper::CreateForWebContents(new_contents);
1478 CheckSecurityInfoForNonSecure(new_contents); 1509 CheckSecurityInfoForNonSecure(new_contents);
1479 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(), 1510 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(),
1480 ui::PAGE_TRANSITION_TYPED, std::string()); 1511 ui::PAGE_TRANSITION_TYPED, std::string());
1481 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); 1512 EXPECT_TRUE(content::WaitForLoadStop(new_contents));
1482 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, 1513 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, false,
1483 security_state::NO_DEPRECATED_SHA1,
1484 security_state::CONTENT_STATUS_NONE, false, 1514 security_state::CONTENT_STATUS_NONE, false,
1485 false /* expect cert status error */); 1515 false /* expect cert status error */);
1486 1516
1487 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, 1517 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents,
1488 TabStripModel::ADD_NONE); 1518 TabStripModel::ADD_NONE);
1489 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, 1519 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, false,
1490 security_state::NO_DEPRECATED_SHA1,
1491 security_state::CONTENT_STATUS_NONE, false, 1520 security_state::CONTENT_STATUS_NONE, false,
1492 false /* expect cert status error */); 1521 false /* expect cert status error */);
1493 } 1522 }
1494 1523
1495 // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires 1524 // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires
1496 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages. 1525 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages.
1497 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest, 1526 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
1498 DidChangeVisibleSecurityStateObserver) { 1527 DidChangeVisibleSecurityStateObserver) {
1499 ASSERT_TRUE(https_server_.Start()); 1528 ASSERT_TRUE(https_server_.Start());
1500 ASSERT_TRUE(embedded_test_server()->Start()); 1529 ASSERT_TRUE(embedded_test_server()->Start());
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 SecurityStateTabHelper* helper = 2047 SecurityStateTabHelper* helper =
2019 SecurityStateTabHelper::FromWebContents(web_contents); 2048 SecurityStateTabHelper::FromWebContents(web_contents);
2020 ASSERT_TRUE(helper); 2049 ASSERT_TRUE(helper);
2021 security_state::SecurityInfo security_info; 2050 security_state::SecurityInfo security_info;
2022 helper->GetSecurityInfo(&security_info); 2051 helper->GetSecurityInfo(&security_info);
2023 EXPECT_EQ(security_state::SECURE, security_info.security_level); 2052 EXPECT_EQ(security_state::SECURE, security_info.security_level);
2024 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); 2053 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses);
2025 } 2054 }
2026 2055
2027 } // namespace 2056 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ssl/security_state_tab_helper.cc ('k') | chrome/browser/ui/website_settings/website_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698