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

Side by Side Diff: components/arc/arc_util_unittest.cc

Issue 2890843002: Policy implementation for encryptfs to ext4 migration strategy (Closed)
Patch Set: Fixed review comments Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/arc/arc_util.h" 5 #include "components/arc/arc_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/shared/app_types.h" 10 #include "ash/shared/app_types.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/test/scoped_feature_list.h" 14 #include "base/test/scoped_feature_list.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/prefs/pref_registry_simple.h"
17 #include "components/prefs/pref_service.h"
18 #include "components/prefs/pref_service_factory.h"
19 #include "components/prefs/testing_pref_store.h"
15 #include "components/signin/core/account_id/account_id.h" 20 #include "components/signin/core/account_id/account_id.h"
16 #include "components/user_manager/fake_user_manager.h" 21 #include "components/user_manager/fake_user_manager.h"
17 #include "components/user_manager/user.h" 22 #include "components/user_manager/user.h"
18 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/test/test_windows.h" 25 #include "ui/aura/test/test_windows.h"
21 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
22 27
23 namespace arc { 28 namespace arc {
24 namespace { 29 namespace {
25 30
31 // The constants matching the values from DeviceEcryptfsMigrationStrategy
32 // policy.
33 constexpr int kMigrationAllowedPolicyUnset = 0;
34 constexpr int kMigrationAllowedPolicyDisabled = 1;
35 constexpr int kMigrationAllowedPolicyEnabled = 2;
36
26 // If an instance is created, based on the value passed to the consturctor, 37 // If an instance is created, based on the value passed to the consturctor,
27 // EnableARC feature is enabled/disabled in the scope. 38 // EnableARC feature is enabled/disabled in the scope.
28 class ScopedArcFeature { 39 class ScopedArcFeature {
29 public: 40 public:
30 explicit ScopedArcFeature(bool enabled) { 41 explicit ScopedArcFeature(bool enabled) {
31 constexpr char kArcFeatureName[] = "EnableARC"; 42 constexpr char kArcFeatureName[] = "EnableARC";
32 if (enabled) { 43 if (enabled) {
33 feature_list.InitFromCommandLine(kArcFeatureName, std::string()); 44 feature_list.InitFromCommandLine(kArcFeatureName, std::string());
34 } else { 45 } else {
35 feature_list.InitFromCommandLine(std::string(), kArcFeatureName); 46 feature_list.InitFromCommandLine(std::string(), kArcFeatureName);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 "test@test.com-hash", false); 243 "test@test.com-hash", false);
233 const user_manager::User* ephemeral_user = fake_user_manager.GetActiveUser(); 244 const user_manager::User* ephemeral_user = fake_user_manager.GetActiveUser();
234 ASSERT_TRUE(ephemeral_user); 245 ASSERT_TRUE(ephemeral_user);
235 ASSERT_TRUE(fake_user_manager.IsUserCryptohomeDataEphemeral( 246 ASSERT_TRUE(fake_user_manager.IsUserCryptohomeDataEphemeral(
236 ephemeral_user->GetAccountId())); 247 ephemeral_user->GetAccountId()));
237 248
238 // Ephemeral user is not allowed for ARC. 249 // Ephemeral user is not allowed for ARC.
239 EXPECT_FALSE(IsArcAllowedForUser(ephemeral_user)); 250 EXPECT_FALSE(IsArcAllowedForUser(ephemeral_user));
240 } 251 }
241 252
253 TEST_F(ArcUtilTest, IsMigrationAllowedDeviceOwned) {
254 ResetGlobalDataForTesting();
255 auto* command_line = base::CommandLine::ForCurrentProcess();
256 command_line->InitFromArgv({"", "--initial-encryption-ecryptfs"});
257 SetHasDeviceOwner();
258 EXPECT_TRUE(IsArcAvailable());
259 }
260
261 TEST_F(ArcUtilTest, IsMigrationAllowedUserNotInitialized) {
262 ResetGlobalDataForTesting();
263 auto* command_line = base::CommandLine::ForCurrentProcess();
264 command_line->InitFromArgv({"", "--initial-encryption-ecryptfs"});
265 EXPECT_FALSE(IsArcAvailable());
266 }
267
268 TEST_F(ArcUtilTest, IsMigrationAllowedNoPolicy) {
269 ResetGlobalDataForTesting();
270 auto* command_line = base::CommandLine::ForCurrentProcess();
271 command_line->InitFromArgv({"", "--initial-encryption-ecryptfs"});
272 user_manager::FakeUserManager fake_user_manager;
273
274 PrefServiceFactory pref_service_factory;
275 scoped_refptr<TestingPrefStore> pref_store(new TestingPrefStore);
276 pref_service_factory.set_user_prefs(pref_store.get());
277 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple);
278 std::unique_ptr<PrefService> pref_service(
279 pref_service_factory.Create(registry.get()));
280
281 fake_user_manager.SetLocalState(pref_service.get());
282 ScopedUserManager scoped_user_manager(&fake_user_manager);
283 EXPECT_FALSE(IsArcAvailable());
284 }
285
286 TEST_F(ArcUtilTest, IsMigrationAllowedPolicyAllowed) {
287 ResetGlobalDataForTesting();
288 auto* command_line = base::CommandLine::ForCurrentProcess();
289 command_line->InitFromArgv({"", "--initial-encryption-ecryptfs"});
290 user_manager::FakeUserManager fake_user_manager;
291
292 PrefServiceFactory pref_service_factory;
293 scoped_refptr<TestingPrefStore> managed_pref_store(new TestingPrefStore);
294 scoped_refptr<TestingPrefStore> user_pref_store(new TestingPrefStore);
295 managed_pref_store->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
296 kMigrationAllowedPolicyEnabled);
297 pref_service_factory.set_managed_prefs(managed_pref_store.get());
298 pref_service_factory.set_user_prefs(user_pref_store.get());
299 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple);
300 registry->RegisterIntegerPref(prefs::kDeviceEcryptfsMigrationStrategy,
301 kMigrationAllowedPolicyUnset);
302 std::unique_ptr<PrefService> pref_service(
303 pref_service_factory.Create(registry.get()));
304 pref_service->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
305 kMigrationAllowedPolicyEnabled);
306
307 fake_user_manager.SetLocalState(pref_service.get());
308 ScopedUserManager scoped_user_manager(&fake_user_manager);
309 EXPECT_TRUE(IsArcAvailable());
310 }
311
312 TEST_F(ArcUtilTest, IsMigrationAllowedPolicyDisabled) {
313 ResetGlobalDataForTesting();
314 auto* command_line = base::CommandLine::ForCurrentProcess();
315 command_line->InitFromArgv({"", "--initial-encryption-ecryptfs"});
316 user_manager::FakeUserManager fake_user_manager;
317
318 PrefServiceFactory pref_service_factory;
319 scoped_refptr<TestingPrefStore> managed_pref_store(new TestingPrefStore);
320 scoped_refptr<TestingPrefStore> user_pref_store(new TestingPrefStore);
321 managed_pref_store->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
322 kMigrationAllowedPolicyDisabled);
323 pref_service_factory.set_managed_prefs(managed_pref_store.get());
324 pref_service_factory.set_user_prefs(user_pref_store.get());
325 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple);
326 registry->RegisterIntegerPref(prefs::kDeviceEcryptfsMigrationStrategy,
327 kMigrationAllowedPolicyUnset);
328 std::unique_ptr<PrefService> pref_service(
329 pref_service_factory.Create(registry.get()));
330 pref_service->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
331 kMigrationAllowedPolicyDisabled);
332
333 fake_user_manager.SetLocalState(pref_service.get());
334 ScopedUserManager scoped_user_manager(&fake_user_manager);
335 EXPECT_FALSE(IsArcAvailable());
336 }
337
242 } // namespace 338 } // namespace
243 } // namespace arc 339 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698