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

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

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

Powered by Google App Engine
This is Rietveld 408576698