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

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

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another test. Created 5 years, 3 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
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"
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/scoped_cros_settings_test_helper.h" 15 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "chromeos/network/fake_network_device_handler.h" 17 #include "chromeos/network/fake_network_device_handler.h"
18 #include "chromeos/network/mock_managed_network_configuration_handler.h" 18 #include "chromeos/network/mock_managed_network_configuration_handler.h"
19 #include "chromeos/network/onc/onc_certificate_importer.h" 19 #include "chromeos/network/onc/onc_certificate_importer.h"
20 #include "chromeos/network/onc/onc_test_utils.h" 20 #include "chromeos/network/onc/onc_test_utils.h"
21 #include "chromeos/network/onc/onc_utils.h" 21 #include "chromeos/network/onc/onc_utils.h"
22 #include "components/onc/onc_constants.h" 22 #include "components/onc/onc_constants.h"
23 #include "components/policy/core/common/external_data_fetcher.h" 23 #include "components/policy/core/common/external_data_fetcher.h"
24 #include "components/policy/core/common/mock_configuration_policy_provider.h" 24 #include "components/policy/core/common/mock_configuration_policy_provider.h"
25 #include "components/policy/core/common/policy_map.h" 25 #include "components/policy/core/common/policy_map.h"
26 #include "components/policy/core/common/policy_service_impl.h" 26 #include "components/policy/core/common/policy_service_impl.h"
27 #include "components/policy/core/common/policy_types.h"
27 #include "components/user_manager/user.h" 28 #include "components/user_manager/user.h"
28 #include "components/user_manager/user_type.h" 29 #include "components/user_manager/user_type.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 30 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "content/public/test/test_utils.h" 31 #include "content/public/test/test_utils.h"
31 #include "net/base/test_data_directory.h" 32 #include "net/base/test_data_directory.h"
32 #include "net/cert/x509_certificate.h" 33 #include "net/cert/x509_certificate.h"
33 #include "net/test/cert_test_util.h" 34 #include "net/test/cert_test_util.h"
34 #include "policy/policy_constants.h" 35 #include "policy/policy_constants.h"
35 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 onc::toplevel_config::kGlobalNetworkConfiguration, 338 onc::toplevel_config::kGlobalNetworkConfiguration,
338 &global_config_repaired); 339 &global_config_repaired);
339 ASSERT_TRUE(global_config_repaired); 340 ASSERT_TRUE(global_config_repaired);
340 341
341 std::string onc_policy = 342 std::string onc_policy =
342 chromeos::onc::test_utils::ReadTestData("toplevel_partially_invalid.onc"); 343 chromeos::onc::test_utils::ReadTestData("toplevel_partially_invalid.onc");
343 PolicyMap policy; 344 PolicyMap policy;
344 policy.Set(key::kOpenNetworkConfiguration, 345 policy.Set(key::kOpenNetworkConfiguration,
345 POLICY_LEVEL_MANDATORY, 346 POLICY_LEVEL_MANDATORY,
346 POLICY_SCOPE_USER, 347 POLICY_SCOPE_USER,
348 POLICY_SOURCE_CLOUD,
347 new base::StringValue(onc_policy), 349 new base::StringValue(onc_policy),
348 NULL); 350 NULL);
349 UpdateProviderPolicy(policy); 351 UpdateProviderPolicy(policy);
350 352
351 EXPECT_CALL(network_config_handler_, 353 EXPECT_CALL(network_config_handler_,
352 SetPolicy(onc::ONC_SOURCE_USER_POLICY, 354 SetPolicy(onc::ONC_SOURCE_USER_POLICY,
353 _, 355 _,
354 IsEqualTo(network_configs_repaired), 356 IsEqualTo(network_configs_repaired),
355 IsEqualTo(global_config_repaired))); 357 IsEqualTo(global_config_repaired)));
356 certificate_importer_->SetExpectedONCSource(onc::ONC_SOURCE_USER_POLICY); 358 certificate_importer_->SetExpectedONCSource(onc::ONC_SOURCE_USER_POLICY);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 net::X509Certificate::FORMAT_AUTO); 462 net::X509Certificate::FORMAT_AUTO);
461 ASSERT_EQ(1u, cert_list.size()); 463 ASSERT_EQ(1u, cert_list.size());
462 certificate_importer_->SetTrustedCertificatesResult(cert_list); 464 certificate_importer_->SetTrustedCertificatesResult(cert_list);
463 465
464 // Change to any non-empty policy, so that updates are triggered. The actual 466 // Change to any non-empty policy, so that updates are triggered. The actual
465 // content of the policy is irrelevant. 467 // content of the policy is irrelevant.
466 PolicyMap policy; 468 PolicyMap policy;
467 policy.Set(key::kOpenNetworkConfiguration, 469 policy.Set(key::kOpenNetworkConfiguration,
468 POLICY_LEVEL_MANDATORY, 470 POLICY_LEVEL_MANDATORY,
469 POLICY_SCOPE_USER, 471 POLICY_SCOPE_USER,
472 POLICY_SOURCE_CLOUD,
470 new base::StringValue(kFakeONC), 473 new base::StringValue(kFakeONC),
471 NULL); 474 NULL);
472 UpdateProviderPolicy(policy); 475 UpdateProviderPolicy(policy);
473 base::RunLoop().RunUntilIdle(); 476 base::RunLoop().RunUntilIdle();
474 477
475 // Certificates with the "Web" trust flag set will be returned and forwarded 478 // Certificates with the "Web" trust flag set will be returned and forwarded
476 // to observers. 479 // to observers.
477 { 480 {
478 net::CertificateList trust_anchors; 481 net::CertificateList trust_anchors;
479 updater->GetWebTrustedCertificates(&trust_anchors); 482 updater->GetWebTrustedCertificates(&trust_anchors);
480 EXPECT_EQ(1u, trust_anchors.size()); 483 EXPECT_EQ(1u, trust_anchors.size());
481 } 484 }
482 EXPECT_EQ(1u, observer.trust_anchors_.size()); 485 EXPECT_EQ(1u, observer.trust_anchors_.size());
483 486
484 updater->RemoveTrustedCertsObserver(&observer); 487 updater->RemoveTrustedCertsObserver(&observer);
485 } 488 }
486 489
487 TEST_F(NetworkConfigurationUpdaterTest, 490 TEST_F(NetworkConfigurationUpdaterTest,
488 DontImportCertificateBeforeCertificateImporterSet) { 491 DontImportCertificateBeforeCertificateImporterSet) {
489 PolicyMap policy; 492 PolicyMap policy;
490 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, 493 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
491 POLICY_SCOPE_USER, new base::StringValue(kFakeONC), NULL); 494 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
495 new base::StringValue(kFakeONC), nullptr);
492 UpdateProviderPolicy(policy); 496 UpdateProviderPolicy(policy);
493 497
494 EXPECT_CALL(network_config_handler_, 498 EXPECT_CALL(network_config_handler_,
495 SetPolicy(onc::ONC_SOURCE_USER_POLICY, 499 SetPolicy(onc::ONC_SOURCE_USER_POLICY,
496 kFakeUsernameHash, 500 kFakeUsernameHash,
497 IsEqualTo(&fake_network_configs_), 501 IsEqualTo(&fake_network_configs_),
498 IsEqualTo(&fake_global_network_config_))); 502 IsEqualTo(&fake_global_network_config_)));
499 503
500 UserNetworkConfigurationUpdater* updater = 504 UserNetworkConfigurationUpdater* updater =
501 CreateNetworkConfigurationUpdaterForUserPolicy( 505 CreateNetworkConfigurationUpdaterForUserPolicy(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 true /* set certificate importer */); 551 true /* set certificate importer */);
548 } else { 552 } else {
549 CreateNetworkConfigurationUpdaterForDevicePolicy(); 553 CreateNetworkConfigurationUpdaterForDevicePolicy();
550 } 554 }
551 } 555 }
552 }; 556 };
553 557
554 TEST_P(NetworkConfigurationUpdaterTestWithParam, InitialUpdates) { 558 TEST_P(NetworkConfigurationUpdaterTestWithParam, InitialUpdates) {
555 PolicyMap policy; 559 PolicyMap policy;
556 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 560 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
557 new base::StringValue(kFakeONC), NULL); 561 POLICY_SOURCE_CLOUD, new base::StringValue(kFakeONC), nullptr);
558 UpdateProviderPolicy(policy); 562 UpdateProviderPolicy(policy);
559 563
560 EXPECT_CALL(network_config_handler_, 564 EXPECT_CALL(network_config_handler_,
561 SetPolicy(CurrentONCSource(), 565 SetPolicy(CurrentONCSource(),
562 ExpectedUsernameHash(), 566 ExpectedUsernameHash(),
563 IsEqualTo(&fake_network_configs_), 567 IsEqualTo(&fake_network_configs_),
564 IsEqualTo(&fake_global_network_config_))); 568 IsEqualTo(&fake_global_network_config_)));
565 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); 569 certificate_importer_->SetExpectedONCCertificates(fake_certificates_);
566 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); 570 certificate_importer_->SetExpectedONCSource(CurrentONCSource());
567 571
568 CreateNetworkConfigurationUpdater(); 572 CreateNetworkConfigurationUpdater();
569 MarkPolicyProviderInitialized(); 573 MarkPolicyProviderInitialized();
570 EXPECT_EQ(ExpectedImportCertificatesCallCount(), 574 EXPECT_EQ(ExpectedImportCertificatesCallCount(),
571 certificate_importer_->GetAndResetImportCount()); 575 certificate_importer_->GetAndResetImportCount());
572 } 576 }
573 577
574 TEST_P(NetworkConfigurationUpdaterTestWithParam, 578 TEST_P(NetworkConfigurationUpdaterTestWithParam,
575 PolicyNotSetBeforePolicyProviderInitialized) { 579 PolicyNotSetBeforePolicyProviderInitialized) {
576 PolicyMap policy; 580 PolicyMap policy;
577 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 581 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
578 new base::StringValue(kFakeONC), NULL); 582 POLICY_SOURCE_CLOUD, new base::StringValue(kFakeONC), nullptr);
579 UpdateProviderPolicy(policy); 583 UpdateProviderPolicy(policy);
580 584
581 CreateNetworkConfigurationUpdater(); 585 CreateNetworkConfigurationUpdater();
582 586
583 Mock::VerifyAndClearExpectations(&network_config_handler_); 587 Mock::VerifyAndClearExpectations(&network_config_handler_);
584 EXPECT_EQ(0u, certificate_importer_->GetAndResetImportCount()); 588 EXPECT_EQ(0u, certificate_importer_->GetAndResetImportCount());
585 589
586 EXPECT_CALL(network_config_handler_, 590 EXPECT_CALL(network_config_handler_,
587 SetPolicy(CurrentONCSource(), 591 SetPolicy(CurrentONCSource(),
588 ExpectedUsernameHash(), 592 ExpectedUsernameHash(),
589 IsEqualTo(&fake_network_configs_), 593 IsEqualTo(&fake_network_configs_),
590 IsEqualTo(&fake_global_network_config_))); 594 IsEqualTo(&fake_global_network_config_)));
591 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); 595 certificate_importer_->SetExpectedONCSource(CurrentONCSource());
592 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); 596 certificate_importer_->SetExpectedONCCertificates(fake_certificates_);
593 597
594 MarkPolicyProviderInitialized(); 598 MarkPolicyProviderInitialized();
595 EXPECT_EQ(ExpectedImportCertificatesCallCount(), 599 EXPECT_EQ(ExpectedImportCertificatesCallCount(),
596 certificate_importer_->GetAndResetImportCount()); 600 certificate_importer_->GetAndResetImportCount());
597 } 601 }
598 602
599 TEST_P(NetworkConfigurationUpdaterTestWithParam, 603 TEST_P(NetworkConfigurationUpdaterTestWithParam,
600 PolicyAppliedImmediatelyIfProvidersInitialized) { 604 PolicyAppliedImmediatelyIfProvidersInitialized) {
601 MarkPolicyProviderInitialized(); 605 MarkPolicyProviderInitialized();
602 606
603 PolicyMap policy; 607 PolicyMap policy;
604 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 608 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
605 new base::StringValue(kFakeONC), NULL); 609 POLICY_SOURCE_CLOUD, new base::StringValue(kFakeONC), nullptr);
606 UpdateProviderPolicy(policy); 610 UpdateProviderPolicy(policy);
607 611
608 EXPECT_CALL(network_config_handler_, 612 EXPECT_CALL(network_config_handler_,
609 SetPolicy(CurrentONCSource(), 613 SetPolicy(CurrentONCSource(),
610 ExpectedUsernameHash(), 614 ExpectedUsernameHash(),
611 IsEqualTo(&fake_network_configs_), 615 IsEqualTo(&fake_network_configs_),
612 IsEqualTo(&fake_global_network_config_))); 616 IsEqualTo(&fake_global_network_config_)));
613 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); 617 certificate_importer_->SetExpectedONCSource(CurrentONCSource());
614 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); 618 certificate_importer_->SetExpectedONCCertificates(fake_certificates_);
615 619
(...skipping 18 matching lines...) Expand all
634 EXPECT_CALL(network_config_handler_, 638 EXPECT_CALL(network_config_handler_,
635 SetPolicy(CurrentONCSource(), 639 SetPolicy(CurrentONCSource(),
636 _, 640 _,
637 IsEqualTo(&fake_network_configs_), 641 IsEqualTo(&fake_network_configs_),
638 IsEqualTo(&fake_global_network_config_))); 642 IsEqualTo(&fake_global_network_config_)));
639 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); 643 certificate_importer_->SetExpectedONCSource(CurrentONCSource());
640 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); 644 certificate_importer_->SetExpectedONCCertificates(fake_certificates_);
641 645
642 PolicyMap policy; 646 PolicyMap policy;
643 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 647 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
644 new base::StringValue(kFakeONC), NULL); 648 POLICY_SOURCE_CLOUD, new base::StringValue(kFakeONC), nullptr);
645 UpdateProviderPolicy(policy); 649 UpdateProviderPolicy(policy);
646 Mock::VerifyAndClearExpectations(&network_config_handler_); 650 Mock::VerifyAndClearExpectations(&network_config_handler_);
647 EXPECT_EQ(ExpectedImportCertificatesCallCount(), 651 EXPECT_EQ(ExpectedImportCertificatesCallCount(),
648 certificate_importer_->GetAndResetImportCount()); 652 certificate_importer_->GetAndResetImportCount());
649 653
650 // Another update is expected if the policy goes away. 654 // Another update is expected if the policy goes away.
651 EXPECT_CALL(network_config_handler_, 655 EXPECT_CALL(network_config_handler_,
652 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty())); 656 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty()));
653 certificate_importer_->SetExpectedONCCertificates(base::ListValue()); 657 certificate_importer_->SetExpectedONCCertificates(base::ListValue());
654 658
655 policy.Erase(GetParam()); 659 policy.Erase(GetParam());
656 UpdateProviderPolicy(policy); 660 UpdateProviderPolicy(policy);
657 EXPECT_EQ(ExpectedImportCertificatesCallCount(), 661 EXPECT_EQ(ExpectedImportCertificatesCallCount(),
658 certificate_importer_->GetAndResetImportCount()); 662 certificate_importer_->GetAndResetImportCount());
659 } 663 }
660 664
661 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, 665 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance,
662 NetworkConfigurationUpdaterTestWithParam, 666 NetworkConfigurationUpdaterTestWithParam,
663 testing::Values(key::kDeviceOpenNetworkConfiguration, 667 testing::Values(key::kDeviceOpenNetworkConfiguration,
664 key::kOpenNetworkConfiguration)); 668 key::kOpenNetworkConfiguration));
665 669
666 } // namespace policy 670 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698