Implement the update engine portion for new enterprise policies.
Enterprises need the ability to stop the auto updates and pin clients
to a given target version. This CL adds support for these features in
the update_engine.
BUG=27307: Implement StopAutoUpdate based on enterprise policy
TEST=Added new unit tests, manually tested all cases on ZGB.
CQ-DEPEND=I523c3f67e0cb07fd24744dc0a30382ff2fe2128a
Change-Id: Id576401afc6d2c93f0e9ece7c6c0ddcf4b1bc00d
Reviewed-on: https://gerrit.chromium.org/gerrit/17867
Commit-Ready: Jay Srinivasan <[email protected]>
Reviewed-by: Jay Srinivasan <[email protected]>
Tested-by: Jay Srinivasan <[email protected]>
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index 776e5e7..e92fb03 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -46,7 +46,9 @@
"unittest",
"OEM MODEL 09235 7471",
false, // delta okay
- "http://url");
+ "http://url",
+ false, // update_disabled
+ ""); // target_version_prefix
string GetNoUpdateResponse(const string& app_id) {
return string(
@@ -65,11 +67,13 @@
const string& needsadmin,
const string& size,
const string& deadline) {
- return string("<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
- "xmlns=\"http://www.google.com/update2/response\" "
- "protocol=\"2.0\"><app "
- "appid=\"") + app_id + "\" status=\"ok\"><ping "
+ return string(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
+ "xmlns=\"http://www.google.com/update2/response\" "
+ "protocol=\"2.0\"><app "
+ "appid=\"") + app_id + "\" status=\"ok\"><ping "
"status=\"ok\"/><updatecheck DisplayVersion=\"" + display_version + "\" "
+ "ChromeOSVersion=\"" + display_version + "\" "
"MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" "
"IsDelta=\"true\" "
"codebase=\"" + codebase + "\" hash=\"not-applicable\" "
@@ -264,6 +268,48 @@
EXPECT_EQ("20101020", response.deadline);
}
+TEST(OmahaRequestActionTest, ValidUpdateBlockedByPolicyTest) {
+ OmahaResponse response;
+ OmahaRequestParams params = kDefaultTestParams;
+ params.update_disabled = true;
+ ASSERT_FALSE(
+ TestUpdateCheck(NULL, // prefs
+ params,
+ GetUpdateResponse(OmahaRequestParams::kAppId,
+ "1.2.3.4", // version
+ "http://more/info",
+ "true", // prompt
+ "http://code/base", // dl url
+ "HASH1234=", // checksum
+ "false", // needs admin
+ "123", // size
+ "20101020"), // deadline
+ -1,
+ false, // ping_only
+ kActionCodeOmahaUpdateIgnoredPerPolicy,
+ &response,
+ NULL));
+ EXPECT_FALSE(response.update_exists);
+}
+
+
+TEST(OmahaRequestActionTest, NoUpdatesSentWhenBlockedByPolicyTest) {
+ OmahaResponse response;
+ OmahaRequestParams params = kDefaultTestParams;
+ params.update_disabled = true;
+ ASSERT_TRUE(
+ TestUpdateCheck(NULL, // prefs
+ params,
+ GetNoUpdateResponse(OmahaRequestParams::kAppId),
+ -1,
+ false, // ping_only
+ kActionCodeSuccess,
+ &response,
+ NULL));
+ EXPECT_FALSE(response.update_exists);
+}
+
+
TEST(OmahaRequestActionTest, NoOutputPipeTest) {
const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId));
@@ -379,6 +425,7 @@
+ "\" status=\"ok\"><ping "
"status=\"ok\"/><updatecheck "
"DisplayVersion=\"1.2.3.4\" "
+ "ChromeOSVersion=\"1.2.3.4\" "
"Prompt=\"false\" "
"IsDelta=\"true\" "
"codebase=\"http://code/base\" hash=\"foo\" "
@@ -461,7 +508,9 @@
"unittest_track<",
"<OEM MODEL>",
false, // delta okay
- "http://url");
+ "http://url",
+ false, // update_disabled
+ ""); // target_version_prefix
OmahaResponse response;
ASSERT_FALSE(
TestUpdateCheck(NULL, // prefs
@@ -550,23 +599,28 @@
// convert post_data to string
string post_str(&post_data[0], post_data.size());
EXPECT_NE(post_str.find(
- " <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
- " <o:updatecheck></o:updatecheck>\n"),
- string::npos);
+ " <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
+ " <o:updatecheck"
+ " updatedisabled=\"false\""
+ " targetversionprefix=\"\""
+ "></o:updatecheck>\n"),
+ string::npos);
EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
string::npos);
EXPECT_EQ(post_str.find("o:event"), string::npos);
}
-TEST(OmahaRequestActionTest, FormatUpdateCheckPrevVersionOutputTest) {
+
+TEST(OmahaRequestActionTest, FormatUpdateDisabledTest) {
vector<char> post_data;
NiceMock<PrefsMock> prefs;
EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
- .WillOnce(DoAll(SetArgumentPointee<1>(string("1.2>3.4")), Return(true)));
- EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, ""))
- .WillOnce(Return(true));
+ .WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true)));
+ EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0);
+ OmahaRequestParams params = kDefaultTestParams;
+ params.update_disabled = true;
ASSERT_FALSE(TestUpdateCheck(&prefs,
- kDefaultTestParams,
+ params,
"invalid xml>",
-1,
false, // ping_only
@@ -576,17 +630,15 @@
// convert post_data to string
string post_str(&post_data[0], post_data.size());
EXPECT_NE(post_str.find(
- " <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
- " <o:updatecheck></o:updatecheck>\n"),
- string::npos);
+ " <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
+ " <o:updatecheck"
+ " updatedisabled=\"true\""
+ " targetversionprefix=\"\""
+ "></o:updatecheck>\n"),
+ string::npos);
EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
string::npos);
- string prev_version_event = StringPrintf(
- " <o:event eventtype=\"%d\" eventresult=\"%d\" "
- "previousversion=\"1.2>3.4\"></o:event>\n",
- OmahaEvent::kTypeUpdateComplete,
- OmahaEvent::kResultSuccessReboot);
- EXPECT_NE(post_str.find(prev_version_event), string::npos);
+ EXPECT_EQ(post_str.find("o:event"), string::npos);
}
TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
@@ -665,7 +717,9 @@
"unittest_track",
"OEM MODEL REV 1234",
delta_okay,
- "http://url");
+ "http://url",
+ false, // update_disabled
+ ""); // target_version_prefix
ASSERT_FALSE(TestUpdateCheck(NULL, // prefs
params,
"invalid xml>",