Set the Quick fix build token if the device is enterprise enrolled
Checks whether the DeviceQuickFixBuildToken has been set when :
- device is enterprise enrolled
- device has the policy been set
BUG=chromium:962467
TEST=./build_packages --board=amd64-generic && \
cros_run_unit_tests --board=amd64-generic --packages update_engine
Change-Id: Ie65167f7a83577256ee4bbfb07ea19ee4e4c6401
Reviewed-on: https://chromium-review.googlesource.com/1611549
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Amr Aboelkher <amraboelkher@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/update_attempter.cc b/update_attempter.cc
index d97917a..fcafd56 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -428,7 +428,8 @@
omaha_request_params_->set_dlc_module_ids(dlc_module_ids_);
omaha_request_params_->set_is_install(is_install_);
- // Set Quick Fix Build token if policy is set.
+ // Set Quick Fix Build token if policy is set and the device is enterprise
+ // enrolled.
string token;
if (system_state_ && system_state_->device_policy()) {
if (!system_state_->device_policy()->GetDeviceQuickFixBuildToken(&token))
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 16819f8..e246e1b 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -188,7 +188,7 @@
void P2PEnabledInteractiveStart();
void P2PEnabledStartingFailsStart();
void P2PEnabledHousekeepingFailsStart();
- void UpdateToQuickFixBuildStart();
+ void UpdateToQuickFixBuildStart(bool set_token);
void ResetRollbackHappenedStart(bool is_consumer,
bool is_policy_available,
bool expected_reset);
@@ -1583,28 +1583,42 @@
attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess);
}
-void UpdateAttempterTest::UpdateToQuickFixBuildStart() {
- // Tests that checks if device_quick_fix_build_token arrives when
- // policy is set.
- const char kToken[] = "some_token";
-
+void UpdateAttempterTest::UpdateToQuickFixBuildStart(bool set_token) {
+ // Tests that checks if |device_quick_fix_build_token| arrives when
+ // policy is set and the device is enterprise enrolled based on |set_token|.
+ string token = set_token ? "some_token" : "";
auto device_policy = std::make_unique<policy::MockDevicePolicy>();
fake_system_state_.set_device_policy(device_policy.get());
-
EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true));
- EXPECT_CALL(*device_policy, GetDeviceQuickFixBuildToken(_))
- .WillOnce(DoAll(SetArgPointee<0>(string(kToken)), Return(true)));
+
+ if (set_token)
+ EXPECT_CALL(*device_policy, GetDeviceQuickFixBuildToken(_))
+ .WillOnce(DoAll(SetArgPointee<0>(token), Return(true)));
+ else
+ EXPECT_CALL(*device_policy, GetDeviceQuickFixBuildToken(_))
+ .WillOnce(Return(false));
attempter_.policy_provider_.reset(
new policy::PolicyProvider(std::move(device_policy)));
attempter_.Update("", "", "", "", false, false, 0, false, false);
+ EXPECT_EQ(token, attempter_.omaha_request_params_->autoupdate_token());
ScheduleQuitMainLoop();
}
-TEST_F(UpdateAttempterTest, UpdateToQuickFixBuildStart) {
+TEST_F(UpdateAttempterTest,
+ QuickFixTokenWhenDeviceIsEnterpriseEnrolledAndPolicyIsSet) {
loop_.PostTask(FROM_HERE,
base::Bind(&UpdateAttempterTest::UpdateToQuickFixBuildStart,
- base::Unretained(this)));
+ base::Unretained(this),
+ /*set_token=*/true));
+ loop_.Run();
+}
+
+TEST_F(UpdateAttempterTest, EmptyQuickFixToken) {
+ loop_.PostTask(FROM_HERE,
+ base::Bind(&UpdateAttempterTest::UpdateToQuickFixBuildStart,
+ base::Unretained(this),
+ /*set_token=*/false));
loop_.Run();
}