Commit f316f599 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Retrive MachineLevelCloudPolicy with DM token only

BrowserDMToken storage should already read DM token from Registry.
MachineLevelCloudPolicyFetcher should be created if there is a DM token
avaiable.

Bug: 852903
Change-Id: Ib10f03a3c0c944358212d076b5c39f38fb88c4ce
Reviewed-on: https://chromium-review.googlesource.com/1101556
Commit-Queue: Owen Min <zmin@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567668}
parent 81661826
...@@ -270,8 +270,6 @@ void BrowserDMTokenStorageWin::InitIfNeeded() { ...@@ -270,8 +270,6 @@ void BrowserDMTokenStorageWin::InitIfNeeded() {
enrollment_token_ = base::WideToUTF8( enrollment_token_ = base::WideToUTF8(
InstallUtil::GetMachineLevelUserCloudPolicyEnrollmentToken()); InstallUtil::GetMachineLevelUserCloudPolicyEnrollmentToken());
DVLOG(1) << "Enrollment token = " << enrollment_token_; DVLOG(1) << "Enrollment token = " << enrollment_token_;
if (enrollment_token_.empty())
return;
dm_token_ = GetDMToken(); dm_token_ = GetDMToken();
DVLOG(1) << "DM Token = " << dm_token_; DVLOG(1) << "DM Token = " << dm_token_;
......
...@@ -101,25 +101,17 @@ TEST_F(BrowserDMTokenStorageWinTest, RetrieveEnrollmentToken) { ...@@ -101,25 +101,17 @@ TEST_F(BrowserDMTokenStorageWinTest, RetrieveEnrollmentToken) {
TEST_F(BrowserDMTokenStorageWinTest, RetrieveDMToken) { TEST_F(BrowserDMTokenStorageWinTest, RetrieveDMToken) {
ASSERT_TRUE(SetMachineGuid(kClientId1)); ASSERT_TRUE(SetMachineGuid(kClientId1));
// The DM token will not be read from the system if there is no enrollment // The DM token will be read from the system regardless there is an enrollment
// token. // token or not.
ASSERT_TRUE(SetDMToken(kDMToken1)); ASSERT_TRUE(SetDMToken(kDMToken1));
BrowserDMTokenStorageWin storage; BrowserDMTokenStorageWin storage;
EXPECT_THAT(storage.RetrieveDMToken(), IsEmpty()); EXPECT_EQ(std::string(kDMToken1), storage.RetrieveDMToken());
// With the enrollment token now set, an already initialized
// BrowserDMTokenStorageWin should still return empty DM token because it
// should cache the value.
ASSERT_TRUE(SetEnrollmentToken(kEnrollmentToken1)); ASSERT_TRUE(SetEnrollmentToken(kEnrollmentToken1));
EXPECT_THAT(storage.RetrieveDMToken(), IsEmpty()); EXPECT_EQ(std::string(kDMToken1), storage.RetrieveDMToken());
// But if enrollment token is set when BrowserDMTokenStorageWin is first used,
// it should return the DM token.
BrowserDMTokenStorageWin storage2;
EXPECT_EQ(std::string(kDMToken1), storage2.RetrieveDMToken());
// The DM token should be cached in memory and not read from the system again. // The DM token should be cached in memory and not read from the system again.
ASSERT_TRUE(SetDMToken(kDMToken2)); ASSERT_TRUE(SetDMToken(kDMToken2));
EXPECT_EQ(std::string(kDMToken1), storage2.RetrieveDMToken()); EXPECT_EQ(std::string(kDMToken1), storage.RetrieveDMToken());
} }
} // namespace policy } // namespace policy
...@@ -103,6 +103,16 @@ void MachineLevelUserCloudPolicyController::Init( ...@@ -103,6 +103,16 @@ void MachineLevelUserCloudPolicyController::Init(
// registered and needs to request a DM token. // registered and needs to request a DM token.
std::string enrollment_token; std::string enrollment_token;
std::string client_id; std::string client_id;
std::string dm_token = BrowserDMTokenStorage::Get()->RetrieveDMToken();
DVLOG(1) << "DM token = " << (dm_token.empty() ? "none" : "from persistence");
if (!dm_token.empty()) {
policy_fetcher_ = std::make_unique<MachineLevelUserCloudPolicyFetcher>(
policy_manager, local_state, device_management_service,
request_context);
return;
}
if (!GetEnrollmentTokenAndClientId(&enrollment_token, &client_id)) if (!GetEnrollmentTokenAndClientId(&enrollment_token, &client_id))
return; return;
...@@ -119,9 +129,6 @@ void MachineLevelUserCloudPolicyController::Init( ...@@ -119,9 +129,6 @@ void MachineLevelUserCloudPolicyController::Init(
policy_register_watcher_ = policy_register_watcher_ =
std::make_unique<MachineLevelUserCloudPolicyRegisterWatcher>(this); std::make_unique<MachineLevelUserCloudPolicyRegisterWatcher>(this);
std::string dm_token = BrowserDMTokenStorage::Get()->RetrieveDMToken();
DVLOG(1) << "DM token = " << (dm_token.empty() ? "none" : "from persistence");
if (dm_token.empty()) { if (dm_token.empty()) {
// Not registered already, so do it now. // Not registered already, so do it now.
policy_registrar_->RegisterForPolicyWithEnrollmentToken( policy_registrar_->RegisterForPolicyWithEnrollmentToken(
......
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