| 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/device_settings_test_helper.h" |
| 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 18 #include "chromeos/network/fake_network_device_handler.h" | 19 #include "chromeos/network/fake_network_device_handler.h" |
| 19 #include "chromeos/network/mock_managed_network_configuration_handler.h" | 20 #include "chromeos/network/mock_managed_network_configuration_handler.h" |
| 20 #include "chromeos/network/onc/onc_certificate_importer.h" | 21 #include "chromeos/network/onc/onc_certificate_importer.h" |
| 21 #include "chromeos/network/onc/onc_test_utils.h" | 22 #include "chromeos/network/onc/onc_test_utils.h" |
| 22 #include "chromeos/network/onc/onc_utils.h" | 23 #include "chromeos/network/onc/onc_utils.h" |
| 23 #include "components/onc/onc_constants.h" | 24 #include "components/onc/onc_constants.h" |
| 24 #include "components/policy/core/common/external_data_fetcher.h" | 25 #include "components/policy/core/common/external_data_fetcher.h" |
| 25 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 26 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 192 } |
| 192 | 193 |
| 193 ACTION_P(SetCertificateList, list) { | 194 ACTION_P(SetCertificateList, list) { |
| 194 if (arg2) | 195 if (arg2) |
| 195 *arg2 = list; | 196 *arg2 = list; |
| 196 return true; | 197 return true; |
| 197 } | 198 } |
| 198 | 199 |
| 199 } // namespace | 200 } // namespace |
| 200 | 201 |
| 201 class NetworkConfigurationUpdaterTest : public testing::Test { | 202 class NetworkConfigurationUpdaterTest : public chromeos::OwnerSettingsTestBase { |
| 202 protected: | 203 protected: |
| 203 NetworkConfigurationUpdaterTest() : certificate_importer_(NULL) {} | 204 NetworkConfigurationUpdaterTest() : certificate_importer_(NULL) {} |
| 204 | 205 |
| 205 virtual void SetUp() override { | 206 virtual void SetUp() override { |
| 207 chromeos::OwnerSettingsTestBase::SetUp(); |
| 206 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 208 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 207 .WillRepeatedly(Return(false)); | 209 .WillRepeatedly(Return(false)); |
| 208 provider_.Init(); | 210 provider_.Init(); |
| 209 PolicyServiceImpl::Providers providers; | 211 PolicyServiceImpl::Providers providers; |
| 210 providers.push_back(&provider_); | 212 providers.push_back(&provider_); |
| 211 policy_service_.reset(new PolicyServiceImpl(providers)); | 213 policy_service_.reset(new PolicyServiceImpl(providers)); |
| 212 | 214 |
| 213 scoped_ptr<base::DictionaryValue> fake_toplevel_onc = | 215 scoped_ptr<base::DictionaryValue> fake_toplevel_onc = |
| 214 chromeos::onc::ReadDictionaryFromJson(kFakeONC); | 216 chromeos::onc::ReadDictionaryFromJson(kFakeONC); |
| 215 | 217 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 226 base::ListValue* certs = NULL; | 228 base::ListValue* certs = NULL; |
| 227 fake_toplevel_onc->GetListWithoutPathExpansion( | 229 fake_toplevel_onc->GetListWithoutPathExpansion( |
| 228 onc::toplevel_config::kCertificates, &certs); | 230 onc::toplevel_config::kCertificates, &certs); |
| 229 AppendAll(*certs, &fake_certificates_); | 231 AppendAll(*certs, &fake_certificates_); |
| 230 | 232 |
| 231 certificate_importer_ = new FakeCertificateImporter; | 233 certificate_importer_ = new FakeCertificateImporter; |
| 232 certificate_importer_owned_.reset(certificate_importer_); | 234 certificate_importer_owned_.reset(certificate_importer_); |
| 233 } | 235 } |
| 234 | 236 |
| 235 virtual void TearDown() override { | 237 virtual void TearDown() override { |
| 238 chromeos::OwnerSettingsTestBase::TearDown(); |
| 236 network_configuration_updater_.reset(); | 239 network_configuration_updater_.reset(); |
| 237 provider_.Shutdown(); | 240 provider_.Shutdown(); |
| 238 base::RunLoop().RunUntilIdle(); | 241 base::RunLoop().RunUntilIdle(); |
| 239 } | 242 } |
| 240 | 243 |
| 241 void MarkPolicyProviderInitialized() { | 244 void MarkPolicyProviderInitialized() { |
| 242 Mock::VerifyAndClearExpectations(&provider_); | 245 Mock::VerifyAndClearExpectations(&provider_); |
| 243 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 246 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 244 .WillRepeatedly(Return(true)); | 247 .WillRepeatedly(Return(true)); |
| 245 provider_.SetAutoRefresh(); | 248 provider_.SetAutoRefresh(); |
| 246 provider_.RefreshPolicies(); | 249 provider_.RefreshPolicies(); |
| 247 base::RunLoop().RunUntilIdle(); | 250 base::RunLoop().RunUntilIdle(); |
| 248 } | 251 } |
| 249 | 252 |
| 250 void UpdateProviderPolicy(const PolicyMap& policy) { | 253 void UpdateProviderPolicy(const PolicyMap& policy) { |
| 251 provider_.UpdateChromePolicy(policy); | 254 provider_.UpdateChromePolicy(policy); |
| 252 base::RunLoop().RunUntilIdle(); | 255 base::RunLoop().RunUntilIdle(); |
| 253 } | 256 } |
| 254 | 257 |
| 255 UserNetworkConfigurationUpdater* | 258 UserNetworkConfigurationUpdater* |
| 256 CreateNetworkConfigurationUpdaterForUserPolicy( | 259 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 257 bool allow_trusted_certs_from_policy, | 260 bool allow_trusted_certs_from_policy, |
| 258 bool set_cert_importer) { | 261 bool set_cert_importer) { |
| 259 UserNetworkConfigurationUpdater* updater = | 262 UserNetworkConfigurationUpdater* updater = |
| 260 UserNetworkConfigurationUpdater::CreateForUserPolicy( | 263 UserNetworkConfigurationUpdater::CreateForUserPolicy( |
| 261 &profile_, | 264 profile_.get(), allow_trusted_certs_from_policy, fake_user_, |
| 262 allow_trusted_certs_from_policy, | 265 policy_service_.get(), &network_config_handler_).release(); |
| 263 fake_user_, | |
| 264 policy_service_.get(), | |
| 265 &network_config_handler_).release(); | |
| 266 if (set_cert_importer) { | 266 if (set_cert_importer) { |
| 267 EXPECT_TRUE(certificate_importer_owned_); | 267 EXPECT_TRUE(certificate_importer_owned_); |
| 268 updater->SetCertificateImporterForTest( | 268 updater->SetCertificateImporterForTest( |
| 269 certificate_importer_owned_.Pass()); | 269 certificate_importer_owned_.Pass()); |
| 270 } | 270 } |
| 271 network_configuration_updater_.reset(updater); | 271 network_configuration_updater_.reset(updater); |
| 272 return updater; | 272 return updater; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void CreateNetworkConfigurationUpdaterForDevicePolicy() { | 275 void CreateNetworkConfigurationUpdaterForDevicePolicy() { |
| 276 network_configuration_updater_ = | 276 network_configuration_updater_ = |
| 277 DeviceNetworkConfigurationUpdater::CreateForDevicePolicy( | 277 DeviceNetworkConfigurationUpdater::CreateForDevicePolicy( |
| 278 policy_service_.get(), | 278 policy_service_.get(), |
| 279 &network_config_handler_, | 279 &network_config_handler_, |
| 280 &network_device_handler_, | 280 &network_device_handler_, |
| 281 chromeos::CrosSettings::Get()); | 281 chromeos::CrosSettings::Get()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 base::ListValue fake_network_configs_; | 284 base::ListValue fake_network_configs_; |
| 285 base::DictionaryValue fake_global_network_config_; | 285 base::DictionaryValue fake_global_network_config_; |
| 286 base::ListValue fake_certificates_; | 286 base::ListValue fake_certificates_; |
| 287 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> | 287 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> |
| 288 network_config_handler_; | 288 network_config_handler_; |
| 289 FakeNetworkDeviceHandler network_device_handler_; | 289 FakeNetworkDeviceHandler network_device_handler_; |
| 290 | 290 |
| 291 // Not used directly. Required for CrosSettings. | |
| 292 chromeos::ScopedTestDeviceSettingsService scoped_device_settings_service_; | |
| 293 chromeos::ScopedTestCrosSettings scoped_cros_settings_; | |
| 294 | |
| 295 // Ownership of certificate_importer_owned_ is passed to the | 291 // Ownership of certificate_importer_owned_ is passed to the |
| 296 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| | 292 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| |
| 297 // continues to point to that instance but |certificate_importer_owned_| is | 293 // continues to point to that instance but |certificate_importer_owned_| is |
| 298 // released. | 294 // released. |
| 299 FakeCertificateImporter* certificate_importer_; | 295 FakeCertificateImporter* certificate_importer_; |
| 300 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; | 296 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; |
| 301 | 297 |
| 302 StrictMock<MockConfigurationPolicyProvider> provider_; | 298 StrictMock<MockConfigurationPolicyProvider> provider_; |
| 303 scoped_ptr<PolicyServiceImpl> policy_service_; | 299 scoped_ptr<PolicyServiceImpl> policy_service_; |
| 304 FakeUser fake_user_; | 300 FakeUser fake_user_; |
| 305 | 301 |
| 306 TestingProfile profile_; | |
| 307 | |
| 308 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; | 302 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; |
| 309 content::TestBrowserThreadBundle thread_bundle_; | |
| 310 }; | 303 }; |
| 311 | 304 |
| 312 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { | 305 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { |
| 313 // Ignore network config updates. | 306 // Ignore network config updates. |
| 314 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); | 307 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); |
| 315 | 308 |
| 316 // Setup the DataRoaming device setting. | 309 ReplaceProvider(chromeos::kSignedDataRoamingEnabled); |
| 317 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); | 310 owner_settings_service_->SetBoolean(chromeos::kSignedDataRoamingEnabled, |
| 318 chromeos::CrosSettingsProvider* device_settings_provider = | 311 false); |
| 319 cros_settings->GetProvider(chromeos::kSignedDataRoamingEnabled); | |
| 320 cros_settings->RemoveSettingsProvider(device_settings_provider); | |
| 321 delete device_settings_provider; | |
| 322 chromeos::StubCrosSettingsProvider* stub_settings_provider = | |
| 323 new chromeos::StubCrosSettingsProvider; | |
| 324 cros_settings->AddSettingsProvider(stub_settings_provider); | |
| 325 | |
| 326 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, | |
| 327 base::FundamentalValue(false)); | |
| 328 EXPECT_FALSE(network_device_handler_.allow_roaming_); | 312 EXPECT_FALSE(network_device_handler_.allow_roaming_); |
| 329 | 313 |
| 330 CreateNetworkConfigurationUpdaterForDevicePolicy(); | 314 CreateNetworkConfigurationUpdaterForDevicePolicy(); |
| 331 MarkPolicyProviderInitialized(); | 315 MarkPolicyProviderInitialized(); |
| 332 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, | 316 owner_settings_service_->SetBoolean(chromeos::kSignedDataRoamingEnabled, |
| 333 base::FundamentalValue(true)); | 317 true); |
| 334 EXPECT_TRUE(network_device_handler_.allow_roaming_); | 318 EXPECT_TRUE(network_device_handler_.allow_roaming_); |
| 335 | 319 |
| 336 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, | 320 owner_settings_service_->SetBoolean(chromeos::kSignedDataRoamingEnabled, |
| 337 base::FundamentalValue(false)); | 321 false); |
| 338 EXPECT_FALSE(network_device_handler_.allow_roaming_); | 322 EXPECT_FALSE(network_device_handler_.allow_roaming_); |
| 339 } | 323 } |
| 340 | 324 |
| 341 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { | 325 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { |
| 342 scoped_ptr<base::DictionaryValue> onc_repaired = | 326 scoped_ptr<base::DictionaryValue> onc_repaired = |
| 343 chromeos::onc::test_utils::ReadTestDictionary( | 327 chromeos::onc::test_utils::ReadTestDictionary( |
| 344 "repaired_toplevel_partially_invalid.onc"); | 328 "repaired_toplevel_partially_invalid.onc"); |
| 345 | 329 |
| 346 base::ListValue* network_configs_repaired = NULL; | 330 base::ListValue* network_configs_repaired = NULL; |
| 347 onc_repaired->GetListWithoutPathExpansion( | 331 onc_repaired->GetListWithoutPathExpansion( |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 EXPECT_EQ(ExpectedImportCertificatesCallCount(), | 657 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
| 674 certificate_importer_->GetAndResetImportCount()); | 658 certificate_importer_->GetAndResetImportCount()); |
| 675 } | 659 } |
| 676 | 660 |
| 677 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, | 661 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, |
| 678 NetworkConfigurationUpdaterTestWithParam, | 662 NetworkConfigurationUpdaterTestWithParam, |
| 679 testing::Values(key::kDeviceOpenNetworkConfiguration, | 663 testing::Values(key::kDeviceOpenNetworkConfiguration, |
| 680 key::kOpenNetworkConfiguration)); | 664 key::kOpenNetworkConfiguration)); |
| 681 | 665 |
| 682 } // namespace policy | 666 } // namespace policy |
| OLD | NEW |