OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| 6 |
| 7 #include "components/security_state/security_state_model.h" |
| 8 #include "content/public/browser/security_style_explanations.h" |
| 9 #include "net/cert/cert_status_flags.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 // Tests that SecurityInfo flags for subresources with certificate |
| 15 // errors are reflected in the SecurityStyleExplanations produced by |
| 16 // ChromeSecurityStateModelClient. |
| 17 TEST(ChromeSecurityStateModelClientTest, |
| 18 GetSecurityStyleForContentWithCertErrors) { |
| 19 content::SecurityStyleExplanations explanations; |
| 20 security_state::SecurityStateModel::SecurityInfo security_info; |
| 21 security_info.cert_status = 0; |
| 22 security_info.scheme_is_cryptographic = true; |
| 23 |
| 24 security_info.content_with_cert_errors_status = |
| 25 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; |
| 26 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 27 &explanations); |
| 28 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 29 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 30 |
| 31 security_info.content_with_cert_errors_status = |
| 32 security_state::SecurityStateModel::CONTENT_STATUS_RAN; |
| 33 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 34 &explanations); |
| 35 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 36 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 37 |
| 38 security_info.content_with_cert_errors_status = |
| 39 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; |
| 40 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 41 &explanations); |
| 42 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 43 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 44 |
| 45 security_info.content_with_cert_errors_status = |
| 46 security_state::SecurityStateModel::CONTENT_STATUS_NONE; |
| 47 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 48 &explanations); |
| 49 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 50 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 51 } |
| 52 |
| 53 // Tests that SecurityStyleExplanations for subresources with cert |
| 54 // errors are *not* set when the main resource has major certificate |
| 55 // errors. If the main resource has certificate errors, it would be |
| 56 // duplicative/confusing to also report subresources with cert errors. |
| 57 TEST(ChromeSecurityStateModelClientTest, |
| 58 SubresourcesAndMainResourceWithMajorCertErrors) { |
| 59 content::SecurityStyleExplanations explanations; |
| 60 security_state::SecurityStateModel::SecurityInfo security_info; |
| 61 security_info.cert_status = net::CERT_STATUS_DATE_INVALID; |
| 62 security_info.scheme_is_cryptographic = true; |
| 63 |
| 64 security_info.content_with_cert_errors_status = |
| 65 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; |
| 66 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 67 &explanations); |
| 68 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 69 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 70 |
| 71 security_info.content_with_cert_errors_status = |
| 72 security_state::SecurityStateModel::CONTENT_STATUS_RAN; |
| 73 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 74 &explanations); |
| 75 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 76 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 77 |
| 78 security_info.content_with_cert_errors_status = |
| 79 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; |
| 80 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 81 &explanations); |
| 82 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 83 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 84 |
| 85 security_info.content_with_cert_errors_status = |
| 86 security_state::SecurityStateModel::CONTENT_STATUS_NONE; |
| 87 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 88 &explanations); |
| 89 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 90 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 91 } |
| 92 |
| 93 // Tests that SecurityStyleExplanations for subresources with cert |
| 94 // errors are set when the main resource has only minor certificate |
| 95 // errors. Minor errors on the main resource should not hide major |
| 96 // errors on subresources. |
| 97 TEST(ChromeSecurityStateModelClientTest, |
| 98 SubresourcesAndMainResourceWithMinorCertErrors) { |
| 99 content::SecurityStyleExplanations explanations; |
| 100 security_state::SecurityStateModel::SecurityInfo security_info; |
| 101 security_info.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; |
| 102 security_info.scheme_is_cryptographic = true; |
| 103 |
| 104 security_info.content_with_cert_errors_status = |
| 105 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; |
| 106 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 107 &explanations); |
| 108 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 109 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 110 |
| 111 security_info.content_with_cert_errors_status = |
| 112 security_state::SecurityStateModel::CONTENT_STATUS_RAN; |
| 113 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 114 &explanations); |
| 115 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 116 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 117 |
| 118 security_info.content_with_cert_errors_status = |
| 119 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; |
| 120 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 121 &explanations); |
| 122 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 123 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 124 |
| 125 security_info.content_with_cert_errors_status = |
| 126 security_state::SecurityStateModel::CONTENT_STATUS_NONE; |
| 127 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 128 &explanations); |
| 129 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 130 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 131 } |
| 132 |
| 133 } // namespace |
OLD | NEW |