Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/pref_proxy_config_service.h" | 5 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "chrome/browser/net/ssl_config_service_manager.h" | 10 #include "chrome/browser/net/ssl_config_service_manager.h" |
| 11 #include "chrome/browser/prefs/pref_service_mock_builder.h" | |
| 12 #include "chrome/browser/prefs/testing_pref_store.h" | |
| 13 #include "chrome/common/chrome_switches.h" | |
| 10 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/test/base/testing_pref_service.h" | 15 #include "chrome/test/base/testing_pref_service.h" |
| 12 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
| 13 #include "net/base/ssl_config_service.h" | 17 #include "net/base/ssl_config_service.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 19 |
| 16 using base::ListValue; | 20 using base::ListValue; |
| 17 using base::Value; | 21 using base::Value; |
| 18 using net::SSLConfig; | 22 using net::SSLConfig; |
| 19 using net::SSLConfigService; | 23 using net::SSLConfigService; |
| 20 | 24 |
| 21 class SSLConfigServiceManagerPrefTest : public testing::Test { | 25 class SSLConfigServiceManagerPrefTest : public testing::Test { |
| 22 public: | 26 public: |
| 23 SSLConfigServiceManagerPrefTest() {} | 27 SSLConfigServiceManagerPrefTest() |
| 24 | 28 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 25 virtual void SetUp() { | 29 io_thread_(BrowserThread::IO, &message_loop_) {} |
| 26 message_loop_.reset(new MessageLoop()); | |
| 27 ui_thread_.reset( | |
| 28 new BrowserThread(BrowserThread::UI, message_loop_.get())); | |
| 29 io_thread_.reset( | |
| 30 new BrowserThread(BrowserThread::IO, message_loop_.get())); | |
| 31 pref_service_.reset(new TestingPrefService()); | |
| 32 SSLConfigServiceManager::RegisterPrefs(pref_service_.get()); | |
|
wtc
2011/10/31 19:48:24
Good cleanup!
Why doesn't this class need the pre
Ryan Sleevi
2011/11/01 03:01:19
It's only used by two of the tests as a member (Go
| |
| 33 } | |
| 34 | |
| 35 virtual void TearDown() { | |
| 36 pref_service_.reset(); | |
| 37 io_thread_.reset(); | |
| 38 ui_thread_.reset(); | |
| 39 message_loop_.reset(); | |
| 40 } | |
| 41 | 30 |
| 42 protected: | 31 protected: |
| 43 scoped_ptr<MessageLoop> message_loop_; | 32 MessageLoop message_loop_; |
| 44 scoped_ptr<BrowserThread> ui_thread_; | 33 BrowserThread ui_thread_; |
| 45 scoped_ptr<BrowserThread> io_thread_; | 34 BrowserThread io_thread_; |
| 46 scoped_ptr<TestingPrefService> pref_service_; | |
| 47 }; | 35 }; |
| 48 | 36 |
| 49 // Test that cipher suites can be disabled. "Good" refers to the fact that | 37 // Test that cipher suites can be disabled. "Good" refers to the fact that |
| 50 // every value is expected to be successfully parsed into a cipher suite. | 38 // every value is expected to be successfully parsed into a cipher suite. |
| 51 TEST_F(SSLConfigServiceManagerPrefTest, GoodDisabledCipherSuites) { | 39 TEST_F(SSLConfigServiceManagerPrefTest, GoodDisabledCipherSuites) { |
| 40 TestingPrefService pref_service; | |
| 41 SSLConfigServiceManager::RegisterPrefs(&pref_service); | |
| 42 | |
| 52 scoped_ptr<SSLConfigServiceManager> config_manager( | 43 scoped_ptr<SSLConfigServiceManager> config_manager( |
| 53 SSLConfigServiceManager::CreateDefaultManager(pref_service_.get())); | 44 SSLConfigServiceManager::CreateDefaultManager(&pref_service)); |
| 54 ASSERT_TRUE(config_manager.get()); | 45 ASSERT_TRUE(config_manager.get()); |
| 55 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | 46 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); |
| 56 ASSERT_TRUE(config_service.get()); | 47 ASSERT_TRUE(config_service.get()); |
| 57 | 48 |
| 58 SSLConfig old_config; | 49 SSLConfig old_config; |
| 59 config_service->GetSSLConfig(&old_config); | 50 config_service->GetSSLConfig(&old_config); |
| 60 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); | 51 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); |
| 61 | 52 |
| 62 ListValue* list_value = new ListValue(); | 53 ListValue* list_value = new ListValue(); |
| 63 list_value->Append(Value::CreateStringValue("0x0004")); | 54 list_value->Append(Value::CreateStringValue("0x0004")); |
| 64 list_value->Append(Value::CreateStringValue("0x0005")); | 55 list_value->Append(Value::CreateStringValue("0x0005")); |
| 65 pref_service_->SetUserPref(prefs::kCipherSuiteBlacklist, list_value); | 56 pref_service.SetUserPref(prefs::kCipherSuiteBlacklist, list_value); |
| 66 | 57 |
| 67 // Pump the message loop to notify the SSLConfigServiceManagerPref that the | 58 // Pump the message loop to notify the SSLConfigServiceManagerPref that the |
| 68 // preferences changed. | 59 // preferences changed. |
| 69 message_loop_->RunAllPending(); | 60 message_loop_.RunAllPending(); |
| 70 | 61 |
| 71 SSLConfig config; | 62 SSLConfig config; |
| 72 config_service->GetSSLConfig(&config); | 63 config_service->GetSSLConfig(&config); |
| 73 | 64 |
| 74 EXPECT_NE(old_config.disabled_cipher_suites, config.disabled_cipher_suites); | 65 EXPECT_NE(old_config.disabled_cipher_suites, config.disabled_cipher_suites); |
| 75 ASSERT_EQ(2u, config.disabled_cipher_suites.size()); | 66 ASSERT_EQ(2u, config.disabled_cipher_suites.size()); |
| 76 EXPECT_EQ(0x0004, config.disabled_cipher_suites[0]); | 67 EXPECT_EQ(0x0004, config.disabled_cipher_suites[0]); |
| 77 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); | 68 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); |
| 78 } | 69 } |
| 79 | 70 |
| 80 // Test that cipher suites can be disabled. "Bad" refers to the fact that | 71 // Test that cipher suites can be disabled. "Bad" refers to the fact that |
| 81 // there are one or more non-cipher suite strings in the preference. They | 72 // there are one or more non-cipher suite strings in the preference. They |
| 82 // should be ignored. | 73 // should be ignored. |
| 83 TEST_F(SSLConfigServiceManagerPrefTest, BadDisabledCipherSuites) { | 74 TEST_F(SSLConfigServiceManagerPrefTest, BadDisabledCipherSuites) { |
| 75 TestingPrefService pref_service; | |
| 76 SSLConfigServiceManager::RegisterPrefs(&pref_service); | |
| 77 | |
| 84 scoped_ptr<SSLConfigServiceManager> config_manager( | 78 scoped_ptr<SSLConfigServiceManager> config_manager( |
| 85 SSLConfigServiceManager::CreateDefaultManager(pref_service_.get())); | 79 SSLConfigServiceManager::CreateDefaultManager(&pref_service)); |
| 86 ASSERT_TRUE(config_manager.get()); | 80 ASSERT_TRUE(config_manager.get()); |
| 87 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | 81 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); |
| 88 ASSERT_TRUE(config_service.get()); | 82 ASSERT_TRUE(config_service.get()); |
| 89 | 83 |
| 90 SSLConfig old_config; | 84 SSLConfig old_config; |
| 91 config_service->GetSSLConfig(&old_config); | 85 config_service->GetSSLConfig(&old_config); |
| 92 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); | 86 EXPECT_TRUE(old_config.disabled_cipher_suites.empty()); |
| 93 | 87 |
| 94 ListValue* list_value = new ListValue(); | 88 ListValue* list_value = new ListValue(); |
| 95 list_value->Append(Value::CreateStringValue("0x0004")); | 89 list_value->Append(Value::CreateStringValue("0x0004")); |
| 96 list_value->Append(Value::CreateStringValue("TLS_NOT_WITH_A_CIPHER_SUITE")); | 90 list_value->Append(Value::CreateStringValue("TLS_NOT_WITH_A_CIPHER_SUITE")); |
| 97 list_value->Append(Value::CreateStringValue("0x0005")); | 91 list_value->Append(Value::CreateStringValue("0x0005")); |
| 98 list_value->Append(Value::CreateStringValue("0xBEEFY")); | 92 list_value->Append(Value::CreateStringValue("0xBEEFY")); |
| 99 pref_service_->SetUserPref(prefs::kCipherSuiteBlacklist, list_value); | 93 pref_service.SetUserPref(prefs::kCipherSuiteBlacklist, list_value); |
| 100 | 94 |
| 101 // Pump the message loop to notify the SSLConfigServiceManagerPref that the | 95 // Pump the message loop to notify the SSLConfigServiceManagerPref that the |
| 102 // preferences changed. | 96 // preferences changed. |
| 103 message_loop_->RunAllPending(); | 97 message_loop_.RunAllPending(); |
| 104 | 98 |
| 105 SSLConfig config; | 99 SSLConfig config; |
| 106 config_service->GetSSLConfig(&config); | 100 config_service->GetSSLConfig(&config); |
| 107 | 101 |
| 108 EXPECT_NE(old_config.disabled_cipher_suites, config.disabled_cipher_suites); | 102 EXPECT_NE(old_config.disabled_cipher_suites, config.disabled_cipher_suites); |
| 109 ASSERT_EQ(2u, config.disabled_cipher_suites.size()); | 103 ASSERT_EQ(2u, config.disabled_cipher_suites.size()); |
| 110 EXPECT_EQ(0x0004, config.disabled_cipher_suites[0]); | 104 EXPECT_EQ(0x0004, config.disabled_cipher_suites[0]); |
| 111 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); | 105 EXPECT_EQ(0x0005, config.disabled_cipher_suites[1]); |
| 112 } | 106 } |
| 107 | |
| 108 // Test that existing user settings for TLS1.0/SSL3.0 are both ignored and | |
| 109 // cleared from user preferences. | |
| 110 TEST_F(SSLConfigServiceManagerPrefTest, IgnoreLegacySSLSettings) { | |
| 111 TestingPrefStore* user_prefs = new TestingPrefStore; | |
|
wtc
2011/10/31 19:48:24
Is user_prefs heap-allocated because the builder.W
Ryan Sleevi
2011/11/01 03:01:19
Right. |user_prefs| is RefCounted, and WithUserPre
| |
| 112 | |
| 113 // SSL3.0 and TLS1.0 used to be user-definable prefs. They are now used as | |
| 114 // command-line options. Ensure any existing user prefs are ignored in | |
| 115 // favour of the command-line flags. | |
| 116 user_prefs->SetBoolean(prefs::kSSL3Enabled, false); | |
| 117 user_prefs->SetBoolean(prefs::kTLS1Enabled, false); | |
| 118 | |
| 119 // Ensure the preferences exist initially. | |
| 120 bool is_ssl3_enabled = false; | |
| 121 EXPECT_TRUE(user_prefs->GetBoolean(prefs::kSSL3Enabled, &is_ssl3_enabled)); | |
| 122 EXPECT_FALSE(is_ssl3_enabled); | |
| 123 | |
| 124 bool is_tls1_enabled = false; | |
|
wtc
2011/10/31 19:48:24
Nit: perhaps initialize is_ssl3_enabled and is_tls
Ryan Sleevi
2011/11/01 03:01:19
Doh, I even had that originally. Done.
| |
| 125 EXPECT_TRUE(user_prefs->GetBoolean(prefs::kTLS1Enabled, &is_tls1_enabled)); | |
| 126 EXPECT_FALSE(is_tls1_enabled); | |
| 127 | |
| 128 PrefServiceMockBuilder builder; | |
| 129 builder.WithUserPrefs(user_prefs); | |
| 130 scoped_ptr<PrefService> pref_service(builder.Create()); | |
| 131 | |
| 132 SSLConfigServiceManager::RegisterPrefs(pref_service.get()); | |
| 133 | |
| 134 scoped_ptr<SSLConfigServiceManager> config_manager( | |
| 135 SSLConfigServiceManager::CreateDefaultManager(pref_service.get())); | |
| 136 ASSERT_TRUE(config_manager.get()); | |
| 137 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | |
| 138 ASSERT_TRUE(config_service.get()); | |
| 139 | |
| 140 SSLConfig ssl_config; | |
| 141 config_service->GetSSLConfig(&ssl_config); | |
| 142 // The default value in the absence of command-line options is that both | |
| 143 // protocols are enabled. | |
| 144 EXPECT_TRUE(ssl_config.ssl3_enabled); | |
| 145 EXPECT_TRUE(ssl_config.tls1_enabled); | |
| 146 | |
| 147 // The existing user settings should be removed from the pref_service. | |
| 148 EXPECT_FALSE(pref_service->HasPrefPath(prefs::kSSL3Enabled)); | |
| 149 EXPECT_FALSE(pref_service->HasPrefPath(prefs::kTLS1Enabled)); | |
| 150 | |
| 151 // Explicitly double-check the settings are not in the user preference | |
| 152 // store. | |
| 153 EXPECT_FALSE(user_prefs->GetBoolean(prefs::kSSL3Enabled, &is_ssl3_enabled)); | |
| 154 EXPECT_FALSE(user_prefs->GetBoolean(prefs::kTLS1Enabled, &is_tls1_enabled)); | |
| 155 } | |
| 156 | |
| 157 // Test that command-line settings for TLS1.0/SSL3.0 are respected, that they | |
| 158 // disregard any existing user preferences, and that they do not persist to | |
| 159 // the user preferences files. | |
| 160 TEST_F(SSLConfigServiceManagerPrefTest, CommandLineOverridesUserPrefs) { | |
| 161 TestingPrefStore* user_prefs = new TestingPrefStore; | |
| 162 | |
| 163 // Explicitly enable SSL3.0/TLS1.0 in the user preferences, to mirror the | |
| 164 // more common legacy file. | |
| 165 user_prefs->SetBoolean(prefs::kSSL3Enabled, true); | |
| 166 user_prefs->SetBoolean(prefs::kTLS1Enabled, true); | |
| 167 | |
| 168 // Ensure the preferences exist initially. | |
| 169 bool is_ssl3_enabled = false; | |
| 170 EXPECT_TRUE(user_prefs->GetBoolean(prefs::kSSL3Enabled, &is_ssl3_enabled)); | |
| 171 EXPECT_TRUE(is_ssl3_enabled); | |
| 172 | |
| 173 bool is_tls1_enabled = false; | |
| 174 EXPECT_TRUE(user_prefs->GetBoolean(prefs::kTLS1Enabled, &is_tls1_enabled)); | |
| 175 EXPECT_TRUE(is_tls1_enabled); | |
| 176 | |
| 177 CommandLine command_line(CommandLine::NO_PROGRAM); | |
| 178 command_line.AppendSwitch(switches::kDisableSSL3); | |
| 179 command_line.AppendSwitch(switches::kDisableTLS1); | |
| 180 | |
| 181 PrefServiceMockBuilder builder; | |
| 182 builder.WithUserPrefs(user_prefs); | |
| 183 builder.WithCommandLine(&command_line); | |
| 184 scoped_ptr<PrefService> pref_service(builder.Create()); | |
| 185 | |
| 186 SSLConfigServiceManager::RegisterPrefs(pref_service.get()); | |
| 187 | |
| 188 scoped_ptr<SSLConfigServiceManager> config_manager( | |
| 189 SSLConfigServiceManager::CreateDefaultManager(pref_service.get())); | |
| 190 ASSERT_TRUE(config_manager.get()); | |
| 191 scoped_refptr<SSLConfigService> config_service(config_manager->Get()); | |
| 192 ASSERT_TRUE(config_service.get()); | |
| 193 | |
| 194 SSLConfig ssl_config; | |
| 195 config_service->GetSSLConfig(&ssl_config); | |
| 196 // Command-line flags to disable should override the user preferences to | |
| 197 // enable. | |
| 198 EXPECT_FALSE(ssl_config.ssl3_enabled); | |
| 199 EXPECT_FALSE(ssl_config.tls1_enabled); | |
| 200 | |
| 201 // Explicitly double-check the settings are not in the user preference | |
| 202 // store. | |
| 203 const PrefService::Preference* ssl3_enabled_pref = | |
| 204 pref_service->FindPreference(prefs::kSSL3Enabled); | |
| 205 EXPECT_FALSE(ssl3_enabled_pref->IsUserModifiable()); | |
| 206 | |
| 207 const PrefService::Preference* tls1_enabled_pref = | |
| 208 pref_service->FindPreference(prefs::kTLS1Enabled); | |
| 209 EXPECT_FALSE(tls1_enabled_pref->IsUserModifiable()); | |
| 210 | |
| 211 EXPECT_FALSE(user_prefs->GetBoolean(prefs::kSSL3Enabled, &is_ssl3_enabled)); | |
| 212 EXPECT_FALSE(user_prefs->GetBoolean(prefs::kTLS1Enabled, &is_tls1_enabled)); | |
| 213 } | |
| OLD | NEW |