| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" | 12 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" |
| 13 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" | 13 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" |
| 14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "chromeos/network/fake_network_device_handler.h" | 18 #include "chromeos/network/fake_network_device_handler.h" |
| 19 #include "chromeos/network/mock_managed_network_configuration_handler.h" | 19 #include "chromeos/network/mock_managed_network_configuration_handler.h" |
| 20 #include "chromeos/network/onc/mock_certificate_importer.h" | 20 #include "chromeos/network/onc/onc_certificate_importer.h" |
| 21 #include "chromeos/network/onc/onc_test_utils.h" | 21 #include "chromeos/network/onc/onc_test_utils.h" |
| 22 #include "chromeos/network/onc/onc_utils.h" | 22 #include "chromeos/network/onc/onc_utils.h" |
| 23 #include "components/onc/onc_constants.h" | 23 #include "components/onc/onc_constants.h" |
| 24 #include "components/policy/core/common/external_data_fetcher.h" | 24 #include "components/policy/core/common/external_data_fetcher.h" |
| 25 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 25 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 26 #include "components/policy/core/common/policy_map.h" | 26 #include "components/policy/core/common/policy_map.h" |
| 27 #include "components/policy/core/common/policy_service_impl.h" | 27 #include "components/policy/core/common/policy_service_impl.h" |
| 28 #include "components/user_manager/user.h" | 28 #include "components/user_manager/user.h" |
| 29 #include "components/user_manager/user_type.h" | 29 #include "components/user_manager/user_type.h" |
| 30 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 class FakeWebTrustedCertsObserver | 71 class FakeWebTrustedCertsObserver |
| 72 : public UserNetworkConfigurationUpdater::WebTrustedCertsObserver { | 72 : public UserNetworkConfigurationUpdater::WebTrustedCertsObserver { |
| 73 public: | 73 public: |
| 74 virtual void OnTrustAnchorsChanged( | 74 virtual void OnTrustAnchorsChanged( |
| 75 const net::CertificateList& trust_anchors) OVERRIDE { | 75 const net::CertificateList& trust_anchors) OVERRIDE { |
| 76 trust_anchors_ = trust_anchors; | 76 trust_anchors_ = trust_anchors; |
| 77 } | 77 } |
| 78 net::CertificateList trust_anchors_; | 78 net::CertificateList trust_anchors_; |
| 79 |
| 80 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(FakeWebTrustedCertsObserver); |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 class FakeNetworkDeviceHandler : public chromeos::FakeNetworkDeviceHandler { | 84 class FakeNetworkDeviceHandler : public chromeos::FakeNetworkDeviceHandler { |
| 82 public: | 85 public: |
| 83 FakeNetworkDeviceHandler() : allow_roaming_(false) {} | 86 FakeNetworkDeviceHandler() : allow_roaming_(false) {} |
| 84 | 87 |
| 85 virtual void SetCellularAllowRoaming(bool allow_roaming) OVERRIDE { | 88 virtual void SetCellularAllowRoaming(bool allow_roaming) OVERRIDE { |
| 86 allow_roaming_ = allow_roaming; | 89 allow_roaming_ = allow_roaming; |
| 87 } | 90 } |
| 88 | 91 |
| 89 bool allow_roaming_; | 92 bool allow_roaming_; |
| 93 |
| 94 private: |
| 95 DISALLOW_COPY_AND_ASSIGN(FakeNetworkDeviceHandler); |
| 96 }; |
| 97 |
| 98 class FakeCertificateImporter : public chromeos::onc::CertificateImporter { |
| 99 public: |
| 100 FakeCertificateImporter() |
| 101 : expected_onc_source_(::onc::ONC_SOURCE_UNKNOWN), call_count_(0) {} |
| 102 virtual ~FakeCertificateImporter() {} |
| 103 |
| 104 void SetTrustedCertificatesResult( |
| 105 net::CertificateList onc_trusted_certificates) { |
| 106 onc_trusted_certificates_ = onc_trusted_certificates; |
| 107 } |
| 108 |
| 109 void SetExpectedONCCertificates(const base::ListValue& certificates) { |
| 110 expected_onc_certificates_.reset(certificates.DeepCopy()); |
| 111 } |
| 112 |
| 113 void SetExpectedONCSource(::onc::ONCSource source) { |
| 114 expected_onc_source_ = source; |
| 115 } |
| 116 |
| 117 unsigned int GetAndResetImportCount() { |
| 118 unsigned int count = call_count_; |
| 119 call_count_ = 0; |
| 120 return count; |
| 121 } |
| 122 |
| 123 virtual void ImportCertificates(const base::ListValue& certificates, |
| 124 ::onc::ONCSource source, |
| 125 const DoneCallback& done_callback) OVERRIDE { |
| 126 if (expected_onc_source_ != ::onc::ONC_SOURCE_UNKNOWN) |
| 127 EXPECT_EQ(expected_onc_source_, source); |
| 128 if (expected_onc_certificates_) { |
| 129 EXPECT_TRUE(chromeos::onc::test_utils::Equals( |
| 130 expected_onc_certificates_.get(), &certificates)); |
| 131 } |
| 132 ++call_count_; |
| 133 done_callback.Run(true, onc_trusted_certificates_); |
| 134 } |
| 135 |
| 136 private: |
| 137 ::onc::ONCSource expected_onc_source_; |
| 138 scoped_ptr<base::ListValue> expected_onc_certificates_; |
| 139 net::CertificateList onc_trusted_certificates_; |
| 140 unsigned int call_count_; |
| 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(FakeCertificateImporter); |
| 90 }; | 143 }; |
| 91 | 144 |
| 92 const char kFakeONC[] = | 145 const char kFakeONC[] = |
| 93 "{ \"NetworkConfigurations\": [" | 146 "{ \"NetworkConfigurations\": [" |
| 94 " { \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5040}\"," | 147 " { \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5040}\"," |
| 95 " \"Type\": \"WiFi\"," | 148 " \"Type\": \"WiFi\"," |
| 96 " \"Name\": \"My WiFi Network\"," | 149 " \"Name\": \"My WiFi Network\"," |
| 97 " \"WiFi\": {" | 150 " \"WiFi\": {" |
| 98 " \"SSID\": \"ssid-none\"," | 151 " \"SSID\": \"ssid-none\"," |
| 99 " \"Security\": \"None\" }" | 152 " \"Security\": \"None\" }" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 ACTION_P(SetCertificateList, list) { | 191 ACTION_P(SetCertificateList, list) { |
| 139 if (arg2) | 192 if (arg2) |
| 140 *arg2 = list; | 193 *arg2 = list; |
| 141 return true; | 194 return true; |
| 142 } | 195 } |
| 143 | 196 |
| 144 } // namespace | 197 } // namespace |
| 145 | 198 |
| 146 class NetworkConfigurationUpdaterTest : public testing::Test { | 199 class NetworkConfigurationUpdaterTest : public testing::Test { |
| 147 protected: | 200 protected: |
| 148 NetworkConfigurationUpdaterTest() { | 201 NetworkConfigurationUpdaterTest() : certificate_importer_(NULL) {} |
| 149 } | |
| 150 | 202 |
| 151 virtual void SetUp() OVERRIDE { | 203 virtual void SetUp() OVERRIDE { |
| 152 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 204 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 153 .WillRepeatedly(Return(false)); | 205 .WillRepeatedly(Return(false)); |
| 154 provider_.Init(); | 206 provider_.Init(); |
| 155 PolicyServiceImpl::Providers providers; | 207 PolicyServiceImpl::Providers providers; |
| 156 providers.push_back(&provider_); | 208 providers.push_back(&provider_); |
| 157 policy_service_.reset(new PolicyServiceImpl(providers)); | 209 policy_service_.reset(new PolicyServiceImpl(providers)); |
| 158 | 210 |
| 159 scoped_ptr<base::DictionaryValue> fake_toplevel_onc = | 211 scoped_ptr<base::DictionaryValue> fake_toplevel_onc = |
| 160 chromeos::onc::ReadDictionaryFromJson(kFakeONC); | 212 chromeos::onc::ReadDictionaryFromJson(kFakeONC); |
| 161 | 213 |
| 162 base::ListValue* network_configs = NULL; | 214 base::ListValue* network_configs = NULL; |
| 163 fake_toplevel_onc->GetListWithoutPathExpansion( | 215 fake_toplevel_onc->GetListWithoutPathExpansion( |
| 164 onc::toplevel_config::kNetworkConfigurations, &network_configs); | 216 onc::toplevel_config::kNetworkConfigurations, &network_configs); |
| 165 AppendAll(*network_configs, &fake_network_configs_); | 217 AppendAll(*network_configs, &fake_network_configs_); |
| 166 | 218 |
| 167 base::DictionaryValue* global_config = NULL; | 219 base::DictionaryValue* global_config = NULL; |
| 168 fake_toplevel_onc->GetDictionaryWithoutPathExpansion( | 220 fake_toplevel_onc->GetDictionaryWithoutPathExpansion( |
| 169 onc::toplevel_config::kGlobalNetworkConfiguration, &global_config); | 221 onc::toplevel_config::kGlobalNetworkConfiguration, &global_config); |
| 170 fake_global_network_config_.MergeDictionary(global_config); | 222 fake_global_network_config_.MergeDictionary(global_config); |
| 171 | 223 |
| 172 base::ListValue* certs = NULL; | 224 base::ListValue* certs = NULL; |
| 173 fake_toplevel_onc->GetListWithoutPathExpansion( | 225 fake_toplevel_onc->GetListWithoutPathExpansion( |
| 174 onc::toplevel_config::kCertificates, &certs); | 226 onc::toplevel_config::kCertificates, &certs); |
| 175 AppendAll(*certs, &fake_certificates_); | 227 AppendAll(*certs, &fake_certificates_); |
| 176 | 228 |
| 177 certificate_importer_ = | 229 certificate_importer_ = new FakeCertificateImporter; |
| 178 new StrictMock<chromeos::onc::MockCertificateImporter>(); | |
| 179 certificate_importer_owned_.reset(certificate_importer_); | 230 certificate_importer_owned_.reset(certificate_importer_); |
| 180 } | 231 } |
| 181 | 232 |
| 182 virtual void TearDown() OVERRIDE { | 233 virtual void TearDown() OVERRIDE { |
| 183 network_configuration_updater_.reset(); | 234 network_configuration_updater_.reset(); |
| 184 provider_.Shutdown(); | 235 provider_.Shutdown(); |
| 185 base::RunLoop().RunUntilIdle(); | 236 base::RunLoop().RunUntilIdle(); |
| 186 } | 237 } |
| 187 | 238 |
| 188 void MarkPolicyProviderInitialized() { | 239 void MarkPolicyProviderInitialized() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 FakeNetworkDeviceHandler network_device_handler_; | 287 FakeNetworkDeviceHandler network_device_handler_; |
| 237 | 288 |
| 238 // Not used directly. Required for CrosSettings. | 289 // Not used directly. Required for CrosSettings. |
| 239 chromeos::ScopedTestDeviceSettingsService scoped_device_settings_service_; | 290 chromeos::ScopedTestDeviceSettingsService scoped_device_settings_service_; |
| 240 chromeos::ScopedTestCrosSettings scoped_cros_settings_; | 291 chromeos::ScopedTestCrosSettings scoped_cros_settings_; |
| 241 | 292 |
| 242 // Ownership of certificate_importer_owned_ is passed to the | 293 // Ownership of certificate_importer_owned_ is passed to the |
| 243 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| | 294 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| |
| 244 // continues to point to that instance but |certificate_importer_owned_| is | 295 // continues to point to that instance but |certificate_importer_owned_| is |
| 245 // released. | 296 // released. |
| 246 StrictMock<chromeos::onc::MockCertificateImporter>* certificate_importer_; | 297 FakeCertificateImporter* certificate_importer_; |
| 247 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; | 298 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; |
| 248 | 299 |
| 249 StrictMock<MockConfigurationPolicyProvider> provider_; | 300 StrictMock<MockConfigurationPolicyProvider> provider_; |
| 250 scoped_ptr<PolicyServiceImpl> policy_service_; | 301 scoped_ptr<PolicyServiceImpl> policy_service_; |
| 251 FakeUser fake_user_; | 302 FakeUser fake_user_; |
| 252 | 303 |
| 253 TestingProfile profile_; | 304 TestingProfile profile_; |
| 254 | 305 |
| 255 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; | 306 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; |
| 256 content::TestBrowserThreadBundle thread_bundle_; | 307 content::TestBrowserThreadBundle thread_bundle_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 POLICY_SCOPE_USER, | 360 POLICY_SCOPE_USER, |
| 310 new base::StringValue(onc_policy), | 361 new base::StringValue(onc_policy), |
| 311 NULL); | 362 NULL); |
| 312 UpdateProviderPolicy(policy); | 363 UpdateProviderPolicy(policy); |
| 313 | 364 |
| 314 EXPECT_CALL(network_config_handler_, | 365 EXPECT_CALL(network_config_handler_, |
| 315 SetPolicy(onc::ONC_SOURCE_USER_POLICY, | 366 SetPolicy(onc::ONC_SOURCE_USER_POLICY, |
| 316 _, | 367 _, |
| 317 IsEqualTo(network_configs_repaired), | 368 IsEqualTo(network_configs_repaired), |
| 318 IsEqualTo(global_config_repaired))); | 369 IsEqualTo(global_config_repaired))); |
| 319 EXPECT_CALL(*certificate_importer_, | 370 certificate_importer_->SetExpectedONCSource(onc::ONC_SOURCE_USER_POLICY); |
| 320 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)); | |
| 321 | 371 |
| 322 CreateNetworkConfigurationUpdaterForUserPolicy( | 372 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 323 false /* do not allow trusted certs from policy */, | 373 false /* do not allow trusted certs from policy */, |
| 324 true /* set certificate importer */); | 374 true /* set certificate importer */); |
| 325 MarkPolicyProviderInitialized(); | 375 MarkPolicyProviderInitialized(); |
| 376 EXPECT_EQ(1u, certificate_importer_->GetAndResetImportCount()); |
| 326 } | 377 } |
| 327 | 378 |
| 328 TEST_F(NetworkConfigurationUpdaterTest, | 379 TEST_F(NetworkConfigurationUpdaterTest, |
| 329 DoNotAllowTrustedCertificatesFromPolicy) { | 380 DoNotAllowTrustedCertificatesFromPolicy) { |
| 330 net::CertificateList cert_list; | 381 net::CertificateList cert_list; |
| 331 cert_list = | 382 cert_list = |
| 332 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), | 383 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), |
| 333 "ok_cert.pem", | 384 "ok_cert.pem", |
| 334 net::X509Certificate::FORMAT_AUTO); | 385 net::X509Certificate::FORMAT_AUTO); |
| 335 ASSERT_EQ(1u, cert_list.size()); | 386 ASSERT_EQ(1u, cert_list.size()); |
| 336 | 387 |
| 337 EXPECT_CALL(network_config_handler_, | 388 EXPECT_CALL(network_config_handler_, |
| 338 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _, _)); | 389 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _, _)); |
| 339 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _)) | 390 certificate_importer_->SetTrustedCertificatesResult(cert_list); |
| 340 .WillRepeatedly(SetCertificateList(cert_list)); | |
| 341 | 391 |
| 342 UserNetworkConfigurationUpdater* updater = | 392 UserNetworkConfigurationUpdater* updater = |
| 343 CreateNetworkConfigurationUpdaterForUserPolicy( | 393 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 344 false /* do not allow trusted certs from policy */, | 394 false /* do not allow trusted certs from policy */, |
| 345 true /* set certificate importer */); | 395 true /* set certificate importer */); |
| 346 MarkPolicyProviderInitialized(); | 396 MarkPolicyProviderInitialized(); |
| 347 | 397 |
| 348 // Certificates with the "Web" trust flag set should not be forwarded to | 398 // Certificates with the "Web" trust flag set should not be forwarded to |
| 349 // observers. | 399 // observers. |
| 350 FakeWebTrustedCertsObserver observer; | 400 FakeWebTrustedCertsObserver observer; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 366 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)) | 416 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)) |
| 367 .Times(AnyNumber()); | 417 .Times(AnyNumber()); |
| 368 | 418 |
| 369 net::CertificateList cert_list; | 419 net::CertificateList cert_list; |
| 370 cert_list = | 420 cert_list = |
| 371 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), | 421 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), |
| 372 "ok_cert.pem", | 422 "ok_cert.pem", |
| 373 net::X509Certificate::FORMAT_AUTO); | 423 net::X509Certificate::FORMAT_AUTO); |
| 374 ASSERT_EQ(1u, cert_list.size()); | 424 ASSERT_EQ(1u, cert_list.size()); |
| 375 | 425 |
| 376 EXPECT_CALL(*certificate_importer_, | 426 certificate_importer_->SetExpectedONCSource(onc::ONC_SOURCE_USER_POLICY); |
| 377 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)) | 427 certificate_importer_->SetTrustedCertificatesResult(cert_list); |
| 378 .WillRepeatedly(SetCertificateList(cert_list)); | |
| 379 | 428 |
| 380 UserNetworkConfigurationUpdater* updater = | 429 UserNetworkConfigurationUpdater* updater = |
| 381 CreateNetworkConfigurationUpdaterForUserPolicy( | 430 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 382 true /* allow trusted certs from policy */, | 431 true /* allow trusted certs from policy */, |
| 383 true /* set certificate importer */); | 432 true /* set certificate importer */); |
| 384 MarkPolicyProviderInitialized(); | 433 MarkPolicyProviderInitialized(); |
| 385 | 434 |
| 386 base::RunLoop().RunUntilIdle(); | 435 base::RunLoop().RunUntilIdle(); |
| 387 | 436 |
| 388 // Certificates with the "Web" trust flag set will be returned. | 437 // Certificates with the "Web" trust flag set will be returned. |
| 389 net::CertificateList trust_anchors; | 438 net::CertificateList trust_anchors; |
| 390 updater->GetWebTrustedCertificates(&trust_anchors); | 439 updater->GetWebTrustedCertificates(&trust_anchors); |
| 391 EXPECT_EQ(1u, trust_anchors.size()); | 440 EXPECT_EQ(1u, trust_anchors.size()); |
| 392 } | 441 } |
| 393 | 442 |
| 394 TEST_F(NetworkConfigurationUpdaterTest, | 443 TEST_F(NetworkConfigurationUpdaterTest, |
| 395 AllowTrustedCertificatesFromPolicyOnUpdate) { | 444 AllowTrustedCertificatesFromPolicyOnUpdate) { |
| 396 // Ignore network configuration changes. | 445 // Ignore network configuration changes. |
| 397 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)) | 446 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)) |
| 398 .Times(AnyNumber()); | 447 .Times(AnyNumber()); |
| 399 | 448 |
| 400 // Start with an empty certificate list. | 449 // Start with an empty certificate list. |
| 401 EXPECT_CALL(*certificate_importer_, | |
| 402 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)) | |
| 403 .WillRepeatedly(SetCertificateList(net::CertificateList())); | |
| 404 | |
| 405 UserNetworkConfigurationUpdater* updater = | 450 UserNetworkConfigurationUpdater* updater = |
| 406 CreateNetworkConfigurationUpdaterForUserPolicy( | 451 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 407 true /* allow trusted certs from policy */, | 452 true /* allow trusted certs from policy */, |
| 408 true /* set certificate importer */); | 453 true /* set certificate importer */); |
| 409 MarkPolicyProviderInitialized(); | 454 MarkPolicyProviderInitialized(); |
| 410 | 455 |
| 411 FakeWebTrustedCertsObserver observer; | 456 FakeWebTrustedCertsObserver observer; |
| 412 updater->AddTrustedCertsObserver(&observer); | 457 updater->AddTrustedCertsObserver(&observer); |
| 413 | 458 |
| 414 base::RunLoop().RunUntilIdle(); | 459 base::RunLoop().RunUntilIdle(); |
| 415 | 460 |
| 416 // Verify that the returned certificate list is empty. | 461 // Verify that the returned certificate list is empty. |
| 417 Mock::VerifyAndClearExpectations(certificate_importer_); | |
| 418 { | 462 { |
| 419 net::CertificateList trust_anchors; | 463 net::CertificateList trust_anchors; |
| 420 updater->GetWebTrustedCertificates(&trust_anchors); | 464 updater->GetWebTrustedCertificates(&trust_anchors); |
| 421 EXPECT_TRUE(trust_anchors.empty()); | 465 EXPECT_TRUE(trust_anchors.empty()); |
| 422 } | 466 } |
| 423 EXPECT_TRUE(observer.trust_anchors_.empty()); | 467 EXPECT_TRUE(observer.trust_anchors_.empty()); |
| 424 | 468 |
| 425 // Now use a non-empty certificate list to test the observer notification. | 469 // Now use a non-empty certificate list to test the observer notification. |
| 426 net::CertificateList cert_list; | 470 net::CertificateList cert_list; |
| 427 cert_list = | 471 cert_list = |
| 428 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), | 472 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), |
| 429 "ok_cert.pem", | 473 "ok_cert.pem", |
| 430 net::X509Certificate::FORMAT_AUTO); | 474 net::X509Certificate::FORMAT_AUTO); |
| 431 ASSERT_EQ(1u, cert_list.size()); | 475 ASSERT_EQ(1u, cert_list.size()); |
| 432 | 476 certificate_importer_->SetTrustedCertificatesResult(cert_list); |
| 433 EXPECT_CALL(*certificate_importer_, | |
| 434 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)) | |
| 435 .WillOnce(SetCertificateList(cert_list)); | |
| 436 | 477 |
| 437 // Change to any non-empty policy, so that updates are triggered. The actual | 478 // Change to any non-empty policy, so that updates are triggered. The actual |
| 438 // content of the policy is irrelevant. | 479 // content of the policy is irrelevant. |
| 439 PolicyMap policy; | 480 PolicyMap policy; |
| 440 policy.Set(key::kOpenNetworkConfiguration, | 481 policy.Set(key::kOpenNetworkConfiguration, |
| 441 POLICY_LEVEL_MANDATORY, | 482 POLICY_LEVEL_MANDATORY, |
| 442 POLICY_SCOPE_USER, | 483 POLICY_SCOPE_USER, |
| 443 new base::StringValue(kFakeONC), | 484 new base::StringValue(kFakeONC), |
| 444 NULL); | 485 NULL); |
| 445 UpdateProviderPolicy(policy); | 486 UpdateProviderPolicy(policy); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 462 PolicyMap policy; | 503 PolicyMap policy; |
| 463 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, | 504 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, |
| 464 POLICY_SCOPE_USER, new base::StringValue(kFakeONC), NULL); | 505 POLICY_SCOPE_USER, new base::StringValue(kFakeONC), NULL); |
| 465 UpdateProviderPolicy(policy); | 506 UpdateProviderPolicy(policy); |
| 466 | 507 |
| 467 EXPECT_CALL(network_config_handler_, | 508 EXPECT_CALL(network_config_handler_, |
| 468 SetPolicy(onc::ONC_SOURCE_USER_POLICY, | 509 SetPolicy(onc::ONC_SOURCE_USER_POLICY, |
| 469 kFakeUsernameHash, | 510 kFakeUsernameHash, |
| 470 IsEqualTo(&fake_network_configs_), | 511 IsEqualTo(&fake_network_configs_), |
| 471 IsEqualTo(&fake_global_network_config_))); | 512 IsEqualTo(&fake_global_network_config_))); |
| 472 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _ , _)).Times(0); | |
| 473 | 513 |
| 474 UserNetworkConfigurationUpdater* updater = | 514 UserNetworkConfigurationUpdater* updater = |
| 475 CreateNetworkConfigurationUpdaterForUserPolicy( | 515 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 476 true /* allow trusted certs from policy */, | 516 true /* allow trusted certs from policy */, |
| 477 false /* do not set certificate importer */); | 517 false /* do not set certificate importer */); |
| 478 MarkPolicyProviderInitialized(); | 518 MarkPolicyProviderInitialized(); |
| 479 | 519 |
| 480 Mock::VerifyAndClearExpectations(&network_config_handler_); | 520 Mock::VerifyAndClearExpectations(&network_config_handler_); |
| 481 Mock::VerifyAndClearExpectations(certificate_importer_); | 521 EXPECT_EQ(0u, certificate_importer_->GetAndResetImportCount()); |
| 482 | 522 |
| 483 EXPECT_CALL(network_config_handler_, | 523 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 484 SetPolicy(onc::ONC_SOURCE_USER_POLICY, | 524 certificate_importer_->SetExpectedONCSource(onc::ONC_SOURCE_USER_POLICY); |
| 485 kFakeUsernameHash, | |
| 486 IsEqualTo(&fake_network_configs_), | |
| 487 IsEqualTo(&fake_global_network_config_))) | |
| 488 .Times(0); | |
| 489 EXPECT_CALL(*certificate_importer_, | |
| 490 ImportCertificates(IsEqualTo(&fake_certificates_), | |
| 491 onc::ONC_SOURCE_USER_POLICY, | |
| 492 _)); | |
| 493 | 525 |
| 494 ASSERT_TRUE(certificate_importer_owned_); | 526 ASSERT_TRUE(certificate_importer_owned_); |
| 495 updater->SetCertificateImporterForTest(certificate_importer_owned_.Pass()); | 527 updater->SetCertificateImporterForTest(certificate_importer_owned_.Pass()); |
| 528 EXPECT_EQ(1u, certificate_importer_->GetAndResetImportCount()); |
| 496 } | 529 } |
| 497 | 530 |
| 498 class NetworkConfigurationUpdaterTestWithParam | 531 class NetworkConfigurationUpdaterTestWithParam |
| 499 : public NetworkConfigurationUpdaterTest, | 532 : public NetworkConfigurationUpdaterTest, |
| 500 public testing::WithParamInterface<const char*> { | 533 public testing::WithParamInterface<const char*> { |
| 501 protected: | 534 protected: |
| 502 // Returns the currently tested ONC source. | 535 // Returns the currently tested ONC source. |
| 503 onc::ONCSource CurrentONCSource() { | 536 onc::ONCSource CurrentONCSource() { |
| 504 if (GetParam() == key::kOpenNetworkConfiguration) | 537 if (GetParam() == key::kOpenNetworkConfiguration) |
| 505 return onc::ONC_SOURCE_USER_POLICY; | 538 return onc::ONC_SOURCE_USER_POLICY; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 536 PolicyMap policy; | 569 PolicyMap policy; |
| 537 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 570 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 538 new base::StringValue(kFakeONC), NULL); | 571 new base::StringValue(kFakeONC), NULL); |
| 539 UpdateProviderPolicy(policy); | 572 UpdateProviderPolicy(policy); |
| 540 | 573 |
| 541 EXPECT_CALL(network_config_handler_, | 574 EXPECT_CALL(network_config_handler_, |
| 542 SetPolicy(CurrentONCSource(), | 575 SetPolicy(CurrentONCSource(), |
| 543 ExpectedUsernameHash(), | 576 ExpectedUsernameHash(), |
| 544 IsEqualTo(&fake_network_configs_), | 577 IsEqualTo(&fake_network_configs_), |
| 545 IsEqualTo(&fake_global_network_config_))); | 578 IsEqualTo(&fake_global_network_config_))); |
| 546 EXPECT_CALL(*certificate_importer_, | 579 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 547 ImportCertificates(IsEqualTo(&fake_certificates_), | 580 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 548 CurrentONCSource(), | |
| 549 _)) | |
| 550 .Times(ExpectedImportCertificatesCallCount()); | |
| 551 | 581 |
| 552 CreateNetworkConfigurationUpdater(); | 582 CreateNetworkConfigurationUpdater(); |
| 553 MarkPolicyProviderInitialized(); | 583 MarkPolicyProviderInitialized(); |
| 584 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 585 certificate_importer_->GetAndResetImportCount()); |
| 554 } | 586 } |
| 555 | 587 |
| 556 TEST_P(NetworkConfigurationUpdaterTestWithParam, | 588 TEST_P(NetworkConfigurationUpdaterTestWithParam, |
| 557 PolicyNotSetBeforePolicyProviderInitialized) { | 589 PolicyNotSetBeforePolicyProviderInitialized) { |
| 558 PolicyMap policy; | 590 PolicyMap policy; |
| 559 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 591 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 560 new base::StringValue(kFakeONC), NULL); | 592 new base::StringValue(kFakeONC), NULL); |
| 561 UpdateProviderPolicy(policy); | 593 UpdateProviderPolicy(policy); |
| 562 | 594 |
| 563 EXPECT_CALL(network_config_handler_, | |
| 564 SetPolicy(CurrentONCSource(), | |
| 565 ExpectedUsernameHash(), | |
| 566 IsEqualTo(&fake_network_configs_), | |
| 567 IsEqualTo(&fake_global_network_config_))) | |
| 568 .Times(0); | |
| 569 EXPECT_CALL(*certificate_importer_, | |
| 570 ImportCertificates(IsEqualTo(&fake_certificates_), | |
| 571 CurrentONCSource(), | |
| 572 _)) | |
| 573 .Times(0); | |
| 574 | |
| 575 CreateNetworkConfigurationUpdater(); | 595 CreateNetworkConfigurationUpdater(); |
| 576 | 596 |
| 577 Mock::VerifyAndClearExpectations(&network_config_handler_); | 597 Mock::VerifyAndClearExpectations(&network_config_handler_); |
| 578 Mock::VerifyAndClearExpectations(certificate_importer_); | 598 EXPECT_EQ(0u, certificate_importer_->GetAndResetImportCount()); |
| 579 | 599 |
| 580 EXPECT_CALL(network_config_handler_, | 600 EXPECT_CALL(network_config_handler_, |
| 581 SetPolicy(CurrentONCSource(), | 601 SetPolicy(CurrentONCSource(), |
| 582 ExpectedUsernameHash(), | 602 ExpectedUsernameHash(), |
| 583 IsEqualTo(&fake_network_configs_), | 603 IsEqualTo(&fake_network_configs_), |
| 584 IsEqualTo(&fake_global_network_config_))); | 604 IsEqualTo(&fake_global_network_config_))); |
| 585 EXPECT_CALL(*certificate_importer_, | 605 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 586 ImportCertificates(IsEqualTo(&fake_certificates_), | 606 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 587 CurrentONCSource(), | |
| 588 _)) | |
| 589 .Times(ExpectedImportCertificatesCallCount()); | |
| 590 | 607 |
| 591 MarkPolicyProviderInitialized(); | 608 MarkPolicyProviderInitialized(); |
| 609 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 610 certificate_importer_->GetAndResetImportCount()); |
| 592 } | 611 } |
| 593 | 612 |
| 594 TEST_P(NetworkConfigurationUpdaterTestWithParam, | 613 TEST_P(NetworkConfigurationUpdaterTestWithParam, |
| 595 PolicyAppliedImmediatelyIfProvidersInitialized) { | 614 PolicyAppliedImmediatelyIfProvidersInitialized) { |
| 596 MarkPolicyProviderInitialized(); | 615 MarkPolicyProviderInitialized(); |
| 597 | 616 |
| 598 PolicyMap policy; | 617 PolicyMap policy; |
| 599 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 618 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 600 new base::StringValue(kFakeONC), NULL); | 619 new base::StringValue(kFakeONC), NULL); |
| 601 UpdateProviderPolicy(policy); | 620 UpdateProviderPolicy(policy); |
| 602 | 621 |
| 603 EXPECT_CALL(network_config_handler_, | 622 EXPECT_CALL(network_config_handler_, |
| 604 SetPolicy(CurrentONCSource(), | 623 SetPolicy(CurrentONCSource(), |
| 605 ExpectedUsernameHash(), | 624 ExpectedUsernameHash(), |
| 606 IsEqualTo(&fake_network_configs_), | 625 IsEqualTo(&fake_network_configs_), |
| 607 IsEqualTo(&fake_global_network_config_))); | 626 IsEqualTo(&fake_global_network_config_))); |
| 608 EXPECT_CALL(*certificate_importer_, | 627 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 609 ImportCertificates(IsEqualTo(&fake_certificates_), | 628 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 610 CurrentONCSource(), | |
| 611 _)) | |
| 612 .Times(ExpectedImportCertificatesCallCount()); | |
| 613 | 629 |
| 614 CreateNetworkConfigurationUpdater(); | 630 CreateNetworkConfigurationUpdater(); |
| 631 |
| 632 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 633 certificate_importer_->GetAndResetImportCount()); |
| 615 } | 634 } |
| 616 | 635 |
| 617 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) { | 636 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) { |
| 618 // Ignore the initial updates. | 637 // Ignore the initial updates. |
| 619 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); | 638 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); |
| 620 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _)) | |
| 621 .Times(AtLeast(ExpectedImportCertificatesCallCount())); | |
| 622 | 639 |
| 623 CreateNetworkConfigurationUpdater(); | 640 CreateNetworkConfigurationUpdater(); |
| 624 MarkPolicyProviderInitialized(); | 641 MarkPolicyProviderInitialized(); |
| 625 | 642 |
| 626 Mock::VerifyAndClearExpectations(&network_config_handler_); | 643 Mock::VerifyAndClearExpectations(&network_config_handler_); |
| 627 Mock::VerifyAndClearExpectations(certificate_importer_); | 644 EXPECT_LE(ExpectedImportCertificatesCallCount(), |
| 645 certificate_importer_->GetAndResetImportCount()); |
| 628 | 646 |
| 629 // The Updater should update if policy changes. | 647 // The Updater should update if policy changes. |
| 630 EXPECT_CALL(network_config_handler_, | 648 EXPECT_CALL(network_config_handler_, |
| 631 SetPolicy(CurrentONCSource(), | 649 SetPolicy(CurrentONCSource(), |
| 632 _, | 650 _, |
| 633 IsEqualTo(&fake_network_configs_), | 651 IsEqualTo(&fake_network_configs_), |
| 634 IsEqualTo(&fake_global_network_config_))); | 652 IsEqualTo(&fake_global_network_config_))); |
| 635 EXPECT_CALL(*certificate_importer_, | 653 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 636 ImportCertificates(IsEqualTo(&fake_certificates_), | 654 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 637 CurrentONCSource(), | |
| 638 _)) | |
| 639 .Times(ExpectedImportCertificatesCallCount()); | |
| 640 | 655 |
| 641 PolicyMap policy; | 656 PolicyMap policy; |
| 642 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 657 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 643 new base::StringValue(kFakeONC), NULL); | 658 new base::StringValue(kFakeONC), NULL); |
| 644 UpdateProviderPolicy(policy); | 659 UpdateProviderPolicy(policy); |
| 645 Mock::VerifyAndClearExpectations(&network_config_handler_); | 660 Mock::VerifyAndClearExpectations(&network_config_handler_); |
| 646 Mock::VerifyAndClearExpectations(certificate_importer_); | 661 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 662 certificate_importer_->GetAndResetImportCount()); |
| 647 | 663 |
| 648 // Another update is expected if the policy goes away. | 664 // Another update is expected if the policy goes away. |
| 649 EXPECT_CALL(network_config_handler_, | 665 EXPECT_CALL(network_config_handler_, |
| 650 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty())); | 666 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty())); |
| 651 EXPECT_CALL(*certificate_importer_, | 667 certificate_importer_->SetExpectedONCCertificates(base::ListValue()); |
| 652 ImportCertificates(IsEmpty(), CurrentONCSource(), _)) | |
| 653 .Times(ExpectedImportCertificatesCallCount()); | |
| 654 | 668 |
| 655 policy.Erase(GetParam()); | 669 policy.Erase(GetParam()); |
| 656 UpdateProviderPolicy(policy); | 670 UpdateProviderPolicy(policy); |
| 671 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 672 certificate_importer_->GetAndResetImportCount()); |
| 657 } | 673 } |
| 658 | 674 |
| 659 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, | 675 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, |
| 660 NetworkConfigurationUpdaterTestWithParam, | 676 NetworkConfigurationUpdaterTestWithParam, |
| 661 testing::Values(key::kDeviceOpenNetworkConfiguration, | 677 testing::Values(key::kDeviceOpenNetworkConfiguration, |
| 662 key::kOpenNetworkConfiguration)); | 678 key::kOpenNetworkConfiguration)); |
| 663 | 679 |
| 664 } // namespace policy | 680 } // namespace policy |
| OLD | NEW |