Commit 13d5680b authored by Robin Lewis's avatar Robin Lewis Committed by Commit Bot

Enable GCPW cloud policies when Omaha has a DM token.

Bug: 1135866
Change-Id: I62b8e8ac10d2898d25daf4dfb742f3880e9d8170
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454421Reviewed-by: default avatarYusuf Sengul <yusufsn@google.com>
Reviewed-by: default avatarRakesh Soma <rakeshsoma@google.com>
Commit-Queue: Rakesh Soma <rakeshsoma@google.com>
Cr-Commit-Position: refs/heads/master@{#815779}
parent 857c4ddd
...@@ -212,8 +212,10 @@ extension::TaskCreator UserPoliciesManager::GetFetchPoliciesTaskCreator() { ...@@ -212,8 +212,10 @@ extension::TaskCreator UserPoliciesManager::GetFetchPoliciesTaskCreator() {
} }
UserPoliciesManager::UserPoliciesManager() : fetch_status_(S_OK) { UserPoliciesManager::UserPoliciesManager() : fetch_status_(S_OK) {
g_cloud_policies_enabled = std::string dm_token;
GetGlobalFlagOrDefault(kCloudPoliciesEnabledRegKey, 0) == 1; bool has_dm_token = SUCCEEDED(GetDmToken(&dm_token)) && !dm_token.empty();
g_cloud_policies_enabled = GetGlobalFlagOrDefault(kCloudPoliciesEnabledRegKey,
has_dm_token ? 1 : 0) == 1;
} }
UserPoliciesManager::~UserPoliciesManager() = default; UserPoliciesManager::~UserPoliciesManager() = default;
......
...@@ -281,5 +281,46 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -281,5 +281,46 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Bool(), ::testing::Bool(),
::testing::Values(L"", L"valid-dm-token"))); ::testing::Values(L"", L"valid-dm-token")));
// Test to verify automatic enabling of cloud policies when DM token is present.
// Parameters:
// string : Value of DM Token on the device.
// int : 0 - Cloud policies disabled through registry.
// 1 - Cloud policies enabled through registry.
// 2 - Cloud policies registry flag not set.
class GcpUserPoliciesEnableOnDmTokenTest
: public GcpUserPoliciesBaseTest,
public ::testing::WithParamInterface<std::tuple<const char*, int>> {};
TEST_P(GcpUserPoliciesEnableOnDmTokenTest, EnableIfFound) {
std::string dm_token(std::get<0>(GetParam()));
int reg_enable_cloud_policies = std::get<1>(GetParam());
if (!dm_token.empty()) {
ASSERT_EQ(S_OK, SetDmTokenForTesting(dm_token));
}
if (reg_enable_cloud_policies < 2) {
SetGlobalFlagForTesting(L"cloud_policies_enabled",
reg_enable_cloud_policies);
}
// This is needed because we want to call the default constructor of the
// UserDeviceManager in each test.
FakeUserPoliciesManager fake_user_policies_manager;
// Feature is enabled if it's explicitly enabled or if the flag is not set and
// a valid DM token exists.
if (reg_enable_cloud_policies == 1 ||
(reg_enable_cloud_policies == 2 && !dm_token.empty())) {
ASSERT_TRUE(UserPoliciesManager::Get()->CloudPoliciesEnabled());
} else {
ASSERT_FALSE(UserPoliciesManager::Get()->CloudPoliciesEnabled());
}
}
INSTANTIATE_TEST_SUITE_P(All,
GcpUserPoliciesEnableOnDmTokenTest,
::testing::Combine(::testing::Values("", "dm-token"),
::testing::Values(0, 1, 2)));
} // namespace testing } // namespace testing
} // namespace credential_provider } // namespace credential_provider
...@@ -1165,6 +1165,11 @@ uint64_t FakeEventLogsUploadManager::GetNumLogsUploaded() { ...@@ -1165,6 +1165,11 @@ uint64_t FakeEventLogsUploadManager::GetNumLogsUploaded() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
FakeUserPoliciesManager::FakeUserPoliciesManager()
: original_manager_(*GetInstanceStorage()) {
*GetInstanceStorage() = this;
}
FakeUserPoliciesManager::FakeUserPoliciesManager(bool cloud_policies_enabled) FakeUserPoliciesManager::FakeUserPoliciesManager(bool cloud_policies_enabled)
: original_manager_(*GetInstanceStorage()) { : original_manager_(*GetInstanceStorage()) {
*GetInstanceStorage() = this; *GetInstanceStorage() = this;
......
...@@ -599,6 +599,7 @@ class FakeEventLogsUploadManager : public EventLogsUploadManager { ...@@ -599,6 +599,7 @@ class FakeEventLogsUploadManager : public EventLogsUploadManager {
class FakeUserPoliciesManager : public UserPoliciesManager { class FakeUserPoliciesManager : public UserPoliciesManager {
public: public:
explicit FakeUserPoliciesManager();
explicit FakeUserPoliciesManager(bool cloud_policies_enabled); explicit FakeUserPoliciesManager(bool cloud_policies_enabled);
~FakeUserPoliciesManager() override; ~FakeUserPoliciesManager() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment