| OLD | NEW |
| 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 "components/security_state/security_state_model.h" | 5 #include "components/security_state/core/security_state.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/ptr_util.h" |
| 10 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
| 11 #include "components/security_state/security_state_model_client.h" | 13 #include "components/security_state/core/switches.h" |
| 12 #include "components/security_state/switches.h" | |
| 13 #include "net/cert/x509_certificate.h" | 14 #include "net/cert/x509_certificate.h" |
| 14 #include "net/ssl/ssl_cipher_suite_names.h" | 15 #include "net/ssl/ssl_cipher_suite_names.h" |
| 15 #include "net/ssl/ssl_connection_status_flags.h" | 16 #include "net/ssl/ssl_connection_status_flags.h" |
| 16 #include "net/test/cert_test_util.h" | 17 #include "net/test/cert_test_util.h" |
| 17 #include "net/test/test_certificate_data.h" | 18 #include "net/test/test_certificate_data.h" |
| 18 #include "net/test/test_data_directory.h" | 19 #include "net/test/test_data_directory.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace security_state { | 22 namespace security_state { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char kHttpsUrl[] = "https://foo.test"; | 26 const char kHttpsUrl[] = "https://foo.test"; |
| 26 const char kHttpUrl[] = "http://foo.test"; | 27 const char kHttpUrl[] = "http://foo.test"; |
| 27 | 28 |
| 28 class TestSecurityStateModelClient : public SecurityStateModelClient { | 29 bool IsOriginSecure(const GURL& url) { |
| 30 return url == GURL(kHttpsUrl); |
| 31 } |
| 32 |
| 33 class TestSecurityStateHelper { |
| 29 public: | 34 public: |
| 30 TestSecurityStateModelClient() | 35 TestSecurityStateHelper() |
| 31 : url_(kHttpsUrl), | 36 : url_(kHttpsUrl), |
| 32 connection_status_(net::SSL_CONNECTION_VERSION_TLS1_2 | 37 connection_status_(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 33 << net::SSL_CONNECTION_VERSION_SHIFT), | 38 << net::SSL_CONNECTION_VERSION_SHIFT), |
| 34 cert_status_(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT), | 39 cert_status_(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT), |
| 35 displayed_mixed_content_(false), | 40 displayed_mixed_content_(false), |
| 36 ran_mixed_content_(false), | 41 ran_mixed_content_(false), |
| 37 fails_malware_check_(false), | 42 fails_malware_check_(false), |
| 38 displayed_password_field_on_http_(false), | 43 displayed_password_field_on_http_(false), |
| 39 displayed_credit_card_field_on_http_(false) { | 44 displayed_credit_card_field_on_http_(false) { |
| 40 cert_ = | 45 cert_ = |
| 41 net::ImportCertFromFile(net::GetTestCertsDirectory(), "sha1_2016.pem"); | 46 net::ImportCertFromFile(net::GetTestCertsDirectory(), "sha1_2016.pem"); |
| 42 } | 47 } |
| 43 ~TestSecurityStateModelClient() override {} | 48 virtual ~TestSecurityStateHelper() {} |
| 44 | 49 |
| 45 void set_connection_status(int connection_status) { | 50 void set_connection_status(int connection_status) { |
| 46 connection_status_ = connection_status; | 51 connection_status_ = connection_status; |
| 47 } | 52 } |
| 48 void SetCipherSuite(uint16_t ciphersuite) { | 53 void SetCipherSuite(uint16_t ciphersuite) { |
| 49 net::SSLConnectionStatusSetCipherSuite(ciphersuite, &connection_status_); | 54 net::SSLConnectionStatusSetCipherSuite(ciphersuite, &connection_status_); |
| 50 } | 55 } |
| 51 void AddCertStatus(net::CertStatus cert_status) { | 56 void AddCertStatus(net::CertStatus cert_status) { |
| 52 cert_status_ |= cert_status; | 57 cert_status_ |= cert_status; |
| 53 } | 58 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 bool displayed_password_field_on_http) { | 69 bool displayed_password_field_on_http) { |
| 65 displayed_password_field_on_http_ = displayed_password_field_on_http; | 70 displayed_password_field_on_http_ = displayed_password_field_on_http; |
| 66 } | 71 } |
| 67 void set_displayed_credit_card_field_on_http( | 72 void set_displayed_credit_card_field_on_http( |
| 68 bool displayed_credit_card_field_on_http) { | 73 bool displayed_credit_card_field_on_http) { |
| 69 displayed_credit_card_field_on_http_ = displayed_credit_card_field_on_http; | 74 displayed_credit_card_field_on_http_ = displayed_credit_card_field_on_http; |
| 70 } | 75 } |
| 71 | 76 |
| 72 void UseHttpUrl() { url_ = GURL(kHttpUrl); } | 77 void UseHttpUrl() { url_ = GURL(kHttpUrl); } |
| 73 | 78 |
| 74 // SecurityStateModelClient: | 79 std::unique_ptr<VisibleSecurityState> GetVisibleSecurityState() { |
| 75 void GetVisibleSecurityState( | 80 auto state = base::MakeUnique<VisibleSecurityState>(); |
| 76 SecurityStateModel::VisibleSecurityState* state) override { | |
| 77 state->connection_info_initialized = true; | 81 state->connection_info_initialized = true; |
| 78 state->url = url_; | 82 state->url = url_; |
| 79 state->certificate = cert_; | 83 state->certificate = cert_; |
| 80 state->cert_status = cert_status_; | 84 state->cert_status = cert_status_; |
| 81 state->connection_status = connection_status_; | 85 state->connection_status = connection_status_; |
| 82 state->security_bits = 256; | 86 state->security_bits = 256; |
| 83 state->displayed_mixed_content = displayed_mixed_content_; | 87 state->displayed_mixed_content = displayed_mixed_content_; |
| 84 state->ran_mixed_content = ran_mixed_content_; | 88 state->ran_mixed_content = ran_mixed_content_; |
| 85 state->fails_malware_check = fails_malware_check_; | 89 state->fails_malware_check = fails_malware_check_; |
| 86 state->displayed_password_field_on_http = displayed_password_field_on_http_; | 90 state->displayed_password_field_on_http = displayed_password_field_on_http_; |
| 87 state->displayed_credit_card_field_on_http = | 91 state->displayed_credit_card_field_on_http = |
| 88 displayed_credit_card_field_on_http_; | 92 displayed_credit_card_field_on_http_; |
| 93 return state; |
| 89 } | 94 } |
| 90 | 95 |
| 91 bool UsedPolicyInstalledCertificate() override { return false; } | 96 void GetSecurityInfo(SecurityInfo* security_info) { |
| 92 | 97 security_state::GetSecurityInfo( |
| 93 bool IsOriginSecure(const GURL& url) override { | 98 GetVisibleSecurityState(), |
| 94 return url_ == GURL(kHttpsUrl); | 99 false /* used policy installed certificate */, |
| 100 base::Bind(&IsOriginSecure), security_info); |
| 95 } | 101 } |
| 96 | 102 |
| 97 private: | 103 private: |
| 98 GURL url_; | 104 GURL url_; |
| 99 scoped_refptr<net::X509Certificate> cert_; | 105 scoped_refptr<net::X509Certificate> cert_; |
| 100 int connection_status_; | 106 int connection_status_; |
| 101 net::CertStatus cert_status_; | 107 net::CertStatus cert_status_; |
| 102 bool displayed_mixed_content_; | 108 bool displayed_mixed_content_; |
| 103 bool ran_mixed_content_; | 109 bool ran_mixed_content_; |
| 104 bool fails_malware_check_; | 110 bool fails_malware_check_; |
| 105 bool displayed_password_field_on_http_; | 111 bool displayed_password_field_on_http_; |
| 106 bool displayed_credit_card_field_on_http_; | 112 bool displayed_credit_card_field_on_http_; |
| 107 }; | 113 }; |
| 108 | 114 |
| 115 } // namespace |
| 116 |
| 109 // Tests that SHA1-signed certificates expiring in 2016 downgrade the | 117 // Tests that SHA1-signed certificates expiring in 2016 downgrade the |
| 110 // security state of the page. | 118 // security state of the page. |
| 111 TEST(SecurityStateModelTest, SHA1Warning) { | 119 TEST(SecurityStateTest, SHA1Warning) { |
| 112 TestSecurityStateModelClient client; | 120 TestSecurityStateHelper helper; |
| 113 SecurityStateModel model; | 121 SecurityInfo security_info; |
| 114 model.SetClient(&client); | 122 helper.GetSecurityInfo(&security_info); |
| 115 SecurityStateModel::SecurityInfo security_info; | 123 EXPECT_EQ(DEPRECATED_SHA1_MINOR, security_info.sha1_deprecation_status); |
| 116 model.GetSecurityInfo(&security_info); | 124 EXPECT_EQ(NONE, security_info.security_level); |
| 117 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | |
| 118 security_info.sha1_deprecation_status); | |
| 119 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | |
| 120 } | 125 } |
| 121 | 126 |
| 122 // Tests that SHA1 warnings don't interfere with the handling of mixed | 127 // Tests that SHA1 warnings don't interfere with the handling of mixed |
| 123 // content. | 128 // content. |
| 124 TEST(SecurityStateModelTest, SHA1WarningMixedContent) { | 129 TEST(SecurityStateTest, SHA1WarningMixedContent) { |
| 125 TestSecurityStateModelClient client; | 130 TestSecurityStateHelper helper; |
| 126 SecurityStateModel model; | 131 helper.SetDisplayedMixedContent(true); |
| 127 model.SetClient(&client); | 132 SecurityInfo security_info1; |
| 128 client.SetDisplayedMixedContent(true); | 133 helper.GetSecurityInfo(&security_info1); |
| 129 SecurityStateModel::SecurityInfo security_info1; | 134 EXPECT_EQ(DEPRECATED_SHA1_MINOR, security_info1.sha1_deprecation_status); |
| 130 model.GetSecurityInfo(&security_info1); | 135 EXPECT_EQ(CONTENT_STATUS_DISPLAYED, security_info1.mixed_content_status); |
| 131 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | 136 EXPECT_EQ(NONE, security_info1.security_level); |
| 132 security_info1.sha1_deprecation_status); | |
| 133 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_DISPLAYED, | |
| 134 security_info1.mixed_content_status); | |
| 135 EXPECT_EQ(SecurityStateModel::NONE, security_info1.security_level); | |
| 136 | 137 |
| 137 client.SetDisplayedMixedContent(false); | 138 helper.SetDisplayedMixedContent(false); |
| 138 client.SetRanMixedContent(true); | 139 helper.SetRanMixedContent(true); |
| 139 SecurityStateModel::SecurityInfo security_info2; | 140 SecurityInfo security_info2; |
| 140 model.GetSecurityInfo(&security_info2); | 141 helper.GetSecurityInfo(&security_info2); |
| 141 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | 142 EXPECT_EQ(DEPRECATED_SHA1_MINOR, security_info2.sha1_deprecation_status); |
| 142 security_info2.sha1_deprecation_status); | 143 EXPECT_EQ(CONTENT_STATUS_RAN, security_info2.mixed_content_status); |
| 143 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_RAN, | 144 EXPECT_EQ(DANGEROUS, security_info2.security_level); |
| 144 security_info2.mixed_content_status); | |
| 145 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info2.security_level); | |
| 146 } | 145 } |
| 147 | 146 |
| 148 // Tests that SHA1 warnings don't interfere with the handling of major | 147 // Tests that SHA1 warnings don't interfere with the handling of major |
| 149 // cert errors. | 148 // cert errors. |
| 150 TEST(SecurityStateModelTest, SHA1WarningBrokenHTTPS) { | 149 TEST(SecurityStateTest, SHA1WarningBrokenHTTPS) { |
| 151 TestSecurityStateModelClient client; | 150 TestSecurityStateHelper helper; |
| 152 SecurityStateModel model; | 151 helper.AddCertStatus(net::CERT_STATUS_DATE_INVALID); |
| 153 model.SetClient(&client); | 152 SecurityInfo security_info; |
| 154 client.AddCertStatus(net::CERT_STATUS_DATE_INVALID); | 153 helper.GetSecurityInfo(&security_info); |
| 155 SecurityStateModel::SecurityInfo security_info; | 154 EXPECT_EQ(DEPRECATED_SHA1_MINOR, security_info.sha1_deprecation_status); |
| 156 model.GetSecurityInfo(&security_info); | 155 EXPECT_EQ(DANGEROUS, security_info.security_level); |
| 157 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | |
| 158 security_info.sha1_deprecation_status); | |
| 159 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); | |
| 160 } | 156 } |
| 161 | 157 |
| 162 // Tests that |security_info.is_secure_protocol_and_ciphersuite| is | 158 // Tests that |security_info.is_secure_protocol_and_ciphersuite| is |
| 163 // computed correctly. | 159 // computed correctly. |
| 164 TEST(SecurityStateModelTest, SecureProtocolAndCiphersuite) { | 160 TEST(SecurityStateTest, SecureProtocolAndCiphersuite) { |
| 165 TestSecurityStateModelClient client; | 161 TestSecurityStateHelper helper; |
| 166 SecurityStateModel model; | |
| 167 model.SetClient(&client); | |
| 168 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 162 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
| 169 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 163 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 170 const uint16_t ciphersuite = 0xc02f; | 164 const uint16_t ciphersuite = 0xc02f; |
| 171 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 165 helper.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 172 << net::SSL_CONNECTION_VERSION_SHIFT); | 166 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 173 client.SetCipherSuite(ciphersuite); | 167 helper.SetCipherSuite(ciphersuite); |
| 174 SecurityStateModel::SecurityInfo security_info; | 168 SecurityInfo security_info; |
| 175 model.GetSecurityInfo(&security_info); | 169 helper.GetSecurityInfo(&security_info); |
| 176 EXPECT_EQ(net::OBSOLETE_SSL_NONE, security_info.obsolete_ssl_status); | 170 EXPECT_EQ(net::OBSOLETE_SSL_NONE, security_info.obsolete_ssl_status); |
| 177 } | 171 } |
| 178 | 172 |
| 179 TEST(SecurityStateModelTest, NonsecureProtocol) { | 173 TEST(SecurityStateTest, NonsecureProtocol) { |
| 180 TestSecurityStateModelClient client; | 174 TestSecurityStateHelper helper; |
| 181 SecurityStateModel model; | |
| 182 model.SetClient(&client); | |
| 183 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 175 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
| 184 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 176 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 185 const uint16_t ciphersuite = 0xc02f; | 177 const uint16_t ciphersuite = 0xc02f; |
| 186 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_1 | 178 helper.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_1 |
| 187 << net::SSL_CONNECTION_VERSION_SHIFT); | 179 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 188 client.SetCipherSuite(ciphersuite); | 180 helper.SetCipherSuite(ciphersuite); |
| 189 SecurityStateModel::SecurityInfo security_info; | 181 SecurityInfo security_info; |
| 190 model.GetSecurityInfo(&security_info); | 182 helper.GetSecurityInfo(&security_info); |
| 191 EXPECT_EQ(net::OBSOLETE_SSL_MASK_PROTOCOL, security_info.obsolete_ssl_status); | 183 EXPECT_EQ(net::OBSOLETE_SSL_MASK_PROTOCOL, security_info.obsolete_ssl_status); |
| 192 } | 184 } |
| 193 | 185 |
| 194 TEST(SecurityStateModelTest, NonsecureCiphersuite) { | 186 TEST(SecurityStateTest, NonsecureCiphersuite) { |
| 195 TestSecurityStateModelClient client; | 187 TestSecurityStateHelper helper; |
| 196 SecurityStateModel model; | |
| 197 model.SetClient(&client); | |
| 198 // TLS_RSA_WITH_AES_128_CCM_8 from | 188 // TLS_RSA_WITH_AES_128_CCM_8 from |
| 199 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 189 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 200 const uint16_t ciphersuite = 0xc0a0; | 190 const uint16_t ciphersuite = 0xc0a0; |
| 201 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 191 helper.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 202 << net::SSL_CONNECTION_VERSION_SHIFT); | 192 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 203 client.SetCipherSuite(ciphersuite); | 193 helper.SetCipherSuite(ciphersuite); |
| 204 SecurityStateModel::SecurityInfo security_info; | 194 SecurityInfo security_info; |
| 205 model.GetSecurityInfo(&security_info); | 195 helper.GetSecurityInfo(&security_info); |
| 206 EXPECT_EQ(net::OBSOLETE_SSL_MASK_KEY_EXCHANGE | net::OBSOLETE_SSL_MASK_CIPHER, | 196 EXPECT_EQ(net::OBSOLETE_SSL_MASK_KEY_EXCHANGE | net::OBSOLETE_SSL_MASK_CIPHER, |
| 207 security_info.obsolete_ssl_status); | 197 security_info.obsolete_ssl_status); |
| 208 } | 198 } |
| 209 | 199 |
| 210 // Tests that the malware/phishing status is set, and it overrides valid HTTPS. | 200 // Tests that the malware/phishing status is set, and it overrides valid HTTPS. |
| 211 TEST(SecurityStateModelTest, MalwareOverride) { | 201 TEST(SecurityStateTest, MalwareOverride) { |
| 212 TestSecurityStateModelClient client; | 202 TestSecurityStateHelper helper; |
| 213 SecurityStateModel model; | |
| 214 model.SetClient(&client); | |
| 215 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 203 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
| 216 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 204 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 217 const uint16_t ciphersuite = 0xc02f; | 205 const uint16_t ciphersuite = 0xc02f; |
| 218 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 206 helper.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 219 << net::SSL_CONNECTION_VERSION_SHIFT); | 207 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 220 client.SetCipherSuite(ciphersuite); | 208 helper.SetCipherSuite(ciphersuite); |
| 221 client.set_fails_malware_check(true); | 209 helper.set_fails_malware_check(true); |
| 222 SecurityStateModel::SecurityInfo security_info; | 210 SecurityInfo security_info; |
| 223 model.GetSecurityInfo(&security_info); | 211 helper.GetSecurityInfo(&security_info); |
| 224 EXPECT_TRUE(security_info.fails_malware_check); | 212 EXPECT_TRUE(security_info.fails_malware_check); |
| 225 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); | 213 EXPECT_EQ(DANGEROUS, security_info.security_level); |
| 226 } | 214 } |
| 227 | 215 |
| 228 // Tests that the malware/phishing status is set, even if other connection info | 216 // Tests that the malware/phishing status is set, even if other connection info |
| 229 // is not available. | 217 // is not available. |
| 230 TEST(SecurityStateModelTest, MalwareWithoutCOnnectionState) { | 218 TEST(SecurityStateTest, MalwareWithoutCOnnectionState) { |
| 231 TestSecurityStateModelClient client; | 219 TestSecurityStateHelper helper; |
| 232 SecurityStateModel model; | 220 helper.set_fails_malware_check(true); |
| 233 model.SetClient(&client); | 221 SecurityInfo security_info; |
| 234 client.set_fails_malware_check(true); | 222 helper.GetSecurityInfo(&security_info); |
| 235 SecurityStateModel::SecurityInfo security_info; | |
| 236 model.GetSecurityInfo(&security_info); | |
| 237 EXPECT_TRUE(security_info.fails_malware_check); | 223 EXPECT_TRUE(security_info.fails_malware_check); |
| 238 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); | 224 EXPECT_EQ(DANGEROUS, security_info.security_level); |
| 239 } | 225 } |
| 240 | 226 |
| 241 // Tests that password fields cause the security level to be downgraded | 227 // Tests that password fields cause the security level to be downgraded |
| 242 // to HTTP_SHOW_WARNING when the command-line switch is set. | 228 // to HTTP_SHOW_WARNING when the command-line switch is set. |
| 243 TEST(SecurityStateModelTest, PasswordFieldWarning) { | 229 TEST(SecurityStateTest, PasswordFieldWarning) { |
| 244 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 230 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 245 switches::kMarkHttpAs, | 231 switches::kMarkHttpAs, switches::kMarkHttpWithPasswordsOrCcWithChip); |
| 246 switches::kMarkHttpWithPasswordsOrCcWithChip); | 232 TestSecurityStateHelper helper; |
| 247 TestSecurityStateModelClient client; | 233 helper.UseHttpUrl(); |
| 248 client.UseHttpUrl(); | 234 helper.set_displayed_password_field_on_http(true); |
| 249 SecurityStateModel model; | 235 SecurityInfo security_info; |
| 250 model.SetClient(&client); | 236 helper.GetSecurityInfo(&security_info); |
| 251 client.set_displayed_password_field_on_http(true); | |
| 252 SecurityStateModel::SecurityInfo security_info; | |
| 253 model.GetSecurityInfo(&security_info); | |
| 254 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); | 237 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); |
| 255 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, | 238 EXPECT_EQ(HTTP_SHOW_WARNING, security_info.security_level); |
| 256 security_info.security_level); | |
| 257 } | 239 } |
| 258 | 240 |
| 259 // Tests that credit card fields cause the security level to be downgraded | 241 // Tests that credit card fields cause the security level to be downgraded |
| 260 // to HTTP_SHOW_WARNING when the command-line switch is set. | 242 // to HTTP_SHOW_WARNING when the command-line switch is set. |
| 261 TEST(SecurityStateModelTest, CreditCardFieldWarning) { | 243 TEST(SecurityStateTest, CreditCardFieldWarning) { |
| 262 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 244 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 263 switches::kMarkHttpAs, | 245 switches::kMarkHttpAs, switches::kMarkHttpWithPasswordsOrCcWithChip); |
| 264 switches::kMarkHttpWithPasswordsOrCcWithChip); | 246 TestSecurityStateHelper helper; |
| 265 TestSecurityStateModelClient client; | 247 helper.UseHttpUrl(); |
| 266 client.UseHttpUrl(); | 248 helper.set_displayed_credit_card_field_on_http(true); |
| 267 SecurityStateModel model; | 249 SecurityInfo security_info; |
| 268 model.SetClient(&client); | 250 helper.GetSecurityInfo(&security_info); |
| 269 client.set_displayed_credit_card_field_on_http(true); | |
| 270 SecurityStateModel::SecurityInfo security_info; | |
| 271 model.GetSecurityInfo(&security_info); | |
| 272 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); | 251 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); |
| 273 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, | 252 EXPECT_EQ(HTTP_SHOW_WARNING, security_info.security_level); |
| 274 security_info.security_level); | |
| 275 } | 253 } |
| 276 | 254 |
| 277 // Tests that neither password nor credit fields cause the security | 255 // Tests that neither password nor credit fields cause the security |
| 278 // level to be downgraded to HTTP_SHOW_WARNING when the command-line switch | 256 // level to be downgraded to HTTP_SHOW_WARNING when the command-line switch |
| 279 // is NOT set. | 257 // is NOT set. |
| 280 TEST(SecurityStateModelTest, HttpWarningNotSetWithoutSwitch) { | 258 TEST(SecurityStateTest, HttpWarningNotSetWithoutSwitch) { |
| 281 TestSecurityStateModelClient client; | 259 TestSecurityStateHelper helper; |
| 282 client.UseHttpUrl(); | 260 helper.UseHttpUrl(); |
| 283 SecurityStateModel model; | 261 helper.set_displayed_password_field_on_http(true); |
| 284 model.SetClient(&client); | 262 helper.set_displayed_credit_card_field_on_http(true); |
| 285 client.set_displayed_password_field_on_http(true); | 263 SecurityInfo security_info; |
| 286 client.set_displayed_credit_card_field_on_http(true); | 264 helper.GetSecurityInfo(&security_info); |
| 287 SecurityStateModel::SecurityInfo security_info; | |
| 288 model.GetSecurityInfo(&security_info); | |
| 289 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); | 265 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); |
| 290 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 266 EXPECT_EQ(NONE, security_info.security_level); |
| 291 } | 267 } |
| 292 | 268 |
| 293 // Tests that |displayed_private_user_data_input_on_http| is not set | 269 // Tests that |displayed_private_user_data_input_on_http| is not set |
| 294 // when the corresponding VisibleSecurityState flags are not set. | 270 // when the corresponding VisibleSecurityState flags are not set. |
| 295 TEST(SecurityStateModelTest, PrivateUserDataNotSet) { | 271 TEST(SecurityStateTest, PrivateUserDataNotSet) { |
| 296 TestSecurityStateModelClient client; | 272 TestSecurityStateHelper helper; |
| 297 client.UseHttpUrl(); | 273 helper.UseHttpUrl(); |
| 298 SecurityStateModel model; | 274 SecurityInfo security_info; |
| 299 model.SetClient(&client); | 275 helper.GetSecurityInfo(&security_info); |
| 300 SecurityStateModel::SecurityInfo security_info; | |
| 301 model.GetSecurityInfo(&security_info); | |
| 302 EXPECT_FALSE(security_info.displayed_private_user_data_input_on_http); | 276 EXPECT_FALSE(security_info.displayed_private_user_data_input_on_http); |
| 303 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 277 EXPECT_EQ(NONE, security_info.security_level); |
| 304 } | 278 } |
| 305 | 279 |
| 306 // Tests that SSL.MarkHttpAsStatus histogram is updated when security state is | 280 // Tests that SSL.MarkHttpAsStatus histogram is updated when security state is |
| 307 // computed for a page. | 281 // computed for a page. |
| 308 TEST(SecurityStateModelTest, MarkHttpAsStatusHistogram) { | 282 TEST(SecurityStateTest, MarkHttpAsStatusHistogram) { |
| 309 const char* kHistogramName = "SSL.MarkHttpAsStatus"; | 283 const char* kHistogramName = "SSL.MarkHttpAsStatus"; |
| 310 base::HistogramTester histograms; | 284 base::HistogramTester histograms; |
| 311 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 285 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 312 switches::kMarkHttpAs, switches::kMarkHttpWithPasswordsOrCcWithChip); | 286 switches::kMarkHttpAs, switches::kMarkHttpWithPasswordsOrCcWithChip); |
| 313 TestSecurityStateModelClient client; | 287 TestSecurityStateHelper helper; |
| 314 client.UseHttpUrl(); | 288 helper.UseHttpUrl(); |
| 315 SecurityStateModel model; | |
| 316 model.SetClient(&client); | |
| 317 | 289 |
| 318 // Ensure histogram recorded correctly when a non-secure password input is | 290 // Ensure histogram recorded correctly when a non-secure password input is |
| 319 // found on the page. | 291 // found on the page. |
| 320 client.set_displayed_password_field_on_http(true); | 292 helper.set_displayed_password_field_on_http(true); |
| 321 SecurityStateModel::SecurityInfo security_info; | 293 SecurityInfo security_info; |
| 322 histograms.ExpectTotalCount(kHistogramName, 0); | 294 histograms.ExpectTotalCount(kHistogramName, 0); |
| 323 model.GetSecurityInfo(&security_info); | 295 helper.GetSecurityInfo(&security_info); |
| 324 histograms.ExpectUniqueSample(kHistogramName, 2 /* HTTP_SHOW_WARNING */, 1); | 296 histograms.ExpectUniqueSample(kHistogramName, 2 /* HTTP_SHOW_WARNING */, 1); |
| 325 | 297 |
| 326 // Ensure histogram recorded correctly even without a password input. | 298 // Ensure histogram recorded correctly even without a password input. |
| 327 client.set_displayed_password_field_on_http(false); | 299 helper.set_displayed_password_field_on_http(false); |
| 328 model.GetSecurityInfo(&security_info); | 300 helper.GetSecurityInfo(&security_info); |
| 329 histograms.ExpectUniqueSample(kHistogramName, 2 /* HTTP_SHOW_WARNING */, 2); | 301 histograms.ExpectUniqueSample(kHistogramName, 2 /* HTTP_SHOW_WARNING */, 2); |
| 330 } | 302 } |
| 331 | 303 |
| 332 } // namespace | |
| 333 | |
| 334 } // namespace security_state | 304 } // namespace security_state |
| OLD | NEW |