Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: chrome/browser/chromeos/policy/network_configuration_updater_unittest.cc

Issue 148183013: Use per-user nssdb in onc certificate importer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 } // namespace 142 } // namespace
143 143
144 class NetworkConfigurationUpdaterTest : public testing::Test { 144 class NetworkConfigurationUpdaterTest : public testing::Test {
145 protected: 145 protected:
146 NetworkConfigurationUpdaterTest() { 146 NetworkConfigurationUpdaterTest() {
147 } 147 }
148 148
149 virtual void SetUp() OVERRIDE { 149 virtual void SetUp() OVERRIDE {
150 EXPECT_CALL(provider_, IsInitializationComplete(_)) 150 EXPECT_CALL(provider_, IsInitializationComplete(_))
151 .WillRepeatedly(Return(true)); 151 .WillRepeatedly(Return(false));
152 provider_.Init(); 152 provider_.Init();
153 PolicyServiceImpl::Providers providers; 153 PolicyServiceImpl::Providers providers;
154 providers.push_back(&provider_); 154 providers.push_back(&provider_);
155 policy_service_.reset(new PolicyServiceImpl(providers)); 155 policy_service_.reset(new PolicyServiceImpl(providers));
156 156
157 scoped_ptr<base::DictionaryValue> fake_toplevel_onc = 157 scoped_ptr<base::DictionaryValue> fake_toplevel_onc =
158 chromeos::onc::ReadDictionaryFromJson(kFakeONC); 158 chromeos::onc::ReadDictionaryFromJson(kFakeONC);
159 159
160 base::ListValue* network_configs = NULL; 160 base::ListValue* network_configs = NULL;
161 fake_toplevel_onc->GetListWithoutPathExpansion( 161 fake_toplevel_onc->GetListWithoutPathExpansion(
(...skipping 14 matching lines...) Expand all
176 new StrictMock<chromeos::onc::MockCertificateImporter>(); 176 new StrictMock<chromeos::onc::MockCertificateImporter>();
177 certificate_importer_owned_.reset(certificate_importer_); 177 certificate_importer_owned_.reset(certificate_importer_);
178 } 178 }
179 179
180 virtual void TearDown() OVERRIDE { 180 virtual void TearDown() OVERRIDE {
181 network_configuration_updater_.reset(); 181 network_configuration_updater_.reset();
182 provider_.Shutdown(); 182 provider_.Shutdown();
183 base::RunLoop().RunUntilIdle(); 183 base::RunLoop().RunUntilIdle();
184 } 184 }
185 185
186 void MarkPolicyProviderInitialized() {
187 Mock::VerifyAndClearExpectations(&provider_);
188 EXPECT_CALL(provider_, IsInitializationComplete(_))
189 .WillRepeatedly(Return(true));
190 provider_.SetAutoRefresh();
191 provider_.RefreshPolicies();
192 base::RunLoop().RunUntilIdle();
193 }
194
186 void UpdateProviderPolicy(const PolicyMap& policy) { 195 void UpdateProviderPolicy(const PolicyMap& policy) {
187 provider_.UpdateChromePolicy(policy); 196 provider_.UpdateChromePolicy(policy);
188 base::RunLoop().RunUntilIdle(); 197 base::RunLoop().RunUntilIdle();
189 } 198 }
190 199
191 UserNetworkConfigurationUpdater* 200 UserNetworkConfigurationUpdater*
192 CreateNetworkConfigurationUpdaterForUserPolicy( 201 CreateNetworkConfigurationUpdaterForUserPolicy(
193 bool allow_trusted_certs_from_policy) { 202 bool allow_trusted_certs_from_policy,
203 bool set_cert_importer) {
194 UserNetworkConfigurationUpdater* updater = 204 UserNetworkConfigurationUpdater* updater =
195 UserNetworkConfigurationUpdater::CreateForUserPolicy( 205 UserNetworkConfigurationUpdater::CreateForUserPolicy(
196 allow_trusted_certs_from_policy, 206 allow_trusted_certs_from_policy,
197 fake_user_, 207 fake_user_,
198 certificate_importer_owned_.Pass(),
199 policy_service_.get(), 208 policy_service_.get(),
200 &network_config_handler_).release(); 209 &network_config_handler_).release();
210 if (set_cert_importer) {
211 EXPECT_TRUE(certificate_importer_owned_);
212 updater->SetCertificateImporter(certificate_importer_owned_.Pass());
213 }
201 network_configuration_updater_.reset(updater); 214 network_configuration_updater_.reset(updater);
202 return updater; 215 return updater;
203 } 216 }
204 217
205 void CreateNetworkConfigurationUpdaterForDevicePolicy() { 218 void CreateNetworkConfigurationUpdaterForDevicePolicy() {
206 network_configuration_updater_ = 219 network_configuration_updater_ =
207 DeviceNetworkConfigurationUpdater::CreateForDevicePolicy( 220 DeviceNetworkConfigurationUpdater::CreateForDevicePolicy(
208 certificate_importer_owned_.Pass(),
209 policy_service_.get(), 221 policy_service_.get(),
210 &network_config_handler_, 222 &network_config_handler_,
211 &network_device_handler_, 223 &network_device_handler_,
212 chromeos::CrosSettings::Get()); 224 chromeos::CrosSettings::Get());
213 } 225 }
214 226
215 base::ListValue fake_network_configs_; 227 base::ListValue fake_network_configs_;
216 base::DictionaryValue fake_global_network_config_; 228 base::DictionaryValue fake_global_network_config_;
217 base::ListValue fake_certificates_; 229 base::ListValue fake_certificates_;
218 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> 230 StrictMock<chromeos::MockManagedNetworkConfigurationHandler>
(...skipping 13 matching lines...) Expand all
232 244
233 StrictMock<MockConfigurationPolicyProvider> provider_; 245 StrictMock<MockConfigurationPolicyProvider> provider_;
234 scoped_ptr<PolicyServiceImpl> policy_service_; 246 scoped_ptr<PolicyServiceImpl> policy_service_;
235 FakeUser fake_user_; 247 FakeUser fake_user_;
236 248
237 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; 249 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
238 content::TestBrowserThreadBundle thread_bundle_; 250 content::TestBrowserThreadBundle thread_bundle_;
239 }; 251 };
240 252
241 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { 253 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) {
242 // Ignore networ config updates. 254 // Ignore network config updates.
243 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); 255 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1));
244 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _))
245 .Times(AtLeast(1));
246 256
247 // Setup the DataRoaming device setting. 257 // Setup the DataRoaming device setting.
248 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); 258 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
249 chromeos::CrosSettingsProvider* device_settings_provider = 259 chromeos::CrosSettingsProvider* device_settings_provider =
250 cros_settings->GetProvider(chromeos::kSignedDataRoamingEnabled); 260 cros_settings->GetProvider(chromeos::kSignedDataRoamingEnabled);
251 cros_settings->RemoveSettingsProvider(device_settings_provider); 261 cros_settings->RemoveSettingsProvider(device_settings_provider);
252 delete device_settings_provider; 262 delete device_settings_provider;
253 chromeos::StubCrosSettingsProvider* stub_settings_provider = 263 chromeos::StubCrosSettingsProvider* stub_settings_provider =
254 new chromeos::StubCrosSettingsProvider; 264 new chromeos::StubCrosSettingsProvider;
255 cros_settings->AddSettingsProvider(stub_settings_provider); 265 cros_settings->AddSettingsProvider(stub_settings_provider);
256 266
257 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, 267 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled,
258 base::FundamentalValue(false)); 268 base::FundamentalValue(false));
259 EXPECT_FALSE(network_device_handler_.allow_roaming_); 269 EXPECT_FALSE(network_device_handler_.allow_roaming_);
260 270
261 CreateNetworkConfigurationUpdaterForDevicePolicy(); 271 CreateNetworkConfigurationUpdaterForDevicePolicy();
272 MarkPolicyProviderInitialized();
262 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, 273 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled,
263 base::FundamentalValue(true)); 274 base::FundamentalValue(true));
264 EXPECT_TRUE(network_device_handler_.allow_roaming_); 275 EXPECT_TRUE(network_device_handler_.allow_roaming_);
265 276
266 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, 277 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled,
267 base::FundamentalValue(false)); 278 base::FundamentalValue(false));
268 EXPECT_FALSE(network_device_handler_.allow_roaming_); 279 EXPECT_FALSE(network_device_handler_.allow_roaming_);
269 } 280 }
270 281
271 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { 282 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) {
(...skipping 21 matching lines...) Expand all
293 new base::StringValue(onc_policy), 304 new base::StringValue(onc_policy),
294 NULL); 305 NULL);
295 UpdateProviderPolicy(policy); 306 UpdateProviderPolicy(policy);
296 307
297 EXPECT_CALL(network_config_handler_, 308 EXPECT_CALL(network_config_handler_,
298 SetPolicy(onc::ONC_SOURCE_USER_POLICY, 309 SetPolicy(onc::ONC_SOURCE_USER_POLICY,
299 _, 310 _,
300 IsEqualTo(network_configs_repaired), 311 IsEqualTo(network_configs_repaired),
301 IsEqualTo(global_config_repaired))); 312 IsEqualTo(global_config_repaired)));
302 EXPECT_CALL(*certificate_importer_, 313 EXPECT_CALL(*certificate_importer_,
303 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)); 314 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _));
304 315
305 CreateNetworkConfigurationUpdaterForUserPolicy( 316 CreateNetworkConfigurationUpdaterForUserPolicy(
306 false /* do not allow trusted certs from policy */ ); 317 false /* do not allow trusted certs from policy */,
318 true /* set certificate importer */);
319 MarkPolicyProviderInitialized();
307 } 320 }
308 321
309 TEST_F(NetworkConfigurationUpdaterTest, 322 TEST_F(NetworkConfigurationUpdaterTest,
310 DoNotAllowTrustedCertificatesFromPolicy) { 323 DoNotAllowTrustedCertificatesFromPolicy) {
311 net::CertificateList cert_list; 324 net::CertificateList cert_list;
312 cert_list = 325 cert_list =
313 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), 326 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(),
314 "ok_cert.pem", 327 "ok_cert.pem",
315 net::X509Certificate::FORMAT_AUTO); 328 net::X509Certificate::FORMAT_AUTO);
316 ASSERT_EQ(1u, cert_list.size()); 329 ASSERT_EQ(1u, cert_list.size());
317 330
318 EXPECT_CALL(network_config_handler_, 331 EXPECT_CALL(network_config_handler_,
319 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _, _)); 332 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _, _));
320 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _)) 333 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _))
321 .WillRepeatedly(SetCertificateList(cert_list)); 334 .WillRepeatedly(SetCertificateList(cert_list));
322 335
323 UserNetworkConfigurationUpdater* updater = 336 UserNetworkConfigurationUpdater* updater =
324 CreateNetworkConfigurationUpdaterForUserPolicy( 337 CreateNetworkConfigurationUpdaterForUserPolicy(
325 false /* do not allow trusted certs from policy */); 338 false /* do not allow trusted certs from policy */,
339 true /* set certificate importer */);
340 MarkPolicyProviderInitialized();
326 341
327 // Certificates with the "Web" trust flag set should not be forwarded to 342 // Certificates with the "Web" trust flag set should not be forwarded to
328 // observers. 343 // observers.
329 FakeWebTrustedCertsObserver observer; 344 FakeWebTrustedCertsObserver observer;
330 updater->AddTrustedCertsObserver(&observer); 345 updater->AddTrustedCertsObserver(&observer);
331 346
332 base::RunLoop().RunUntilIdle(); 347 base::RunLoop().RunUntilIdle();
333 348
334 net::CertificateList trust_anchors; 349 net::CertificateList trust_anchors;
335 updater->GetWebTrustedCertificates(&trust_anchors); 350 updater->GetWebTrustedCertificates(&trust_anchors);
(...skipping 15 matching lines...) Expand all
351 "ok_cert.pem", 366 "ok_cert.pem",
352 net::X509Certificate::FORMAT_AUTO); 367 net::X509Certificate::FORMAT_AUTO);
353 ASSERT_EQ(1u, cert_list.size()); 368 ASSERT_EQ(1u, cert_list.size());
354 369
355 EXPECT_CALL(*certificate_importer_, 370 EXPECT_CALL(*certificate_importer_,
356 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)) 371 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _))
357 .WillRepeatedly(SetCertificateList(cert_list)); 372 .WillRepeatedly(SetCertificateList(cert_list));
358 373
359 UserNetworkConfigurationUpdater* updater = 374 UserNetworkConfigurationUpdater* updater =
360 CreateNetworkConfigurationUpdaterForUserPolicy( 375 CreateNetworkConfigurationUpdaterForUserPolicy(
361 true /* allow trusted certs from policy */); 376 true /* allow trusted certs from policy */,
377 true /* set certificate importer */);
378 MarkPolicyProviderInitialized();
362 379
363 base::RunLoop().RunUntilIdle(); 380 base::RunLoop().RunUntilIdle();
364 381
365 // Certificates with the "Web" trust flag set will be returned. 382 // Certificates with the "Web" trust flag set will be returned.
366 net::CertificateList trust_anchors; 383 net::CertificateList trust_anchors;
367 updater->GetWebTrustedCertificates(&trust_anchors); 384 updater->GetWebTrustedCertificates(&trust_anchors);
368 EXPECT_EQ(1u, trust_anchors.size()); 385 EXPECT_EQ(1u, trust_anchors.size());
369 } 386 }
370 387
371 TEST_F(NetworkConfigurationUpdaterTest, 388 TEST_F(NetworkConfigurationUpdaterTest,
372 AllowTrustedCertificatesFromPolicyOnUpdate) { 389 AllowTrustedCertificatesFromPolicyOnUpdate) {
373 // Ignore network configuration changes. 390 // Ignore network configuration changes.
374 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)) 391 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _))
375 .Times(AnyNumber()); 392 .Times(AnyNumber());
376 393
377 // Start with an empty certificate list. 394 // Start with an empty certificate list.
378 EXPECT_CALL(*certificate_importer_, 395 EXPECT_CALL(*certificate_importer_,
379 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)) 396 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _))
380 .WillRepeatedly(SetCertificateList(net::CertificateList())); 397 .WillRepeatedly(SetCertificateList(net::CertificateList()));
381 398
382 UserNetworkConfigurationUpdater* updater = 399 UserNetworkConfigurationUpdater* updater =
383 CreateNetworkConfigurationUpdaterForUserPolicy( 400 CreateNetworkConfigurationUpdaterForUserPolicy(
384 true /* allow trusted certs from policy */); 401 true /* allow trusted certs from policy */,
402 true /* set certificate importer */);
403 MarkPolicyProviderInitialized();
385 404
386 FakeWebTrustedCertsObserver observer; 405 FakeWebTrustedCertsObserver observer;
387 updater->AddTrustedCertsObserver(&observer); 406 updater->AddTrustedCertsObserver(&observer);
388 407
389 base::RunLoop().RunUntilIdle(); 408 base::RunLoop().RunUntilIdle();
390 409
391 // Verify that the returned certificate list is empty. 410 // Verify that the returned certificate list is empty.
392 Mock::VerifyAndClearExpectations(certificate_importer_); 411 Mock::VerifyAndClearExpectations(certificate_importer_);
393 { 412 {
394 net::CertificateList trust_anchors; 413 net::CertificateList trust_anchors;
(...skipping 30 matching lines...) Expand all
425 { 444 {
426 net::CertificateList trust_anchors; 445 net::CertificateList trust_anchors;
427 updater->GetWebTrustedCertificates(&trust_anchors); 446 updater->GetWebTrustedCertificates(&trust_anchors);
428 EXPECT_EQ(1u, trust_anchors.size()); 447 EXPECT_EQ(1u, trust_anchors.size());
429 } 448 }
430 EXPECT_EQ(1u, observer.trust_anchors_.size()); 449 EXPECT_EQ(1u, observer.trust_anchors_.size());
431 450
432 updater->RemoveTrustedCertsObserver(&observer); 451 updater->RemoveTrustedCertsObserver(&observer);
433 } 452 }
434 453
454 TEST_F(NetworkConfigurationUpdaterTest,
455 DontImportCertificateBeforeCertificateImporterSet) {
456 PolicyMap policy;
457 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
458 POLICY_SCOPE_USER, new base::StringValue(kFakeONC), NULL);
459 UpdateProviderPolicy(policy);
460
461 EXPECT_CALL(network_config_handler_,
462 SetPolicy(onc::ONC_SOURCE_USER_POLICY,
463 kFakeUsernameHash,
464 IsEqualTo(&fake_network_configs_),
465 IsEqualTo(&fake_global_network_config_)));
466 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _ , _)).Times(0);
467
468 UserNetworkConfigurationUpdater* updater =
469 CreateNetworkConfigurationUpdaterForUserPolicy(
470 true /* allow trusted certs from policy */,
471 false /* do not set certificate importer */);
472 MarkPolicyProviderInitialized();
473
474 Mock::VerifyAndClearExpectations(&network_config_handler_);
475 Mock::VerifyAndClearExpectations(certificate_importer_);
476
477 EXPECT_CALL(network_config_handler_,
478 SetPolicy(onc::ONC_SOURCE_USER_POLICY,
479 kFakeUsernameHash,
480 IsEqualTo(&fake_network_configs_),
481 IsEqualTo(&fake_global_network_config_)))
482 .Times(0);
483 EXPECT_CALL(*certificate_importer_,
484 ImportCertificates(IsEqualTo(&fake_certificates_),
485 onc::ONC_SOURCE_USER_POLICY,
486 _));
487
488 ASSERT_TRUE(certificate_importer_owned_);
489 updater->SetCertificateImporter(certificate_importer_owned_.Pass());
490 }
491
435 class NetworkConfigurationUpdaterTestWithParam 492 class NetworkConfigurationUpdaterTestWithParam
436 : public NetworkConfigurationUpdaterTest, 493 : public NetworkConfigurationUpdaterTest,
437 public testing::WithParamInterface<const char*> { 494 public testing::WithParamInterface<const char*> {
438 protected: 495 protected:
439 // Returns the currently tested ONC source. 496 // Returns the currently tested ONC source.
440 onc::ONCSource CurrentONCSource() { 497 onc::ONCSource CurrentONCSource() {
441 if (GetParam() == key::kOpenNetworkConfiguration) 498 if (GetParam() == key::kOpenNetworkConfiguration)
442 return onc::ONC_SOURCE_USER_POLICY; 499 return onc::ONC_SOURCE_USER_POLICY;
443 DCHECK(GetParam() == key::kDeviceOpenNetworkConfiguration); 500 DCHECK(GetParam() == key::kDeviceOpenNetworkConfiguration);
444 return onc::ONC_SOURCE_DEVICE_POLICY; 501 return onc::ONC_SOURCE_DEVICE_POLICY;
445 } 502 }
446 503
447 // Returns the expected username hash to push policies to 504 // Returns the expected username hash to push policies to
448 // ManagedNetworkConfigurationHandler. 505 // ManagedNetworkConfigurationHandler.
449 std::string ExpectedUsernameHash() { 506 std::string ExpectedUsernameHash() {
450 if (GetParam() == key::kOpenNetworkConfiguration) 507 if (GetParam() == key::kOpenNetworkConfiguration)
451 return kFakeUsernameHash; 508 return kFakeUsernameHash;
452 return std::string(); 509 return std::string();
453 } 510 }
454 511
512 size_t ExpectedImportCertificatesCallCount() {
513 if (GetParam() == key::kOpenNetworkConfiguration)
514 return 1u;
515 return 0u;
516 }
517
455 void CreateNetworkConfigurationUpdater() { 518 void CreateNetworkConfigurationUpdater() {
456 if (GetParam() == key::kOpenNetworkConfiguration) { 519 if (GetParam() == key::kOpenNetworkConfiguration) {
457 CreateNetworkConfigurationUpdaterForUserPolicy( 520 CreateNetworkConfigurationUpdaterForUserPolicy(
458 false /* do not allow trusted certs from policy */); 521 false /* do not allow trusted certs from policy */,
522 true /* set certificate importer */);
459 } else { 523 } else {
460 CreateNetworkConfigurationUpdaterForDevicePolicy(); 524 CreateNetworkConfigurationUpdaterForDevicePolicy();
461 } 525 }
462 } 526 }
463 }; 527 };
464 528
465 TEST_P(NetworkConfigurationUpdaterTestWithParam, InitialUpdates) { 529 TEST_P(NetworkConfigurationUpdaterTestWithParam, InitialUpdates) {
466 PolicyMap policy; 530 PolicyMap policy;
467 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 531 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
468 new base::StringValue(kFakeONC), NULL); 532 new base::StringValue(kFakeONC), NULL);
469 UpdateProviderPolicy(policy); 533 UpdateProviderPolicy(policy);
470 534
471 EXPECT_CALL(network_config_handler_, 535 EXPECT_CALL(network_config_handler_,
472 SetPolicy(CurrentONCSource(), 536 SetPolicy(CurrentONCSource(),
473 ExpectedUsernameHash(), 537 ExpectedUsernameHash(),
474 IsEqualTo(&fake_network_configs_), 538 IsEqualTo(&fake_network_configs_),
475 IsEqualTo(&fake_global_network_config_))); 539 IsEqualTo(&fake_global_network_config_)));
476 EXPECT_CALL(*certificate_importer_, 540 EXPECT_CALL(*certificate_importer_,
477 ImportCertificates( 541 ImportCertificates(IsEqualTo(&fake_certificates_),
478 IsEqualTo(&fake_certificates_), CurrentONCSource(), _)); 542 CurrentONCSource(),
543 _))
544 .Times(ExpectedImportCertificatesCallCount());
545
546 CreateNetworkConfigurationUpdater();
547 MarkPolicyProviderInitialized();
548 }
549
550 TEST_P(NetworkConfigurationUpdaterTestWithParam,
551 PolicyNotSetBeforePolicyProviderInitialized) {
552 PolicyMap policy;
553 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
554 new base::StringValue(kFakeONC), NULL);
555 UpdateProviderPolicy(policy);
556
557 EXPECT_CALL(network_config_handler_,
558 SetPolicy(CurrentONCSource(),
559 ExpectedUsernameHash(),
560 IsEqualTo(&fake_network_configs_),
561 IsEqualTo(&fake_global_network_config_)))
562 .Times(0);
563 EXPECT_CALL(*certificate_importer_,
564 ImportCertificates(IsEqualTo(&fake_certificates_),
565 CurrentONCSource(),
566 _))
567 .Times(0);
568
569 CreateNetworkConfigurationUpdater();
570
571 Mock::VerifyAndClearExpectations(&network_config_handler_);
572 Mock::VerifyAndClearExpectations(certificate_importer_);
573
574 EXPECT_CALL(network_config_handler_,
575 SetPolicy(CurrentONCSource(),
576 ExpectedUsernameHash(),
577 IsEqualTo(&fake_network_configs_),
578 IsEqualTo(&fake_global_network_config_)));
579 EXPECT_CALL(*certificate_importer_,
580 ImportCertificates(IsEqualTo(&fake_certificates_),
581 CurrentONCSource(),
582 _))
583 .Times(ExpectedImportCertificatesCallCount());
584
585 MarkPolicyProviderInitialized();
586 }
587
588 TEST_P(NetworkConfigurationUpdaterTestWithParam,
589 PolicyAppliedImidiatellyIfProvidersInitialized) {
pneubeck (no reviews) 2014/02/06 09:37:46 Imidiatelly -> Immediately
tbarzic 2014/02/06 23:02:36 Done.
590 MarkPolicyProviderInitialized();
591
592 PolicyMap policy;
593 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
594 new base::StringValue(kFakeONC), NULL);
595 UpdateProviderPolicy(policy);
596
597 EXPECT_CALL(network_config_handler_,
598 SetPolicy(CurrentONCSource(),
599 ExpectedUsernameHash(),
600 IsEqualTo(&fake_network_configs_),
601 IsEqualTo(&fake_global_network_config_)));
602 EXPECT_CALL(*certificate_importer_,
603 ImportCertificates(IsEqualTo(&fake_certificates_),
604 CurrentONCSource(),
605 _))
606 .Times(ExpectedImportCertificatesCallCount());
479 607
480 CreateNetworkConfigurationUpdater(); 608 CreateNetworkConfigurationUpdater();
481 } 609 }
482 610
483
484 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) { 611 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) {
485 // Ignore the initial updates. 612 // Ignore the initial updates.
486 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); 613 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1));
487 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _)) 614 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _))
488 .Times(AtLeast(1)); 615 .Times(AtLeast(ExpectedImportCertificatesCallCount()));
616
489 CreateNetworkConfigurationUpdater(); 617 CreateNetworkConfigurationUpdater();
618 MarkPolicyProviderInitialized();
619
490 Mock::VerifyAndClearExpectations(&network_config_handler_); 620 Mock::VerifyAndClearExpectations(&network_config_handler_);
491 Mock::VerifyAndClearExpectations(certificate_importer_); 621 Mock::VerifyAndClearExpectations(certificate_importer_);
492 622
493 // The Updater should update if policy changes. 623 // The Updater should update if policy changes.
494 EXPECT_CALL(network_config_handler_, 624 EXPECT_CALL(network_config_handler_,
495 SetPolicy(CurrentONCSource(), 625 SetPolicy(CurrentONCSource(),
496 _, 626 _,
497 IsEqualTo(&fake_network_configs_), 627 IsEqualTo(&fake_network_configs_),
498 IsEqualTo(&fake_global_network_config_))); 628 IsEqualTo(&fake_global_network_config_)));
499 EXPECT_CALL(*certificate_importer_, 629 EXPECT_CALL(*certificate_importer_,
500 ImportCertificates( 630 ImportCertificates(IsEqualTo(&fake_certificates_),
501 IsEqualTo(&fake_certificates_), CurrentONCSource(), _)); 631 CurrentONCSource(),
632 _))
633 .Times(ExpectedImportCertificatesCallCount());
502 634
503 PolicyMap policy; 635 PolicyMap policy;
504 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 636 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
505 new base::StringValue(kFakeONC), NULL); 637 new base::StringValue(kFakeONC), NULL);
506 UpdateProviderPolicy(policy); 638 UpdateProviderPolicy(policy);
507 Mock::VerifyAndClearExpectations(&network_config_handler_); 639 Mock::VerifyAndClearExpectations(&network_config_handler_);
508 Mock::VerifyAndClearExpectations(certificate_importer_); 640 Mock::VerifyAndClearExpectations(certificate_importer_);
509 641
510 // Another update is expected if the policy goes away. 642 // Another update is expected if the policy goes away.
511 EXPECT_CALL(network_config_handler_, 643 EXPECT_CALL(network_config_handler_,
512 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty())); 644 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty()));
513 EXPECT_CALL(*certificate_importer_, 645 EXPECT_CALL(*certificate_importer_,
514 ImportCertificates(IsEmpty(), CurrentONCSource(), _)); 646 ImportCertificates(IsEmpty(), CurrentONCSource(), _))
647 .Times(ExpectedImportCertificatesCallCount());
515 648
516 policy.Erase(GetParam()); 649 policy.Erase(GetParam());
517 UpdateProviderPolicy(policy); 650 UpdateProviderPolicy(policy);
518 } 651 }
519 652
520 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, 653 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance,
521 NetworkConfigurationUpdaterTestWithParam, 654 NetworkConfigurationUpdaterTestWithParam,
522 testing::Values(key::kDeviceOpenNetworkConfiguration, 655 testing::Values(key::kDeviceOpenNetworkConfiguration,
523 key::kOpenNetworkConfiguration)); 656 key::kOpenNetworkConfiguration));
524 657
525 } // namespace policy 658 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698