update_engine: Query Omaha with correct version/delta_okay during DLC Installations
When DLC(s) are being installed, the Omaha request to check should pass
a version of "0.0.0.0" instead of the same version as the platform and
the delta_okay should always be false.
During a DLC installation, the "<updatecheck></updatecheck>" is also
skipped for the platform and tests are included for those checks.
This means that dlcservice should be extra cautious in not passing in
DLC(s) that are already installed as update_engine can potentially
overwrite the file that's already in use/installed+mounted.
Example Omaha request for DLC installations:
<?xml version="1.0" encoding="UTF-8"?>
<request requestid="79a08366-3a0a-4d18-a1a7-a01a6ad7c34c" sessionid="" protocol="3.0" updater="ChromeOSUpdateEngine" updaterversion="0.1.0.0" installsource="scheduler" ismachine="1">
<os version="Indy" platform="Chrome OS" sp=""></os>
<app appid="" version="" track="" board="" hardware_class="" delta_okay="false" lang="" fw_version="" ec_version="" installdate="0" >
<event eventtype="54" eventresult="1" previousversion="0.0.0.0"></event>
</app>
<app appid="_dlc_1" version="0.0.0.0" track="" board="" hardware_class="" delta_okay="false" >
<updatecheck></updatecheck>
<event eventtype="54" eventresult="1" previousversion="0.0.0.0"></event>
</app>
<app appid="_dlc_2" version="0.0.0.0" track="" board="" hardware_class="" delta_okay="false" >
<updatecheck></updatecheck>
<event eventtype="54" eventresult="1" previousversion="0.0.0.0"></event>
</app>
</request>
BUG=chromium:1039898
TEST=FEATURES=test emerge-$B update_engine
Change-Id: Ibc1a29449e9244f38deb661d400d3fc569e7478f
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1992194
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/omaha_request_builder_xml_unittest.cc b/omaha_request_builder_xml_unittest.cc
index ecab0e0..8cf7473 100644
--- a/omaha_request_builder_xml_unittest.cc
+++ b/omaha_request_builder_xml_unittest.cc
@@ -44,6 +44,13 @@
return "";
return xml.substr(val_start_pos + key_with_quotes.size(), val_size);
}
+// Helper to find the count of substring in a string.
+static size_t CountSubstringInString(const string& str, const string& substr) {
+ size_t count = 0, pos = 0;
+ while ((pos = str.find(substr, pos ? pos + 1 : 0)) != string::npos)
+ ++count;
+ return count;
+}
} // namespace
class OmahaRequestBuilderXmlTest : public ::testing::Test {
@@ -131,9 +138,8 @@
}
TEST_F(OmahaRequestBuilderXmlTest, GetRequestXmlRequestIdTest) {
- OmahaEvent omaha_event;
OmahaRequestParams omaha_request_params{&fake_system_state_};
- OmahaRequestBuilderXml omaha_request{&omaha_event,
+ OmahaRequestBuilderXml omaha_request{nullptr,
&omaha_request_params,
false,
false,
@@ -153,9 +159,8 @@
TEST_F(OmahaRequestBuilderXmlTest, GetRequestXmlSessionIdTest) {
const string gen_session_id = base::GenerateGUID();
- OmahaEvent omaha_event;
OmahaRequestParams omaha_request_params{&fake_system_state_};
- OmahaRequestBuilderXml omaha_request{&omaha_event,
+ OmahaRequestBuilderXml omaha_request{nullptr,
&omaha_request_params,
false,
false,
@@ -175,4 +180,74 @@
EXPECT_EQ(gen_session_id, session_id);
}
+TEST_F(OmahaRequestBuilderXmlTest, GetRequestXmlPlatformUpdateTest) {
+ OmahaRequestParams omaha_request_params{&fake_system_state_};
+ OmahaRequestBuilderXml omaha_request{nullptr,
+ &omaha_request_params,
+ false,
+ false,
+ 0,
+ 0,
+ 0,
+ fake_system_state_.prefs(),
+ ""};
+ const string request_xml = omaha_request.GetRequest();
+ EXPECT_EQ(1, CountSubstringInString(request_xml, "<updatecheck"))
+ << request_xml;
+}
+
+TEST_F(OmahaRequestBuilderXmlTest, GetRequestXmlPlatformUpdateWithDlcsTest) {
+ OmahaRequestParams omaha_request_params{&fake_system_state_};
+ omaha_request_params.set_dlc_module_ids({"dlc_1", "dlc_2"});
+ OmahaRequestBuilderXml omaha_request{nullptr,
+ &omaha_request_params,
+ false,
+ false,
+ 0,
+ 0,
+ 0,
+ fake_system_state_.prefs(),
+ ""};
+ const string request_xml = omaha_request.GetRequest();
+ EXPECT_EQ(3, CountSubstringInString(request_xml, "<updatecheck"))
+ << request_xml;
+}
+
+TEST_F(OmahaRequestBuilderXmlTest, GetRequestXmlDlcInstallationTest) {
+ OmahaRequestParams omaha_request_params{&fake_system_state_};
+ const vector<string> dlcs = {"dlc_1", "dlc_2"};
+ omaha_request_params.set_dlc_module_ids(dlcs);
+ omaha_request_params.set_is_install(true);
+ OmahaRequestBuilderXml omaha_request{nullptr,
+ &omaha_request_params,
+ false,
+ false,
+ 0,
+ 0,
+ 0,
+ fake_system_state_.prefs(),
+ ""};
+ const string request_xml = omaha_request.GetRequest();
+ EXPECT_EQ(2, CountSubstringInString(request_xml, "<updatecheck"))
+ << request_xml;
+
+ auto FindAppId = [request_xml](size_t pos) -> size_t {
+ return request_xml.find("<app appid", pos);
+ };
+ // Skip over the Platform AppID, which is always first.
+ size_t pos = FindAppId(0);
+ for (auto&& _ : dlcs) {
+ (void)_;
+ EXPECT_NE(string::npos, (pos = FindAppId(pos + 1))) << request_xml;
+ const string dlc_app_id_version = FindAttributeKeyValueInXml(
+ request_xml.substr(pos), "version", string(kNoVersion).size());
+ EXPECT_EQ(kNoVersion, dlc_app_id_version);
+
+ const string false_str = "false";
+ const string dlc_app_id_delta_okay = FindAttributeKeyValueInXml(
+ request_xml.substr(pos), "delta_okay", false_str.length());
+ EXPECT_EQ(false_str, dlc_app_id_delta_okay);
+ }
+}
+
} // namespace chromeos_update_engine