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

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

Issue 2677563005: Chromad: Use DM server reply to determine enrollment type (Closed)
Patch Set: Thiemo's comments Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
22 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" 22 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
23 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 23 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
24 #include "chrome/browser/chromeos/policy/enrollment_config.h" 24 #include "chrome/browser/chromeos/policy/enrollment_config.h"
25 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 25 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
26 #include "chrome/browser/chromeos/policy/fake_active_directory_join_delegate.h"
26 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 27 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
27 #include "chrome/browser/chromeos/settings/cros_settings.h" 28 #include "chrome/browser/chromeos/settings/cros_settings.h"
28 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 29 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
29 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 30 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
30 #include "chrome/browser/chromeos/settings/device_settings_service.h" 31 #include "chrome/browser/chromeos/settings/device_settings_service.h"
31 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 32 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
32 #include "chrome/browser/chromeos/settings/install_attributes.h" 33 #include "chrome/browser/chromeos/settings/install_attributes.h"
33 #include "chrome/browser/prefs/browser_prefs.h" 34 #include "chrome/browser/prefs/browser_prefs.h"
34 #include "chrome/test/base/testing_browser_process.h" 35 #include "chrome/test/base/testing_browser_process.h"
35 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 manager_->AddDeviceCloudPolicyManagerObserver(this); 217 manager_->AddDeviceCloudPolicyManagerObserver(this);
217 initializer_ = base::MakeUnique<DeviceCloudPolicyInitializer>( 218 initializer_ = base::MakeUnique<DeviceCloudPolicyInitializer>(
218 &local_state_, &device_management_service_, 219 &local_state_, &device_management_service_,
219 base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(), 220 base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(),
220 &state_keys_broker_, store_, manager_.get(), 221 &state_keys_broker_, store_, manager_.get(),
221 cryptohome::AsyncMethodCaller::GetInstance(), std::move(unique_flow), 222 cryptohome::AsyncMethodCaller::GetInstance(), std::move(unique_flow),
222 &fake_statistics_provider_); 223 &fake_statistics_provider_);
223 initializer_->SetSigningServiceForTesting( 224 initializer_->SetSigningServiceForTesting(
224 base::MakeUnique<FakeSigningService>()); 225 base::MakeUnique<FakeSigningService>());
225 initializer_->Init(); 226 initializer_->Init();
227 fake_ad_join_delegate_ =
228 base::MakeUnique<chromeos::FakeActiveDirectoryJoinDelegate>();
226 } 229 }
227 230
228 void VerifyPolicyPopulated() { 231 void VerifyPolicyPopulated() {
229 PolicyBundle bundle; 232 PolicyBundle bundle;
230 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 233 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
231 .Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY, 234 .Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY,
232 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, 235 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
233 base::MakeUnique<base::FundamentalValue>(false), nullptr); 236 base::MakeUnique<base::FundamentalValue>(false), nullptr);
234 EXPECT_TRUE(manager_->policies().Equals(bundle)); 237 EXPECT_TRUE(manager_->policies().Equals(bundle));
235 } 238 }
(...skipping 27 matching lines...) Expand all
263 chromeos::ScopedTestCrosSettings test_cros_settings_; 266 chromeos::ScopedTestCrosSettings test_cros_settings_;
264 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; 267 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_;
265 chromeos::FakeSessionManagerClient fake_session_manager_client_; 268 chromeos::FakeSessionManagerClient fake_session_manager_client_;
266 chromeos::FakeCryptohomeClient* fake_cryptohome_client_; 269 chromeos::FakeCryptohomeClient* fake_cryptohome_client_;
267 ServerBackedStateKeysBroker state_keys_broker_; 270 ServerBackedStateKeysBroker state_keys_broker_;
268 271
269 DeviceCloudPolicyStoreChromeOS* store_; 272 DeviceCloudPolicyStoreChromeOS* store_;
270 SchemaRegistry schema_registry_; 273 SchemaRegistry schema_registry_;
271 std::unique_ptr<TestingDeviceCloudPolicyManagerChromeOS> manager_; 274 std::unique_ptr<TestingDeviceCloudPolicyManagerChromeOS> manager_;
272 std::unique_ptr<DeviceCloudPolicyInitializer> initializer_; 275 std::unique_ptr<DeviceCloudPolicyInitializer> initializer_;
276 std::unique_ptr<chromeos::FakeActiveDirectoryJoinDelegate>
277 fake_ad_join_delegate_;
278
273 private: 279 private:
274 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSTest); 280 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSTest);
275 }; 281 };
276 282
277 TEST_F(DeviceCloudPolicyManagerChromeOSTest, FreshDevice) { 283 TEST_F(DeviceCloudPolicyManagerChromeOSTest, FreshDevice) {
278 owner_key_util_->Clear(); 284 owner_key_util_->Clear();
279 FlushDeviceSettings(); 285 FlushDeviceSettings();
280 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 286 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
281 287
282 manager_->Initialize(&local_state_); 288 manager_->Initialize(&local_state_);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 profile_.get()); 503 profile_.get());
498 ASSERT_TRUE(owner_settings_service); 504 ASSERT_TRUE(owner_settings_service);
499 505
500 EnrollmentConfig enrollment_config; 506 EnrollmentConfig enrollment_config;
501 enrollment_config.auth_mechanism = 507 enrollment_config.auth_mechanism =
502 EnrollmentConfig::AUTH_MECHANISM_BEST_AVAILABLE; 508 EnrollmentConfig::AUTH_MECHANISM_BEST_AVAILABLE;
503 enrollment_config.mode = with_cert ? EnrollmentConfig::MODE_ATTESTATION 509 enrollment_config.mode = with_cert ? EnrollmentConfig::MODE_ATTESTATION
504 : EnrollmentConfig::MODE_MANUAL; 510 : EnrollmentConfig::MODE_MANUAL;
505 std::string token = with_cert ? "" : "auth token"; 511 std::string token = with_cert ? "" : "auth token";
506 initializer_->StartEnrollment( 512 initializer_->StartEnrollment(
507 &device_management_service_, enrollment_config, token, 513 &device_management_service_, fake_ad_join_delegate_.get(),
Thiemo Nagel 2017/02/14 16:43:06 nullptr?
Roman Sorokin (ftl) 2017/02/15 14:01:45 Done.
514 enrollment_config, token,
508 base::Bind(&DeviceCloudPolicyManagerChromeOSEnrollmentTest::Done, 515 base::Bind(&DeviceCloudPolicyManagerChromeOSEnrollmentTest::Done,
509 base::Unretained(this))); 516 base::Unretained(this)));
510 base::RunLoop().RunUntilIdle(); 517 base::RunLoop().RunUntilIdle();
511 Mock::VerifyAndClearExpectations(&device_management_service_); 518 Mock::VerifyAndClearExpectations(&device_management_service_);
512 AllowUninterestingRemoteCommandFetches(); 519 AllowUninterestingRemoteCommandFetches();
513 520
514 if (done_) 521 if (done_)
515 return; 522 return;
516 523
517 // Process registration. 524 // Process registration.
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 DeviceCloudPolicyManagerChromeOSEnrollmentTest, 828 DeviceCloudPolicyManagerChromeOSEnrollmentTest,
822 ::testing::Values(false, true)); 829 ::testing::Values(false, true));
823 830
824 INSTANTIATE_TEST_CASE_P( 831 INSTANTIATE_TEST_CASE_P(
825 Cert, 832 Cert,
826 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, 833 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest,
827 ::testing::Values(false, true)); 834 ::testing::Values(false, true));
828 835
829 } // namespace 836 } // namespace
830 } // namespace policy 837 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698