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

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: Final nits 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 security state after clickthrough for a SHA-1 certificate that is
395 // blocked by default.
396 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1CertificateBlocked) {
397 ASSERT_TRUE(https_server_.Start());
398 SetUpMockCertVerifierForHttpsServer(
399 net::CERT_STATUS_SHA1_SIGNATURE_PRESENT |
400 net::CERT_STATUS_WEAK_SIGNATURE_ALGORITHM,
401 net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM);
402
403 content::WebContents* web_contents =
404 browser()->tab_strip_model()->GetActiveWebContents();
405 SecurityStyleTestObserver observer(web_contents);
406 ui_test_utils::NavigateToURL(browser(),
407 https_server_.GetURL("/ssl/google.html"));
408 CheckSecurityInfoForSecure(
409 browser()->tab_strip_model()->GetActiveWebContents(),
410 security_state::DANGEROUS, true, security_state::CONTENT_STATUS_NONE,
411 false, true /* expect cert status error */);
412
413 const content::SecurityStyleExplanations& interstitial_explanation =
414 observer.latest_explanations();
415 ASSERT_EQ(1u, interstitial_explanation.broken_explanations.size());
416 ASSERT_EQ(1u, interstitial_explanation.unauthenticated_explanations.size());
417 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SHA1),
418 interstitial_explanation.unauthenticated_explanations[0].summary);
419
420 ProceedThroughInterstitial(
421 browser()->tab_strip_model()->GetActiveWebContents());
422
423 CheckSecurityInfoForSecure(
424 browser()->tab_strip_model()->GetActiveWebContents(),
425 security_state::DANGEROUS, true, security_state::CONTENT_STATUS_NONE,
426 false, true /* expect cert status error */);
427
428 const content::SecurityStyleExplanations& page_explanation =
429 observer.latest_explanations();
430 ASSERT_EQ(1u, page_explanation.broken_explanations.size());
431 ASSERT_EQ(1u, page_explanation.unauthenticated_explanations.size());
432 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SHA1),
433 page_explanation.unauthenticated_explanations[0].summary);
434 }
435
436 // Test security state for a SHA-1 certificate that is allowed by policy.
437 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1CertificateWarning) {
398 ASSERT_TRUE(https_server_.Start()); 438 ASSERT_TRUE(https_server_.Start());
399 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 439 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
400 net::OK); 440 net::OK);
401 441
442 content::WebContents* web_contents =
443 browser()->tab_strip_model()->GetActiveWebContents();
444 SecurityStyleTestObserver observer(web_contents);
402 ui_test_utils::NavigateToURL(browser(), 445 ui_test_utils::NavigateToURL(browser(),
403 https_server_.GetURL("/ssl/google.html")); 446 https_server_.GetURL("/ssl/google.html"));
404 CheckSecurityInfoForSecure( 447 CheckSecurityInfoForSecure(
405 browser()->tab_strip_model()->GetActiveWebContents(), 448 browser()->tab_strip_model()->GetActiveWebContents(),
406 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 449 security_state::NONE, true, security_state::CONTENT_STATUS_NONE, false,
407 security_state::CONTENT_STATUS_NONE, false,
408 false /* expect cert status error */); 450 false /* expect cert status error */);
451
452 const content::SecurityStyleExplanations& explanation =
453 observer.latest_explanations();
454
455 ASSERT_EQ(0u, explanation.broken_explanations.size());
456 ASSERT_EQ(1u, explanation.unauthenticated_explanations.size());
457 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SHA1),
458 explanation.unauthenticated_explanations[0].summary);
409 } 459 }
410 460
411 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContent) { 461 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContent) {
412 ASSERT_TRUE(embedded_test_server()->Start()); 462 ASSERT_TRUE(embedded_test_server()->Start());
413 ASSERT_TRUE(https_server_.Start()); 463 ASSERT_TRUE(https_server_.Start());
414 SetUpMockCertVerifierForHttpsServer(0, net::OK); 464 SetUpMockCertVerifierForHttpsServer(0, net::OK);
415 host_resolver()->AddRule("example.test", 465 host_resolver()->AddRule("example.test",
416 https_server_.GetURL("/title1.html").host()); 466 https_server_.GetURL("/title1.html").host());
417 467
418 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 468 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
419 replacement_pair.set_host("example.test"); 469 replacement_pair.set_host("example.test");
420 470
421 // Navigate to an HTTPS page that displays mixed content. 471 // Navigate to an HTTPS page that displays mixed content.
422 std::string replacement_path; 472 std::string replacement_path;
423 GetFilePathWithHostAndPortReplacement( 473 GetFilePathWithHostAndPortReplacement(
424 "/ssl/page_displays_insecure_content.html", replacement_pair, 474 "/ssl/page_displays_insecure_content.html", replacement_pair,
425 &replacement_path); 475 &replacement_path);
426 ui_test_utils::NavigateToURL(browser(), 476 ui_test_utils::NavigateToURL(browser(),
427 https_server_.GetURL(replacement_path)); 477 https_server_.GetURL(replacement_path));
428 CheckSecurityInfoForSecure( 478 CheckSecurityInfoForSecure(
429 browser()->tab_strip_model()->GetActiveWebContents(), 479 browser()->tab_strip_model()->GetActiveWebContents(),
430 security_state::NONE, security_state::NO_DEPRECATED_SHA1, 480 security_state::NONE, false, security_state::CONTENT_STATUS_DISPLAYED,
431 security_state::CONTENT_STATUS_DISPLAYED, false, 481 false, false /* expect cert status error */);
432 false /* expect cert status error */);
433 482
434 // Navigate to an HTTPS page that displays mixed content dynamically. 483 // Navigate to an HTTPS page that displays mixed content dynamically.
435 GetFilePathWithHostAndPortReplacement( 484 GetFilePathWithHostAndPortReplacement(
436 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair, 485 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
437 &replacement_path); 486 &replacement_path);
438 ui_test_utils::NavigateToURL(browser(), 487 ui_test_utils::NavigateToURL(browser(),
439 https_server_.GetURL(replacement_path)); 488 https_server_.GetURL(replacement_path));
440 CheckSecurityInfoForSecure( 489 CheckSecurityInfoForSecure(
441 browser()->tab_strip_model()->GetActiveWebContents(), 490 browser()->tab_strip_model()->GetActiveWebContents(),
442 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 491 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
443 security_state::CONTENT_STATUS_NONE, false,
444 false /* expect cert status error */); 492 false /* expect cert status error */);
445 // Load the insecure image. 493 // Load the insecure image.
446 bool js_result = false; 494 bool js_result = false;
447 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 495 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
448 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 496 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
449 &js_result)); 497 &js_result));
450 EXPECT_TRUE(js_result); 498 EXPECT_TRUE(js_result);
451 CheckSecurityInfoForSecure( 499 CheckSecurityInfoForSecure(
452 browser()->tab_strip_model()->GetActiveWebContents(), 500 browser()->tab_strip_model()->GetActiveWebContents(),
453 security_state::NONE, security_state::NO_DEPRECATED_SHA1, 501 security_state::NONE, false, security_state::CONTENT_STATUS_DISPLAYED,
454 security_state::CONTENT_STATUS_DISPLAYED, false, 502 false, false /* expect cert status error */);
455 false /* expect cert status error */);
456 503
457 // Navigate to an HTTPS page that runs mixed content. 504 // Navigate to an HTTPS page that runs mixed content.
458 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html", 505 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
459 replacement_pair, &replacement_path); 506 replacement_pair, &replacement_path);
460 ui_test_utils::NavigateToURL(browser(), 507 ui_test_utils::NavigateToURL(browser(),
461 https_server_.GetURL(replacement_path)); 508 https_server_.GetURL(replacement_path));
462 CheckSecurityInfoForSecure( 509 CheckSecurityInfoForSecure(
463 browser()->tab_strip_model()->GetActiveWebContents(), 510 browser()->tab_strip_model()->GetActiveWebContents(),
464 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 511 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_RAN,
465 security_state::CONTENT_STATUS_RAN, false, 512 false, false /* expect cert status error */);
466 false /* expect cert status error */);
467 513
468 // Navigate to an HTTPS page that runs and displays mixed content. 514 // Navigate to an HTTPS page that runs and displays mixed content.
469 GetFilePathWithHostAndPortReplacement( 515 GetFilePathWithHostAndPortReplacement(
470 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair, 516 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
471 &replacement_path); 517 &replacement_path);
472 ui_test_utils::NavigateToURL(browser(), 518 ui_test_utils::NavigateToURL(browser(),
473 https_server_.GetURL(replacement_path)); 519 https_server_.GetURL(replacement_path));
474 CheckSecurityInfoForSecure( 520 CheckSecurityInfoForSecure(
475 browser()->tab_strip_model()->GetActiveWebContents(), 521 browser()->tab_strip_model()->GetActiveWebContents(),
476 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 522 security_state::DANGEROUS, false,
477 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 523 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
478 false /* expect cert status error */); 524 false /* expect cert status error */);
479 525
480 // Navigate to an HTTPS page that runs mixed content in an iframe. 526 // Navigate to an HTTPS page that runs mixed content in an iframe.
481 net::HostPortPair host_port_pair = 527 net::HostPortPair host_port_pair =
482 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 528 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
483 host_port_pair.set_host("different-host.test"); 529 host_port_pair.set_host("different-host.test");
484 host_resolver()->AddRule("different-host.test", 530 host_resolver()->AddRule("different-host.test",
485 https_server_.GetURL("/title1.html").host()); 531 https_server_.GetURL("/title1.html").host());
486 host_resolver()->AddRule( 532 host_resolver()->AddRule(
487 "different-http-host.test", 533 "different-http-host.test",
488 embedded_test_server()->GetURL("/title1.html").host()); 534 embedded_test_server()->GetURL("/title1.html").host());
489 GetFilePathWithHostAndPortReplacement( 535 GetFilePathWithHostAndPortReplacement(
490 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, 536 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair,
491 &replacement_path); 537 &replacement_path);
492 ui_test_utils::NavigateToURL(browser(), 538 ui_test_utils::NavigateToURL(browser(),
493 https_server_.GetURL(replacement_path)); 539 https_server_.GetURL(replacement_path));
494 CheckSecurityInfoForSecure( 540 CheckSecurityInfoForSecure(
495 browser()->tab_strip_model()->GetActiveWebContents(), 541 browser()->tab_strip_model()->GetActiveWebContents(),
496 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 542 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_RAN,
497 security_state::CONTENT_STATUS_RAN, false, 543 false, false /* expect cert status error */);
498 false /* expect cert status error */);
499 } 544 }
500 545
501 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, 546 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
502 ActiveContentWithCertErrors) { 547 ActiveContentWithCertErrors) {
503 ASSERT_TRUE(https_server_.Start()); 548 ASSERT_TRUE(https_server_.Start());
504 SetUpMockCertVerifierForHttpsServer(0, net::OK); 549 SetUpMockCertVerifierForHttpsServer(0, net::OK);
505 550
506 // Navigate to an HTTPS page and simulate active content with 551 // Navigate to an HTTPS page and simulate active content with
507 // certificate errors. 552 // certificate errors.
508 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); 553 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); 625 ASSERT_TRUE(helper);
581 security_state::SecurityInfo security_info; 626 security_state::SecurityInfo security_info;
582 helper->GetSecurityInfo(&security_info); 627 helper->GetSecurityInfo(&security_info);
583 628
584 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 629 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
585 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level); 630 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level);
586 EXPECT_EQ(security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, 631 EXPECT_EQ(security_state::CONTENT_STATUS_DISPLAYED_AND_RAN,
587 security_info.content_with_cert_errors_status); 632 security_info.content_with_cert_errors_status);
588 } 633 }
589 634
590 // Same as the test above but with a long-lived SHA1 cert. 635 // Same as SecurityStateTabHelperTest.ActiveAndPassiveContentWithCertErrors but
636 // with a SHA1 cert.
591 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentWithSHA1Cert) { 637 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentWithSHA1Cert) {
592 ASSERT_TRUE(embedded_test_server()->Start()); 638 ASSERT_TRUE(embedded_test_server()->Start());
593 ASSERT_TRUE(https_server_.Start()); 639 ASSERT_TRUE(https_server_.Start());
594 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 640 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
595 net::OK); 641 net::OK);
596 642
597 host_resolver()->AddRule("example.test", 643 host_resolver()->AddRule("example.test",
598 https_server_.GetURL("/title1.html").host()); 644 https_server_.GetURL("/title1.html").host());
599 645
600 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 646 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
601 replacement_pair.set_host("example.test"); 647 replacement_pair.set_host("example.test");
602 648
603 // Navigate to an HTTPS page that displays mixed content. 649 // Navigate to an HTTPS page that displays mixed content.
604 std::string replacement_path; 650 std::string replacement_path;
605 GetFilePathWithHostAndPortReplacement( 651 GetFilePathWithHostAndPortReplacement(
606 "/ssl/page_displays_insecure_content.html", replacement_pair, 652 "/ssl/page_displays_insecure_content.html", replacement_pair,
607 &replacement_path); 653 &replacement_path);
608 ui_test_utils::NavigateToURL(browser(), 654 ui_test_utils::NavigateToURL(browser(),
609 https_server_.GetURL(replacement_path)); 655 https_server_.GetURL(replacement_path));
610 CheckSecurityInfoForSecure( 656 CheckSecurityInfoForSecure(
611 browser()->tab_strip_model()->GetActiveWebContents(), 657 browser()->tab_strip_model()->GetActiveWebContents(),
612 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 658 security_state::NONE, true, security_state::CONTENT_STATUS_DISPLAYED,
613 security_state::CONTENT_STATUS_DISPLAYED, false, 659 false, false /* expect cert status error */);
614 false /* expect cert status error */);
615 660
616 // Navigate to an HTTPS page that displays mixed content dynamically. 661 // Navigate to an HTTPS page that displays mixed content dynamically.
617 GetFilePathWithHostAndPortReplacement( 662 GetFilePathWithHostAndPortReplacement(
618 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair, 663 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
619 &replacement_path); 664 &replacement_path);
620 ui_test_utils::NavigateToURL(browser(), 665 ui_test_utils::NavigateToURL(browser(),
621 https_server_.GetURL(replacement_path)); 666 https_server_.GetURL(replacement_path));
622 CheckSecurityInfoForSecure( 667 CheckSecurityInfoForSecure(
623 browser()->tab_strip_model()->GetActiveWebContents(), 668 browser()->tab_strip_model()->GetActiveWebContents(),
624 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 669 security_state::NONE, true, security_state::CONTENT_STATUS_NONE, false,
625 security_state::CONTENT_STATUS_NONE, false,
626 false /* expect cert status error */); 670 false /* expect cert status error */);
627 // Load the insecure image. 671 // Load the insecure image.
628 bool js_result = false; 672 bool js_result = false;
629 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 673 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
630 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 674 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
631 &js_result)); 675 &js_result));
632 EXPECT_TRUE(js_result); 676 EXPECT_TRUE(js_result);
633 CheckSecurityInfoForSecure( 677 CheckSecurityInfoForSecure(
634 browser()->tab_strip_model()->GetActiveWebContents(), 678 browser()->tab_strip_model()->GetActiveWebContents(),
635 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 679 security_state::NONE, true, security_state::CONTENT_STATUS_DISPLAYED,
636 security_state::CONTENT_STATUS_DISPLAYED, false, 680 false, false /* expect cert status error */);
637 false /* expect cert status error */);
638 681
639 // Navigate to an HTTPS page that runs mixed content. 682 // Navigate to an HTTPS page that runs mixed content.
640 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html", 683 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
641 replacement_pair, &replacement_path); 684 replacement_pair, &replacement_path);
642 ui_test_utils::NavigateToURL(browser(), 685 ui_test_utils::NavigateToURL(browser(),
643 https_server_.GetURL(replacement_path)); 686 https_server_.GetURL(replacement_path));
644 CheckSecurityInfoForSecure( 687 CheckSecurityInfoForSecure(
645 browser()->tab_strip_model()->GetActiveWebContents(), 688 browser()->tab_strip_model()->GetActiveWebContents(),
646 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 689 security_state::DANGEROUS, true, security_state::CONTENT_STATUS_RAN,
647 security_state::CONTENT_STATUS_RAN, false, 690 false, false /* expect cert status error */);
648 false /* expect cert status error */);
649 691
650 // Navigate to an HTTPS page that runs and displays mixed content. 692 // Navigate to an HTTPS page that runs and displays mixed content.
651 GetFilePathWithHostAndPortReplacement( 693 GetFilePathWithHostAndPortReplacement(
652 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair, 694 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
653 &replacement_path); 695 &replacement_path);
654 ui_test_utils::NavigateToURL(browser(), 696 ui_test_utils::NavigateToURL(browser(),
655 https_server_.GetURL(replacement_path)); 697 https_server_.GetURL(replacement_path));
656 CheckSecurityInfoForSecure( 698 CheckSecurityInfoForSecure(
657 browser()->tab_strip_model()->GetActiveWebContents(), 699 browser()->tab_strip_model()->GetActiveWebContents(),
658 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 700 security_state::DANGEROUS, true,
659 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 701 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
660 false /* expect cert status error */); 702 false /* expect cert status error */);
661 } 703 }
662 704
663 // Tests that the Content Security Policy block-all-mixed-content 705 // Tests that the Content Security Policy block-all-mixed-content
664 // directive stops mixed content from running. 706 // directive stops mixed content from running.
665 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentStrictBlocking) { 707 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentStrictBlocking) {
666 ASSERT_TRUE(https_server_.Start()); 708 ASSERT_TRUE(https_server_.Start());
667 SetUpMockCertVerifierForHttpsServer(0, net::OK); 709 SetUpMockCertVerifierForHttpsServer(0, net::OK);
668 710
669 // Navigate to an HTTPS page that tries to run mixed content in an 711 // Navigate to an HTTPS page that tries to run mixed content in an
670 // iframe, with strict mixed content blocking. 712 // iframe, with strict mixed content blocking.
671 std::string replacement_path; 713 std::string replacement_path;
672 net::HostPortPair host_port_pair = 714 net::HostPortPair host_port_pair =
673 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 715 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
674 host_port_pair.set_host("different-host.test"); 716 host_port_pair.set_host("different-host.test");
675 host_resolver()->AddRule("different-host.test", 717 host_resolver()->AddRule("different-host.test",
676 https_server_.GetURL("/title1.html").host()); 718 https_server_.GetURL("/title1.html").host());
677 GetFilePathWithHostAndPortReplacement( 719 GetFilePathWithHostAndPortReplacement(
678 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html", 720 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html",
679 host_port_pair, &replacement_path); 721 host_port_pair, &replacement_path);
680 ui_test_utils::NavigateToURL(browser(), 722 ui_test_utils::NavigateToURL(browser(),
681 https_server_.GetURL(replacement_path)); 723 https_server_.GetURL(replacement_path));
682 CheckSecurityInfoForSecure( 724 CheckSecurityInfoForSecure(
683 browser()->tab_strip_model()->GetActiveWebContents(), 725 browser()->tab_strip_model()->GetActiveWebContents(),
684 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 726 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
685 security_state::CONTENT_STATUS_NONE, false,
686 false /* expect cert status error */); 727 false /* expect cert status error */);
687 } 728 }
688 729
689 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, BrokenHTTPS) { 730 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, BrokenHTTPS) {
690 ASSERT_TRUE(embedded_test_server()->Start()); 731 ASSERT_TRUE(embedded_test_server()->Start());
691 ASSERT_TRUE(https_server_.Start()); 732 ASSERT_TRUE(https_server_.Start());
692 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, 733 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID,
693 net::ERR_CERT_DATE_INVALID); 734 net::ERR_CERT_DATE_INVALID);
694 735
695 ui_test_utils::NavigateToURL(browser(), 736 ui_test_utils::NavigateToURL(browser(),
696 https_server_.GetURL("/ssl/google.html")); 737 https_server_.GetURL("/ssl/google.html"));
697 CheckSecurityInfoForSecure( 738 CheckSecurityInfoForSecure(
698 browser()->tab_strip_model()->GetActiveWebContents(), 739 browser()->tab_strip_model()->GetActiveWebContents(),
699 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 740 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_NONE,
700 security_state::CONTENT_STATUS_NONE, false, 741 false, true /* expect cert status error */);
701 true /* expect cert status error */);
702 742
703 ProceedThroughInterstitial( 743 ProceedThroughInterstitial(
704 browser()->tab_strip_model()->GetActiveWebContents()); 744 browser()->tab_strip_model()->GetActiveWebContents());
705 745
706 CheckSecurityInfoForSecure( 746 CheckSecurityInfoForSecure(
707 browser()->tab_strip_model()->GetActiveWebContents(), 747 browser()->tab_strip_model()->GetActiveWebContents(),
708 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 748 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_NONE,
709 security_state::CONTENT_STATUS_NONE, false, 749 false, true /* expect cert status error */);
710 true /* expect cert status error */);
711 750
712 // Navigate to a broken HTTPS page that displays mixed content. 751 // Navigate to a broken HTTPS page that displays mixed content.
713 std::string replacement_path; 752 std::string replacement_path;
714 GetFilePathWithHostAndPortReplacement( 753 GetFilePathWithHostAndPortReplacement(
715 "/ssl/page_displays_insecure_content.html", 754 "/ssl/page_displays_insecure_content.html",
716 embedded_test_server()->host_port_pair(), &replacement_path); 755 embedded_test_server()->host_port_pair(), &replacement_path);
717 ui_test_utils::NavigateToURL(browser(), 756 ui_test_utils::NavigateToURL(browser(),
718 https_server_.GetURL(replacement_path)); 757 https_server_.GetURL(replacement_path));
719 CheckSecurityInfoForSecure( 758 CheckSecurityInfoForSecure(
720 browser()->tab_strip_model()->GetActiveWebContents(), 759 browser()->tab_strip_model()->GetActiveWebContents(),
721 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 760 security_state::DANGEROUS, false,
722 security_state::CONTENT_STATUS_DISPLAYED, false, 761 security_state::CONTENT_STATUS_DISPLAYED, false,
723 true /* expect cert status error */); 762 true /* expect cert status error */);
724 } 763 }
725 764
726 const char kReportURI[] = "https://report-hpkp.test"; 765 const char kReportURI[] = "https://report-hpkp.test";
727 766
728 class PKPModelClientTest : public SecurityStateTabHelperTest { 767 class PKPModelClientTest : public SecurityStateTabHelperTest {
729 public: 768 public:
730 void SetUpOnMainThread() override { 769 void SetUpOnMainThread() override {
731 ASSERT_TRUE(https_server_.Start()); 770 ASSERT_TRUE(https_server_.Start());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 memset(hash.data(), 1, hash.size()); 811 memset(hash.data(), 1, hash.size());
773 verify_result.public_key_hashes.push_back(hash); 812 verify_result.public_key_hashes.push_back(hash);
774 813
775 mock_cert_verifier()->AddResultForCert(cert, verify_result, net::OK); 814 mock_cert_verifier()->AddResultForCert(cert, verify_result, net::OK);
776 815
777 ui_test_utils::NavigateToURL(browser(), 816 ui_test_utils::NavigateToURL(browser(),
778 https_server_.GetURL("/ssl/google.html")); 817 https_server_.GetURL("/ssl/google.html"));
779 818
780 CheckSecurityInfoForSecure( 819 CheckSecurityInfoForSecure(
781 browser()->tab_strip_model()->GetActiveWebContents(), 820 browser()->tab_strip_model()->GetActiveWebContents(),
782 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 821 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, true,
783 security_state::CONTENT_STATUS_NONE, true, false); 822 false);
784 823
785 const content::SecurityStyleExplanations& explanation = 824 const content::SecurityStyleExplanations& explanation =
786 observer.latest_explanations(); 825 observer.latest_explanations();
787 EXPECT_TRUE(explanation.pkp_bypassed); 826 EXPECT_TRUE(explanation.pkp_bypassed);
788 EXPECT_FALSE(explanation.info_explanations.empty()); 827 EXPECT_FALSE(explanation.info_explanations.empty());
789 } 828 }
790 829
791 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) { 830 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) {
792 content::WebContents* web_contents = 831 content::WebContents* web_contents =
793 browser()->tab_strip_model()->GetActiveWebContents(); 832 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 // updated. 897 // updated.
859 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) { 898 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) {
860 ASSERT_TRUE(https_server_.Start()); 899 ASSERT_TRUE(https_server_.Start());
861 SetUpMockCertVerifierForHttpsServer(0, net::OK); 900 SetUpMockCertVerifierForHttpsServer(0, net::OK);
862 901
863 // Navigate to an HTTPS page. 902 // Navigate to an HTTPS page.
864 ui_test_utils::NavigateToURL(browser(), 903 ui_test_utils::NavigateToURL(browser(),
865 https_server_.GetURL("/ssl/google.html")); 904 https_server_.GetURL("/ssl/google.html"));
866 CheckSecurityInfoForSecure( 905 CheckSecurityInfoForSecure(
867 browser()->tab_strip_model()->GetActiveWebContents(), 906 browser()->tab_strip_model()->GetActiveWebContents(),
868 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 907 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
869 security_state::CONTENT_STATUS_NONE, false,
870 false /* expect cert status error */); 908 false /* expect cert status error */);
871 909
872 // Navigate to a page that doesn't finish loading. Test that the 910 // Navigate to a page that doesn't finish loading. Test that the
873 // security state is neutral while the page is loading. 911 // security state is neutral while the page is loading.
874 browser()->OpenURL(content::OpenURLParams( 912 browser()->OpenURL(content::OpenURLParams(
875 embedded_test_server()->GetURL("/title1.html"), content::Referrer(), 913 embedded_test_server()->GetURL("/title1.html"), content::Referrer(),
876 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); 914 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
877 CheckSecurityInfoForNonSecure( 915 CheckSecurityInfoForNonSecure(
878 browser()->tab_strip_model()->GetActiveWebContents()); 916 browser()->tab_strip_model()->GetActiveWebContents());
879 } 917 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 ASSERT_TRUE(tab); 1510 ASSERT_TRUE(tab);
1473 1511
1474 content::WebContents* new_contents = content::WebContents::Create( 1512 content::WebContents* new_contents = content::WebContents::Create(
1475 content::WebContents::CreateParams(tab->GetBrowserContext())); 1513 content::WebContents::CreateParams(tab->GetBrowserContext()));
1476 content::NavigationController& controller = new_contents->GetController(); 1514 content::NavigationController& controller = new_contents->GetController();
1477 SecurityStateTabHelper::CreateForWebContents(new_contents); 1515 SecurityStateTabHelper::CreateForWebContents(new_contents);
1478 CheckSecurityInfoForNonSecure(new_contents); 1516 CheckSecurityInfoForNonSecure(new_contents);
1479 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(), 1517 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(),
1480 ui::PAGE_TRANSITION_TYPED, std::string()); 1518 ui::PAGE_TRANSITION_TYPED, std::string());
1481 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); 1519 EXPECT_TRUE(content::WaitForLoadStop(new_contents));
1482 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, 1520 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, false,
1483 security_state::NO_DEPRECATED_SHA1,
1484 security_state::CONTENT_STATUS_NONE, false, 1521 security_state::CONTENT_STATUS_NONE, false,
1485 false /* expect cert status error */); 1522 false /* expect cert status error */);
1486 1523
1487 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, 1524 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents,
1488 TabStripModel::ADD_NONE); 1525 TabStripModel::ADD_NONE);
1489 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, 1526 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, false,
1490 security_state::NO_DEPRECATED_SHA1,
1491 security_state::CONTENT_STATUS_NONE, false, 1527 security_state::CONTENT_STATUS_NONE, false,
1492 false /* expect cert status error */); 1528 false /* expect cert status error */);
1493 } 1529 }
1494 1530
1495 // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires 1531 // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires
1496 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages. 1532 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages.
1497 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest, 1533 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
1498 DidChangeVisibleSecurityStateObserver) { 1534 DidChangeVisibleSecurityStateObserver) {
1499 ASSERT_TRUE(https_server_.Start()); 1535 ASSERT_TRUE(https_server_.Start());
1500 ASSERT_TRUE(embedded_test_server()->Start()); 1536 ASSERT_TRUE(embedded_test_server()->Start());
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 SecurityStateTabHelper* helper = 2054 SecurityStateTabHelper* helper =
2019 SecurityStateTabHelper::FromWebContents(web_contents); 2055 SecurityStateTabHelper::FromWebContents(web_contents);
2020 ASSERT_TRUE(helper); 2056 ASSERT_TRUE(helper);
2021 security_state::SecurityInfo security_info; 2057 security_state::SecurityInfo security_info;
2022 helper->GetSecurityInfo(&security_info); 2058 helper->GetSecurityInfo(&security_info);
2023 EXPECT_EQ(security_state::SECURE, security_info.security_level); 2059 EXPECT_EQ(security_state::SECURE, security_info.security_level);
2024 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); 2060 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses);
2025 } 2061 }
2026 2062
2027 } // namespace 2063 } // 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