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

Unified Diff: chrome/browser/chromeos/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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/arc_util_unittest.cc
diff --git a/chrome/browser/chromeos/arc/arc_util_unittest.cc b/chrome/browser/chromeos/arc/arc_util_unittest.cc
index 92daee101c29c72f2f400ee6dac39c9d3462f048..023badf4685f622b3e0c167efc5720bfcd6a93b8 100644
--- a/chrome/browser/chromeos/arc/arc_util_unittest.cc
+++ b/chrome/browser/chromeos/arc/arc_util_unittest.cc
@@ -17,12 +17,17 @@
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/chromeos/settings/install_attributes.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
+#include "components/prefs/pref_service_factory.h"
#include "components/prefs/testing_pref_service.h"
+#include "components/prefs/testing_pref_store.h"
#include "components/signin/core/account_id/account_id.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_manager/known_user.h"
@@ -39,6 +44,12 @@ namespace {
constexpr char kTestProfileName[] = "user@gmail.com";
constexpr char kTestGaiaId[] = "1234567890";
+// The constants matching the values from DeviceEcryptfsMigrationStrategy
+// policy.
+constexpr int kMigrationAllowedPolicyUnset = 0;
+constexpr int kMigrationAllowedPolicyDisabled = 1;
+constexpr int kMigrationAllowedPolicyEnabled = 2;
+
class ScopedLogIn {
public:
ScopedLogIn(
@@ -88,6 +99,22 @@ class ScopedLogIn {
DISALLOW_COPY_AND_ASSIGN(ScopedLogIn);
};
+class FakeInstallAttributesManaged : public chromeos::InstallAttributes {
+ public:
+ FakeInstallAttributesManaged() : chromeos::InstallAttributes(nullptr) {
+ device_locked_ = true;
+ }
+
+ ~FakeInstallAttributesManaged() {
+ policy::BrowserPolicyConnectorChromeOS::RemoveInstallAttributesForTesting();
+ }
+
+ void SetIsManaged(bool is_managed) {
+ registration_mode_ = is_managed ? policy::DEVICE_MODE_ENTERPRISE
bartfab (slow) 2017/06/12 12:49:04 Nit: #include "components/policy/core/common/cloud
igorcov 2017/06/12 16:50:10 Done.
+ : policy::DEVICE_MODE_CONSUMER;
+ }
+};
+
class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager {
public:
FakeUserManagerWithLocalState()
@@ -96,11 +123,18 @@ class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager {
}
PrefService* GetLocalState() const override {
+ if (pref_service_)
+ return pref_service_;
return test_local_state_.get();
}
+ void SetLocalState(PrefService* pref_service) {
+ pref_service_ = pref_service;
+ }
+
private:
std::unique_ptr<TestingPrefServiceSimple> test_local_state_;
+ PrefService* pref_service_ = nullptr;
bartfab (slow) 2017/06/12 12:49:04 How about calling this |local_state_| instead so t
igorcov 2017/06/12 16:50:10 Done.
DISALLOW_COPY_AND_ASSIGN(FakeUserManagerWithLocalState);
};
@@ -109,7 +143,13 @@ class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager {
class ChromeArcUtilTest : public testing::Test {
public:
- ChromeArcUtilTest() = default;
+ ChromeArcUtilTest() {
+ auto attributes = base::MakeUnique<FakeInstallAttributesManaged>();
+ attributes_ = attributes.get();
+ policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
+ attributes.release());
+ }
+
~ChromeArcUtilTest() override = default;
void SetUp() override {
@@ -137,6 +177,15 @@ class ChromeArcUtilTest : public testing::Test {
user_manager::UserManager::Get());
}
+ FakeUserManagerWithLocalState* GetFakeUserManagerWithLocalState() const {
+ return static_cast<FakeUserManagerWithLocalState*>(
+ user_manager::UserManager::Get());
+ }
+
+ void SetDeviceIsEnterpriseManaged(bool is_managed) {
+ attributes_->SetIsManaged(is_managed);
+ }
+
void LogIn() {
const auto account_id = AccountId::FromUserEmailGaiaId(
profile()->GetProfileUserName(), kTestGaiaId);
@@ -149,6 +198,7 @@ class ChromeArcUtilTest : public testing::Test {
content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
std::unique_ptr<TestingProfile> profile_;
+ FakeInstallAttributesManaged* attributes_;
DISALLOW_COPY_AND_ASSIGN(ChromeArcUtilTest);
};
@@ -474,5 +524,90 @@ TEST_F(ChromeArcUtilTest, AreArcAllOptInPreferencesManagedForProfile) {
EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile()));
}
+TEST_F(ChromeArcUtilTest, IsMigrationAllowedDeviceOwned) {
bartfab (slow) 2017/06/12 12:49:04 Nit: What do you mean by "DeviceOwned"? Should thi
igorcov 2017/06/12 16:50:10 Done.
+ ResetArcMigrationAllowedForTesting();
+ auto* command_line = base::CommandLine::ForCurrentProcess();
bartfab (slow) 2017/06/12 12:49:04 Nit: const pointer.
igorcov 2017/06/12 16:50:10 const not accepted by the compiler here.
bartfab (slow) 2017/06/13 09:56:01 Are you sure you were trying to make it a const po
igorcov 2017/06/16 11:13:03 I'm sorry, I guess C++ syntax is not that intuitiv
+ command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
+ "--arc-availability=officially-supported"});
+ SetDeviceIsEnterpriseManaged(false);
+ ScopedLogIn login(GetFakeUserManager(),
+ AccountId::FromUserEmailGaiaId(
+ profile()->GetProfileUserName(), kTestGaiaId));
+ EXPECT_TRUE(IsArcAllowedForProfile(profile()));
+}
+
+TEST_F(ChromeArcUtilTest, IsMigrationAllowedNoPolicy) {
+ ResetArcMigrationAllowedForTesting();
+ auto* command_line = base::CommandLine::ForCurrentProcess();
+ command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
+ "--arc-availability=officially-supported"});
+ SetDeviceIsEnterpriseManaged(true);
+ ScopedLogIn login(GetFakeUserManager(),
+ AccountId::FromUserEmailGaiaId(
+ profile()->GetProfileUserName(), kTestGaiaId));
+
+ EXPECT_FALSE(IsArcAllowedForProfile(profile()));
+}
+
+TEST_F(ChromeArcUtilTest, IsMigrationAllowedPolicyAllowed) {
+ ResetArcMigrationAllowedForTesting();
+ auto* command_line = base::CommandLine::ForCurrentProcess();
+ command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
+ "--arc-availability=officially-supported"});
+ SetDeviceIsEnterpriseManaged(true);
+ FakeUserManagerWithLocalState* fake_user_manager =
bartfab (slow) 2017/06/12 12:49:04 Nit: const pointer
igorcov 2017/06/12 16:50:10 Compiler complains.
igorcov 2017/06/16 11:13:03 Const-ed this too.
+ GetFakeUserManagerWithLocalState();
+ PrefServiceFactory pref_service_factory;
+ scoped_refptr<TestingPrefStore> managed_pref_store(new TestingPrefStore());
+ scoped_refptr<TestingPrefStore> user_pref_store(new TestingPrefStore());
+ managed_pref_store->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
+ kMigrationAllowedPolicyEnabled);
+ pref_service_factory.set_managed_prefs(managed_pref_store.get());
+ pref_service_factory.set_user_prefs(user_pref_store.get());
+ scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
+ registry->RegisterIntegerPref(prefs::kDeviceEcryptfsMigrationStrategy,
+ kMigrationAllowedPolicyUnset);
+ std::unique_ptr<PrefService> pref_service(
+ pref_service_factory.Create(registry.get()));
+ pref_service->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
+ kMigrationAllowedPolicyEnabled);
+ fake_user_manager->SetLocalState(pref_service.get());
+ ScopedLogIn login(fake_user_manager,
+ AccountId::FromUserEmailGaiaId(
+ profile()->GetProfileUserName(), kTestGaiaId));
+
+ EXPECT_TRUE(IsArcAllowedForProfile(profile()));
+}
+
+TEST_F(ChromeArcUtilTest, IsMigrationAllowedPolicyDisabled) {
bartfab (slow) 2017/06/12 12:49:04 Nit: There is a lot of copy & paste between these
igorcov 2017/06/12 16:50:10 Done.
+ ResetArcMigrationAllowedForTesting();
+ auto* command_line = base::CommandLine::ForCurrentProcess();
+ command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
+ "--arc-availability=officially-supported"});
+ SetDeviceIsEnterpriseManaged(true);
+ FakeUserManagerWithLocalState* fake_user_manager =
+ GetFakeUserManagerWithLocalState();
+ PrefServiceFactory pref_service_factory;
+ scoped_refptr<TestingPrefStore> managed_pref_store(new TestingPrefStore());
+ scoped_refptr<TestingPrefStore> user_pref_store(new TestingPrefStore());
+ managed_pref_store->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
+ kMigrationAllowedPolicyDisabled);
+ pref_service_factory.set_managed_prefs(managed_pref_store.get());
+ pref_service_factory.set_user_prefs(user_pref_store.get());
+ scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
+ registry->RegisterIntegerPref(prefs::kDeviceEcryptfsMigrationStrategy,
+ kMigrationAllowedPolicyUnset);
+ std::unique_ptr<PrefService> pref_service(
+ pref_service_factory.Create(registry.get()));
+ pref_service->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
+ kMigrationAllowedPolicyDisabled);
+ fake_user_manager->SetLocalState(pref_service.get());
+ ScopedLogIn login(fake_user_manager,
+ AccountId::FromUserEmailGaiaId(
+ profile()->GetProfileUserName(), kTestGaiaId));
+
+ EXPECT_FALSE(IsArcAllowedForProfile(profile()));
+}
+
} // namespace util
} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698