OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/ssl_config_service_manager.h" | 5 #include "chrome/browser/net/ssl_config_service_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/prefs/testing_pref_store.h" | 10 #include "base/prefs/testing_pref_store.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/prefs/pref_registry_simple.h" |
13 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 14 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/content_settings.h" | 16 #include "chrome/common/content_settings.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_pref_service.h" | 18 #include "chrome/test/base/testing_pref_service.h" |
18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
20 #include "net/base/ssl_config_service.h" | 21 #include "net/base/ssl_config_service.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 55 } |
55 | 56 |
56 MessageLoop message_loop_; | 57 MessageLoop message_loop_; |
57 content::TestBrowserThread ui_thread_; | 58 content::TestBrowserThread ui_thread_; |
58 content::TestBrowserThread io_thread_; | 59 content::TestBrowserThread io_thread_; |
59 }; | 60 }; |
60 | 61 |
61 // Test channel id with no user prefs. | 62 // Test channel id with no user prefs. |
62 TEST_F(SSLConfigServiceManagerPrefTest, ChannelIDWithoutUserPrefs) { | 63 TEST_F(SSLConfigServiceManagerPrefTest, ChannelIDWithoutUserPrefs) { |
63 TestingPrefServiceSimple local_state; | 64 TestingPrefServiceSimple local_state; |
64 SSLConfigServiceManager::RegisterPrefs(&local_state); | 65 SSLConfigServiceManager::RegisterPrefs(local_state.registry()); |
65 local_state.SetUserPref(prefs::kEnableOriginBoundCerts, | 66 local_state.SetUserPref(prefs::kEnableOriginBoundCerts, |
66 Value::CreateBooleanValue(false)); | 67 Value::CreateBooleanValue(false)); |
67 | 68 |
68 scoped_ptr<SSLConfigServiceManager> config_manager( | 69 scoped_ptr<SSLConfigServiceManager> config_manager( |
69 SSLConfigServiceManager::CreateDefaultManager(&local_state, NULL)); | 70 SSLConfigServiceManager::CreateDefaultManager(&local_state, NULL)); |
70 ASSERT_TRUE(config_manager.get()); | 71 ASSERT_TRUE(config_manager.get()); |
71 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | 72 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); |
72 ASSERT_TRUE(config_service.get()); | 73 ASSERT_TRUE(config_service.get()); |
73 | 74 |
74 SSLConfig config; | 75 SSLConfig config; |
75 config_service->GetSSLConfig(&config); | 76 config_service->GetSSLConfig(&config); |
76 EXPECT_FALSE(config.channel_id_enabled); | 77 EXPECT_FALSE(config.channel_id_enabled); |
77 | 78 |
78 local_state.SetUserPref(prefs::kEnableOriginBoundCerts, | 79 local_state.SetUserPref(prefs::kEnableOriginBoundCerts, |
79 Value::CreateBooleanValue(true)); | 80 Value::CreateBooleanValue(true)); |
80 // Pump the message loop to notify the SSLConfigServiceManagerPref that the | 81 // Pump the message loop to notify the SSLConfigServiceManagerPref that the |
81 // preferences changed. | 82 // preferences changed. |
82 message_loop_.RunUntilIdle(); | 83 message_loop_.RunUntilIdle(); |
83 config_service->GetSSLConfig(&config); | 84 config_service->GetSSLConfig(&config); |
84 EXPECT_TRUE(config.channel_id_enabled); | 85 EXPECT_TRUE(config.channel_id_enabled); |
85 } | 86 } |
86 | 87 |
87 // Test channel id with user prefs. | 88 // Test channel id with user prefs. |
88 TEST_F(SSLConfigServiceManagerPrefTest, ChannelIDWithUserPrefs) { | 89 TEST_F(SSLConfigServiceManagerPrefTest, ChannelIDWithUserPrefs) { |
89 TestingPrefServiceSimple local_state; | 90 TestingPrefServiceSimple local_state; |
90 SSLConfigServiceManager::RegisterPrefs(&local_state); | 91 SSLConfigServiceManager::RegisterPrefs(local_state.registry()); |
91 local_state.SetUserPref(prefs::kEnableOriginBoundCerts, | 92 local_state.SetUserPref(prefs::kEnableOriginBoundCerts, |
92 Value::CreateBooleanValue(false)); | 93 Value::CreateBooleanValue(false)); |
93 | 94 |
94 TestingProfile testing_profile; | 95 TestingProfile testing_profile; |
95 TestingPrefServiceSyncable* user_prefs = | 96 TestingPrefServiceSyncable* user_prefs = |
96 testing_profile.GetTestingPrefService(); | 97 testing_profile.GetTestingPrefService(); |
97 SetCookiePref(&testing_profile, CONTENT_SETTING_BLOCK); | 98 SetCookiePref(&testing_profile, CONTENT_SETTING_BLOCK); |
98 user_prefs->SetUserPref(prefs::kBlockThirdPartyCookies, | 99 user_prefs->SetUserPref(prefs::kBlockThirdPartyCookies, |
99 Value::CreateBooleanValue(true)); | 100 Value::CreateBooleanValue(true)); |
100 | 101 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // channelid=true, cookies=allow, 3rdpartycookies=allow | 146 // channelid=true, cookies=allow, 3rdpartycookies=allow |
146 user_prefs->SetUserPref(prefs::kBlockThirdPartyCookies, | 147 user_prefs->SetUserPref(prefs::kBlockThirdPartyCookies, |
147 Value::CreateBooleanValue(false)); | 148 Value::CreateBooleanValue(false)); |
148 EXPECT_TRUE(IsChannelIdEnabled(config_service)); | 149 EXPECT_TRUE(IsChannelIdEnabled(config_service)); |
149 } | 150 } |
150 | 151 |
151 // Test that cipher suites can be disabled. "Good" refers to the fact that | 152 // Test that cipher suites can be disabled. "Good" refers to the fact that |
152 // every value is expected to be successfully parsed into a cipher suite. | 153 // every value is expected to be successfully parsed into a cipher suite. |
153 TEST_F(SSLConfigServiceManagerPrefTest, GoodDisabledCipherSuites) { | 154 TEST_F(SSLConfigServiceManagerPrefTest, GoodDisabledCipherSuites) { |
154 TestingPrefServiceSimple local_state; | 155 TestingPrefServiceSimple local_state; |
155 SSLConfigServiceManager::RegisterPrefs(&local_state); | 156 SSLConfigServiceManager::RegisterPrefs(local_state.registry()); |
156 | 157 |
157 scoped_ptr<SSLConfigServiceManager> config_manager( | 158 scoped_ptr<SSLConfigServiceManager> config_manager( |
158 SSLConfigServiceManager::CreateDefaultManager(&local_state, NULL)); | 159 SSLConfigServiceManager::CreateDefaultManager(&local_state, NULL)); |
159 ASSERT_TRUE(config_manager.get()); | 160 ASSERT_TRUE(config_manager.get()); |
160 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | 161 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); |
161 ASSERT_TRUE(config_service.get()); | 162 ASSERT_TRUE(config_service.get()); |
162 | 163 |
163 SSLConfig old_config; | 164 SSLConfig old_config; |
164 config_service->GetSSLConfig(&old_config); | 165 config_service->GetSSLConfig(&old_config); |
165 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); | 166 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); |
(...skipping 14 matching lines...) Expand all Loading... |
180 ASSERT_EQ(2u, config.disabled_cipher_suites.size()); | 181 ASSERT_EQ(2u, config.disabled_cipher_suites.size()); |
181 EXPECT_EQ(0x0004, config.disabled_cipher_suites[0]); | 182 EXPECT_EQ(0x0004, config.disabled_cipher_suites[0]); |
182 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); | 183 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); |
183 } | 184 } |
184 | 185 |
185 // Test that cipher suites can be disabled. "Bad" refers to the fact that | 186 // Test that cipher suites can be disabled. "Bad" refers to the fact that |
186 // there are one or more non-cipher suite strings in the preference. They | 187 // there are one or more non-cipher suite strings in the preference. They |
187 // should be ignored. | 188 // should be ignored. |
188 TEST_F(SSLConfigServiceManagerPrefTest, BadDisabledCipherSuites) { | 189 TEST_F(SSLConfigServiceManagerPrefTest, BadDisabledCipherSuites) { |
189 TestingPrefServiceSimple local_state; | 190 TestingPrefServiceSimple local_state; |
190 SSLConfigServiceManager::RegisterPrefs(&local_state); | 191 SSLConfigServiceManager::RegisterPrefs(local_state.registry()); |
191 | 192 |
192 scoped_ptr<SSLConfigServiceManager> config_manager( | 193 scoped_ptr<SSLConfigServiceManager> config_manager( |
193 SSLConfigServiceManager::CreateDefaultManager(&local_state, NULL)); | 194 SSLConfigServiceManager::CreateDefaultManager(&local_state, NULL)); |
194 ASSERT_TRUE(config_manager.get()); | 195 ASSERT_TRUE(config_manager.get()); |
195 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | 196 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); |
196 ASSERT_TRUE(config_service.get()); | 197 ASSERT_TRUE(config_service.get()); |
197 | 198 |
198 SSLConfig old_config; | 199 SSLConfig old_config; |
199 config_service->GetSSLConfig(&old_config); | 200 config_service->GetSSLConfig(&old_config); |
200 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); | 201 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); |
(...skipping 18 matching lines...) Expand all Loading... |
219 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); | 220 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); |
220 } | 221 } |
221 | 222 |
222 // Test that without command-line settings for minimum and maximum SSL | 223 // Test that without command-line settings for minimum and maximum SSL |
223 // versions, SSL 3.0 ~ default_version_max() are enabled. | 224 // versions, SSL 3.0 ~ default_version_max() are enabled. |
224 TEST_F(SSLConfigServiceManagerPrefTest, NoCommandLinePrefs) { | 225 TEST_F(SSLConfigServiceManagerPrefTest, NoCommandLinePrefs) { |
225 scoped_refptr<TestingPrefStore> local_state_store(new TestingPrefStore()); | 226 scoped_refptr<TestingPrefStore> local_state_store(new TestingPrefStore()); |
226 | 227 |
227 PrefServiceMockBuilder builder; | 228 PrefServiceMockBuilder builder; |
228 builder.WithUserPrefs(local_state_store.get()); | 229 builder.WithUserPrefs(local_state_store.get()); |
229 scoped_ptr<PrefServiceSimple> local_state(builder.CreateSimple()); | 230 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple; |
| 231 scoped_ptr<PrefService> local_state(builder.Create(registry)); |
230 | 232 |
231 SSLConfigServiceManager::RegisterPrefs(local_state.get()); | 233 SSLConfigServiceManager::RegisterPrefs(registry); |
232 | 234 |
233 scoped_ptr<SSLConfigServiceManager> config_manager( | 235 scoped_ptr<SSLConfigServiceManager> config_manager( |
234 SSLConfigServiceManager::CreateDefaultManager(local_state.get(), NULL)); | 236 SSLConfigServiceManager::CreateDefaultManager(local_state.get(), NULL)); |
235 ASSERT_TRUE(config_manager.get()); | 237 ASSERT_TRUE(config_manager.get()); |
236 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | 238 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); |
237 ASSERT_TRUE(config_service.get()); | 239 ASSERT_TRUE(config_service.get()); |
238 | 240 |
239 SSLConfig ssl_config; | 241 SSLConfig ssl_config; |
240 config_service->GetSSLConfig(&ssl_config); | 242 config_service->GetSSLConfig(&ssl_config); |
241 // The default value in the absence of command-line options is that | 243 // The default value in the absence of command-line options is that |
(...skipping 20 matching lines...) Expand all Loading... |
262 TEST_F(SSLConfigServiceManagerPrefTest, CommandLinePrefs) { | 264 TEST_F(SSLConfigServiceManagerPrefTest, CommandLinePrefs) { |
263 scoped_refptr<TestingPrefStore> local_state_store(new TestingPrefStore()); | 265 scoped_refptr<TestingPrefStore> local_state_store(new TestingPrefStore()); |
264 | 266 |
265 CommandLine command_line(CommandLine::NO_PROGRAM); | 267 CommandLine command_line(CommandLine::NO_PROGRAM); |
266 command_line.AppendSwitchASCII(switches::kSSLVersionMin, "tls1"); | 268 command_line.AppendSwitchASCII(switches::kSSLVersionMin, "tls1"); |
267 command_line.AppendSwitchASCII(switches::kSSLVersionMax, "ssl3"); | 269 command_line.AppendSwitchASCII(switches::kSSLVersionMax, "ssl3"); |
268 | 270 |
269 PrefServiceMockBuilder builder; | 271 PrefServiceMockBuilder builder; |
270 builder.WithUserPrefs(local_state_store.get()); | 272 builder.WithUserPrefs(local_state_store.get()); |
271 builder.WithCommandLine(&command_line); | 273 builder.WithCommandLine(&command_line); |
272 scoped_ptr<PrefServiceSimple> local_state(builder.CreateSimple()); | 274 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple; |
| 275 scoped_ptr<PrefService> local_state(builder.Create(registry)); |
273 | 276 |
274 SSLConfigServiceManager::RegisterPrefs(local_state.get()); | 277 SSLConfigServiceManager::RegisterPrefs(registry); |
275 | 278 |
276 scoped_ptr<SSLConfigServiceManager> config_manager( | 279 scoped_ptr<SSLConfigServiceManager> config_manager( |
277 SSLConfigServiceManager::CreateDefaultManager(local_state.get(), NULL)); | 280 SSLConfigServiceManager::CreateDefaultManager(local_state.get(), NULL)); |
278 ASSERT_TRUE(config_manager.get()); | 281 ASSERT_TRUE(config_manager.get()); |
279 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | 282 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); |
280 ASSERT_TRUE(config_service.get()); | 283 ASSERT_TRUE(config_service.get()); |
281 | 284 |
282 SSLConfig ssl_config; | 285 SSLConfig ssl_config; |
283 config_service->GetSSLConfig(&ssl_config); | 286 config_service->GetSSLConfig(&ssl_config); |
284 // Command-line flags should be respected. | 287 // Command-line flags should be respected. |
285 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1, ssl_config.version_min); | 288 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1, ssl_config.version_min); |
286 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_SSL3, ssl_config.version_max); | 289 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_SSL3, ssl_config.version_max); |
287 | 290 |
288 // Explicitly double-check the settings are not in the preference store. | 291 // Explicitly double-check the settings are not in the preference store. |
289 const PrefService::Preference* version_min_pref = | 292 const PrefService::Preference* version_min_pref = |
290 local_state->FindPreference(prefs::kSSLVersionMin); | 293 local_state->FindPreference(prefs::kSSLVersionMin); |
291 EXPECT_FALSE(version_min_pref->IsUserModifiable()); | 294 EXPECT_FALSE(version_min_pref->IsUserModifiable()); |
292 | 295 |
293 const PrefService::Preference* version_max_pref = | 296 const PrefService::Preference* version_max_pref = |
294 local_state->FindPreference(prefs::kSSLVersionMax); | 297 local_state->FindPreference(prefs::kSSLVersionMax); |
295 EXPECT_FALSE(version_max_pref->IsUserModifiable()); | 298 EXPECT_FALSE(version_max_pref->IsUserModifiable()); |
296 | 299 |
297 std::string version_min_str; | 300 std::string version_min_str; |
298 std::string version_max_str; | 301 std::string version_max_str; |
299 EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMin, | 302 EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMin, |
300 &version_min_str)); | 303 &version_min_str)); |
301 EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMax, | 304 EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMax, |
302 &version_max_str)); | 305 &version_max_str)); |
303 } | 306 } |
OLD | NEW |