| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 onc_repaired->GetDictionaryWithoutPathExpansion( | 351 onc_repaired->GetDictionaryWithoutPathExpansion( |
| 352 onc::toplevel_config::kGlobalNetworkConfiguration, | 352 onc::toplevel_config::kGlobalNetworkConfiguration, |
| 353 &global_config_repaired); | 353 &global_config_repaired); |
| 354 ASSERT_TRUE(global_config_repaired); | 354 ASSERT_TRUE(global_config_repaired); |
| 355 | 355 |
| 356 std::string onc_policy = | 356 std::string onc_policy = |
| 357 chromeos::onc::test_utils::ReadTestData("toplevel_partially_invalid.onc"); | 357 chromeos::onc::test_utils::ReadTestData("toplevel_partially_invalid.onc"); |
| 358 PolicyMap policy; | 358 PolicyMap policy; |
| 359 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, | 359 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, |
| 360 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 360 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 361 base::WrapUnique(new base::StringValue(onc_policy)), nullptr); | 361 base::MakeUnique<base::StringValue>(onc_policy), nullptr); |
| 362 UpdateProviderPolicy(policy); | 362 UpdateProviderPolicy(policy); |
| 363 | 363 |
| 364 EXPECT_CALL(network_config_handler_, | 364 EXPECT_CALL(network_config_handler_, |
| 365 SetPolicy(onc::ONC_SOURCE_USER_POLICY, | 365 SetPolicy(onc::ONC_SOURCE_USER_POLICY, |
| 366 _, | 366 _, |
| 367 IsEqualTo(network_configs_repaired), | 367 IsEqualTo(network_configs_repaired), |
| 368 IsEqualTo(global_config_repaired))); | 368 IsEqualTo(global_config_repaired))); |
| 369 certificate_importer_->SetExpectedONCSource(onc::ONC_SOURCE_USER_POLICY); | 369 certificate_importer_->SetExpectedONCSource(onc::ONC_SOURCE_USER_POLICY); |
| 370 | 370 |
| 371 CreateNetworkConfigurationUpdaterForUserPolicy( | 371 CreateNetworkConfigurationUpdaterForUserPolicy( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 "ok_cert.pem", | 472 "ok_cert.pem", |
| 473 net::X509Certificate::FORMAT_AUTO); | 473 net::X509Certificate::FORMAT_AUTO); |
| 474 ASSERT_EQ(1u, cert_list.size()); | 474 ASSERT_EQ(1u, cert_list.size()); |
| 475 certificate_importer_->SetTrustedCertificatesResult(cert_list); | 475 certificate_importer_->SetTrustedCertificatesResult(cert_list); |
| 476 | 476 |
| 477 // Change to any non-empty policy, so that updates are triggered. The actual | 477 // Change to any non-empty policy, so that updates are triggered. The actual |
| 478 // content of the policy is irrelevant. | 478 // content of the policy is irrelevant. |
| 479 PolicyMap policy; | 479 PolicyMap policy; |
| 480 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, | 480 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, |
| 481 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 481 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 482 base::WrapUnique(new base::StringValue(kFakeONC)), nullptr); | 482 base::MakeUnique<base::StringValue>(kFakeONC), nullptr); |
| 483 UpdateProviderPolicy(policy); | 483 UpdateProviderPolicy(policy); |
| 484 base::RunLoop().RunUntilIdle(); | 484 base::RunLoop().RunUntilIdle(); |
| 485 | 485 |
| 486 // Certificates with the "Web" trust flag set will be returned and forwarded | 486 // Certificates with the "Web" trust flag set will be returned and forwarded |
| 487 // to observers. | 487 // to observers. |
| 488 { | 488 { |
| 489 net::CertificateList trust_anchors; | 489 net::CertificateList trust_anchors; |
| 490 updater->GetWebTrustedCertificates(&trust_anchors); | 490 updater->GetWebTrustedCertificates(&trust_anchors); |
| 491 EXPECT_EQ(1u, trust_anchors.size()); | 491 EXPECT_EQ(1u, trust_anchors.size()); |
| 492 } | 492 } |
| 493 EXPECT_EQ(1u, observer.trust_anchors_.size()); | 493 EXPECT_EQ(1u, observer.trust_anchors_.size()); |
| 494 | 494 |
| 495 updater->RemoveTrustedCertsObserver(&observer); | 495 updater->RemoveTrustedCertsObserver(&observer); |
| 496 } | 496 } |
| 497 | 497 |
| 498 TEST_F(NetworkConfigurationUpdaterTest, | 498 TEST_F(NetworkConfigurationUpdaterTest, |
| 499 DontImportCertificateBeforeCertificateImporterSet) { | 499 DontImportCertificateBeforeCertificateImporterSet) { |
| 500 PolicyMap policy; | 500 PolicyMap policy; |
| 501 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, | 501 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, |
| 502 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 502 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 503 base::WrapUnique(new base::StringValue(kFakeONC)), nullptr); | 503 base::MakeUnique<base::StringValue>(kFakeONC), nullptr); |
| 504 UpdateProviderPolicy(policy); | 504 UpdateProviderPolicy(policy); |
| 505 | 505 |
| 506 EXPECT_CALL(network_config_handler_, | 506 EXPECT_CALL(network_config_handler_, |
| 507 SetPolicy(onc::ONC_SOURCE_USER_POLICY, | 507 SetPolicy(onc::ONC_SOURCE_USER_POLICY, |
| 508 kFakeUsernameHash, | 508 kFakeUsernameHash, |
| 509 IsEqualTo(&fake_network_configs_), | 509 IsEqualTo(&fake_network_configs_), |
| 510 IsEqualTo(&fake_global_network_config_))); | 510 IsEqualTo(&fake_global_network_config_))); |
| 511 | 511 |
| 512 UserNetworkConfigurationUpdater* updater = | 512 UserNetworkConfigurationUpdater* updater = |
| 513 CreateNetworkConfigurationUpdaterForUserPolicy( | 513 CreateNetworkConfigurationUpdaterForUserPolicy( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 true /* set certificate importer */); | 560 true /* set certificate importer */); |
| 561 } else { | 561 } else { |
| 562 CreateNetworkConfigurationUpdaterForDevicePolicy(); | 562 CreateNetworkConfigurationUpdaterForDevicePolicy(); |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 }; | 565 }; |
| 566 | 566 |
| 567 TEST_P(NetworkConfigurationUpdaterTestWithParam, InitialUpdates) { | 567 TEST_P(NetworkConfigurationUpdaterTestWithParam, InitialUpdates) { |
| 568 PolicyMap policy; | 568 PolicyMap policy; |
| 569 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 569 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 570 POLICY_SOURCE_CLOUD, | 570 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>(kFakeONC), |
| 571 base::WrapUnique(new base::StringValue(kFakeONC)), nullptr); | 571 nullptr); |
| 572 UpdateProviderPolicy(policy); | 572 UpdateProviderPolicy(policy); |
| 573 | 573 |
| 574 EXPECT_CALL(network_config_handler_, | 574 EXPECT_CALL(network_config_handler_, |
| 575 SetPolicy(CurrentONCSource(), | 575 SetPolicy(CurrentONCSource(), |
| 576 ExpectedUsernameHash(), | 576 ExpectedUsernameHash(), |
| 577 IsEqualTo(&fake_network_configs_), | 577 IsEqualTo(&fake_network_configs_), |
| 578 IsEqualTo(&fake_global_network_config_))); | 578 IsEqualTo(&fake_global_network_config_))); |
| 579 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); | 579 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 580 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); | 580 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 581 | 581 |
| 582 CreateNetworkConfigurationUpdater(); | 582 CreateNetworkConfigurationUpdater(); |
| 583 MarkPolicyProviderInitialized(); | 583 MarkPolicyProviderInitialized(); |
| 584 EXPECT_EQ(ExpectedImportCertificatesCallCount(), | 584 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 585 certificate_importer_->GetAndResetImportCount()); | 585 certificate_importer_->GetAndResetImportCount()); |
| 586 } | 586 } |
| 587 | 587 |
| 588 TEST_P(NetworkConfigurationUpdaterTestWithParam, | 588 TEST_P(NetworkConfigurationUpdaterTestWithParam, |
| 589 PolicyNotSetBeforePolicyProviderInitialized) { | 589 PolicyNotSetBeforePolicyProviderInitialized) { |
| 590 PolicyMap policy; | 590 PolicyMap policy; |
| 591 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 591 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 592 POLICY_SOURCE_CLOUD, | 592 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>(kFakeONC), |
| 593 base::WrapUnique(new base::StringValue(kFakeONC)), nullptr); | 593 nullptr); |
| 594 UpdateProviderPolicy(policy); | 594 UpdateProviderPolicy(policy); |
| 595 | 595 |
| 596 CreateNetworkConfigurationUpdater(); | 596 CreateNetworkConfigurationUpdater(); |
| 597 | 597 |
| 598 Mock::VerifyAndClearExpectations(&network_config_handler_); | 598 Mock::VerifyAndClearExpectations(&network_config_handler_); |
| 599 EXPECT_EQ(0u, certificate_importer_->GetAndResetImportCount()); | 599 EXPECT_EQ(0u, certificate_importer_->GetAndResetImportCount()); |
| 600 | 600 |
| 601 EXPECT_CALL(network_config_handler_, | 601 EXPECT_CALL(network_config_handler_, |
| 602 SetPolicy(CurrentONCSource(), | 602 SetPolicy(CurrentONCSource(), |
| 603 ExpectedUsernameHash(), | 603 ExpectedUsernameHash(), |
| 604 IsEqualTo(&fake_network_configs_), | 604 IsEqualTo(&fake_network_configs_), |
| 605 IsEqualTo(&fake_global_network_config_))); | 605 IsEqualTo(&fake_global_network_config_))); |
| 606 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); | 606 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 607 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); | 607 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 608 | 608 |
| 609 MarkPolicyProviderInitialized(); | 609 MarkPolicyProviderInitialized(); |
| 610 EXPECT_EQ(ExpectedImportCertificatesCallCount(), | 610 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 611 certificate_importer_->GetAndResetImportCount()); | 611 certificate_importer_->GetAndResetImportCount()); |
| 612 } | 612 } |
| 613 | 613 |
| 614 TEST_P(NetworkConfigurationUpdaterTestWithParam, | 614 TEST_P(NetworkConfigurationUpdaterTestWithParam, |
| 615 PolicyAppliedImmediatelyIfProvidersInitialized) { | 615 PolicyAppliedImmediatelyIfProvidersInitialized) { |
| 616 MarkPolicyProviderInitialized(); | 616 MarkPolicyProviderInitialized(); |
| 617 | 617 |
| 618 PolicyMap policy; | 618 PolicyMap policy; |
| 619 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 619 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 620 POLICY_SOURCE_CLOUD, | 620 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>(kFakeONC), |
| 621 base::WrapUnique(new base::StringValue(kFakeONC)), nullptr); | 621 nullptr); |
| 622 UpdateProviderPolicy(policy); | 622 UpdateProviderPolicy(policy); |
| 623 | 623 |
| 624 EXPECT_CALL(network_config_handler_, | 624 EXPECT_CALL(network_config_handler_, |
| 625 SetPolicy(CurrentONCSource(), | 625 SetPolicy(CurrentONCSource(), |
| 626 ExpectedUsernameHash(), | 626 ExpectedUsernameHash(), |
| 627 IsEqualTo(&fake_network_configs_), | 627 IsEqualTo(&fake_network_configs_), |
| 628 IsEqualTo(&fake_global_network_config_))); | 628 IsEqualTo(&fake_global_network_config_))); |
| 629 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); | 629 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 630 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); | 630 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 631 | 631 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 650 EXPECT_CALL(network_config_handler_, | 650 EXPECT_CALL(network_config_handler_, |
| 651 SetPolicy(CurrentONCSource(), | 651 SetPolicy(CurrentONCSource(), |
| 652 _, | 652 _, |
| 653 IsEqualTo(&fake_network_configs_), | 653 IsEqualTo(&fake_network_configs_), |
| 654 IsEqualTo(&fake_global_network_config_))); | 654 IsEqualTo(&fake_global_network_config_))); |
| 655 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); | 655 certificate_importer_->SetExpectedONCSource(CurrentONCSource()); |
| 656 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); | 656 certificate_importer_->SetExpectedONCCertificates(fake_certificates_); |
| 657 | 657 |
| 658 PolicyMap policy; | 658 PolicyMap policy; |
| 659 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 659 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 660 POLICY_SOURCE_CLOUD, | 660 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>(kFakeONC), |
| 661 base::WrapUnique(new base::StringValue(kFakeONC)), nullptr); | 661 nullptr); |
| 662 UpdateProviderPolicy(policy); | 662 UpdateProviderPolicy(policy); |
| 663 Mock::VerifyAndClearExpectations(&network_config_handler_); | 663 Mock::VerifyAndClearExpectations(&network_config_handler_); |
| 664 EXPECT_EQ(ExpectedImportCertificatesCallCount(), | 664 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 665 certificate_importer_->GetAndResetImportCount()); | 665 certificate_importer_->GetAndResetImportCount()); |
| 666 | 666 |
| 667 // Another update is expected if the policy goes away. | 667 // Another update is expected if the policy goes away. |
| 668 EXPECT_CALL(network_config_handler_, | 668 EXPECT_CALL(network_config_handler_, |
| 669 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty())); | 669 SetPolicy(CurrentONCSource(), _, IsEmpty(), IsEmpty())); |
| 670 certificate_importer_->SetExpectedONCCertificates(base::ListValue()); | 670 certificate_importer_->SetExpectedONCCertificates(base::ListValue()); |
| 671 | 671 |
| 672 policy.Erase(GetParam()); | 672 policy.Erase(GetParam()); |
| 673 UpdateProviderPolicy(policy); | 673 UpdateProviderPolicy(policy); |
| 674 EXPECT_EQ(ExpectedImportCertificatesCallCount(), | 674 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 675 certificate_importer_->GetAndResetImportCount()); | 675 certificate_importer_->GetAndResetImportCount()); |
| 676 } | 676 } |
| 677 | 677 |
| 678 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, | 678 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, |
| 679 NetworkConfigurationUpdaterTestWithParam, | 679 NetworkConfigurationUpdaterTestWithParam, |
| 680 testing::Values(key::kDeviceOpenNetworkConfiguration, | 680 testing::Values(key::kDeviceOpenNetworkConfiguration, |
| 681 key::kOpenNetworkConfiguration)); | 681 key::kOpenNetworkConfiguration)); |
| 682 | 682 |
| 683 } // namespace policy | 683 } // namespace policy |
| OLD | NEW |