blob: 2e54a43b98a5d52528034654a19e27bdc3714057 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2012 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Darin Petkov6a5b3222010-07-13 14:55:28 -070016
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#include "update_engine/cros/omaha_request_action.h"
Alex Deymo8427b4a2014-11-05 14:00:32 -080018
Ben Chan9abb7632014-08-07 00:10:53 -070019#include <stdint.h>
20
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -070021#include <limits>
Ben Chanab5a0af2017-10-12 14:57:50 -070022#include <memory>
Darin Petkov6a5b3222010-07-13 14:55:28 -070023#include <string>
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -080024#include <utility>
Darin Petkov6a5b3222010-07-13 14:55:28 -070025#include <vector>
Darin Petkov0dc8e9a2010-07-14 14:51:57 -070026
Alex Deymo60ca1a72015-06-18 18:19:15 -070027#include <base/bind.h>
Alex Deymo110e0302015-10-19 20:35:21 -070028#include <base/files/file_util.h>
Sen Jiang297e5832016-03-17 14:45:51 -070029#include <base/files/scoped_temp_dir.h>
Ben Chan5c02c132017-06-27 07:10:36 -070030#include <base/memory/ptr_util.h>
Alex Deymo8e18f932015-03-27 16:16:59 -070031#include <base/strings/string_number_conversions.h>
Alex Vakulenko75039d72014-03-25 12:36:28 -070032#include <base/strings/string_util.h>
33#include <base/strings/stringprintf.h>
34#include <base/time/time.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070035#include <brillo/message_loops/fake_message_loop.h>
36#include <brillo/message_loops/message_loop.h>
37#include <brillo/message_loops/message_loop_utils.h>
Andrewe045aef2020-01-08 16:29:22 -080038#include <expat.h>
Alex Deymoe1e3afe2014-10-30 13:02:49 -070039#include <gtest/gtest.h>
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -080040#include <policy/libpolicy.h>
41#include <policy/mock_libpolicy.h>
Jay Srinivasand29695d2013-04-08 15:08:05 -070042
Alex Deymo39910dc2015-11-09 17:04:30 -080043#include "update_engine/common/action_pipe.h"
44#include "update_engine/common/constants.h"
45#include "update_engine/common/fake_prefs.h"
46#include "update_engine/common/hash_calculator.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070047#include "update_engine/common/metrics_reporter_interface.h"
Jae Hoon Kim694eeb02020-06-01 14:24:08 -070048#include "update_engine/common/mock_excluder.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080049#include "update_engine/common/mock_http_fetcher.h"
50#include "update_engine/common/platform_constants.h"
51#include "update_engine/common/prefs.h"
52#include "update_engine/common/test_utils.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070053#include "update_engine/cros/fake_system_state.h"
54#include "update_engine/cros/mock_connection_manager.h"
55#include "update_engine/cros/mock_payload_state.h"
56#include "update_engine/cros/omaha_request_builder_xml.h"
57#include "update_engine/cros/omaha_request_params.h"
58#include "update_engine/cros/omaha_utils.h"
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -080059#include "update_engine/update_manager/rollback_prefs.h"
Darin Petkov6a5b3222010-07-13 14:55:28 -070060
Darin Petkov1cbd78f2010-07-29 12:38:34 -070061using base::Time;
62using base::TimeDelta;
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -080063using chromeos_update_manager::kRollforwardInfinity;
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -070064using std::pair;
Darin Petkov6a5b3222010-07-13 14:55:28 -070065using std::string;
66using std::vector;
Amin Hassani7cc8bb02019-01-14 16:29:47 -080067using testing::_;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070068using testing::AllOf;
Alex Deymof329b932014-10-30 01:37:48 -070069using testing::AnyNumber;
Jay Srinivasan34b5d862012-07-23 11:43:22 -070070using testing::DoAll;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070071using testing::Ge;
72using testing::Le;
Darin Petkov9c096d62010-11-17 14:49:04 -080073using testing::NiceMock;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070074using testing::Return;
Gilad Arnold74b5f552014-10-07 08:17:16 -070075using testing::ReturnPointee;
Amin Hassani7cc8bb02019-01-14 16:29:47 -080076using testing::ReturnRef;
Gilad Arnold74b5f552014-10-07 08:17:16 -070077using testing::SaveArg;
Ben Chan672c1f52017-10-23 15:41:39 -070078using testing::SetArgPointee;
Jae Hoon Kim694eeb02020-06-01 14:24:08 -070079using testing::StrictMock;
Darin Petkov6a5b3222010-07-13 14:55:28 -070080
Alex Deymo8e18f932015-03-27 16:16:59 -070081namespace {
82
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -080083static_assert(kRollforwardInfinity == 0xfffffffe,
84 "Don't change the value of kRollforward infinity unless its "
85 "size has been changed in firmware.");
86
Xiaochu Liu6310be62018-10-11 15:09:03 -070087const char kCurrentVersion[] = "0.1.0.0";
Alex Deymo85616652015-10-15 18:48:31 -070088const char kTestAppId[] = "test-app-id";
Aaron Wood7dcdedf2017-09-06 17:17:41 -070089const char kTestAppId2[] = "test-app2-id";
Xiaochu Liu6310be62018-10-11 15:09:03 -070090const char kTestAppIdSkipUpdatecheck[] = "test-app-id-skip-updatecheck";
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -080091const char kDlcId1[] = "dlc-id-1";
92const char kDlcId2[] = "dlc-id-2";
Alex Deymo85616652015-10-15 18:48:31 -070093
Alex Deymo8e18f932015-03-27 16:16:59 -070094// This is a helper struct to allow unit tests build an update response with the
95// values they care about.
96struct FakeUpdateResponse {
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -070097 string GetRollbackVersionAttributes() const {
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -070098 string num_milestones;
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -070099 num_milestones = base::NumberToString(rollback_allowed_milestones);
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -0700100 const string rollback_version =
101 " _firmware_version_" + num_milestones + "=\"" +
102 past_rollback_key_version.first + "\"" + " _kernel_version_" +
103 num_milestones + "=\"" + past_rollback_key_version.second + "\"";
104
105 return (rollback ? " _rollback=\"true\"" : "") + rollback_version +
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -0700106 (!rollback_firmware_version.empty()
107 ? " _firmware_version=\"" + rollback_firmware_version + "\""
108 : "") +
109 (!rollback_kernel_version.empty()
110 ? " _kernel_version=\"" + rollback_kernel_version + "\""
111 : "");
112 }
113
Alex Deymo8e18f932015-03-27 16:16:59 -0700114 string GetNoUpdateResponse() const {
115 string entity_str;
116 if (include_entity)
117 entity_str = "<!DOCTYPE response [<!ENTITY CrOS \"ChromeOS\">]>";
Sen Jiang81259682017-03-30 15:11:30 -0700118 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + entity_str +
119 "<response protocol=\"3.0\">"
120 "<daystart elapsed_seconds=\"100\"/>"
121 "<app appid=\"" +
122 app_id + "\" " +
123 (include_cohorts
124 ? "cohort=\"" + cohort + "\" cohorthint=\"" + cohorthint +
125 "\" cohortname=\"" + cohortname + "\" "
126 : "") +
127 " status=\"ok\">"
128 "<ping status=\"ok\"/>"
129 "<updatecheck status=\"noupdate\"/></app>" +
130 (multi_app_no_update
Aaron Wood7dcdedf2017-09-06 17:17:41 -0700131 ? "<app appid=\"" + app_id2 +
132 "\"><updatecheck status=\"noupdate\"/></app>"
Sen Jiang81259682017-03-30 15:11:30 -0700133 : "") +
134 "</response>";
Alex Deymo8e18f932015-03-27 16:16:59 -0700135 }
136
137 string GetUpdateResponse() const {
Amin Hassani538bd592020-11-04 20:46:08 -0800138 chromeos_update_engine::OmahaRequestParams request_params;
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -0800139 request_params.set_app_id(app_id);
Sen Jiang2703ef42017-03-16 13:36:21 -0700140 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
141 "protocol=\"3.0\">"
142 "<daystart elapsed_seconds=\"100\"" +
143 (elapsed_days.empty() ? ""
144 : (" elapsed_days=\"" + elapsed_days + "\"")) +
145 "/>"
146 "<app appid=\"" +
147 app_id + "\" " +
148 (include_cohorts
149 ? "cohort=\"" + cohort + "\" cohorthint=\"" + cohorthint +
150 "\" cohortname=\"" + cohortname + "\" "
151 : "") +
152 " status=\"ok\">"
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -0700153 "<ping status=\"ok\"/><updatecheck status=\"ok\"" +
154 GetRollbackVersionAttributes() + ">" + "<urls><url codebase=\"" +
Sen Jiang2703ef42017-03-16 13:36:21 -0700155 codebase +
156 "\"/></urls>"
157 "<manifest version=\"" +
158 version +
159 "\">"
160 "<packages><package hash=\"not-used\" name=\"" +
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800161 filename + "\" size=\"" + base::NumberToString(size) + "\" fp=\"" +
162 fp + "\" hash_sha256=\"" + hash + "\"/>" +
163 (multi_package ? "<package name=\"package2\" size=\"222\" fp=\"" +
164 fp2 + "\" hash_sha256=\"hash2\"/>"
Sen Jiang0affc2c2017-02-10 15:55:05 -0800165 : "") +
166 "</packages>"
Sen Jiang81259682017-03-30 15:11:30 -0700167 "<actions><action event=\"postinstall\" MetadataSize=\"11" +
Amin Hassanic482bbd2018-09-21 16:07:20 -0700168 (multi_package ? ":22" : "") + "\" MoreInfo=\"" + more_info_url +
169 "\" Prompt=\"" + prompt +
Sen Jiang2703ef42017-03-16 13:36:21 -0700170 "\" "
Sen Jiangcdd52062017-05-18 15:33:10 -0700171 "IsDeltaPayload=\"true" +
172 (multi_package ? ":false" : "") +
173 "\" "
Sen Jiang2703ef42017-03-16 13:36:21 -0700174 "MaxDaysToScatter=\"" +
175 max_days_to_scatter +
176 "\" "
Amin Hassanic482bbd2018-09-21 16:07:20 -0700177 "sha256=\"not-used\" " +
Sen Jiang2703ef42017-03-16 13:36:21 -0700178 (deadline.empty() ? "" : ("deadline=\"" + deadline + "\" ")) +
179 (disable_p2p_for_downloading ? "DisableP2PForDownloading=\"true\" "
180 : "") +
181 (disable_p2p_for_sharing ? "DisableP2PForSharing=\"true\" " : "") +
Sen Jiangfe284402018-03-21 14:03:50 -0700182 (powerwash ? "Powerwash=\"true\" " : "") +
Sen Jiang81259682017-03-30 15:11:30 -0700183 "/></actions></manifest></updatecheck></app>" +
184 (multi_app
Sen Jiangb1e063a2017-09-15 17:44:31 -0700185 ? "<app appid=\"" + app_id2 + "\"" +
186 (include_cohorts ? " cohort=\"cohort2\"" : "") +
187 "><updatecheck status=\"ok\"><urls><url codebase=\"" +
Aaron Wood7dcdedf2017-09-06 17:17:41 -0700188 codebase2 + "\"/></urls><manifest version=\"" + version2 +
189 "\"><packages>"
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800190 "<package name=\"package3\" size=\"333\" fp=\"" +
191 fp2 +
192 "\" hash_sha256=\"hash3\"/></packages>"
Sen Jiang00adf7b2017-06-26 15:57:29 -0700193 "<actions><action event=\"postinstall\" " +
194 (multi_app_self_update
195 ? "noupdate=\"true\" IsDeltaPayload=\"true\" "
196 : "IsDeltaPayload=\"false\" ") +
197 "MetadataSize=\"33\"/></actions>"
Sen Jiang81259682017-03-30 15:11:30 -0700198 "</manifest></updatecheck></app>"
199 : "") +
200 (multi_app_no_update
201 ? "<app><updatecheck status=\"noupdate\"/></app>"
202 : "") +
Xiaochu Liu6310be62018-10-11 15:09:03 -0700203 (multi_app_skip_updatecheck
204 ? "<app appid=\"" + app_id_skip_updatecheck + "\"></app>"
205 : "") +
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -0800206 (dlc_app_update
207 ? "<app appid=\"" + request_params.GetDlcAppId(kDlcId1) +
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800208 "\" " +
209 (include_dlc_cohorts
210 ? "cohort=\"" + dlc_cohort + "\" cohorthint=\"" +
211 dlc_cohorthint + "\" cohortname=\"" +
212 dlc_cohortname + "\" "
213 : "") +
214 "status=\"ok\">"
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -0800215 "<updatecheck status=\"ok\"><urls><url codebase=\"" +
Jae Hoon Kim694eeb02020-06-01 14:24:08 -0700216 codebase + "\"/><url codebase=\"" + codebase2 +
217 "\"/></urls><manifest version=\"" + version +
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -0800218 "\"><packages><package name=\"package3\" size=\"333\" "
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800219 "fp=\"" +
220 fp2 +
221 "\" hash_sha256=\"hash3\"/></packages>"
222 "<actions><action event=\"install\" run=\".signed\"/>"
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -0800223 "<action event=\"postinstall\" MetadataSize=\"33\"/>"
224 "</actions></manifest></updatecheck></app>"
225 : "") +
226 (dlc_app_no_update
227 ? "<app appid=\"" + request_params.GetDlcAppId(kDlcId2) +
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800228 +"\" " +
229 (include_dlc_cohorts
230 ? "cohort=\"" + dlc_cohort + "\" cohorthint=\"" +
231 dlc_cohorthint + "\" cohortname=\"" +
232 dlc_cohortname + "\" "
233 : "") +
234 "><updatecheck status=\"noupdate\"/></app>"
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -0800235 : "") +
Sen Jiang81259682017-03-30 15:11:30 -0700236 "</response>";
Alex Deymo8e18f932015-03-27 16:16:59 -0700237 }
238
239 // Return the payload URL, which is split in two fields in the XML response.
Amin Hassani7cc8bb02019-01-14 16:29:47 -0800240 string GetPayloadUrl() { return codebase + filename; }
Alex Deymo8e18f932015-03-27 16:16:59 -0700241
Alex Deymo85616652015-10-15 18:48:31 -0700242 string app_id = kTestAppId;
Aaron Wood7dcdedf2017-09-06 17:17:41 -0700243 string app_id2 = kTestAppId2;
Xiaochu Liu6310be62018-10-11 15:09:03 -0700244 string app_id_skip_updatecheck = kTestAppIdSkipUpdatecheck;
245 string current_version = kCurrentVersion;
Alex Deymo8e18f932015-03-27 16:16:59 -0700246 string version = "1.2.3.4";
Aaron Wood7dcdedf2017-09-06 17:17:41 -0700247 string version2 = "2.3.4.5";
Alex Deymo8e18f932015-03-27 16:16:59 -0700248 string more_info_url = "http://more/info";
249 string prompt = "true";
250 string codebase = "http://code/base/";
Sen Jiang81259682017-03-30 15:11:30 -0700251 string codebase2 = "http://code/base/2/";
Alex Deymo8e18f932015-03-27 16:16:59 -0700252 string filename = "file.signed";
Sen Jiang2703ef42017-03-16 13:36:21 -0700253 string hash = "4841534831323334";
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800254 string fp = "3.98ba213e";
255 string fp2 = "3.755aff78e";
Sen Jiang0affc2c2017-02-10 15:55:05 -0800256 uint64_t size = 123;
Alex Deymo8e18f932015-03-27 16:16:59 -0700257 string deadline = "";
258 string max_days_to_scatter = "7";
259 string elapsed_days = "42";
260
261 // P2P setting defaults to allowed.
262 bool disable_p2p_for_downloading = false;
263 bool disable_p2p_for_sharing = false;
264
Sen Jiangfe284402018-03-21 14:03:50 -0700265 bool powerwash = false;
266
Alex Deymo8e18f932015-03-27 16:16:59 -0700267 // Omaha cohorts settings.
268 bool include_cohorts = false;
269 string cohort = "";
270 string cohorthint = "";
271 string cohortname = "";
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800272 // Whether to include Omaha cohorts for DLC apps.
273 bool include_dlc_cohorts = false;
274 string dlc_cohort = "";
275 string dlc_cohorthint = "";
276 string dlc_cohortname = "";
Alex Deymo8e18f932015-03-27 16:16:59 -0700277
278 // Whether to include the CrOS <!ENTITY> in the XML response.
279 bool include_entity = false;
Sen Jiang0affc2c2017-02-10 15:55:05 -0800280
Sen Jiang81259682017-03-30 15:11:30 -0700281 // Whether to include more than one app.
282 bool multi_app = false;
Sen Jiang00adf7b2017-06-26 15:57:29 -0700283 // Whether to include an app with noupdate="true".
284 bool multi_app_self_update = false;
285 // Whether to include an additional app with status="noupdate".
Sen Jiang81259682017-03-30 15:11:30 -0700286 bool multi_app_no_update = false;
Xiaochu Liu6310be62018-10-11 15:09:03 -0700287 // Whether to include an additional app with no updatecheck tag.
288 bool multi_app_skip_updatecheck = false;
Sen Jiang81259682017-03-30 15:11:30 -0700289 // Whether to include more than one package in an app.
Sen Jiang0affc2c2017-02-10 15:55:05 -0800290 bool multi_package = false;
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -0800291 // Whether to include a DLC app with updatecheck tag.
292 bool dlc_app_update = false;
293 // Whether to include a DLC app with no updatecheck tag.
294 bool dlc_app_no_update = false;
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -0700295
296 // Whether the payload is a rollback.
297 bool rollback = false;
298 // The verified boot firmware key version for the rollback image.
299 string rollback_firmware_version = "";
300 // The verified boot kernel key version for the rollback image.
301 string rollback_kernel_version = "";
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -0700302 // The number of milestones back that the verified boot key version has been
303 // supplied.
304 uint32_t rollback_allowed_milestones = 0;
305 // The verified boot key version for the
306 // |current - rollback_allowed_milestones| most recent release.
307 // The pair contains <firmware_key_version, kernel_key_version> each
308 // of which is in the form "key_version.version".
309 pair<string, string> past_rollback_key_version;
Alex Deymo8e18f932015-03-27 16:16:59 -0700310};
311
312} // namespace
313
Darin Petkov6a5b3222010-07-13 14:55:28 -0700314namespace chromeos_update_engine {
315
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700316class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate {
317 public:
318 OmahaRequestActionTestProcessorDelegate()
319 : expected_code_(ErrorCode::kSuccess),
320 interactive_(false),
321 test_http_fetcher_headers_(false) {}
322 ~OmahaRequestActionTestProcessorDelegate() override = default;
323
324 void ProcessingDone(const ActionProcessor* processor,
325 ErrorCode code) override {
326 brillo::MessageLoop::current()->BreakLoop();
327 }
328
329 void ActionCompleted(ActionProcessor* processor,
330 AbstractAction* action,
331 ErrorCode code) override {
332 // Make sure actions always succeed.
333 if (action->Type() == OmahaRequestAction::StaticType()) {
334 EXPECT_EQ(expected_code_, code);
335 // Check that the headers were set in the fetcher during the action. Note
336 // that we set this request as "interactive".
337 auto fetcher = static_cast<const MockHttpFetcher*>(
338 static_cast<OmahaRequestAction*>(action)->http_fetcher_.get());
339
340 if (test_http_fetcher_headers_) {
341 EXPECT_EQ(interactive_ ? "fg" : "bg",
342 fetcher->GetHeader("X-Goog-Update-Interactivity"));
343 EXPECT_EQ(kTestAppId, fetcher->GetHeader("X-Goog-Update-AppId"));
344 EXPECT_NE("", fetcher->GetHeader("X-Goog-Update-Updater"));
345 }
346 post_data_ = fetcher->post_data();
347 } else if (action->Type() ==
348 ObjectCollectorAction<OmahaResponse>::StaticType()) {
349 EXPECT_EQ(ErrorCode::kSuccess, code);
350 auto collector_action =
351 static_cast<ObjectCollectorAction<OmahaResponse>*>(action);
352 omaha_response_.reset(new OmahaResponse(collector_action->object()));
353 EXPECT_TRUE(omaha_response_);
354 } else {
355 EXPECT_EQ(ErrorCode::kSuccess, code);
356 }
357 }
358 ErrorCode expected_code_;
359 brillo::Blob post_data_;
360 bool interactive_;
361 bool test_http_fetcher_headers_;
362 std::unique_ptr<OmahaResponse> omaha_response_;
363};
364
Amin Hassani41ac04b2019-03-29 11:31:03 -0700365struct TestUpdateCheckParams {
366 string http_response;
367 int fail_http_response_code;
368 bool ping_only;
369 bool is_consumer_device;
370 int rollback_allowed_milestones;
371 bool is_policy_loaded;
372 ErrorCode expected_code;
373 metrics::CheckResult expected_check_result;
374 metrics::CheckReaction expected_check_reaction;
375 metrics::DownloadErrorCode expected_download_error_code;
Jae Hoon Kimedb65502019-06-14 11:52:17 -0700376 string session_id;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700377};
378
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700379class OmahaRequestActionTest : public ::testing::Test {
380 protected:
Alex Deymo610277e2014-11-11 21:18:11 -0800381 void SetUp() override {
Amin Hassani538bd592020-11-04 20:46:08 -0800382 FakeSystemState::CreateInstance();
383
Marton Hunyady2abda312018-04-24 18:21:49 +0200384 request_params_.set_os_sp("service_pack");
385 request_params_.set_os_board("x86-generic");
386 request_params_.set_app_id(kTestAppId);
Xiaochu Liu6310be62018-10-11 15:09:03 -0700387 request_params_.set_app_version(kCurrentVersion);
Marton Hunyady2abda312018-04-24 18:21:49 +0200388 request_params_.set_app_lang("en-US");
389 request_params_.set_current_channel("unittest");
390 request_params_.set_target_channel("unittest");
391 request_params_.set_hwid("OEM MODEL 09235 7471");
Marton Hunyady2abda312018-04-24 18:21:49 +0200392 request_params_.set_delta_okay(true);
393 request_params_.set_interactive(false);
394 request_params_.set_update_url("http://url");
395 request_params_.set_target_version_prefix("");
Marton Hunyadyba51c3f2018-04-25 15:18:10 +0200396 request_params_.set_rollback_allowed(false);
Marton Hunyady2abda312018-04-24 18:21:49 +0200397 request_params_.set_is_powerwash_allowed(false);
Xiaochu Liu6310be62018-10-11 15:09:03 -0700398 request_params_.set_is_install(false);
Andrewe045aef2020-01-08 16:29:22 -0800399 request_params_.set_dlc_apps_params({});
Marton Hunyady2abda312018-04-24 18:21:49 +0200400
Amin Hassani538bd592020-11-04 20:46:08 -0800401 FakeSystemState::Get()->set_request_params(&request_params_);
402 FakeSystemState::Get()->set_prefs(&fake_prefs_);
Amin Hassani41ac04b2019-03-29 11:31:03 -0700403
404 // Setting the default update check params. Lookup |TestUpdateCheck()|.
405 tuc_params_ = {
406 .http_response = "",
407 .fail_http_response_code = -1,
408 .ping_only = false,
409 .is_consumer_device = true,
410 .rollback_allowed_milestones = 0,
411 .is_policy_loaded = false,
412 .expected_code = ErrorCode::kSuccess,
413 .expected_check_result = metrics::CheckResult::kUpdateAvailable,
414 .expected_check_reaction = metrics::CheckReaction::kUpdating,
415 .expected_download_error_code = metrics::DownloadErrorCode::kUnset,
416 };
Jae Hoon Kim694eeb02020-06-01 14:24:08 -0700417
Amin Hassani538bd592020-11-04 20:46:08 -0800418 ON_CALL(*FakeSystemState::Get()->mock_update_attempter(), GetExcluder())
Jae Hoon Kim694eeb02020-06-01 14:24:08 -0700419 .WillByDefault(Return(&mock_excluder_));
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700420 }
421
Andrewe045aef2020-01-08 16:29:22 -0800422 // This function uses the parameters in |tuc_params_| to do an update check.
423 // It will fill out |post_str| with the result data and |response| with
Amin Hassani41ac04b2019-03-29 11:31:03 -0700424 // |OmahaResponse|. Returns true iff an output response was obtained from the
425 // |OmahaRequestAction|. If |fail_http_response_code| is non-negative, the
426 // transfer will fail with that code. |ping_only| is passed through to the
427 // |OmahaRequestAction| constructor.
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700428 //
429 // The |expected_check_result|, |expected_check_reaction| and
Amin Hassani41ac04b2019-03-29 11:31:03 -0700430 // |expected_error_code| parameters are for checking expectations about
431 // reporting UpdateEngine.Check.{Result,Reaction,DownloadError} UMA
432 // statistics. Use the appropriate ::kUnset value to specify that the given
433 // metric should not be reported.
434 bool TestUpdateCheck();
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700435
Amin Hassani41ac04b2019-03-29 11:31:03 -0700436 // Tests events using |event| and |https_response|. It will fill up |post_str|
437 // with the result data.
438 void TestEvent(OmahaEvent* event, const string& http_response);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700439
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800440 // Runs and checks a ping test. |ping_only| indicates whether it should send
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700441 // only a ping or also an updatecheck.
442 void PingTest(bool ping_only);
443
444 // InstallDate test helper function.
Amin Hassani7cc8bb02019-01-14 16:29:47 -0800445 bool InstallDateParseHelper(const string& elapsed_days,
446 OmahaResponse* response);
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700447
448 // P2P test helper function.
Amin Hassani7cc8bb02019-01-14 16:29:47 -0800449 void P2PTest(bool initial_allow_p2p_for_downloading,
450 bool initial_allow_p2p_for_sharing,
451 bool omaha_disable_p2p_for_downloading,
452 bool omaha_disable_p2p_for_sharing,
453 bool payload_state_allow_p2p_attempt,
454 bool expect_p2p_client_lookup,
455 const string& p2p_client_result_url,
456 bool expected_allow_p2p_for_downloading,
457 bool expected_allow_p2p_for_sharing,
458 const string& expected_p2p_url);
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700459
Jae Hoon Kim694eeb02020-06-01 14:24:08 -0700460 StrictMock<MockExcluder> mock_excluder_;
Alex Deymo8e18f932015-03-27 16:16:59 -0700461 FakeUpdateResponse fake_update_response_;
Marton Hunyady2abda312018-04-24 18:21:49 +0200462 // Used by all tests.
Amin Hassani538bd592020-11-04 20:46:08 -0800463 OmahaRequestParams request_params_;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700464
465 FakePrefs fake_prefs_;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700466
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700467 OmahaRequestActionTestProcessorDelegate delegate_;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700468
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700469 bool test_http_fetcher_headers_{false};
Amin Hassani41ac04b2019-03-29 11:31:03 -0700470
471 TestUpdateCheckParams tuc_params_;
472
473 // TODO(ahassani): Add trailing _ to these two variables.
474 OmahaResponse response;
475 string post_str;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700476};
477
Andrew065d78d2020-04-07 15:43:07 -0700478class OmahaRequestActionDlcPingTest : public OmahaRequestActionTest {
479 protected:
480 void SetUp() override {
481 OmahaRequestActionTest::SetUp();
482 dlc_id_ = "dlc0";
483 active_key_ = PrefsInterface::CreateSubKey(
Jae Hoon Kimc1f36922020-05-11 18:20:18 -0700484 {kDlcPrefsSubDir, dlc_id_, kPrefsPingActive});
Andrew065d78d2020-04-07 15:43:07 -0700485 last_active_key_ = PrefsInterface::CreateSubKey(
Jae Hoon Kimc1f36922020-05-11 18:20:18 -0700486 {kDlcPrefsSubDir, dlc_id_, kPrefsPingLastActive});
Andrew065d78d2020-04-07 15:43:07 -0700487 last_rollcall_key_ = PrefsInterface::CreateSubKey(
Jae Hoon Kimc1f36922020-05-11 18:20:18 -0700488 {kDlcPrefsSubDir, dlc_id_, kPrefsPingLastRollcall});
Andrew065d78d2020-04-07 15:43:07 -0700489
490 tuc_params_.http_response =
491 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
492 "protocol=\"3.0\"><daystart elapsed_days=\"4763\" "
493 "elapsed_seconds=\"36540\"/><app appid=\"test-app-id\" status=\"ok\">\""
494 "<updatecheck status=\"noupdate\"/></app><app "
495 "appid=\"test-app-id_dlc0\" "
496 "status=\"ok\"><ping status=\"ok\"/><updatecheck status=\"noupdate\"/>"
497 "</app></response>";
498 tuc_params_.expected_check_result =
499 metrics::CheckResult::kNoUpdateAvailable;
500 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
501 }
502
503 std::string dlc_id_;
504 std::string active_key_;
505 std::string last_active_key_;
506 std::string last_rollcall_key_;
507};
Amin Hassani41ac04b2019-03-29 11:31:03 -0700508bool OmahaRequestActionTest::TestUpdateCheck() {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700509 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700510 loop.SetAsCurrent();
Amin Hassani41ac04b2019-03-29 11:31:03 -0700511 auto fetcher =
512 std::make_unique<MockHttpFetcher>(tuc_params_.http_response.data(),
513 tuc_params_.http_response.size(),
514 nullptr);
515 if (tuc_params_.fail_http_response_code >= 0) {
516 fetcher->FailTransfer(tuc_params_.fail_http_response_code);
Darin Petkovedc522e2010-11-05 09:35:17 -0700517 }
Amin Hassani538bd592020-11-04 20:46:08 -0800518 // This ensures the tests didn't forget to update |FakeSystemState| if they
Amin Hassani61789032020-11-13 16:20:12 -0800519 // are not using the default |request_params_|.
Amin Hassani538bd592020-11-04 20:46:08 -0800520 EXPECT_EQ(&request_params_, FakeSystemState::Get()->request_params());
Marton Hunyady2abda312018-04-24 18:21:49 +0200521
Jae Hoon Kimedb65502019-06-14 11:52:17 -0700522 auto omaha_request_action =
Amin Hassani538bd592020-11-04 20:46:08 -0800523 std::make_unique<OmahaRequestAction>(nullptr,
Jae Hoon Kimedb65502019-06-14 11:52:17 -0700524 std::move(fetcher),
525 tuc_params_.ping_only,
526 tuc_params_.session_id);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700527
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -0800528 auto mock_policy_provider =
529 std::make_unique<NiceMock<policy::MockPolicyProvider>>();
530 EXPECT_CALL(*mock_policy_provider, IsConsumerDevice())
Amin Hassani41ac04b2019-03-29 11:31:03 -0700531 .WillRepeatedly(Return(tuc_params_.is_consumer_device));
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -0800532
533 EXPECT_CALL(*mock_policy_provider, device_policy_is_loaded())
Amin Hassani41ac04b2019-03-29 11:31:03 -0700534 .WillRepeatedly(Return(tuc_params_.is_policy_loaded));
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -0800535
536 const policy::MockDevicePolicy device_policy;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700537 const bool get_allowed_milestone_succeeds =
538 tuc_params_.rollback_allowed_milestones >= 0;
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -0800539 EXPECT_CALL(device_policy, GetRollbackAllowedMilestones(_))
Amin Hassani41ac04b2019-03-29 11:31:03 -0700540 .WillRepeatedly(
541 DoAll(SetArgPointee<0>(tuc_params_.rollback_allowed_milestones),
542 Return(get_allowed_milestone_succeeds)));
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -0800543
544 EXPECT_CALL(*mock_policy_provider, GetDevicePolicy())
545 .WillRepeatedly(ReturnRef(device_policy));
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700546 omaha_request_action->policy_provider_ = std::move(mock_policy_provider);
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -0800547
Amin Hassani41ac04b2019-03-29 11:31:03 -0700548 delegate_.expected_code_ = tuc_params_.expected_code;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700549 delegate_.interactive_ = request_params_.interactive();
550 delegate_.test_http_fetcher_headers_ = test_http_fetcher_headers_;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700551 ActionProcessor processor;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700552 processor.set_delegate(&delegate_);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700553
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700554 auto collector_action =
555 std::make_unique<ObjectCollectorAction<OmahaResponse>>();
556 BondActions(omaha_request_action.get(), collector_action.get());
557 processor.EnqueueAction(std::move(omaha_request_action));
558 processor.EnqueueAction(std::move(collector_action));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700559
Amin Hassani538bd592020-11-04 20:46:08 -0800560 EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),
561 ReportUpdateCheckMetrics(_, _, _))
David Zeuthen33bae492014-02-25 16:16:18 -0800562 .Times(AnyNumber());
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700563
Amin Hassani41ac04b2019-03-29 11:31:03 -0700564 EXPECT_CALL(
Amin Hassani538bd592020-11-04 20:46:08 -0800565 *FakeSystemState::Get()->mock_metrics_reporter(),
566 ReportUpdateCheckMetrics(tuc_params_.expected_check_result,
Amin Hassani41ac04b2019-03-29 11:31:03 -0700567 tuc_params_.expected_check_reaction,
568 tuc_params_.expected_download_error_code))
569 .Times(tuc_params_.ping_only ? 0 : 1);
David Zeuthen33bae492014-02-25 16:16:18 -0800570
Luis Hector Chavezf1cf3482016-07-19 14:29:19 -0700571 loop.PostTask(base::Bind(
572 [](ActionProcessor* processor) { processor->StartProcessing(); },
573 base::Unretained(&processor)));
Alex Deymo60ca1a72015-06-18 18:19:15 -0700574 loop.Run();
Alex Deymo60ca1a72015-06-18 18:19:15 -0700575 EXPECT_FALSE(loop.PendingTasks());
Amin Hassani41ac04b2019-03-29 11:31:03 -0700576 if (delegate_.omaha_response_)
577 response = *delegate_.omaha_response_;
578 post_str = string(delegate_.post_data_.begin(), delegate_.post_data_.end());
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700579 return delegate_.omaha_response_ != nullptr;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700580}
581
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700582// Tests Event requests -- they should always succeed. |out_post_data| may be
583// null; if non-null, the post-data received by the mock HttpFetcher is
584// returned.
585void OmahaRequestActionTest::TestEvent(OmahaEvent* event,
Amin Hassani41ac04b2019-03-29 11:31:03 -0700586 const string& http_response) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700587 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700588 loop.SetAsCurrent();
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700589
590 auto action = std::make_unique<OmahaRequestAction>(
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700591 event,
592 std::make_unique<MockHttpFetcher>(
593 http_response.data(), http_response.size(), nullptr),
Jae Hoon Kimedb65502019-06-14 11:52:17 -0700594 false,
595 "");
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700596 ActionProcessor processor;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700597 processor.set_delegate(&delegate_);
598 processor.EnqueueAction(std::move(action));
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700599
Luis Hector Chavezf1cf3482016-07-19 14:29:19 -0700600 loop.PostTask(base::Bind(
601 [](ActionProcessor* processor) { processor->StartProcessing(); },
602 base::Unretained(&processor)));
Alex Deymo60ca1a72015-06-18 18:19:15 -0700603 loop.Run();
Alex Deymo72a25672016-03-23 15:44:39 -0700604 EXPECT_FALSE(loop.PendingTasks());
Alex Deymo60ca1a72015-06-18 18:19:15 -0700605
Amin Hassani41ac04b2019-03-29 11:31:03 -0700606 post_str = string(delegate_.post_data_.begin(), delegate_.post_data_.end());
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700607}
608
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700609TEST_F(OmahaRequestActionTest, RejectEntities) {
Alex Deymo8e18f932015-03-27 16:16:59 -0700610 fake_update_response_.include_entity = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700611 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
612 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLHasEntityDecl;
613 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
614 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
615
616 ASSERT_FALSE(TestUpdateCheck());
David Zeuthenf3e28012014-08-26 18:23:52 -0400617 EXPECT_FALSE(response.update_exists);
618}
619
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700620TEST_F(OmahaRequestActionTest, NoUpdateTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -0700621 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
622 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
623 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
624
625 ASSERT_TRUE(TestUpdateCheck());
Darin Petkov6a5b3222010-07-13 14:55:28 -0700626 EXPECT_FALSE(response.update_exists);
627}
628
Sen Jiang81259682017-03-30 15:11:30 -0700629TEST_F(OmahaRequestActionTest, MultiAppNoUpdateTest) {
Sen Jiang81259682017-03-30 15:11:30 -0700630 fake_update_response_.multi_app_no_update = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700631 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
632 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
633 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
634
635 ASSERT_TRUE(TestUpdateCheck());
Sen Jiang81259682017-03-30 15:11:30 -0700636 EXPECT_FALSE(response.update_exists);
637}
638
Sen Jiang00adf7b2017-06-26 15:57:29 -0700639TEST_F(OmahaRequestActionTest, MultiAppNoPartialUpdateTest) {
Sen Jiang00adf7b2017-06-26 15:57:29 -0700640 fake_update_response_.multi_app_no_update = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700641 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
642 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
643 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
644
645 ASSERT_TRUE(TestUpdateCheck());
Sen Jiang00adf7b2017-06-26 15:57:29 -0700646 EXPECT_FALSE(response.update_exists);
647}
648
649TEST_F(OmahaRequestActionTest, NoSelfUpdateTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -0700650 tuc_params_.http_response =
Sen Jiang00adf7b2017-06-26 15:57:29 -0700651 "<response><app><updatecheck status=\"ok\"><manifest><actions><action "
652 "event=\"postinstall\" noupdate=\"true\"/></actions>"
Amin Hassani41ac04b2019-03-29 11:31:03 -0700653 "</manifest></updatecheck></app></response>";
654 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
655 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
656
657 ASSERT_TRUE(TestUpdateCheck());
Sen Jiang00adf7b2017-06-26 15:57:29 -0700658 EXPECT_FALSE(response.update_exists);
659}
660
Alex Deymo8e18f932015-03-27 16:16:59 -0700661// Test that all the values in the response are parsed in a normal update
662// response.
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700663TEST_F(OmahaRequestActionTest, ValidUpdateTest) {
Alex Deymo8e18f932015-03-27 16:16:59 -0700664 fake_update_response_.deadline = "20101020";
Amin Hassani41ac04b2019-03-29 11:31:03 -0700665 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
666
667 ASSERT_TRUE(TestUpdateCheck());
668
Darin Petkov6a5b3222010-07-13 14:55:28 -0700669 EXPECT_TRUE(response.update_exists);
Alex Deymo8e18f932015-03-27 16:16:59 -0700670 EXPECT_EQ(fake_update_response_.version, response.version);
Sen Jiang0affc2c2017-02-10 15:55:05 -0800671 EXPECT_EQ(fake_update_response_.GetPayloadUrl(),
672 response.packages[0].payload_urls[0]);
Alex Deymo8e18f932015-03-27 16:16:59 -0700673 EXPECT_EQ(fake_update_response_.more_info_url, response.more_info_url);
Sen Jiang0affc2c2017-02-10 15:55:05 -0800674 EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash);
675 EXPECT_EQ(fake_update_response_.size, response.packages[0].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800676 EXPECT_EQ(fake_update_response_.fp, response.packages[0].fp);
Sen Jiangcdd52062017-05-18 15:33:10 -0700677 EXPECT_EQ(true, response.packages[0].is_delta);
Alex Deymo8e18f932015-03-27 16:16:59 -0700678 EXPECT_EQ(fake_update_response_.prompt == "true", response.prompt);
679 EXPECT_EQ(fake_update_response_.deadline, response.deadline);
Sen Jiangfe284402018-03-21 14:03:50 -0700680 EXPECT_FALSE(response.powerwash_required);
Aaron Wood7dcdedf2017-09-06 17:17:41 -0700681 // Omaha cohort attributes are not set in the response, so they should not be
Alex Deymo8e18f932015-03-27 16:16:59 -0700682 // persisted.
683 EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohort));
684 EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortHint));
685 EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortName));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700686}
687
Sen Jiang0affc2c2017-02-10 15:55:05 -0800688TEST_F(OmahaRequestActionTest, MultiPackageUpdateTest) {
Sen Jiang0affc2c2017-02-10 15:55:05 -0800689 fake_update_response_.multi_package = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700690 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
691
692 ASSERT_TRUE(TestUpdateCheck());
693
Sen Jiang0affc2c2017-02-10 15:55:05 -0800694 EXPECT_TRUE(response.update_exists);
695 EXPECT_EQ(fake_update_response_.version, response.version);
696 EXPECT_EQ(fake_update_response_.GetPayloadUrl(),
697 response.packages[0].payload_urls[0]);
698 EXPECT_EQ(fake_update_response_.codebase + "package2",
699 response.packages[1].payload_urls[0]);
700 EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash);
701 EXPECT_EQ(fake_update_response_.size, response.packages[0].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800702 EXPECT_EQ(fake_update_response_.fp, response.packages[0].fp);
Sen Jiangcdd52062017-05-18 15:33:10 -0700703 EXPECT_EQ(true, response.packages[0].is_delta);
Sen Jiang81259682017-03-30 15:11:30 -0700704 EXPECT_EQ(11u, response.packages[0].metadata_size);
Sen Jiang0affc2c2017-02-10 15:55:05 -0800705 ASSERT_EQ(2u, response.packages.size());
Sen Jiang81259682017-03-30 15:11:30 -0700706 EXPECT_EQ(string("hash2"), response.packages[1].hash);
Sen Jiang0affc2c2017-02-10 15:55:05 -0800707 EXPECT_EQ(222u, response.packages[1].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800708 EXPECT_EQ(fake_update_response_.fp2, response.packages[1].fp);
Sen Jiang81259682017-03-30 15:11:30 -0700709 EXPECT_EQ(22u, response.packages[1].metadata_size);
Sen Jiangcdd52062017-05-18 15:33:10 -0700710 EXPECT_EQ(false, response.packages[1].is_delta);
Sen Jiang81259682017-03-30 15:11:30 -0700711}
712
713TEST_F(OmahaRequestActionTest, MultiAppUpdateTest) {
Sen Jiang81259682017-03-30 15:11:30 -0700714 fake_update_response_.multi_app = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700715 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
716
717 ASSERT_TRUE(TestUpdateCheck());
718
Sen Jiang81259682017-03-30 15:11:30 -0700719 EXPECT_TRUE(response.update_exists);
720 EXPECT_EQ(fake_update_response_.version, response.version);
721 EXPECT_EQ(fake_update_response_.GetPayloadUrl(),
722 response.packages[0].payload_urls[0]);
723 EXPECT_EQ(fake_update_response_.codebase2 + "package3",
724 response.packages[1].payload_urls[0]);
725 EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash);
726 EXPECT_EQ(fake_update_response_.size, response.packages[0].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800727 EXPECT_EQ(fake_update_response_.fp, response.packages[0].fp);
Sen Jiang81259682017-03-30 15:11:30 -0700728 EXPECT_EQ(11u, response.packages[0].metadata_size);
Sen Jiangcdd52062017-05-18 15:33:10 -0700729 EXPECT_EQ(true, response.packages[0].is_delta);
Sen Jiang81259682017-03-30 15:11:30 -0700730 ASSERT_EQ(2u, response.packages.size());
731 EXPECT_EQ(string("hash3"), response.packages[1].hash);
732 EXPECT_EQ(333u, response.packages[1].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800733 EXPECT_EQ(fake_update_response_.fp2, response.packages[1].fp);
Sen Jiang81259682017-03-30 15:11:30 -0700734 EXPECT_EQ(33u, response.packages[1].metadata_size);
Sen Jiangcdd52062017-05-18 15:33:10 -0700735 EXPECT_EQ(false, response.packages[1].is_delta);
Sen Jiang81259682017-03-30 15:11:30 -0700736}
737
738TEST_F(OmahaRequestActionTest, MultiAppPartialUpdateTest) {
Sen Jiang00adf7b2017-06-26 15:57:29 -0700739 fake_update_response_.multi_app = true;
740 fake_update_response_.multi_app_self_update = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700741 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
742
743 ASSERT_TRUE(TestUpdateCheck());
744
Sen Jiang81259682017-03-30 15:11:30 -0700745 EXPECT_TRUE(response.update_exists);
746 EXPECT_EQ(fake_update_response_.version, response.version);
747 EXPECT_EQ(fake_update_response_.GetPayloadUrl(),
748 response.packages[0].payload_urls[0]);
749 EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash);
750 EXPECT_EQ(fake_update_response_.size, response.packages[0].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800751 EXPECT_EQ(fake_update_response_.fp, response.packages[0].fp);
Sen Jiang81259682017-03-30 15:11:30 -0700752 EXPECT_EQ(11u, response.packages[0].metadata_size);
Sen Jiang00adf7b2017-06-26 15:57:29 -0700753 ASSERT_EQ(2u, response.packages.size());
754 EXPECT_EQ(string("hash3"), response.packages[1].hash);
755 EXPECT_EQ(333u, response.packages[1].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800756 EXPECT_EQ(fake_update_response_.fp2, response.packages[1].fp);
Sen Jiang00adf7b2017-06-26 15:57:29 -0700757 EXPECT_EQ(33u, response.packages[1].metadata_size);
758 EXPECT_EQ(true, response.packages[1].is_delta);
Sen Jiang81259682017-03-30 15:11:30 -0700759}
760
761TEST_F(OmahaRequestActionTest, MultiAppMultiPackageUpdateTest) {
Sen Jiang81259682017-03-30 15:11:30 -0700762 fake_update_response_.multi_app = true;
763 fake_update_response_.multi_package = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700764 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
765
766 ASSERT_TRUE(TestUpdateCheck());
767
Sen Jiang81259682017-03-30 15:11:30 -0700768 EXPECT_TRUE(response.update_exists);
769 EXPECT_EQ(fake_update_response_.version, response.version);
770 EXPECT_EQ(fake_update_response_.GetPayloadUrl(),
771 response.packages[0].payload_urls[0]);
772 EXPECT_EQ(fake_update_response_.codebase + "package2",
773 response.packages[1].payload_urls[0]);
774 EXPECT_EQ(fake_update_response_.codebase2 + "package3",
775 response.packages[2].payload_urls[0]);
776 EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash);
777 EXPECT_EQ(fake_update_response_.size, response.packages[0].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800778 EXPECT_EQ(fake_update_response_.fp, response.packages[0].fp);
Sen Jiang81259682017-03-30 15:11:30 -0700779 EXPECT_EQ(11u, response.packages[0].metadata_size);
Sen Jiangcdd52062017-05-18 15:33:10 -0700780 EXPECT_EQ(true, response.packages[0].is_delta);
Sen Jiang81259682017-03-30 15:11:30 -0700781 ASSERT_EQ(3u, response.packages.size());
782 EXPECT_EQ(string("hash2"), response.packages[1].hash);
783 EXPECT_EQ(222u, response.packages[1].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800784 EXPECT_EQ(fake_update_response_.fp2, response.packages[1].fp);
Sen Jiang81259682017-03-30 15:11:30 -0700785 EXPECT_EQ(22u, response.packages[1].metadata_size);
Sen Jiangcdd52062017-05-18 15:33:10 -0700786 EXPECT_EQ(false, response.packages[1].is_delta);
Sen Jiang81259682017-03-30 15:11:30 -0700787 EXPECT_EQ(string("hash3"), response.packages[2].hash);
788 EXPECT_EQ(333u, response.packages[2].size);
Vyshu Khota4c5413d2020-11-04 16:17:25 -0800789 EXPECT_EQ(fake_update_response_.fp2, response.packages[2].fp);
Sen Jiang81259682017-03-30 15:11:30 -0700790 EXPECT_EQ(33u, response.packages[2].metadata_size);
Sen Jiangcdd52062017-05-18 15:33:10 -0700791 EXPECT_EQ(false, response.packages[2].is_delta);
Sen Jiang0affc2c2017-02-10 15:55:05 -0800792}
793
Sen Jiangfe284402018-03-21 14:03:50 -0700794TEST_F(OmahaRequestActionTest, PowerwashTest) {
Sen Jiangfe284402018-03-21 14:03:50 -0700795 fake_update_response_.powerwash = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700796 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
797
798 ASSERT_TRUE(TestUpdateCheck());
799
Sen Jiangfe284402018-03-21 14:03:50 -0700800 EXPECT_TRUE(response.update_exists);
801 EXPECT_TRUE(response.powerwash_required);
802}
803
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700804TEST_F(OmahaRequestActionTest, ExtraHeadersSentInteractiveTest) {
Alex Deymo14ad88e2016-06-29 12:30:14 -0700805 request_params_.set_interactive(true);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700806 test_http_fetcher_headers_ = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700807 tuc_params_.http_response = "invalid xml>";
808 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
809 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
810 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
811
812 ASSERT_FALSE(TestUpdateCheck());
813
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700814 EXPECT_FALSE(response.update_exists);
815}
Alex Deymo14ad88e2016-06-29 12:30:14 -0700816
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700817TEST_F(OmahaRequestActionTest, ExtraHeadersSentNoInteractiveTest) {
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700818 request_params_.set_interactive(false);
819 test_http_fetcher_headers_ = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -0700820 tuc_params_.http_response = "invalid xml>";
821 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
822 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
823 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
824
825 ASSERT_FALSE(TestUpdateCheck());
826
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700827 EXPECT_FALSE(response.update_exists);
Alex Deymo14ad88e2016-06-29 12:30:14 -0700828}
829
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700830TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByConnection) {
Chris Sosa77f79e82014-06-02 18:16:24 -0700831 // Set up a connection manager that doesn't allow a valid update over
832 // the current ethernet connection.
Alex Deymof6ee0162015-07-31 12:35:22 -0700833 MockConnectionManager mock_cm;
Amin Hassani538bd592020-11-04 20:46:08 -0800834 FakeSystemState::Get()->set_connection_manager(&mock_cm);
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700835
Alex Deymo30534502015-07-20 15:06:33 -0700836 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
Amin Hassani7cc8bb02019-01-14 16:29:47 -0800837 .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kEthernet),
838 SetArgPointee<1>(ConnectionTethering::kUnknown),
839 Return(true)));
Sen Jiang255e22b2016-05-20 16:15:29 -0700840 EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kEthernet, _))
841 .WillRepeatedly(Return(false));
Chris Sosa77f79e82014-06-02 18:16:24 -0700842
Amin Hassani41ac04b2019-03-29 11:31:03 -0700843 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
844 tuc_params_.expected_code = ErrorCode::kOmahaUpdateIgnoredPerPolicy;
845 tuc_params_.expected_check_reaction = metrics::CheckReaction::kIgnored;
846
847 ASSERT_FALSE(TestUpdateCheck());
848
Chris Sosa77f79e82014-06-02 18:16:24 -0700849 EXPECT_FALSE(response.update_exists);
850}
851
Weidong Guo421ff332017-04-17 10:08:38 -0700852TEST_F(OmahaRequestActionTest, ValidUpdateOverCellularAllowedByDevicePolicy) {
853 // This test tests that update over cellular is allowed as device policy
854 // says yes.
Weidong Guo421ff332017-04-17 10:08:38 -0700855 MockConnectionManager mock_cm;
Amin Hassani538bd592020-11-04 20:46:08 -0800856 FakeSystemState::Get()->set_connection_manager(&mock_cm);
Weidong Guo421ff332017-04-17 10:08:38 -0700857
858 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
859 .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular),
860 SetArgPointee<1>(ConnectionTethering::kUnknown),
861 Return(true)));
862 EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet())
863 .WillRepeatedly(Return(true));
864 EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _))
865 .WillRepeatedly(Return(true));
866
Amin Hassani41ac04b2019-03-29 11:31:03 -0700867 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
868
869 ASSERT_TRUE(TestUpdateCheck());
870
Weidong Guo421ff332017-04-17 10:08:38 -0700871 EXPECT_TRUE(response.update_exists);
872}
873
874TEST_F(OmahaRequestActionTest, ValidUpdateOverCellularBlockedByDevicePolicy) {
875 // This test tests that update over cellular is blocked as device policy
876 // says no.
Weidong Guo421ff332017-04-17 10:08:38 -0700877 MockConnectionManager mock_cm;
Amin Hassani538bd592020-11-04 20:46:08 -0800878 FakeSystemState::Get()->set_connection_manager(&mock_cm);
Weidong Guo421ff332017-04-17 10:08:38 -0700879
880 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
881 .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular),
882 SetArgPointee<1>(ConnectionTethering::kUnknown),
883 Return(true)));
884 EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet())
885 .WillRepeatedly(Return(true));
886 EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _))
887 .WillRepeatedly(Return(false));
888
Amin Hassani41ac04b2019-03-29 11:31:03 -0700889 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
890 tuc_params_.expected_code = ErrorCode::kOmahaUpdateIgnoredPerPolicy;
891 tuc_params_.expected_check_reaction = metrics::CheckReaction::kIgnored;
892
893 ASSERT_FALSE(TestUpdateCheck());
894
Weidong Guo421ff332017-04-17 10:08:38 -0700895 EXPECT_FALSE(response.update_exists);
896}
897
898TEST_F(OmahaRequestActionTest,
899 ValidUpdateOverCellularAllowedByUserPermissionTrue) {
900 // This test tests that, when device policy is not set, update over cellular
901 // is allowed as permission for update over cellular is set to true.
Weidong Guo421ff332017-04-17 10:08:38 -0700902 MockConnectionManager mock_cm;
Weidong Guo421ff332017-04-17 10:08:38 -0700903 fake_prefs_.SetBoolean(kPrefsUpdateOverCellularPermission, true);
Amin Hassani538bd592020-11-04 20:46:08 -0800904 FakeSystemState::Get()->set_connection_manager(&mock_cm);
Weidong Guo421ff332017-04-17 10:08:38 -0700905
906 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
907 .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular),
908 SetArgPointee<1>(ConnectionTethering::kUnknown),
909 Return(true)));
910 EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet())
911 .WillRepeatedly(Return(false));
912 EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _))
913 .WillRepeatedly(Return(true));
914
Amin Hassani41ac04b2019-03-29 11:31:03 -0700915 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
916
917 ASSERT_TRUE(TestUpdateCheck());
918
Weidong Guo421ff332017-04-17 10:08:38 -0700919 EXPECT_TRUE(response.update_exists);
920}
921
922TEST_F(OmahaRequestActionTest,
923 ValidUpdateOverCellularBlockedByUpdateTargetNotMatch) {
924 // This test tests that, when device policy is not set and permission for
925 // update over cellular is set to false or does not exist, update over
926 // cellular is blocked as update target does not match the omaha response.
Weidong Guo421ff332017-04-17 10:08:38 -0700927 MockConnectionManager mock_cm;
928 // A version different from the version in omaha response.
929 string diff_version = "99.99.99";
930 // A size different from the size in omaha response.
931 int64_t diff_size = 999;
932
933 fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, diff_version);
934 fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, diff_size);
935 // This test tests cellular (3G) being the only connection type being allowed.
Amin Hassani538bd592020-11-04 20:46:08 -0800936 FakeSystemState::Get()->set_connection_manager(&mock_cm);
Weidong Guo421ff332017-04-17 10:08:38 -0700937
938 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
939 .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular),
940 SetArgPointee<1>(ConnectionTethering::kUnknown),
941 Return(true)));
942 EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet())
943 .WillRepeatedly(Return(false));
944 EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _))
945 .WillRepeatedly(Return(true));
946
Amin Hassani41ac04b2019-03-29 11:31:03 -0700947 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
948 tuc_params_.expected_code = ErrorCode::kOmahaUpdateIgnoredOverCellular;
949 tuc_params_.expected_check_reaction = metrics::CheckReaction::kIgnored;
950
951 ASSERT_FALSE(TestUpdateCheck());
952
Weidong Guo421ff332017-04-17 10:08:38 -0700953 EXPECT_FALSE(response.update_exists);
954}
955
956TEST_F(OmahaRequestActionTest,
957 ValidUpdateOverCellularAllowedByUpdateTargetMatch) {
958 // This test tests that, when device policy is not set and permission for
959 // update over cellular is set to false or does not exist, update over
960 // cellular is allowed as update target matches the omaha response.
Weidong Guo421ff332017-04-17 10:08:38 -0700961 MockConnectionManager mock_cm;
962 // A version same as the version in omaha response.
963 string new_version = fake_update_response_.version;
964 // A size same as the size in omaha response.
965 int64_t new_size = fake_update_response_.size;
966
967 fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, new_version);
968 fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, new_size);
Amin Hassani538bd592020-11-04 20:46:08 -0800969 FakeSystemState::Get()->set_connection_manager(&mock_cm);
Weidong Guo421ff332017-04-17 10:08:38 -0700970
971 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
972 .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular),
973 SetArgPointee<1>(ConnectionTethering::kUnknown),
974 Return(true)));
975 EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet())
976 .WillRepeatedly(Return(false));
977 EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _))
978 .WillRepeatedly(Return(true));
979
Amin Hassani41ac04b2019-03-29 11:31:03 -0700980 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
981
982 ASSERT_TRUE(TestUpdateCheck());
983
Weidong Guo421ff332017-04-17 10:08:38 -0700984 EXPECT_TRUE(response.update_exists);
985}
986
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700987TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByRollback) {
Chris Sosa77f79e82014-06-02 18:16:24 -0700988 string rollback_version = "1234.0.0";
Chris Sosa77f79e82014-06-02 18:16:24 -0700989 MockPayloadState mock_payload_state;
Amin Hassani538bd592020-11-04 20:46:08 -0800990 FakeSystemState::Get()->set_payload_state(&mock_payload_state);
Amin Hassani41ac04b2019-03-29 11:31:03 -0700991 fake_update_response_.version = rollback_version;
992 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
993 tuc_params_.expected_code = ErrorCode::kOmahaUpdateIgnoredPerPolicy;
994 tuc_params_.expected_check_reaction = metrics::CheckReaction::kIgnored;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700995
Chris Sosa77f79e82014-06-02 18:16:24 -0700996 EXPECT_CALL(mock_payload_state, GetRollbackVersion())
Amin Hassani7cc8bb02019-01-14 16:29:47 -0800997 .WillRepeatedly(Return(rollback_version));
Chris Sosa77f79e82014-06-02 18:16:24 -0700998
Amin Hassani41ac04b2019-03-29 11:31:03 -0700999 ASSERT_FALSE(TestUpdateCheck());
1000
Chris Sosa77f79e82014-06-02 18:16:24 -07001001 EXPECT_FALSE(response.update_exists);
1002}
1003
Marton Hunyadyc2882062018-05-14 17:28:25 +02001004// Verify that update checks called during OOBE will not try to download an
1005// update if the response doesn't include the deadline field.
Kevin Cernekee2494e282016-03-29 18:03:53 -07001006TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBE) {
Amin Hassani538bd592020-11-04 20:46:08 -08001007 FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
Amin Hassani41ac04b2019-03-29 11:31:03 -07001008 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1009 tuc_params_.expected_code = ErrorCode::kNonCriticalUpdateInOOBE;
1010 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1011 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
Kevin Cernekee2494e282016-03-29 18:03:53 -07001012
Sen Jiang8cd42342018-01-31 12:06:59 -08001013 // TODO(senj): set better default value for metrics::checkresult in
Tianjie Xu282aa1f2017-09-05 13:42:45 -07001014 // OmahaRequestAction::ActionCompleted.
Amin Hassani41ac04b2019-03-29 11:31:03 -07001015 ASSERT_FALSE(TestUpdateCheck());
1016
Kevin Cernekee2494e282016-03-29 18:03:53 -07001017 EXPECT_FALSE(response.update_exists);
Marton Hunyadyc2882062018-05-14 17:28:25 +02001018}
Kevin Cernekee2494e282016-03-29 18:03:53 -07001019
Marton Hunyadyc2882062018-05-14 17:28:25 +02001020// Verify that the IsOOBEComplete() value is ignored when the OOBE flow is not
1021// enabled.
1022TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBEDisabled) {
Amin Hassani538bd592020-11-04 20:46:08 -08001023 FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
1024 FakeSystemState::Get()->fake_hardware()->SetIsOOBEEnabled(false);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001025 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Alex Deymo46a9aae2016-05-04 20:20:11 -07001026
Amin Hassani41ac04b2019-03-29 11:31:03 -07001027 ASSERT_TRUE(TestUpdateCheck());
1028
Kevin Cernekee2494e282016-03-29 18:03:53 -07001029 EXPECT_TRUE(response.update_exists);
1030}
1031
Marton Hunyadyc2882062018-05-14 17:28:25 +02001032// Verify that update checks called during OOBE will still try to download an
1033// update if the response includes the deadline field.
1034TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBEDeadlineSet) {
Amin Hassani538bd592020-11-04 20:46:08 -08001035 FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
Marton Hunyadyc2882062018-05-14 17:28:25 +02001036 fake_update_response_.deadline = "20101020";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001037 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Marton Hunyadyc2882062018-05-14 17:28:25 +02001038
Amin Hassani41ac04b2019-03-29 11:31:03 -07001039 ASSERT_TRUE(TestUpdateCheck());
1040
Marton Hunyadyc2882062018-05-14 17:28:25 +02001041 EXPECT_TRUE(response.update_exists);
1042}
1043
1044// Verify that update checks called during OOBE will not try to download an
1045// update if a rollback happened, even when the response includes the deadline
1046// field.
1047TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBERollback) {
Amin Hassani538bd592020-11-04 20:46:08 -08001048 FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
Marton Hunyadyc2882062018-05-14 17:28:25 +02001049 fake_update_response_.deadline = "20101020";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001050 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1051 tuc_params_.expected_code = ErrorCode::kNonCriticalUpdateInOOBE;
1052 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1053 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1054
Amin Hassani538bd592020-11-04 20:46:08 -08001055 EXPECT_CALL(*(FakeSystemState::Get()->mock_payload_state()),
1056 GetRollbackHappened())
Marton Hunyadyc2882062018-05-14 17:28:25 +02001057 .WillOnce(Return(true));
1058
Amin Hassani41ac04b2019-03-29 11:31:03 -07001059 ASSERT_FALSE(TestUpdateCheck());
1060
Marton Hunyadyc2882062018-05-14 17:28:25 +02001061 EXPECT_FALSE(response.update_exists);
1062}
1063
Toni Barzic61544e62018-10-11 14:37:30 -07001064// Verify that non-critical updates are skipped by reporting the
1065// kNonCriticalUpdateInOOBE error code when attempted over cellular network -
1066// i.e. when the update would need user permission. Note that reporting
1067// kOmahaUpdateIgnoredOverCellular error in this case might cause undesired UX
1068// in OOBE (warning the user about an update that will be skipped).
1069TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesInOOBEOverCellular) {
Amin Hassani538bd592020-11-04 20:46:08 -08001070 FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
Toni Barzic61544e62018-10-11 14:37:30 -07001071
1072 MockConnectionManager mock_cm;
Amin Hassani538bd592020-11-04 20:46:08 -08001073 FakeSystemState::Get()->set_connection_manager(&mock_cm);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001074 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1075 tuc_params_.expected_code = ErrorCode::kNonCriticalUpdateInOOBE;
1076 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1077 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
Toni Barzic61544e62018-10-11 14:37:30 -07001078
1079 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
1080 .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular),
1081 SetArgPointee<1>(ConnectionTethering::kUnknown),
1082 Return(true)));
1083 EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet())
1084 .WillRepeatedly(Return(false));
1085
Amin Hassani41ac04b2019-03-29 11:31:03 -07001086 ASSERT_FALSE(TestUpdateCheck());
1087
Toni Barzic61544e62018-10-11 14:37:30 -07001088 EXPECT_FALSE(response.update_exists);
1089}
1090
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001091TEST_F(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001092 request_params_.set_wall_clock_based_wait_enabled(true);
1093 request_params_.set_update_check_count_wait_enabled(false);
1094 request_params_.set_waiting_period(TimeDelta::FromDays(2));
Amin Hassani538bd592020-11-04 20:46:08 -08001095 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
Amin Hassani41ac04b2019-03-29 11:31:03 -07001096 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1097 tuc_params_.expected_code = ErrorCode::kOmahaUpdateDeferredPerPolicy;
1098 tuc_params_.expected_check_reaction = metrics::CheckReaction::kDeferring;
May Lippert60aa3ca2018-08-15 16:55:29 -07001099
Amin Hassani41ac04b2019-03-29 11:31:03 -07001100 ASSERT_FALSE(TestUpdateCheck());
1101
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001102 EXPECT_FALSE(response.update_exists);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001103}
1104
1105TEST_F(OmahaRequestActionTest,
1106 WallClockBasedWaitAloneCausesScatteringInteractive) {
1107 request_params_.set_wall_clock_based_wait_enabled(true);
1108 request_params_.set_update_check_count_wait_enabled(false);
1109 request_params_.set_waiting_period(TimeDelta::FromDays(2));
1110 request_params_.set_interactive(true);
Amin Hassani538bd592020-11-04 20:46:08 -08001111 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
Amin Hassani41ac04b2019-03-29 11:31:03 -07001112 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Chris Sosa968d0572013-08-23 14:46:02 -07001113
1114 // Verify if we are interactive check we don't defer.
Amin Hassani41ac04b2019-03-29 11:31:03 -07001115 ASSERT_TRUE(TestUpdateCheck());
1116
Chris Sosa968d0572013-08-23 14:46:02 -07001117 EXPECT_TRUE(response.update_exists);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001118}
1119
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001120TEST_F(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001121 request_params_.set_wall_clock_based_wait_enabled(false);
1122 request_params_.set_waiting_period(TimeDelta::FromDays(2));
1123 request_params_.set_update_check_count_wait_enabled(true);
1124 request_params_.set_min_update_checks_needed(1);
1125 request_params_.set_max_update_checks_allowed(8);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001126 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001127
Amin Hassani41ac04b2019-03-29 11:31:03 -07001128 ASSERT_TRUE(TestUpdateCheck());
1129
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001130 EXPECT_TRUE(response.update_exists);
1131}
1132
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001133TEST_F(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001134 request_params_.set_wall_clock_based_wait_enabled(true);
1135 request_params_.set_waiting_period(TimeDelta::FromDays(2));
1136 request_params_.set_update_check_count_wait_enabled(true);
1137 request_params_.set_min_update_checks_needed(1);
1138 request_params_.set_max_update_checks_allowed(8);
Alex Deymo8e18f932015-03-27 16:16:59 -07001139 fake_update_response_.max_days_to_scatter = "0";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001140 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1141
1142 ASSERT_TRUE(TestUpdateCheck());
1143
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001144 EXPECT_TRUE(response.update_exists);
1145}
1146
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001147TEST_F(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001148 request_params_.set_wall_clock_based_wait_enabled(true);
1149 request_params_.set_waiting_period(TimeDelta());
1150 request_params_.set_update_check_count_wait_enabled(true);
1151 request_params_.set_min_update_checks_needed(0);
1152 request_params_.set_max_update_checks_allowed(0);
Amin Hassani538bd592020-11-04 20:46:08 -08001153 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
Amin Hassani41ac04b2019-03-29 11:31:03 -07001154 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
May Lippert60aa3ca2018-08-15 16:55:29 -07001155
Amin Hassani41ac04b2019-03-29 11:31:03 -07001156 ASSERT_TRUE(TestUpdateCheck());
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001157
Ben Chan9abb7632014-08-07 00:10:53 -07001158 int64_t count;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001159 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001160 ASSERT_EQ(count, 0);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001161 EXPECT_TRUE(response.update_exists);
1162}
1163
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001164TEST_F(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001165 request_params_.set_wall_clock_based_wait_enabled(true);
1166 request_params_.set_waiting_period(TimeDelta());
1167 request_params_.set_update_check_count_wait_enabled(true);
1168 request_params_.set_min_update_checks_needed(1);
1169 request_params_.set_max_update_checks_allowed(8);
Amin Hassani538bd592020-11-04 20:46:08 -08001170 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
Amin Hassani41ac04b2019-03-29 11:31:03 -07001171 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1172 tuc_params_.expected_code = ErrorCode::kOmahaUpdateDeferredPerPolicy;
1173 tuc_params_.expected_check_reaction = metrics::CheckReaction::kDeferring;
May Lippert60aa3ca2018-08-15 16:55:29 -07001174
Amin Hassani41ac04b2019-03-29 11:31:03 -07001175 ASSERT_FALSE(TestUpdateCheck());
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001176
Ben Chan9abb7632014-08-07 00:10:53 -07001177 int64_t count;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001178 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001179 ASSERT_GT(count, 0);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001180 EXPECT_FALSE(response.update_exists);
1181}
1182
Amin Hassani41ac04b2019-03-29 11:31:03 -07001183TEST_F(OmahaRequestActionTest,
1184 NonZeroUpdateCheckCountCausesScatteringInteractive) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001185 request_params_.set_wall_clock_based_wait_enabled(true);
1186 request_params_.set_waiting_period(TimeDelta());
1187 request_params_.set_update_check_count_wait_enabled(true);
1188 request_params_.set_min_update_checks_needed(1);
1189 request_params_.set_max_update_checks_allowed(8);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001190 request_params_.set_interactive(true);
Amin Hassani538bd592020-11-04 20:46:08 -08001191 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
Amin Hassani41ac04b2019-03-29 11:31:03 -07001192 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1193
1194 // Verify if we are interactive check we don't defer.
1195 ASSERT_TRUE(TestUpdateCheck());
1196
1197 EXPECT_TRUE(response.update_exists);
1198}
1199
1200TEST_F(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) {
1201 request_params_.set_wall_clock_based_wait_enabled(true);
1202 request_params_.set_waiting_period(TimeDelta());
1203 request_params_.set_update_check_count_wait_enabled(true);
1204 request_params_.set_min_update_checks_needed(1);
1205 request_params_.set_max_update_checks_allowed(8);
Amin Hassani538bd592020-11-04 20:46:08 -08001206 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
Amin Hassani41ac04b2019-03-29 11:31:03 -07001207 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1208 tuc_params_.expected_code = ErrorCode::kOmahaUpdateDeferredPerPolicy;
1209 tuc_params_.expected_check_reaction = metrics::CheckReaction::kDeferring;
May Lippert60aa3ca2018-08-15 16:55:29 -07001210
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001211 ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001212 ASSERT_FALSE(TestUpdateCheck());
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001213
Ben Chan9abb7632014-08-07 00:10:53 -07001214 int64_t count;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001215 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001216 // |count| remains the same, as the decrementing happens in update_attempter
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001217 // which this test doesn't exercise.
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001218 ASSERT_EQ(count, 5);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001219 EXPECT_FALSE(response.update_exists);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001220}
1221
1222TEST_F(OmahaRequestActionTest,
1223 ExistingUpdateCheckCountCausesScatteringInteractive) {
1224 request_params_.set_wall_clock_based_wait_enabled(true);
1225 request_params_.set_waiting_period(TimeDelta());
1226 request_params_.set_update_check_count_wait_enabled(true);
1227 request_params_.set_min_update_checks_needed(1);
1228 request_params_.set_max_update_checks_allowed(8);
1229 request_params_.set_interactive(true);
Amin Hassani538bd592020-11-04 20:46:08 -08001230 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
Amin Hassani41ac04b2019-03-29 11:31:03 -07001231 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1232
1233 ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5));
Chris Sosa968d0572013-08-23 14:46:02 -07001234
1235 // Verify if we are interactive check we don't defer.
Amin Hassani41ac04b2019-03-29 11:31:03 -07001236 ASSERT_TRUE(TestUpdateCheck());
Chris Sosa968d0572013-08-23 14:46:02 -07001237 EXPECT_TRUE(response.update_exists);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001238}
Jay Srinivasan0a708742012-03-20 11:26:12 -07001239
Adolfo Victoria497044c2018-07-18 07:51:42 -07001240TEST_F(OmahaRequestActionTest, StagingTurnedOnCausesScattering) {
1241 // If staging is on, the value for max days to scatter should be ignored, and
1242 // staging's scatter value should be used.
Adolfo Victoria497044c2018-07-18 07:51:42 -07001243 request_params_.set_wall_clock_based_wait_enabled(true);
1244 request_params_.set_waiting_period(TimeDelta::FromDays(6));
1245 request_params_.set_update_check_count_wait_enabled(false);
Amin Hassani538bd592020-11-04 20:46:08 -08001246 FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
May Lippert60aa3ca2018-08-15 16:55:29 -07001247
Adolfo Victoria497044c2018-07-18 07:51:42 -07001248 ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsWallClockStagingWaitPeriod, 6));
1249 // This should not prevent scattering due to staging.
1250 fake_update_response_.max_days_to_scatter = "0";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001251 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1252 tuc_params_.expected_code = ErrorCode::kOmahaUpdateDeferredPerPolicy;
1253 tuc_params_.expected_check_reaction = metrics::CheckReaction::kDeferring;
1254
1255 ASSERT_FALSE(TestUpdateCheck());
1256
Adolfo Victoria497044c2018-07-18 07:51:42 -07001257 EXPECT_FALSE(response.update_exists);
1258
1259 // Interactive updates should not be affected.
1260 request_params_.set_interactive(true);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001261 tuc_params_.expected_code = ErrorCode::kSuccess;
1262 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUpdating;
1263
1264 ASSERT_TRUE(TestUpdateCheck());
1265
Adolfo Victoria497044c2018-07-18 07:51:42 -07001266 EXPECT_TRUE(response.update_exists);
1267}
1268
Alex Deymo8e18f932015-03-27 16:16:59 -07001269TEST_F(OmahaRequestActionTest, CohortsArePersisted) {
Alex Deymo8e18f932015-03-27 16:16:59 -07001270 fake_update_response_.include_cohorts = true;
1271 fake_update_response_.cohort = "s/154454/8479665";
1272 fake_update_response_.cohorthint = "please-put-me-on-beta";
1273 fake_update_response_.cohortname = "stable";
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001274 request_params_.set_dlc_apps_params(
1275 {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}}});
1276 fake_update_response_.dlc_app_update = true;
1277 fake_update_response_.include_dlc_cohorts = true;
1278 fake_update_response_.dlc_cohort = "s/154454/8479665/dlc";
1279 fake_update_response_.dlc_cohorthint = "please-put-me-on-beta-dlc";
1280 fake_update_response_.dlc_cohortname = "stable-dlc";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001281 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Alex Deymo8e18f932015-03-27 16:16:59 -07001282
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001283 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001284 ASSERT_TRUE(TestUpdateCheck());
Alex Deymo8e18f932015-03-27 16:16:59 -07001285
1286 string value;
1287 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
1288 EXPECT_EQ(fake_update_response_.cohort, value);
1289
1290 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
1291 EXPECT_EQ(fake_update_response_.cohorthint, value);
1292
1293 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
1294 EXPECT_EQ(fake_update_response_.cohortname, value);
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001295
1296 EXPECT_TRUE(fake_prefs_.GetString(
1297 fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort}),
1298 &value));
1299 EXPECT_EQ(fake_update_response_.dlc_cohort, value);
1300
1301 EXPECT_TRUE(fake_prefs_.GetString(
1302 fake_prefs_.CreateSubKey(
1303 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint}),
1304 &value));
1305 EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
1306
1307 EXPECT_TRUE(fake_prefs_.GetString(
1308 fake_prefs_.CreateSubKey(
1309 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName}),
1310 &value));
1311 EXPECT_EQ(fake_update_response_.dlc_cohortname, value);
Alex Deymo8e18f932015-03-27 16:16:59 -07001312}
1313
1314TEST_F(OmahaRequestActionTest, CohortsAreUpdated) {
Alex Deymo8e18f932015-03-27 16:16:59 -07001315 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value"));
1316 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortHint, "old_hint"));
1317 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortName, "old_name"));
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001318 const string dlc_cohort_key =
1319 fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort});
1320 const string dlc_cohort_hint_key = fake_prefs_.CreateSubKey(
1321 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint});
1322 const string dlc_cohort_name_key = fake_prefs_.CreateSubKey(
1323 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName});
1324 request_params_.set_dlc_apps_params(
1325 {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}}});
1326 EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_key, "old_value_dlc"));
1327 EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_hint_key, "old_hint_dlc"));
1328 EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_name_key, "old_name_dlc"));
Alex Deymo8e18f932015-03-27 16:16:59 -07001329 fake_update_response_.include_cohorts = true;
1330 fake_update_response_.cohort = "s/154454/8479665";
1331 fake_update_response_.cohorthint = "please-put-me-on-beta";
1332 fake_update_response_.cohortname = "";
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001333 fake_update_response_.dlc_app_update = true;
1334 fake_update_response_.include_dlc_cohorts = true;
1335 fake_update_response_.dlc_cohort = "s/154454/8479665/dlc";
1336 fake_update_response_.dlc_cohorthint = "please-put-me-on-beta-dlc";
1337 fake_update_response_.dlc_cohortname = "";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001338 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Alex Deymo8e18f932015-03-27 16:16:59 -07001339
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001340 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001341 ASSERT_TRUE(TestUpdateCheck());
Alex Deymo8e18f932015-03-27 16:16:59 -07001342
1343 string value;
1344 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
1345 EXPECT_EQ(fake_update_response_.cohort, value);
1346
1347 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
1348 EXPECT_EQ(fake_update_response_.cohorthint, value);
1349
1350 EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001351
1352 EXPECT_TRUE(fake_prefs_.GetString(dlc_cohort_key, &value));
1353 EXPECT_EQ(fake_update_response_.dlc_cohort, value);
1354
1355 EXPECT_TRUE(fake_prefs_.GetString(dlc_cohort_hint_key, &value));
1356 EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
1357
1358 EXPECT_FALSE(fake_prefs_.GetString(dlc_cohort_name_key, &value));
Alex Deymo8e18f932015-03-27 16:16:59 -07001359}
1360
1361TEST_F(OmahaRequestActionTest, CohortsAreNotModifiedWhenMissing) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001362 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Alex Deymo8e18f932015-03-27 16:16:59 -07001363
Amin Hassani41ac04b2019-03-29 11:31:03 -07001364 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value"));
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001365 const string dlc_cohort_key =
1366 fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort});
1367 EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_key, "old_value_dlc"));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001368 ASSERT_TRUE(TestUpdateCheck());
Alex Deymo8e18f932015-03-27 16:16:59 -07001369
1370 string value;
1371 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
1372 EXPECT_EQ("old_value", value);
1373
1374 EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
1375 EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001376
1377 EXPECT_TRUE(fake_prefs_.GetString(dlc_cohort_key, &value));
1378 EXPECT_EQ("old_value_dlc", value);
1379
1380 EXPECT_FALSE(fake_prefs_.GetString(
1381 fake_prefs_.CreateSubKey(
1382 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint}),
1383 &value));
1384 EXPECT_FALSE(fake_prefs_.GetString(
1385 fake_prefs_.CreateSubKey(
1386 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName}),
1387 &value));
Alex Deymo8e18f932015-03-27 16:16:59 -07001388}
1389
Alex Deymo00d79ac2015-06-29 15:41:49 -07001390TEST_F(OmahaRequestActionTest, CohortsArePersistedWhenNoUpdate) {
Alex Deymo00d79ac2015-06-29 15:41:49 -07001391 fake_update_response_.include_cohorts = true;
1392 fake_update_response_.cohort = "s/154454/8479665";
1393 fake_update_response_.cohorthint = "please-put-me-on-beta";
1394 fake_update_response_.cohortname = "stable";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001395 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
1396 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
1397 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
Alex Deymo00d79ac2015-06-29 15:41:49 -07001398
Amin Hassani41ac04b2019-03-29 11:31:03 -07001399 ASSERT_TRUE(TestUpdateCheck());
Alex Deymo00d79ac2015-06-29 15:41:49 -07001400
1401 string value;
1402 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
1403 EXPECT_EQ(fake_update_response_.cohort, value);
1404
1405 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
1406 EXPECT_EQ(fake_update_response_.cohorthint, value);
1407
1408 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
1409 EXPECT_EQ(fake_update_response_.cohortname, value);
1410}
1411
Sen Jiangb1e063a2017-09-15 17:44:31 -07001412TEST_F(OmahaRequestActionTest, MultiAppCohortTest) {
Sen Jiangb1e063a2017-09-15 17:44:31 -07001413 fake_update_response_.multi_app = true;
1414 fake_update_response_.include_cohorts = true;
1415 fake_update_response_.cohort = "s/154454/8479665";
1416 fake_update_response_.cohorthint = "please-put-me-on-beta";
1417 fake_update_response_.cohortname = "stable";
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001418 request_params_.set_dlc_apps_params(
1419 {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}},
1420 {request_params_.GetDlcAppId(kDlcId2), {.name = kDlcId2}}});
1421 fake_update_response_.dlc_app_update = true;
1422 fake_update_response_.dlc_app_no_update = true;
1423 fake_update_response_.include_dlc_cohorts = true;
1424 fake_update_response_.dlc_cohort = "s/154454/8479665/dlc";
1425 fake_update_response_.dlc_cohorthint = "please-put-me-on-beta-dlc";
1426 fake_update_response_.dlc_cohortname = "stable-dlc";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001427 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Sen Jiangb1e063a2017-09-15 17:44:31 -07001428
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001429 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001430 ASSERT_TRUE(TestUpdateCheck());
Sen Jiangb1e063a2017-09-15 17:44:31 -07001431
1432 string value;
1433 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
1434 EXPECT_EQ(fake_update_response_.cohort, value);
1435
1436 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
1437 EXPECT_EQ(fake_update_response_.cohorthint, value);
1438
1439 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
1440 EXPECT_EQ(fake_update_response_.cohortname, value);
Jae Hoon Kime2cac612020-11-02 18:30:29 -08001441
1442 EXPECT_TRUE(fake_prefs_.GetString(
1443 fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort}),
1444 &value));
1445 EXPECT_EQ(fake_update_response_.dlc_cohort, value);
1446 EXPECT_TRUE(fake_prefs_.GetString(
1447 fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId2, kPrefsOmahaCohort}),
1448 &value));
1449 EXPECT_EQ(fake_update_response_.dlc_cohort, value);
1450
1451 EXPECT_TRUE(fake_prefs_.GetString(
1452 fake_prefs_.CreateSubKey(
1453 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint}),
1454 &value));
1455 EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
1456 EXPECT_TRUE(fake_prefs_.GetString(
1457 fake_prefs_.CreateSubKey(
1458 {kDlcPrefsSubDir, kDlcId2, kPrefsOmahaCohortHint}),
1459 &value));
1460 EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
1461
1462 EXPECT_TRUE(fake_prefs_.GetString(
1463 fake_prefs_.CreateSubKey(
1464 {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName}),
1465 &value));
1466 EXPECT_EQ(fake_update_response_.dlc_cohortname, value);
1467 EXPECT_TRUE(fake_prefs_.GetString(
1468 fake_prefs_.CreateSubKey(
1469 {kDlcPrefsSubDir, kDlcId2, kPrefsOmahaCohortName}),
1470 &value));
1471 EXPECT_EQ(fake_update_response_.dlc_cohortname, value);
Sen Jiangb1e063a2017-09-15 17:44:31 -07001472}
1473
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001474TEST_F(OmahaRequestActionTest, NoOutputPipeTest) {
Alex Deymo8e18f932015-03-27 16:16:59 -07001475 const string http_response(fake_update_response_.GetNoUpdateResponse());
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001476 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -07001477 loop.SetAsCurrent();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001478
Amin Hassanid3f4bea2018-04-30 14:52:40 -07001479 auto action = std::make_unique<OmahaRequestAction>(
Ben Chan5c02c132017-06-27 07:10:36 -07001480 nullptr,
Amin Hassanid3f4bea2018-04-30 14:52:40 -07001481 std::make_unique<MockHttpFetcher>(
1482 http_response.data(), http_response.size(), nullptr),
Jae Hoon Kimedb65502019-06-14 11:52:17 -07001483 false,
1484 "");
Darin Petkov6a5b3222010-07-13 14:55:28 -07001485 ActionProcessor processor;
Amin Hassanid3f4bea2018-04-30 14:52:40 -07001486 processor.set_delegate(&delegate_);
1487 processor.EnqueueAction(std::move(action));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001488
Luis Hector Chavezf1cf3482016-07-19 14:29:19 -07001489 loop.PostTask(base::Bind(
1490 [](ActionProcessor* processor) { processor->StartProcessing(); },
1491 base::Unretained(&processor)));
Alex Deymo60ca1a72015-06-18 18:19:15 -07001492 loop.Run();
1493 EXPECT_FALSE(loop.PendingTasks());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001494 EXPECT_FALSE(processor.IsRunning());
1495}
1496
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001497TEST_F(OmahaRequestActionTest, InvalidXmlTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001498 tuc_params_.http_response = "invalid xml>";
1499 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
1500 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1501 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1502
1503 ASSERT_FALSE(TestUpdateCheck());
Darin Petkovedc522e2010-11-05 09:35:17 -07001504 EXPECT_FALSE(response.update_exists);
1505}
1506
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001507TEST_F(OmahaRequestActionTest, EmptyResponseTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001508 tuc_params_.expected_code = ErrorCode::kOmahaRequestEmptyResponseError;
1509 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1510 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1511
1512 ASSERT_FALSE(TestUpdateCheck());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001513 EXPECT_FALSE(response.update_exists);
1514}
1515
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001516TEST_F(OmahaRequestActionTest, MissingStatusTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001517 tuc_params_.http_response =
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001518 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
1519 "<daystart elapsed_seconds=\"100\"/>"
1520 "<app appid=\"foo\" status=\"ok\">"
1521 "<ping status=\"ok\"/>"
Amin Hassani41ac04b2019-03-29 11:31:03 -07001522 "<updatecheck/></app></response>";
1523 tuc_params_.expected_code = ErrorCode::kOmahaResponseInvalid;
1524 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1525 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1526
1527 ASSERT_FALSE(TestUpdateCheck());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001528 EXPECT_FALSE(response.update_exists);
1529}
1530
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001531TEST_F(OmahaRequestActionTest, InvalidStatusTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001532 tuc_params_.http_response =
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001533 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
1534 "<daystart elapsed_seconds=\"100\"/>"
1535 "<app appid=\"foo\" status=\"ok\">"
1536 "<ping status=\"ok\"/>"
Amin Hassani41ac04b2019-03-29 11:31:03 -07001537 "<updatecheck status=\"InvalidStatusTest\"/></app></response>";
1538 tuc_params_.expected_code = ErrorCode::kOmahaResponseInvalid;
1539 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1540 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1541
1542 ASSERT_FALSE(TestUpdateCheck());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001543 EXPECT_FALSE(response.update_exists);
1544}
1545
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001546TEST_F(OmahaRequestActionTest, MissingNodesetTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001547 tuc_params_.http_response =
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001548 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
1549 "<daystart elapsed_seconds=\"100\"/>"
1550 "<app appid=\"foo\" status=\"ok\">"
1551 "<ping status=\"ok\"/>"
Amin Hassani41ac04b2019-03-29 11:31:03 -07001552 "</app></response>";
1553 tuc_params_.expected_code = ErrorCode::kOmahaResponseInvalid;
1554 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1555 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1556
1557 ASSERT_FALSE(TestUpdateCheck());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001558 EXPECT_FALSE(response.update_exists);
1559}
1560
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001561TEST_F(OmahaRequestActionTest, MissingFieldTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001562 tuc_params_.http_response =
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001563 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
1564 "<daystart elapsed_seconds=\"100\"/>"
Aaron Wood7dcdedf2017-09-06 17:17:41 -07001565 // the appid needs to match that in the request params
1566 "<app appid=\"" +
1567 fake_update_response_.app_id +
1568 "\" status=\"ok\">"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001569 "<updatecheck status=\"ok\">"
1570 "<urls><url codebase=\"http://missing/field/test/\"/></urls>"
Chris Sosa3b748432013-06-20 16:42:59 -07001571 "<manifest version=\"10.2.3.4\">"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001572 "<packages><package hash=\"not-used\" name=\"f\" "
Vyshu Khota4c5413d2020-11-04 16:17:25 -08001573 "size=\"587\" fp=\"3.789\" hash_sha256=\"lkq34j5345\"/></packages>"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001574 "<actions><action event=\"postinstall\" "
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001575 "Prompt=\"false\" "
Jay Srinivasand671e972013-01-11 17:17:19 -08001576 "IsDeltaPayload=\"false\" "
Sen Jiang2703ef42017-03-16 13:36:21 -07001577 "sha256=\"not-used\" "
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001578 "/></actions></manifest></updatecheck></app></response>";
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001579
Amin Hassani41ac04b2019-03-29 11:31:03 -07001580 ASSERT_TRUE(TestUpdateCheck());
1581
Darin Petkov6a5b3222010-07-13 14:55:28 -07001582 EXPECT_TRUE(response.update_exists);
Chris Sosa3b748432013-06-20 16:42:59 -07001583 EXPECT_EQ("10.2.3.4", response.version);
Sen Jiang0affc2c2017-02-10 15:55:05 -08001584 EXPECT_EQ("http://missing/field/test/f",
1585 response.packages[0].payload_urls[0]);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001586 EXPECT_EQ("", response.more_info_url);
Sen Jiang0affc2c2017-02-10 15:55:05 -08001587 EXPECT_EQ("lkq34j5345", response.packages[0].hash);
Vyshu Khota4c5413d2020-11-04 16:17:25 -08001588 EXPECT_EQ(string("3.789"), response.packages[0].fp);
Sen Jiang0affc2c2017-02-10 15:55:05 -08001589 EXPECT_EQ(587u, response.packages[0].size);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001590 EXPECT_FALSE(response.prompt);
Darin Petkov6c118642010-10-21 12:06:30 -07001591 EXPECT_TRUE(response.deadline.empty());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001592}
1593
1594namespace {
1595class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate {
1596 public:
1597 void ProcessingStopped(const ActionProcessor* processor) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001598 brillo::MessageLoop::current()->BreakLoop();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001599 }
Darin Petkov6a5b3222010-07-13 14:55:28 -07001600};
1601
Alex Deymo60ca1a72015-06-18 18:19:15 -07001602void TerminateTransferTestStarter(ActionProcessor* processor) {
Darin Petkov6a5b3222010-07-13 14:55:28 -07001603 processor->StartProcessing();
1604 CHECK(processor->IsRunning());
1605 processor->StopProcessing();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001606}
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001607} // namespace
Darin Petkov6a5b3222010-07-13 14:55:28 -07001608
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001609TEST_F(OmahaRequestActionTest, TerminateTransferTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001610 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -07001611 loop.SetAsCurrent();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001612
Alex Deymo60ca1a72015-06-18 18:19:15 -07001613 string http_response("doesn't matter");
Amin Hassanid3f4bea2018-04-30 14:52:40 -07001614 auto action = std::make_unique<OmahaRequestAction>(
Ben Chan5c02c132017-06-27 07:10:36 -07001615 nullptr,
Amin Hassanid3f4bea2018-04-30 14:52:40 -07001616 std::make_unique<MockHttpFetcher>(
1617 http_response.data(), http_response.size(), nullptr),
Jae Hoon Kimedb65502019-06-14 11:52:17 -07001618 false,
1619 "");
Darin Petkov6a5b3222010-07-13 14:55:28 -07001620 TerminateEarlyTestProcessorDelegate delegate;
Darin Petkov6a5b3222010-07-13 14:55:28 -07001621 ActionProcessor processor;
1622 processor.set_delegate(&delegate);
Amin Hassanid3f4bea2018-04-30 14:52:40 -07001623 processor.EnqueueAction(std::move(action));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001624
Alex Deymo60ca1a72015-06-18 18:19:15 -07001625 loop.PostTask(base::Bind(&TerminateTransferTestStarter, &processor));
1626 loop.Run();
1627 EXPECT_FALSE(loop.PendingTasks());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001628}
1629
Alex Deymob0d74eb2015-03-30 17:59:17 -07001630TEST_F(OmahaRequestActionTest, XmlEncodeIsUsedForParams) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001631 // Make sure XML Encode is being called on the params.
Marton Hunyady2abda312018-04-24 18:21:49 +02001632 request_params_.set_os_sp("testtheservice_pack>");
1633 request_params_.set_os_board("x86 generic<id");
1634 request_params_.set_current_channel("unittest_track&lt;");
1635 request_params_.set_target_channel("unittest_track&lt;");
Amin Hassani37b67232020-08-13 09:29:48 -07001636 request_params_.set_lts_tag("unittest_hint&lt;");
Marton Hunyady2abda312018-04-24 18:21:49 +02001637 request_params_.set_hwid("<OEM MODEL>");
Alex Deymo8e18f932015-03-27 16:16:59 -07001638 fake_prefs_.SetString(kPrefsOmahaCohort, "evil\nstring");
1639 fake_prefs_.SetString(kPrefsOmahaCohortHint, "evil&string\\");
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001640 fake_prefs_.SetString(
1641 kPrefsOmahaCohortName,
1642 base::JoinString(vector<string>(100, "My spoon is too big."), " "));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001643 tuc_params_.http_response = "invalid xml>";
1644 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
1645 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1646 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1647
1648 ASSERT_FALSE(TestUpdateCheck());
1649
Alex Deymo8e18f932015-03-27 16:16:59 -07001650 EXPECT_NE(string::npos, post_str.find("testtheservice_pack&gt;"));
1651 EXPECT_EQ(string::npos, post_str.find("testtheservice_pack>"));
1652 EXPECT_NE(string::npos, post_str.find("x86 generic&lt;id"));
1653 EXPECT_EQ(string::npos, post_str.find("x86 generic<id"));
1654 EXPECT_NE(string::npos, post_str.find("unittest_track&amp;lt;"));
1655 EXPECT_EQ(string::npos, post_str.find("unittest_track&lt;"));
Amin Hassani37b67232020-08-13 09:29:48 -07001656 EXPECT_NE(string::npos, post_str.find("unittest_hint&amp;lt;"));
1657 EXPECT_EQ(string::npos, post_str.find("unittest_hint&lt;"));
Alex Deymo8e18f932015-03-27 16:16:59 -07001658 EXPECT_NE(string::npos, post_str.find("&lt;OEM MODEL&gt;"));
1659 EXPECT_EQ(string::npos, post_str.find("<OEM MODEL>"));
1660 EXPECT_NE(string::npos, post_str.find("cohort=\"evil\nstring\""));
1661 EXPECT_EQ(string::npos, post_str.find("cohorthint=\"evil&string\\\""));
1662 EXPECT_NE(string::npos, post_str.find("cohorthint=\"evil&amp;string\\\""));
1663 // Values from Prefs that are too big are removed from the XML instead of
1664 // encoded.
1665 EXPECT_EQ(string::npos, post_str.find("cohortname="));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001666}
1667
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001668TEST_F(OmahaRequestActionTest, XmlDecodeTest) {
Alex Deymo8e18f932015-03-27 16:16:59 -07001669 fake_update_response_.deadline = "&lt;20110101";
1670 fake_update_response_.more_info_url = "testthe&lt;url";
1671 fake_update_response_.codebase = "testthe&amp;codebase/";
Amin Hassani41ac04b2019-03-29 11:31:03 -07001672 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
1673
1674 ASSERT_TRUE(TestUpdateCheck());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001675
Sen Jiang0affc2c2017-02-10 15:55:05 -08001676 EXPECT_EQ("testthe<url", response.more_info_url);
1677 EXPECT_EQ("testthe&codebase/file.signed",
1678 response.packages[0].payload_urls[0]);
1679 EXPECT_EQ("<20110101", response.deadline);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001680}
1681
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001682TEST_F(OmahaRequestActionTest, ParseIntTest) {
Alex Deymo8e18f932015-03-27 16:16:59 -07001683 // overflows int32_t:
Sen Jiang0affc2c2017-02-10 15:55:05 -08001684 fake_update_response_.size = 123123123123123ull;
Amin Hassani41ac04b2019-03-29 11:31:03 -07001685 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001686
Amin Hassani41ac04b2019-03-29 11:31:03 -07001687 ASSERT_TRUE(TestUpdateCheck());
Sen Jiang0affc2c2017-02-10 15:55:05 -08001688 EXPECT_EQ(fake_update_response_.size, response.packages[0].size);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001689}
1690
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001691TEST_F(OmahaRequestActionTest, FormatUpdateCheckOutputTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001692 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08001693 FakeSystemState::Get()->set_prefs(&prefs);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001694 tuc_params_.http_response = "invalid xml>";
1695 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
1696 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1697 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001698
Darin Petkov95508da2011-01-05 12:42:29 -08001699 EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001700 .WillOnce(DoAll(SetArgPointee<1>(string("")), Return(true)));
Alex Deymoefb9d832015-11-02 18:39:02 -08001701 // An existing but empty previous version means that we didn't reboot to a new
1702 // update, therefore, no need to update the previous version.
1703 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0);
Amin Hassani41ac04b2019-03-29 11:31:03 -07001704 ASSERT_FALSE(TestUpdateCheck());
1705
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001706 EXPECT_NE(
1707 post_str.find(" <ping active=\"1\" a=\"-1\" r=\"-1\"></ping>\n"
1708 " <updatecheck></updatecheck>\n"),
Jay Srinivasan0a708742012-03-20 11:26:12 -07001709 string::npos);
Darin Petkovfbb40092010-07-29 17:05:50 -07001710 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
1711 string::npos);
Alex Deymoefb9d832015-11-02 18:39:02 -08001712 // No <event> tag should be sent if we didn't reboot to an update.
1713 EXPECT_EQ(post_str.find("<event"), string::npos);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001714}
1715
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001716TEST_F(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001717 TestEvent(new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted),
Amin Hassani41ac04b2019-03-29 11:31:03 -07001718 "invalid xml>");
1719
Alex Vakulenko75039d72014-03-25 12:36:28 -07001720 string expected_event = base::StringPrintf(
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001721 " <event eventtype=\"%d\" eventresult=\"%d\"></event>\n",
Darin Petkove17f86b2010-07-20 09:12:01 -07001722 OmahaEvent::kTypeUpdateDownloadStarted,
1723 OmahaEvent::kResultSuccess);
1724 EXPECT_NE(post_str.find(expected_event), string::npos);
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001725 EXPECT_EQ(post_str.find("ping"), string::npos);
1726 EXPECT_EQ(post_str.find("updatecheck"), string::npos);
Darin Petkove17f86b2010-07-20 09:12:01 -07001727}
1728
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001729TEST_F(OmahaRequestActionTest, FormatErrorEventOutputTest) {
Marton Hunyady2abda312018-04-24 18:21:49 +02001730 TestEvent(new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
Darin Petkove17f86b2010-07-20 09:12:01 -07001731 OmahaEvent::kResultError,
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001732 ErrorCode::kError),
Amin Hassani41ac04b2019-03-29 11:31:03 -07001733 "invalid xml>");
1734
Alex Vakulenko75039d72014-03-25 12:36:28 -07001735 string expected_event = base::StringPrintf(
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001736 " <event eventtype=\"%d\" eventresult=\"%d\" "
1737 "errorcode=\"%d\"></event>\n",
Darin Petkove17f86b2010-07-20 09:12:01 -07001738 OmahaEvent::kTypeDownloadComplete,
1739 OmahaEvent::kResultError,
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001740 static_cast<int>(ErrorCode::kError));
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001741 EXPECT_NE(post_str.find(expected_event), string::npos);
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001742 EXPECT_EQ(post_str.find("updatecheck"), string::npos);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001743}
1744
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001745TEST_F(OmahaRequestActionTest, IsEventTest) {
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001746 string http_response("doesn't matter");
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001747 OmahaRequestAction update_check_action(
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001748 nullptr,
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001749 std::make_unique<MockHttpFetcher>(
1750 http_response.data(), http_response.size(), nullptr),
Jae Hoon Kimedb65502019-06-14 11:52:17 -07001751 false,
1752 "");
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001753 EXPECT_FALSE(update_check_action.IsEvent());
1754
1755 OmahaRequestAction event_action(
Darin Petkove17f86b2010-07-20 09:12:01 -07001756 new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001757 std::make_unique<MockHttpFetcher>(
1758 http_response.data(), http_response.size(), nullptr),
Jae Hoon Kimedb65502019-06-14 11:52:17 -07001759 false,
1760 "");
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001761 EXPECT_TRUE(event_action.IsEvent());
1762}
1763
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001764TEST_F(OmahaRequestActionTest, FormatDeltaOkayOutputTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001765 tuc_params_.http_response = "invalid xml>";
1766 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
1767 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1768 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1769
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001770 for (int i = 0; i < 2; i++) {
1771 bool delta_okay = i == 1;
1772 const char* delta_okay_str = delta_okay ? "true" : "false";
Marton Hunyady2abda312018-04-24 18:21:49 +02001773 request_params_.set_delta_okay(delta_okay);
1774
Amin Hassani41ac04b2019-03-29 11:31:03 -07001775 ASSERT_FALSE(TestUpdateCheck());
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001776 EXPECT_NE(
1777 post_str.find(base::StringPrintf(" delta_okay=\"%s\"", delta_okay_str)),
1778 string::npos)
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001779 << "i = " << i;
1780 }
1781}
1782
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001783TEST_F(OmahaRequestActionTest, FormatInteractiveOutputTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001784 tuc_params_.http_response = "invalid xml>";
1785 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
1786 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1787 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1788
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001789 for (int i = 0; i < 2; i++) {
1790 bool interactive = i == 1;
Gilad Arnold8a659d82013-01-24 11:26:00 -08001791 const char* interactive_str = interactive ? "ondemandupdate" : "scheduler";
Marton Hunyady2abda312018-04-24 18:21:49 +02001792 request_params_.set_interactive(interactive);
1793
Amin Hassani41ac04b2019-03-29 11:31:03 -07001794 ASSERT_FALSE(TestUpdateCheck());
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001795 EXPECT_NE(post_str.find(
1796 base::StringPrintf("installsource=\"%s\"", interactive_str)),
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001797 string::npos)
1798 << "i = " << i;
1799 }
1800}
1801
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001802TEST_F(OmahaRequestActionTest, FormatTargetVersionPrefixOutputTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001803 tuc_params_.http_response = "invalid xml>";
1804 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
1805 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1806 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1807
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001808 for (int i = 0; i < 2; i++) {
1809 bool target_version_set = i == 1;
1810 const char* target_version_prefix = target_version_set ? "10032." : "";
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001811 request_params_.set_target_version_prefix(target_version_prefix);
1812
Amin Hassani41ac04b2019-03-29 11:31:03 -07001813 ASSERT_FALSE(TestUpdateCheck());
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001814 if (target_version_set) {
1815 EXPECT_NE(post_str.find("<updatecheck targetversionprefix=\"10032.\">"),
1816 string::npos)
1817 << "i = " << i;
1818 } else {
1819 EXPECT_EQ(post_str.find("targetversionprefix"), string::npos)
1820 << "i = " << i;
1821 }
1822 }
1823}
1824
1825TEST_F(OmahaRequestActionTest, FormatRollbackAllowedOutputTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07001826 tuc_params_.http_response = "invalid xml>";
1827 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
1828 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
1829 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1830
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001831 for (int i = 0; i < 4; i++) {
1832 bool rollback_allowed = i / 2 == 0;
1833 bool target_version_set = i % 2 == 0;
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001834 request_params_.set_target_version_prefix(target_version_set ? "10032."
1835 : "");
1836 request_params_.set_rollback_allowed(rollback_allowed);
1837
Amin Hassani41ac04b2019-03-29 11:31:03 -07001838 ASSERT_FALSE(TestUpdateCheck());
Marton Hunyadyba51c3f2018-04-25 15:18:10 +02001839 if (rollback_allowed && target_version_set) {
1840 EXPECT_NE(post_str.find("rollback_allowed=\"true\""), string::npos)
1841 << "i = " << i;
1842 } else {
1843 EXPECT_EQ(post_str.find("rollback_allowed"), string::npos) << "i = " << i;
1844 }
1845 }
1846}
1847
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001848TEST_F(OmahaRequestActionTest, OmahaEventTest) {
Darin Petkove17f86b2010-07-20 09:12:01 -07001849 OmahaEvent default_event;
1850 EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type);
1851 EXPECT_EQ(OmahaEvent::kResultError, default_event.result);
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001852 EXPECT_EQ(ErrorCode::kError, default_event.error_code);
Darin Petkove17f86b2010-07-20 09:12:01 -07001853
1854 OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted);
1855 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type);
1856 EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result);
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001857 EXPECT_EQ(ErrorCode::kSuccess, success_event.error_code);
Darin Petkove17f86b2010-07-20 09:12:01 -07001858
1859 OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished,
1860 OmahaEvent::kResultError,
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001861 ErrorCode::kError);
Darin Petkove17f86b2010-07-20 09:12:01 -07001862 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type);
1863 EXPECT_EQ(OmahaEvent::kResultError, error_event.result);
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001864 EXPECT_EQ(ErrorCode::kError, error_event.error_code);
Darin Petkove17f86b2010-07-20 09:12:01 -07001865}
1866
Askar Aitzhan570ca872019-04-24 11:16:12 +02001867TEST_F(OmahaRequestActionTest, DeviceQuickFixBuildTokenIsSetTest) {
Askar Aitzhan18fff842019-06-21 23:24:37 +02001868 // If DeviceQuickFixBuildToken value is set it takes precedence over pref
1869 // value.
1870 constexpr char autoupdate_token[] = "autoupdate_token>";
1871 constexpr char xml_encoded_autoupdate_token[] = "autoupdate_token&gt;";
1872 constexpr char omaha_cohort_hint[] = "cohort_hint";
Askar Aitzhan570ca872019-04-24 11:16:12 +02001873
1874 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
1875 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
1876 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1877 request_params_.set_autoupdate_token(autoupdate_token);
Askar Aitzhan18fff842019-06-21 23:24:37 +02001878 fake_prefs_.SetString(kPrefsOmahaCohortHint, omaha_cohort_hint);
Askar Aitzhan570ca872019-04-24 11:16:12 +02001879
1880 ASSERT_TRUE(TestUpdateCheck());
1881
Askar Aitzhan18fff842019-06-21 23:24:37 +02001882 EXPECT_NE(string::npos,
1883 post_str.find("cohorthint=\"" +
1884 string(xml_encoded_autoupdate_token) + "\""));
1885 EXPECT_EQ(string::npos, post_str.find(autoupdate_token));
1886 EXPECT_EQ(string::npos, post_str.find(omaha_cohort_hint));
1887}
1888
1889TEST_F(OmahaRequestActionTest, DeviceQuickFixBuildTokenIsNotSetTest) {
1890 // If DeviceQuickFixBuildToken is not set, pref value will be provided in
1891 // cohorthint attribute.
1892 constexpr char omaha_cohort_hint[] = "evil_string>";
1893 constexpr char xml_encoded_cohort_hint[] = "evil_string&gt;";
1894
1895 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
1896 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
1897 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1898 fake_prefs_.SetString(kPrefsOmahaCohortHint, omaha_cohort_hint);
1899
1900 ASSERT_TRUE(TestUpdateCheck());
1901
1902 EXPECT_NE(
1903 string::npos,
1904 post_str.find("cohorthint=\"" + string(xml_encoded_cohort_hint) + "\""));
1905 EXPECT_EQ(string::npos, post_str.find(omaha_cohort_hint));
Askar Aitzhan570ca872019-04-24 11:16:12 +02001906}
1907
Amin Hassani37b67232020-08-13 09:29:48 -07001908TEST_F(OmahaRequestActionTest, TargetChannelHintTest) {
1909 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
1910 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
1911 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1912 request_params_.set_lts_tag("hint>");
1913
1914 ASSERT_TRUE(TestUpdateCheck());
1915
1916 EXPECT_NE(string::npos, post_str.find("ltstag=\"hint&gt;\""));
1917}
1918
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001919void OmahaRequestActionTest::PingTest(bool ping_only) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001920 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08001921 FakeSystemState::Get()->set_prefs(&prefs);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001922 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001923 .Times(AnyNumber());
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001924 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
1925 // Add a few hours to the day difference to test no rounding, etc.
1926 int64_t five_days_ago =
1927 (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue();
1928 int64_t six_days_ago =
1929 (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue();
1930 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001931 .WillOnce(DoAll(SetArgPointee<1>(0), Return(true)));
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001932 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001933 .WillOnce(DoAll(SetArgPointee<1>(six_days_ago), Return(true)));
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001934 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001935 .WillOnce(DoAll(SetArgPointee<1>(five_days_ago), Return(true)));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001936
1937 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
1938 tuc_params_.ping_only = ping_only;
1939 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
1940 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1941
1942 ASSERT_TRUE(TestUpdateCheck());
1943
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001944 EXPECT_NE(post_str.find("<ping active=\"1\" a=\"6\" r=\"5\"></ping>"),
1945 string::npos);
1946 if (ping_only) {
1947 EXPECT_EQ(post_str.find("updatecheck"), string::npos);
1948 EXPECT_EQ(post_str.find("previousversion"), string::npos);
1949 } else {
1950 EXPECT_NE(post_str.find("updatecheck"), string::npos);
1951 EXPECT_NE(post_str.find("previousversion"), string::npos);
Darin Petkov265f2902011-05-09 15:17:40 -07001952 }
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001953}
1954
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001955TEST_F(OmahaRequestActionTest, PingTestSendOnlyAPing) {
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001956 PingTest(true /* ping_only */);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001957}
1958
1959TEST_F(OmahaRequestActionTest, PingTestSendAlsoAnUpdateCheck) {
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001960 PingTest(false /* ping_only */);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001961}
1962
1963TEST_F(OmahaRequestActionTest, ActivePingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001964 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08001965 FakeSystemState::Get()->set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001966 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001967 .Times(AnyNumber());
David Zeuthen33bae492014-02-25 16:16:18 -08001968 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001969 int64_t three_days_ago =
1970 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue();
1971 int64_t now = Time::Now().ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08001972 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001973 .WillOnce(DoAll(SetArgPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001974 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001975 .WillOnce(DoAll(SetArgPointee<1>(three_days_ago), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001976 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001977 .WillOnce(DoAll(SetArgPointee<1>(now), Return(true)));
Amin Hassani41ac04b2019-03-29 11:31:03 -07001978
1979 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
1980 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
1981 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
1982
1983 ASSERT_TRUE(TestUpdateCheck());
1984
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001985 EXPECT_NE(post_str.find("<ping active=\"1\" a=\"3\"></ping>"), string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001986}
1987
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001988TEST_F(OmahaRequestActionTest, RollCallPingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001989 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08001990 FakeSystemState::Get()->set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001991 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
Amin Hassani7cc8bb02019-01-14 16:29:47 -08001992 .Times(AnyNumber());
David Zeuthen33bae492014-02-25 16:16:18 -08001993 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001994 int64_t four_days_ago =
1995 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue();
1996 int64_t now = Time::Now().ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08001997 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
Ben Chan672c1f52017-10-23 15:41:39 -07001998 .WillOnce(DoAll(SetArgPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001999 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002000 .WillOnce(DoAll(SetArgPointee<1>(now), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002001 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002002 .WillOnce(DoAll(SetArgPointee<1>(four_days_ago), Return(true)));
Amin Hassani41ac04b2019-03-29 11:31:03 -07002003
2004 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
2005 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2006 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2007
2008 ASSERT_TRUE(TestUpdateCheck());
2009
Jay Srinivasan23b92a52012-10-27 02:00:21 -07002010 EXPECT_NE(post_str.find("<ping active=\"1\" r=\"4\"></ping>\n"),
Thieu Le116fda32011-04-19 11:01:54 -07002011 string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002012}
2013
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002014TEST_F(OmahaRequestActionTest, NoPingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08002015 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08002016 FakeSystemState::Get()->set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08002017 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002018 .Times(AnyNumber());
David Zeuthen33bae492014-02-25 16:16:18 -08002019 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002020 int64_t one_hour_ago =
2021 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08002022 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002023 .WillOnce(DoAll(SetArgPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002024 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002025 .WillOnce(DoAll(SetArgPointee<1>(one_hour_ago), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002026 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002027 .WillOnce(DoAll(SetArgPointee<1>(one_hour_ago), Return(true)));
Alex Deymoebbe7ef2014-10-30 13:02:49 -07002028 // LastActivePingDay and PrefsLastRollCallPingDay are set even if we didn't
2029 // send a ping.
2030 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _))
2031 .WillOnce(Return(true));
2032 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _))
2033 .WillOnce(Return(true));
Amin Hassani41ac04b2019-03-29 11:31:03 -07002034
2035 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
2036 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2037 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2038
2039 ASSERT_TRUE(TestUpdateCheck());
2040
Jay Srinivasan23b92a52012-10-27 02:00:21 -07002041 EXPECT_EQ(post_str.find("ping"), string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002042}
2043
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002044TEST_F(OmahaRequestActionTest, IgnoreEmptyPingTest) {
Thieu Leb44e9e82011-06-06 14:34:04 -07002045 // This test ensures that we ignore empty ping only requests.
Alex Deymo8427b4a2014-11-05 14:00:32 -08002046 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08002047 FakeSystemState::Get()->set_prefs(&prefs);
Thieu Leb44e9e82011-06-06 14:34:04 -07002048 int64_t now = Time::Now().ToInternalValue();
2049 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002050 .WillOnce(DoAll(SetArgPointee<1>(now), Return(true)));
Thieu Leb44e9e82011-06-06 14:34:04 -07002051 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002052 .WillOnce(DoAll(SetArgPointee<1>(now), Return(true)));
Thieu Leb44e9e82011-06-06 14:34:04 -07002053 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
2054 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002055
2056 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
2057 tuc_params_.ping_only = true;
2058 tuc_params_.expected_check_result = metrics::CheckResult::kUnset;
2059 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2060
2061 EXPECT_TRUE(TestUpdateCheck());
2062 EXPECT_TRUE(post_str.empty());
Thieu Leb44e9e82011-06-06 14:34:04 -07002063}
2064
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002065TEST_F(OmahaRequestActionTest, BackInTimePingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08002066 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08002067 FakeSystemState::Get()->set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08002068 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002069 .Times(AnyNumber());
David Zeuthen33bae492014-02-25 16:16:18 -08002070 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002071 int64_t future =
2072 (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08002073 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002074 .WillOnce(DoAll(SetArgPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002075 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002076 .WillOnce(DoAll(SetArgPointee<1>(future), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002077 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
Ben Chan672c1f52017-10-23 15:41:39 -07002078 .WillOnce(DoAll(SetArgPointee<1>(future), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002079 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _))
2080 .WillOnce(Return(true));
2081 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _))
2082 .WillOnce(Return(true));
Amin Hassani41ac04b2019-03-29 11:31:03 -07002083
2084 tuc_params_.http_response =
2085 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
2086 "protocol=\"3.0\"><daystart elapsed_seconds=\"100\"/>"
2087 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
2088 "<updatecheck status=\"noupdate\"/></app></response>";
2089 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2090 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2091
2092 ASSERT_TRUE(TestUpdateCheck());
Jay Srinivasan23b92a52012-10-27 02:00:21 -07002093 EXPECT_EQ(post_str.find("ping"), string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002094}
2095
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002096TEST_F(OmahaRequestActionTest, LastPingDayUpdateTest) {
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002097 // This test checks that the action updates the last ping day to now
Darin Petkov84c763c2010-07-29 16:27:58 -07002098 // minus 200 seconds with a slack of 5 seconds. Therefore, the test
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002099 // may fail if it runs for longer than 5 seconds. It shouldn't run
2100 // that long though.
2101 int64_t midnight =
2102 (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue();
2103 int64_t midnight_slack =
2104 (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue();
Alex Deymo8427b4a2014-11-05 14:00:32 -08002105 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08002106 FakeSystemState::Get()->set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08002107 EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
2108 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002109 EXPECT_CALL(prefs,
2110 SetInt64(kPrefsLastActivePingDay,
2111 AllOf(Ge(midnight), Le(midnight_slack))))
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002112 .WillOnce(Return(true));
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002113 EXPECT_CALL(prefs,
2114 SetInt64(kPrefsLastRollCallPingDay,
2115 AllOf(Ge(midnight), Le(midnight_slack))))
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002116 .WillOnce(Return(true));
Amin Hassani41ac04b2019-03-29 11:31:03 -07002117
2118 tuc_params_.http_response =
2119 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
2120 "protocol=\"3.0\"><daystart elapsed_seconds=\"200\"/>"
2121 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
2122 "<updatecheck status=\"noupdate\"/></app></response>";
2123 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2124 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2125
2126 ASSERT_TRUE(TestUpdateCheck());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002127}
2128
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002129TEST_F(OmahaRequestActionTest, NoElapsedSecondsTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08002130 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08002131 FakeSystemState::Get()->set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08002132 EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
2133 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002134 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
2135 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002136
2137 tuc_params_.http_response =
2138 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
2139 "protocol=\"3.0\"><daystart blah=\"200\"/>"
2140 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
2141 "<updatecheck status=\"noupdate\"/></app></response>";
2142 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2143 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2144
2145 ASSERT_TRUE(TestUpdateCheck());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002146}
2147
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002148TEST_F(OmahaRequestActionTest, BadElapsedSecondsTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08002149 NiceMock<MockPrefs> prefs;
Amin Hassani538bd592020-11-04 20:46:08 -08002150 FakeSystemState::Get()->set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08002151 EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
2152 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002153 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
2154 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002155
2156 tuc_params_.http_response =
2157 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
2158 "protocol=\"3.0\"><daystart elapsed_seconds=\"x\"/>"
2159 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
2160 "<updatecheck status=\"noupdate\"/></app></response>";
2161 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2162 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2163
2164 ASSERT_TRUE(TestUpdateCheck());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07002165}
2166
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002167TEST_F(OmahaRequestActionTest, NoUniqueIDTest) {
Amin Hassani41ac04b2019-03-29 11:31:03 -07002168 tuc_params_.http_response = "invalid xml>";
2169 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
2170 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
2171 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2172
2173 ASSERT_FALSE(TestUpdateCheck());
2174
Darin Petkov84c763c2010-07-29 16:27:58 -07002175 EXPECT_EQ(post_str.find("machineid="), string::npos);
2176 EXPECT_EQ(post_str.find("userid="), string::npos);
2177}
2178
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002179TEST_F(OmahaRequestActionTest, NetworkFailureTest) {
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07002180 const int http_error_code =
2181 static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 501;
Amin Hassani41ac04b2019-03-29 11:31:03 -07002182 tuc_params_.fail_http_response_code = 501;
2183 tuc_params_.expected_code = static_cast<ErrorCode>(http_error_code);
2184 tuc_params_.expected_check_result = metrics::CheckResult::kDownloadError;
2185 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2186 tuc_params_.expected_download_error_code =
2187 static_cast<metrics::DownloadErrorCode>(501);
2188
2189 ASSERT_FALSE(TestUpdateCheck());
2190
Darin Petkovedc522e2010-11-05 09:35:17 -07002191 EXPECT_FALSE(response.update_exists);
2192}
2193
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002194TEST_F(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) {
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07002195 const int http_error_code =
2196 static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 999;
Amin Hassani41ac04b2019-03-29 11:31:03 -07002197
2198 tuc_params_.fail_http_response_code = 1500;
2199 tuc_params_.expected_code = static_cast<ErrorCode>(http_error_code);
2200 tuc_params_.expected_check_result = metrics::CheckResult::kDownloadError;
2201 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2202 tuc_params_.expected_download_error_code =
2203 metrics::DownloadErrorCode::kHttpStatusOther;
2204
2205 ASSERT_FALSE(TestUpdateCheck());
Darin Petkovedc522e2010-11-05 09:35:17 -07002206 EXPECT_FALSE(response.update_exists);
2207}
2208
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002209TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsPersistedFirstTime) {
Marton Hunyady2abda312018-04-24 18:21:49 +02002210 request_params_.set_wall_clock_based_wait_enabled(true);
2211 request_params_.set_waiting_period(TimeDelta().FromDays(1));
2212 request_params_.set_update_check_count_wait_enabled(false);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002213
Sen Jiang7c1171e2016-06-23 11:35:40 -07002214 Time arbitrary_date;
Eric Caruso761be2c2018-05-22 16:23:33 -07002215 ASSERT_TRUE(Time::FromString("6/4/1989", &arbitrary_date));
Amin Hassani538bd592020-11-04 20:46:08 -08002216 FakeSystemState::Get()->fake_clock()->SetWallclockTime(arbitrary_date);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002217
2218 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2219 tuc_params_.expected_code = ErrorCode::kOmahaUpdateDeferredPerPolicy;
2220 tuc_params_.expected_check_reaction = metrics::CheckReaction::kDeferring;
2221
2222 ASSERT_FALSE(TestUpdateCheck());
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002223
Ben Chan9abb7632014-08-07 00:10:53 -07002224 int64_t timestamp = 0;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002225 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
Sen Jiang7c1171e2016-06-23 11:35:40 -07002226 EXPECT_EQ(arbitrary_date.ToInternalValue(), timestamp);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002227 EXPECT_FALSE(response.update_exists);
Chris Sosa968d0572013-08-23 14:46:02 -07002228
2229 // Verify if we are interactive check we don't defer.
Marton Hunyady2abda312018-04-24 18:21:49 +02002230 request_params_.set_interactive(true);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002231 tuc_params_.expected_code = ErrorCode::kSuccess;
2232 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUpdating;
2233
2234 ASSERT_TRUE(TestUpdateCheck());
Chris Sosa968d0572013-08-23 14:46:02 -07002235 EXPECT_TRUE(response.update_exists);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002236}
2237
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002238TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsUsedIfAlreadyPresent) {
Marton Hunyady2abda312018-04-24 18:21:49 +02002239 request_params_.set_wall_clock_based_wait_enabled(true);
2240 request_params_.set_waiting_period(TimeDelta().FromDays(1));
2241 request_params_.set_update_check_count_wait_enabled(false);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002242
Sen Jiang7c1171e2016-06-23 11:35:40 -07002243 Time t1, t2;
Eric Caruso761be2c2018-05-22 16:23:33 -07002244 ASSERT_TRUE(Time::FromString("1/1/2012", &t1));
2245 ASSERT_TRUE(Time::FromString("1/3/2012", &t2));
Sen Jiang7c1171e2016-06-23 11:35:40 -07002246 ASSERT_TRUE(
2247 fake_prefs_.SetInt64(kPrefsUpdateFirstSeenAt, t1.ToInternalValue()));
Amin Hassani538bd592020-11-04 20:46:08 -08002248 FakeSystemState::Get()->fake_clock()->SetWallclockTime(t2);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002249
Amin Hassani41ac04b2019-03-29 11:31:03 -07002250 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2251
2252 ASSERT_TRUE(TestUpdateCheck());
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002253 EXPECT_TRUE(response.update_exists);
2254
2255 // Make sure the timestamp t1 is unchanged showing that it was reused.
Ben Chan9abb7632014-08-07 00:10:53 -07002256 int64_t timestamp = 0;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002257 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
Jay Srinivasan34b5d862012-07-23 11:43:22 -07002258 ASSERT_TRUE(timestamp == t1.ToInternalValue());
2259}
2260
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002261TEST_F(OmahaRequestActionTest, TestChangingToMoreStableChannel) {
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07002262 // Create a uniquely named test directory.
Sen Jiang297e5832016-03-17 14:45:51 -07002263 base::ScopedTempDir tempdir;
2264 ASSERT_TRUE(tempdir.CreateUniqueTempDir());
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07002265
Marton Hunyady2abda312018-04-24 18:21:49 +02002266 request_params_.set_root(tempdir.GetPath().value());
2267 request_params_.set_app_id("{22222222-2222-2222-2222-222222222222}");
2268 request_params_.set_app_version("1.2.3.4");
2269 request_params_.set_product_components("o.bundle=1");
2270 request_params_.set_current_channel("canary-channel");
2271 EXPECT_TRUE(
2272 request_params_.SetTargetChannel("stable-channel", true, nullptr));
2273 request_params_.UpdateDownloadChannel();
2274 EXPECT_TRUE(request_params_.ShouldPowerwash());
Amin Hassani41ac04b2019-03-29 11:31:03 -07002275
2276 tuc_params_.http_response = "invalid xml>";
2277 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
2278 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
2279 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2280
2281 ASSERT_FALSE(TestUpdateCheck());
2282
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002283 EXPECT_NE(
2284 string::npos,
2285 post_str.find("appid=\"{22222222-2222-2222-2222-222222222222}\" "
2286 "version=\"0.0.0.0\" from_version=\"1.2.3.4\" "
2287 "track=\"stable-channel\" from_track=\"canary-channel\" "));
Sen Jiang8cd42342018-01-31 12:06:59 -08002288 EXPECT_EQ(string::npos, post_str.find("o.bundle"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -07002289}
2290
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002291TEST_F(OmahaRequestActionTest, TestChangingToLessStableChannel) {
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07002292 // Create a uniquely named test directory.
Sen Jiang297e5832016-03-17 14:45:51 -07002293 base::ScopedTempDir tempdir;
2294 ASSERT_TRUE(tempdir.CreateUniqueTempDir());
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07002295
Marton Hunyady2abda312018-04-24 18:21:49 +02002296 request_params_.set_root(tempdir.GetPath().value());
2297 request_params_.set_app_id("{11111111-1111-1111-1111-111111111111}");
2298 request_params_.set_app_version("5.6.7.8");
2299 request_params_.set_product_components("o.bundle=1");
2300 request_params_.set_current_channel("stable-channel");
2301 EXPECT_TRUE(
2302 request_params_.SetTargetChannel("canary-channel", false, nullptr));
2303 request_params_.UpdateDownloadChannel();
2304 EXPECT_FALSE(request_params_.ShouldPowerwash());
Amin Hassani41ac04b2019-03-29 11:31:03 -07002305
2306 tuc_params_.http_response = "invalid xml>";
2307 tuc_params_.expected_code = ErrorCode::kOmahaRequestXMLParseError;
2308 tuc_params_.expected_check_result = metrics::CheckResult::kParsingError;
2309 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2310
2311 ASSERT_FALSE(TestUpdateCheck());
2312
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002313 EXPECT_NE(
2314 string::npos,
2315 post_str.find("appid=\"{11111111-1111-1111-1111-111111111111}\" "
2316 "version=\"5.6.7.8\" "
2317 "track=\"canary-channel\" from_track=\"stable-channel\""));
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002318 EXPECT_EQ(string::npos, post_str.find("from_version"));
Sen Jiang8cd42342018-01-31 12:06:59 -08002319 EXPECT_NE(string::npos, post_str.find("o.bundle.version=\"1\""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -07002320}
2321
Alex Deymoebbe7ef2014-10-30 13:02:49 -07002322// Checks that the initial ping with a=-1 r=-1 is not send when the device
2323// was powerwashed.
2324TEST_F(OmahaRequestActionTest, PingWhenPowerwashed) {
2325 fake_prefs_.SetString(kPrefsPreviousVersion, "");
2326
2327 // Flag that the device was powerwashed in the past.
Amin Hassani538bd592020-11-04 20:46:08 -08002328 FakeSystemState::Get()->fake_hardware()->SetPowerwashCount(1);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002329 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
2330 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2331 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
Alex Deymoebbe7ef2014-10-30 13:02:49 -07002332
Amin Hassani41ac04b2019-03-29 11:31:03 -07002333 ASSERT_TRUE(TestUpdateCheck());
2334
Alex Deymoebbe7ef2014-10-30 13:02:49 -07002335 // We shouldn't send a ping in this case since powerwash > 0.
Alex Deymoebbe7ef2014-10-30 13:02:49 -07002336 EXPECT_EQ(string::npos, post_str.find("<ping"));
2337}
2338
Amin Hassani1677e812017-06-21 13:36:36 -07002339// Checks that the initial ping with a=-1 r=-1 is not send when the device
2340// first_active_omaha_ping_sent is set.
2341TEST_F(OmahaRequestActionTest, PingWhenFirstActiveOmahaPingIsSent) {
2342 fake_prefs_.SetString(kPrefsPreviousVersion, "");
2343
2344 // Flag that the device was not powerwashed in the past.
Amin Hassani538bd592020-11-04 20:46:08 -08002345 FakeSystemState::Get()->fake_hardware()->SetPowerwashCount(0);
Amin Hassani1677e812017-06-21 13:36:36 -07002346
2347 // Flag that the device has sent first active ping in the past.
Amin Hassani538bd592020-11-04 20:46:08 -08002348 FakeSystemState::Get()->fake_hardware()->SetFirstActiveOmahaPingSent();
Amin Hassani1677e812017-06-21 13:36:36 -07002349
Amin Hassani41ac04b2019-03-29 11:31:03 -07002350 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
2351 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2352 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2353
2354 ASSERT_TRUE(TestUpdateCheck());
2355
Amin Hassani1677e812017-06-21 13:36:36 -07002356 // We shouldn't send a ping in this case since
2357 // first_active_omaha_ping_sent=true
Amin Hassani1677e812017-06-21 13:36:36 -07002358 EXPECT_EQ(string::npos, post_str.find("<ping"));
2359}
2360
Alex Deymo9fded1e2015-11-05 12:31:19 -08002361// Checks that the event 54 is sent on a reboot to a new update.
2362TEST_F(OmahaRequestActionTest, RebootAfterUpdateEvent) {
2363 // Flag that the device was updated in a previous boot.
2364 fake_prefs_.SetString(kPrefsPreviousVersion, "1.2.3.4");
2365
Amin Hassani41ac04b2019-03-29 11:31:03 -07002366 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
2367 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2368 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2369
2370 ASSERT_TRUE(TestUpdateCheck());
Alex Deymo9fded1e2015-11-05 12:31:19 -08002371
2372 // An event 54 is included and has the right version.
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002373 EXPECT_NE(
2374 string::npos,
2375 post_str.find(base::StringPrintf("<event eventtype=\"%d\"",
2376 OmahaEvent::kTypeRebootedAfterUpdate)));
Alex Deymo9fded1e2015-11-05 12:31:19 -08002377 EXPECT_NE(string::npos,
2378 post_str.find("previousversion=\"1.2.3.4\"></event>"));
2379
2380 // The previous version flag should have been removed.
2381 EXPECT_TRUE(fake_prefs_.Exists(kPrefsPreviousVersion));
2382 string prev_version;
2383 EXPECT_TRUE(fake_prefs_.GetString(kPrefsPreviousVersion, &prev_version));
2384 EXPECT_TRUE(prev_version.empty());
2385}
2386
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002387void OmahaRequestActionTest::P2PTest(bool initial_allow_p2p_for_downloading,
2388 bool initial_allow_p2p_for_sharing,
2389 bool omaha_disable_p2p_for_downloading,
2390 bool omaha_disable_p2p_for_sharing,
2391 bool payload_state_allow_p2p_attempt,
2392 bool expect_p2p_client_lookup,
2393 const string& p2p_client_result_url,
2394 bool expected_allow_p2p_for_downloading,
2395 bool expected_allow_p2p_for_sharing,
2396 const string& expected_p2p_url) {
Gilad Arnold74b5f552014-10-07 08:17:16 -07002397 bool actual_allow_p2p_for_downloading = initial_allow_p2p_for_downloading;
2398 bool actual_allow_p2p_for_sharing = initial_allow_p2p_for_sharing;
2399 string actual_p2p_url;
David Zeuthen8f191b22013-08-06 12:27:50 -07002400
2401 MockPayloadState mock_payload_state;
Amin Hassani538bd592020-11-04 20:46:08 -08002402 FakeSystemState::Get()->set_payload_state(&mock_payload_state);
David Zeuthen8f191b22013-08-06 12:27:50 -07002403 EXPECT_CALL(mock_payload_state, P2PAttemptAllowed())
2404 .WillRepeatedly(Return(payload_state_allow_p2p_attempt));
Gilad Arnold74b5f552014-10-07 08:17:16 -07002405 EXPECT_CALL(mock_payload_state, GetUsingP2PForDownloading())
2406 .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_downloading));
2407 EXPECT_CALL(mock_payload_state, GetUsingP2PForSharing())
2408 .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_sharing));
2409 EXPECT_CALL(mock_payload_state, SetUsingP2PForDownloading(_))
2410 .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_downloading));
2411 EXPECT_CALL(mock_payload_state, SetUsingP2PForSharing(_))
2412 .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_sharing));
2413 EXPECT_CALL(mock_payload_state, SetP2PUrl(_))
2414 .WillRepeatedly(SaveArg<0>(&actual_p2p_url));
2415
David Zeuthen8f191b22013-08-06 12:27:50 -07002416 MockP2PManager mock_p2p_manager;
Amin Hassani538bd592020-11-04 20:46:08 -08002417 FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager);
David Zeuthen8f191b22013-08-06 12:27:50 -07002418 mock_p2p_manager.fake().SetLookupUrlForFileResult(p2p_client_result_url);
2419
David Zeuthen4cc5ed22014-01-15 12:35:03 -08002420 TimeDelta timeout = TimeDelta::FromSeconds(kMaxP2PNetworkWaitTimeSeconds);
2421 EXPECT_CALL(mock_p2p_manager, LookupUrlForFile(_, _, timeout, _))
David Zeuthen8f191b22013-08-06 12:27:50 -07002422 .Times(expect_p2p_client_lookup ? 1 : 0);
2423
Alex Deymo8e18f932015-03-27 16:16:59 -07002424 fake_update_response_.disable_p2p_for_downloading =
2425 omaha_disable_p2p_for_downloading;
2426 fake_update_response_.disable_p2p_for_sharing = omaha_disable_p2p_for_sharing;
Amin Hassani41ac04b2019-03-29 11:31:03 -07002427
2428 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2429 tuc_params_.expected_check_result = metrics::CheckResult::kUpdateAvailable;
2430
2431 ASSERT_TRUE(TestUpdateCheck());
David Zeuthen8f191b22013-08-06 12:27:50 -07002432 EXPECT_TRUE(response.update_exists);
2433
Gilad Arnold74b5f552014-10-07 08:17:16 -07002434 EXPECT_EQ(omaha_disable_p2p_for_downloading,
2435 response.disable_p2p_for_downloading);
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002436 EXPECT_EQ(omaha_disable_p2p_for_sharing, response.disable_p2p_for_sharing);
David Zeuthen8f191b22013-08-06 12:27:50 -07002437
Gilad Arnold74b5f552014-10-07 08:17:16 -07002438 EXPECT_EQ(expected_allow_p2p_for_downloading,
2439 actual_allow_p2p_for_downloading);
2440 EXPECT_EQ(expected_allow_p2p_for_sharing, actual_allow_p2p_for_sharing);
2441 EXPECT_EQ(expected_p2p_url, actual_p2p_url);
David Zeuthen8f191b22013-08-06 12:27:50 -07002442}
2443
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002444TEST_F(OmahaRequestActionTest, P2PWithPeer) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002445 P2PTest(true, // initial_allow_p2p_for_downloading
2446 true, // initial_allow_p2p_for_sharing
2447 false, // omaha_disable_p2p_for_downloading
2448 false, // omaha_disable_p2p_for_sharing
2449 true, // payload_state_allow_p2p_attempt
2450 true, // expect_p2p_client_lookup
2451 "http://1.3.5.7/p2p", // p2p_client_result_url
2452 true, // expected_allow_p2p_for_downloading
2453 true, // expected_allow_p2p_for_sharing
2454 "http://1.3.5.7/p2p"); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002455}
2456
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002457TEST_F(OmahaRequestActionTest, P2PWithoutPeer) {
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002458 P2PTest(true, // initial_allow_p2p_for_downloading
2459 true, // initial_allow_p2p_for_sharing
2460 false, // omaha_disable_p2p_for_downloading
2461 false, // omaha_disable_p2p_for_sharing
2462 true, // payload_state_allow_p2p_attempt
2463 true, // expect_p2p_client_lookup
2464 "", // p2p_client_result_url
2465 false, // expected_allow_p2p_for_downloading
2466 true, // expected_allow_p2p_for_sharing
2467 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002468}
2469
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002470TEST_F(OmahaRequestActionTest, P2PDownloadNotAllowed) {
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002471 P2PTest(false, // initial_allow_p2p_for_downloading
2472 true, // initial_allow_p2p_for_sharing
2473 false, // omaha_disable_p2p_for_downloading
2474 false, // omaha_disable_p2p_for_sharing
2475 true, // payload_state_allow_p2p_attempt
2476 false, // expect_p2p_client_lookup
2477 "unset", // p2p_client_result_url
2478 false, // expected_allow_p2p_for_downloading
2479 true, // expected_allow_p2p_for_sharing
2480 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002481}
2482
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002483TEST_F(OmahaRequestActionTest, P2PWithPeerDownloadDisabledByOmaha) {
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002484 P2PTest(true, // initial_allow_p2p_for_downloading
2485 true, // initial_allow_p2p_for_sharing
2486 true, // omaha_disable_p2p_for_downloading
2487 false, // omaha_disable_p2p_for_sharing
2488 true, // payload_state_allow_p2p_attempt
2489 false, // expect_p2p_client_lookup
2490 "unset", // p2p_client_result_url
2491 false, // expected_allow_p2p_for_downloading
2492 true, // expected_allow_p2p_for_sharing
2493 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002494}
2495
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002496TEST_F(OmahaRequestActionTest, P2PWithPeerSharingDisabledByOmaha) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002497 P2PTest(true, // initial_allow_p2p_for_downloading
2498 true, // initial_allow_p2p_for_sharing
2499 false, // omaha_disable_p2p_for_downloading
2500 true, // omaha_disable_p2p_for_sharing
2501 true, // payload_state_allow_p2p_attempt
2502 true, // expect_p2p_client_lookup
2503 "http://1.3.5.7/p2p", // p2p_client_result_url
2504 true, // expected_allow_p2p_for_downloading
2505 false, // expected_allow_p2p_for_sharing
2506 "http://1.3.5.7/p2p"); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002507}
2508
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002509TEST_F(OmahaRequestActionTest, P2PWithPeerBothDisabledByOmaha) {
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002510 P2PTest(true, // initial_allow_p2p_for_downloading
2511 true, // initial_allow_p2p_for_sharing
2512 true, // omaha_disable_p2p_for_downloading
2513 true, // omaha_disable_p2p_for_sharing
2514 true, // payload_state_allow_p2p_attempt
2515 false, // expect_p2p_client_lookup
2516 "unset", // p2p_client_result_url
2517 false, // expected_allow_p2p_for_downloading
2518 false, // expected_allow_p2p_for_sharing
2519 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002520}
2521
Amin Hassani7cc8bb02019-01-14 16:29:47 -08002522bool OmahaRequestActionTest::InstallDateParseHelper(const string& elapsed_days,
2523 OmahaResponse* response) {
Alex Deymo8e18f932015-03-27 16:16:59 -07002524 fake_update_response_.elapsed_days = elapsed_days;
Amin Hassani41ac04b2019-03-29 11:31:03 -07002525 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2526
2527 return TestUpdateCheck();
David Zeuthen639aa362014-02-03 16:23:44 -08002528}
2529
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002530TEST_F(OmahaRequestActionTest, ParseInstallDateFromResponse) {
Kevin Cernekee2494e282016-03-29 18:03:53 -07002531 // Simulate a successful update check that happens during OOBE. The
2532 // deadline in the response is needed to force the update attempt to
2533 // occur; responses without a deadline seen during OOBE will normally
2534 // return ErrorCode::kNonCriticalUpdateInOOBE.
Amin Hassani538bd592020-11-04 20:46:08 -08002535 FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
Kevin Cernekee2494e282016-03-29 18:03:53 -07002536 fake_update_response_.deadline = "20101020";
2537
David Zeuthen639aa362014-02-03 16:23:44 -08002538 // Check that we parse elapsed_days in the Omaha Response correctly.
2539 // and that the kPrefsInstallDateDays value is written to.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002540 EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
2541 EXPECT_TRUE(InstallDateParseHelper("42", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002542 EXPECT_TRUE(response.update_exists);
2543 EXPECT_EQ(42, response.install_date_days);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002544 EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
David Zeuthen639aa362014-02-03 16:23:44 -08002545 int64_t prefs_days;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002546 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
David Zeuthen639aa362014-02-03 16:23:44 -08002547 EXPECT_EQ(prefs_days, 42);
2548
2549 // If there already is a value set, we shouldn't do anything.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002550 EXPECT_TRUE(InstallDateParseHelper("7", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002551 EXPECT_TRUE(response.update_exists);
2552 EXPECT_EQ(7, response.install_date_days);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002553 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
David Zeuthen639aa362014-02-03 16:23:44 -08002554 EXPECT_EQ(prefs_days, 42);
2555
2556 // Note that elapsed_days is not necessarily divisible by 7 so check
2557 // that we round down correctly when populating kPrefsInstallDateDays.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002558 EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
2559 EXPECT_TRUE(InstallDateParseHelper("23", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002560 EXPECT_TRUE(response.update_exists);
2561 EXPECT_EQ(23, response.install_date_days);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002562 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
David Zeuthen639aa362014-02-03 16:23:44 -08002563 EXPECT_EQ(prefs_days, 21);
2564
2565 // Check that we correctly handle elapsed_days not being included in
2566 // the Omaha Response.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002567 EXPECT_TRUE(InstallDateParseHelper("", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002568 EXPECT_TRUE(response.update_exists);
2569 EXPECT_EQ(-1, response.install_date_days);
David Zeuthen639aa362014-02-03 16:23:44 -08002570}
2571
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002572// If there is no prefs and OOBE is not complete, we should not
2573// report anything to Omaha.
2574TEST_F(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE) {
Amin Hassani538bd592020-11-04 20:46:08 -08002575 FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
2576 EXPECT_EQ(OmahaRequestAction::GetInstallDate(), -1);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002577 EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
2578}
David Zeuthen639aa362014-02-03 16:23:44 -08002579
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002580// If OOBE is complete and happened on a valid date (e.g. after Jan
2581// 1 2007 0:00 PST), that date should be used and written to
2582// prefs. However, first try with an invalid date and check we do
2583// nothing.
2584TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithInvalidDate) {
2585 Time oobe_date = Time::FromTimeT(42); // Dec 31, 1969 16:00:42 PST.
Amin Hassani538bd592020-11-04 20:46:08 -08002586 FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(oobe_date);
2587 EXPECT_EQ(OmahaRequestAction::GetInstallDate(), -1);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002588 EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
2589}
David Zeuthen639aa362014-02-03 16:23:44 -08002590
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002591// Then check with a valid date. The date Jan 20, 2007 0:00 PST
2592// should yield an InstallDate of 14.
2593TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithValidDate) {
2594 Time oobe_date = Time::FromTimeT(1169280000); // Jan 20, 2007 0:00 PST.
Amin Hassani538bd592020-11-04 20:46:08 -08002595 FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(oobe_date);
2596 EXPECT_EQ(OmahaRequestAction::GetInstallDate(), 14);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002597 EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
David Zeuthen639aa362014-02-03 16:23:44 -08002598
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002599 int64_t prefs_days;
2600 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
2601 EXPECT_EQ(prefs_days, 14);
2602}
David Zeuthen639aa362014-02-03 16:23:44 -08002603
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002604// Now that we have a valid date in prefs, check that we keep using
2605// that even if OOBE date reports something else. The date Jan 30,
2606// 2007 0:00 PST should yield an InstallDate of 28... but since
2607// there's a prefs file, we should still get 14.
2608TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedDateChanges) {
2609 // Set a valid date in the prefs first.
2610 EXPECT_TRUE(fake_prefs_.SetInt64(kPrefsInstallDateDays, 14));
David Zeuthen639aa362014-02-03 16:23:44 -08002611
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002612 Time oobe_date = Time::FromTimeT(1170144000); // Jan 30, 2007 0:00 PST.
Amin Hassani538bd592020-11-04 20:46:08 -08002613 FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(oobe_date);
2614 EXPECT_EQ(OmahaRequestAction::GetInstallDate(), 14);
David Zeuthen639aa362014-02-03 16:23:44 -08002615
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002616 int64_t prefs_days;
2617 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
2618 EXPECT_EQ(prefs_days, 14);
David Zeuthen639aa362014-02-03 16:23:44 -08002619
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002620 // If we delete the prefs file, we should get 28 days.
2621 EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
Amin Hassani538bd592020-11-04 20:46:08 -08002622 EXPECT_EQ(OmahaRequestAction::GetInstallDate(), 28);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002623 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
2624 EXPECT_EQ(prefs_days, 28);
David Zeuthen639aa362014-02-03 16:23:44 -08002625}
2626
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002627// Verifies that a device with no device policy, and is not a consumer
2628// device sets the max kernel key version to the current version.
2629// ie. the same behavior as if rollback is enabled.
2630TEST_F(OmahaRequestActionTest, NoPolicyEnterpriseDevicesSetMaxRollback) {
Amin Hassani538bd592020-11-04 20:46:08 -08002631 FakeHardware* fake_hw = FakeSystemState::Get()->fake_hardware();
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002632
2633 // Setup and verify some initial default values for the kernel TPM
2634 // values that control verified boot and rollback.
2635 const int min_kernel_version = 4;
2636 fake_hw->SetMinKernelKeyVersion(min_kernel_version);
2637 fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity);
2638 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2639 EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward());
2640
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002641 EXPECT_CALL(
Amin Hassani538bd592020-11-04 20:46:08 -08002642 *FakeSystemState::Get()->mock_metrics_reporter(),
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002643 ReportKeyVersionMetrics(min_kernel_version, min_kernel_version, true))
2644 .Times(1);
2645
Amin Hassani41ac04b2019-03-29 11:31:03 -07002646 fake_update_response_.deadline = "20101020";
2647 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2648 tuc_params_.is_consumer_device = false;
2649 tuc_params_.rollback_allowed_milestones = 3;
2650
2651 EXPECT_TRUE(TestUpdateCheck());
2652 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002653
Zentaro Kavanagh5d956152018-05-15 09:40:33 -07002654 // Verify kernel_max_rollforward was set to the current minimum
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002655 // kernel key version. This has the effect of freezing roll
2656 // forwards indefinitely. This will hold the rollback window
2657 // open until a future change will be able to move this forward
2658 // relative the configured window.
2659 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2660 EXPECT_EQ(min_kernel_version, fake_hw->GetMaxKernelKeyRollforward());
2661}
2662
2663// Verifies that a conmsumer device with no device policy sets the
2664// max kernel key version to the current version. ie. the same
2665// behavior as if rollback is enabled.
2666TEST_F(OmahaRequestActionTest, NoPolicyConsumerDevicesSetMaxRollback) {
Amin Hassani538bd592020-11-04 20:46:08 -08002667 FakeHardware* fake_hw = FakeSystemState::Get()->fake_hardware();
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002668
2669 // Setup and verify some initial default values for the kernel TPM
2670 // values that control verified boot and rollback.
2671 const int min_kernel_version = 3;
2672 fake_hw->SetMinKernelKeyVersion(min_kernel_version);
2673 fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity);
2674 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2675 EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward());
2676
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002677 EXPECT_CALL(
Amin Hassani538bd592020-11-04 20:46:08 -08002678 *FakeSystemState::Get()->mock_metrics_reporter(),
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002679 ReportKeyVersionMetrics(min_kernel_version, kRollforwardInfinity, true))
2680 .Times(1);
2681
Amin Hassani41ac04b2019-03-29 11:31:03 -07002682 fake_update_response_.deadline = "20101020";
2683 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2684 tuc_params_.is_consumer_device = true;
2685 tuc_params_.rollback_allowed_milestones = 3;
2686
2687 EXPECT_TRUE(TestUpdateCheck());
2688 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002689
Zentaro Kavanagh5d956152018-05-15 09:40:33 -07002690 // Verify that with rollback disabled that kernel_max_rollforward
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002691 // was set to logical infinity. This is the expected behavior for
2692 // consumer devices and matches the existing behavior prior to the
2693 // rollback features.
2694 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2695 EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward());
2696}
2697
Zentaro Kavanagh5d956152018-05-15 09:40:33 -07002698// Verifies that a device with rollback enabled sets kernel_max_rollforward
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002699// in the TPM to prevent roll forward.
2700TEST_F(OmahaRequestActionTest, RollbackEnabledDevicesSetMaxRollback) {
Amin Hassani538bd592020-11-04 20:46:08 -08002701 FakeHardware* fake_hw = FakeSystemState::Get()->fake_hardware();
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002702
2703 // Setup and verify some initial default values for the kernel TPM
2704 // values that control verified boot and rollback.
2705 const int allowed_milestones = 4;
2706 const int min_kernel_version = 3;
2707 fake_hw->SetMinKernelKeyVersion(min_kernel_version);
2708 fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity);
2709 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2710 EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward());
2711
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002712 EXPECT_CALL(
Amin Hassani538bd592020-11-04 20:46:08 -08002713 *FakeSystemState::Get()->mock_metrics_reporter(),
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002714 ReportKeyVersionMetrics(min_kernel_version, min_kernel_version, true))
2715 .Times(1);
2716
Amin Hassani41ac04b2019-03-29 11:31:03 -07002717 fake_update_response_.deadline = "20101020";
2718 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2719 tuc_params_.is_consumer_device = false;
2720 tuc_params_.rollback_allowed_milestones = allowed_milestones;
2721 tuc_params_.is_policy_loaded = true;
2722
2723 EXPECT_TRUE(TestUpdateCheck());
2724 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002725
Zentaro Kavanagh5d956152018-05-15 09:40:33 -07002726 // Verify that with rollback enabled that kernel_max_rollforward
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002727 // was set to the current minimum kernel key version. This has
2728 // the effect of freezing roll forwards indefinitely. This will
2729 // hold the rollback window open until a future change will
2730 // be able to move this forward relative the configured window.
2731 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2732 EXPECT_EQ(min_kernel_version, fake_hw->GetMaxKernelKeyRollforward());
2733}
2734
Zentaro Kavanagh5d956152018-05-15 09:40:33 -07002735// Verifies that a device with rollback disabled sets kernel_max_rollforward
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002736// in the TPM to logical infinity, to allow roll forward.
2737TEST_F(OmahaRequestActionTest, RollbackDisabledDevicesSetMaxRollback) {
Amin Hassani538bd592020-11-04 20:46:08 -08002738 FakeHardware* fake_hw = FakeSystemState::Get()->fake_hardware();
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002739
2740 // Setup and verify some initial default values for the kernel TPM
2741 // values that control verified boot and rollback.
2742 const int allowed_milestones = 0;
2743 const int min_kernel_version = 3;
2744 fake_hw->SetMinKernelKeyVersion(min_kernel_version);
2745 fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity);
2746 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2747 EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward());
2748
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002749 EXPECT_CALL(
Amin Hassani538bd592020-11-04 20:46:08 -08002750 *FakeSystemState::Get()->mock_metrics_reporter(),
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +02002751 ReportKeyVersionMetrics(min_kernel_version, kRollforwardInfinity, true))
2752 .Times(1);
2753
Amin Hassani41ac04b2019-03-29 11:31:03 -07002754 fake_update_response_.deadline = "20101020";
2755 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2756 tuc_params_.is_consumer_device = false;
2757 tuc_params_.rollback_allowed_milestones = allowed_milestones;
2758 tuc_params_.is_policy_loaded = true;
2759
2760 EXPECT_TRUE(TestUpdateCheck());
2761 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002762
Zentaro Kavanagh5d956152018-05-15 09:40:33 -07002763 // Verify that with rollback disabled that kernel_max_rollforward
Zentaro Kavanagh1f899d52018-02-27 15:02:47 -08002764 // was set to logical infinity.
2765 EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion());
2766 EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward());
2767}
2768
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -07002769TEST_F(OmahaRequestActionTest, RollbackResponseParsedNoEntries) {
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -07002770 fake_update_response_.rollback = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -07002771 fake_update_response_.deadline = "20101020";
2772 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2773 tuc_params_.is_consumer_device = false;
2774 tuc_params_.rollback_allowed_milestones = 4;
2775 tuc_params_.is_policy_loaded = true;
2776
2777 EXPECT_TRUE(TestUpdateCheck());
2778 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -07002779 EXPECT_TRUE(response.is_rollback);
2780}
2781
2782TEST_F(OmahaRequestActionTest, RollbackResponseValidVersionsParsed) {
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -07002783 fake_update_response_.rollback_firmware_version = "1.2";
2784 fake_update_response_.rollback_kernel_version = "3.4";
2785 fake_update_response_.rollback = true;
Amin Hassani41ac04b2019-03-29 11:31:03 -07002786 fake_update_response_.deadline = "20101020";
2787 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2788 tuc_params_.is_consumer_device = false;
2789 tuc_params_.rollback_allowed_milestones = 4;
2790 tuc_params_.is_policy_loaded = true;
2791
2792 EXPECT_TRUE(TestUpdateCheck());
2793 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh0ff621c2018-07-13 13:06:56 -07002794 EXPECT_TRUE(response.is_rollback);
2795 EXPECT_EQ(1, response.rollback_key_version.firmware_key);
2796 EXPECT_EQ(2, response.rollback_key_version.firmware);
2797 EXPECT_EQ(3, response.rollback_key_version.kernel_key);
2798 EXPECT_EQ(4, response.rollback_key_version.kernel);
2799}
2800
May Lippert60aa3ca2018-08-15 16:55:29 -07002801TEST_F(OmahaRequestActionTest,
2802 TestUpdateFirstSeenAtPrefPersistedIfUpdateExists) {
2803 FakeClock fake_clock;
2804 Time now = Time::Now();
2805 fake_clock.SetWallclockTime(now);
Amin Hassani538bd592020-11-04 20:46:08 -08002806 FakeSystemState::Get()->set_clock(&fake_clock);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002807 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
May Lippert60aa3ca2018-08-15 16:55:29 -07002808
Amin Hassani41ac04b2019-03-29 11:31:03 -07002809 ASSERT_TRUE(TestUpdateCheck());
2810
May Lippert60aa3ca2018-08-15 16:55:29 -07002811 EXPECT_TRUE(response.update_exists);
2812 EXPECT_TRUE(fake_prefs_.Exists(kPrefsUpdateFirstSeenAt));
2813
2814 int64_t stored_first_seen_at_time;
2815 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt,
2816 &stored_first_seen_at_time));
2817 EXPECT_EQ(now.ToInternalValue(), stored_first_seen_at_time);
2818}
2819
2820TEST_F(OmahaRequestActionTest,
2821 TestUpdateFirstSeenAtPrefNotPersistedIfUpdateFails) {
2822 FakeClock fake_clock;
2823 Time now = Time::Now();
2824 fake_clock.SetWallclockTime(now);
Amin Hassani538bd592020-11-04 20:46:08 -08002825 FakeSystemState::Get()->set_clock(&fake_clock);
May Lippert60aa3ca2018-08-15 16:55:29 -07002826
Amin Hassani41ac04b2019-03-29 11:31:03 -07002827 tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
2828 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
2829 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
2830
2831 ASSERT_TRUE(TestUpdateCheck());
2832
May Lippert60aa3ca2018-08-15 16:55:29 -07002833 EXPECT_FALSE(response.update_exists);
2834 EXPECT_FALSE(fake_prefs_.Exists(kPrefsUpdateFirstSeenAt));
2835}
2836
Xiaochu Liu88d90382018-08-29 16:09:11 -07002837TEST_F(OmahaRequestActionTest, InstallTest) {
Xiaochu Liu6310be62018-10-11 15:09:03 -07002838 request_params_.set_is_install(true);
Andrewe045aef2020-01-08 16:29:22 -08002839 request_params_.set_dlc_apps_params(
2840 {{request_params_.GetDlcAppId("dlc_no_0"), {.name = "dlc_no_0"}},
2841 {request_params_.GetDlcAppId("dlc_no_1"), {.name = "dlc_no_1"}}});
Amin Hassani41ac04b2019-03-29 11:31:03 -07002842 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2843
2844 ASSERT_TRUE(TestUpdateCheck());
2845
Andrewe045aef2020-01-08 16:29:22 -08002846 for (const auto& it : request_params_.dlc_apps_params()) {
2847 EXPECT_NE(string::npos, post_str.find("appid=\"" + it.first + "\""));
Xiaochu Liu88d90382018-08-29 16:09:11 -07002848 }
Xiaochu Liu6310be62018-10-11 15:09:03 -07002849 EXPECT_NE(string::npos,
2850 post_str.find("appid=\"" + fake_update_response_.app_id + "\""));
2851
2852 // Count number of updatecheck tag in response.
2853 int updatecheck_count = 0;
2854 size_t pos = 0;
2855 while ((pos = post_str.find("<updatecheck", pos)) != string::npos) {
2856 updatecheck_count++;
2857 pos++;
2858 }
Andrewe045aef2020-01-08 16:29:22 -08002859 EXPECT_EQ(request_params_.dlc_apps_params().size(), updatecheck_count);
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -08002860 EXPECT_TRUE(response.update_exists);
Xiaochu Liu6310be62018-10-11 15:09:03 -07002861}
2862
2863TEST_F(OmahaRequestActionTest, InstallMissingPlatformVersionTest) {
2864 fake_update_response_.multi_app_skip_updatecheck = true;
2865 fake_update_response_.multi_app_no_update = false;
2866 request_params_.set_is_install(true);
Andrewe045aef2020-01-08 16:29:22 -08002867 request_params_.set_dlc_apps_params(
2868 {{request_params_.GetDlcAppId("dlc_no_0"), {.name = "dlc_no_0"}},
2869 {request_params_.GetDlcAppId("dlc_no_1"), {.name = "dlc_no_1"}}});
Xiaochu Liu6310be62018-10-11 15:09:03 -07002870 request_params_.set_app_id(fake_update_response_.app_id_skip_updatecheck);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002871 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2872
2873 ASSERT_TRUE(TestUpdateCheck());
2874
Xiaochu Liu6310be62018-10-11 15:09:03 -07002875 EXPECT_TRUE(response.update_exists);
2876 EXPECT_EQ(fake_update_response_.current_version, response.version);
Xiaochu Liu88d90382018-08-29 16:09:11 -07002877}
2878
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -08002879TEST_F(OmahaRequestActionTest, UpdateWithDlcTest) {
2880 request_params_.set_dlc_apps_params(
2881 {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}}});
2882 fake_update_response_.dlc_app_update = true;
2883 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07002884 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -08002885 ASSERT_TRUE(TestUpdateCheck());
2886
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07002887 EXPECT_EQ(response.packages.size(), 2u);
2888 // Two candidate URLs.
2889 EXPECT_EQ(response.packages[1].payload_urls.size(), 2u);
2890 EXPECT_TRUE(response.update_exists);
2891}
2892
2893TEST_F(OmahaRequestActionTest, UpdateWithPartiallyExcludedDlcTest) {
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -07002894 const string kDlcAppId = request_params_.GetDlcAppId(kDlcId1);
2895 request_params_.set_dlc_apps_params({{kDlcAppId, {.name = kDlcId1}}});
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07002896 fake_update_response_.dlc_app_update = true;
2897 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2898 // The first DLC candidate URL is excluded.
2899 EXPECT_CALL(mock_excluder_, IsExcluded(_))
2900 .WillOnce(Return(true))
2901 .WillOnce(Return(false));
2902 ASSERT_TRUE(TestUpdateCheck());
2903
2904 EXPECT_EQ(response.packages.size(), 2u);
2905 // One candidate URL.
2906 EXPECT_EQ(response.packages[1].payload_urls.size(), 1u);
2907 EXPECT_TRUE(response.update_exists);
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -07002908 EXPECT_TRUE(request_params_.dlc_apps_params().at(kDlcAppId).updated);
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07002909}
2910
2911TEST_F(OmahaRequestActionTest, UpdateWithExcludedDlcTest) {
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -07002912 const string kDlcAppId = request_params_.GetDlcAppId(kDlcId1);
2913 request_params_.set_dlc_apps_params({{kDlcAppId, {.name = kDlcId1}}});
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07002914 fake_update_response_.dlc_app_update = true;
2915 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2916 // Both DLC candidate URLs are excluded.
2917 EXPECT_CALL(mock_excluder_, IsExcluded(_))
2918 .WillOnce(Return(true))
2919 .WillOnce(Return(true));
2920 ASSERT_TRUE(TestUpdateCheck());
2921
2922 EXPECT_EQ(response.packages.size(), 1u);
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -08002923 EXPECT_TRUE(response.update_exists);
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -07002924 EXPECT_FALSE(request_params_.dlc_apps_params().at(kDlcAppId).updated);
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -08002925}
2926
2927TEST_F(OmahaRequestActionTest, UpdateWithDeprecatedDlcTest) {
2928 request_params_.set_dlc_apps_params(
2929 {{request_params_.GetDlcAppId(kDlcId2), {.name = kDlcId2}}});
2930 fake_update_response_.dlc_app_no_update = true;
2931 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07002932 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -08002933 ASSERT_TRUE(TestUpdateCheck());
2934
2935 EXPECT_TRUE(response.update_exists);
2936}
2937
2938TEST_F(OmahaRequestActionTest, UpdateWithDlcAndDeprecatedDlcTest) {
2939 request_params_.set_dlc_apps_params(
2940 {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}},
2941 {request_params_.GetDlcAppId(kDlcId2), {.name = kDlcId2}}});
2942 fake_update_response_.dlc_app_update = true;
2943 fake_update_response_.dlc_app_no_update = true;
2944 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07002945 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
Jae Hoon Kim5e9cd712020-02-12 15:28:28 -08002946 ASSERT_TRUE(TestUpdateCheck());
2947
2948 EXPECT_TRUE(response.update_exists);
2949}
2950
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07002951TEST_F(OmahaRequestActionTest, PastRollbackVersionsNoEntries) {
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07002952 fake_update_response_.rollback = true;
2953 fake_update_response_.rollback_allowed_milestones = 4;
2954 request_params_.set_rollback_allowed_milestones(4);
Amin Hassani41ac04b2019-03-29 11:31:03 -07002955 fake_update_response_.deadline = "20101020";
2956 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2957 tuc_params_.is_consumer_device = false;
2958 tuc_params_.rollback_allowed_milestones = 4;
2959 tuc_params_.is_policy_loaded = true;
2960
2961 EXPECT_TRUE(TestUpdateCheck());
2962 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07002963 EXPECT_TRUE(response.is_rollback);
2964 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
2965 response.past_rollback_key_version.firmware_key);
2966 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
2967 response.past_rollback_key_version.firmware);
2968 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
2969 response.past_rollback_key_version.kernel_key);
2970 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
2971 response.past_rollback_key_version.kernel);
2972}
2973
2974TEST_F(OmahaRequestActionTest, PastRollbackVersionsValidEntries) {
Bailey Berrof3ce47f2019-02-25 18:22:17 -08002975 request_params_.set_rollback_allowed_milestones(4);
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07002976 fake_update_response_.rollback = true;
2977 fake_update_response_.rollback_allowed_milestones = 4;
2978 fake_update_response_.rollback_firmware_version = "4.3";
2979 fake_update_response_.rollback_kernel_version = "2.1";
2980 fake_update_response_.past_rollback_key_version =
2981 std::make_pair("16.15", "14.13");
Amin Hassani41ac04b2019-03-29 11:31:03 -07002982 fake_update_response_.deadline = "20101020";
2983 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
2984 tuc_params_.is_consumer_device = false;
2985 tuc_params_.rollback_allowed_milestones = 4;
2986 tuc_params_.is_policy_loaded = true;
2987
2988 EXPECT_TRUE(TestUpdateCheck());
2989 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07002990 EXPECT_TRUE(response.is_rollback);
2991 EXPECT_EQ(16, response.past_rollback_key_version.firmware_key);
2992 EXPECT_EQ(15, response.past_rollback_key_version.firmware);
2993 EXPECT_EQ(14, response.past_rollback_key_version.kernel_key);
2994 EXPECT_EQ(13, response.past_rollback_key_version.kernel);
2995}
2996
2997TEST_F(OmahaRequestActionTest, MismatchNumberOfVersions) {
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07002998 fake_update_response_.rollback = true;
2999 fake_update_response_.rollback_allowed_milestones = 2;
Amin Hassani41ac04b2019-03-29 11:31:03 -07003000 fake_update_response_.deadline = "20101020";
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07003001 request_params_.set_rollback_allowed_milestones(4);
3002
3003 // Since |request_params_.rollback_allowed_milestones| is 4 but the response
3004 // is constructed with |fake_update_response_.rollback_allowed_milestones| set
3005 // to 2, OmahaRequestAction will look for the key values of N-4 version but
3006 // only the N-2 version will exist.
Amin Hassani41ac04b2019-03-29 11:31:03 -07003007 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
3008 tuc_params_.is_consumer_device = false;
3009 tuc_params_.rollback_allowed_milestones = 2;
3010 tuc_params_.is_policy_loaded = true;
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07003011
Amin Hassani41ac04b2019-03-29 11:31:03 -07003012 EXPECT_TRUE(TestUpdateCheck());
3013 EXPECT_TRUE(response.update_exists);
Zentaro Kavanagh0ef9a2f2018-07-02 12:05:07 -07003014 EXPECT_TRUE(response.is_rollback);
3015 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
3016 response.past_rollback_key_version.firmware_key);
3017 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
3018 response.past_rollback_key_version.firmware);
3019 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
3020 response.past_rollback_key_version.kernel_key);
3021 EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
3022 response.past_rollback_key_version.kernel);
3023}
3024
Matt Ziegelbaumaa8e1a42019-05-09 21:41:58 -04003025TEST_F(OmahaRequestActionTest, IncludeRequisitionTest) {
3026 request_params_.set_device_requisition("remora");
3027 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
3028 ASSERT_TRUE(TestUpdateCheck());
3029 EXPECT_NE(string::npos, post_str.find("requisition=\"remora\""));
3030}
3031
3032TEST_F(OmahaRequestActionTest, NoIncludeRequisitionTest) {
3033 request_params_.set_device_requisition("");
3034 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
3035 ASSERT_TRUE(TestUpdateCheck());
3036 EXPECT_EQ(string::npos, post_str.find("requisition"));
3037}
3038
Amin Hassani2cbb0692019-10-30 13:36:17 -07003039TEST_F(OmahaRequestActionTest, PersistEolDateTest) {
Jae Hoon Kim051627a2019-09-03 12:56:32 -07003040 tuc_params_.http_response =
3041 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
3042 "protocol=\"3.0\"><app appid=\"foo\" status=\"ok\">"
3043 "<ping status=\"ok\"/><updatecheck status=\"noupdate\" "
Amin Hassani2cbb0692019-10-30 13:36:17 -07003044 "_eol_date=\"200\" _foo=\"bar\"/></app></response>";
3045 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
3046 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
3047
3048 ASSERT_TRUE(TestUpdateCheck());
3049
3050 string eol_date;
Amin Hassani538bd592020-11-04 20:46:08 -08003051 EXPECT_TRUE(FakeSystemState::Get()->prefs()->GetString(kPrefsOmahaEolDate,
3052 &eol_date));
Amin Hassani2cbb0692019-10-30 13:36:17 -07003053 EXPECT_EQ("200", eol_date);
3054}
3055
3056TEST_F(OmahaRequestActionTest, PersistEolMissingDateTest) {
3057 tuc_params_.http_response =
3058 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
3059 "protocol=\"3.0\"><app appid=\"foo\" status=\"ok\">"
3060 "<ping status=\"ok\"/><updatecheck status=\"noupdate\" "
Jae Hoon Kim051627a2019-09-03 12:56:32 -07003061 "_foo=\"bar\"/></app></response>";
3062 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
3063 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
3064
Jae Hoon Kimb3146742019-11-07 13:24:24 -08003065 const string kDate = "123";
Amin Hassani538bd592020-11-04 20:46:08 -08003066 FakeSystemState::Get()->prefs()->SetString(kPrefsOmahaEolDate, kDate);
Jae Hoon Kimb3146742019-11-07 13:24:24 -08003067
Jae Hoon Kim051627a2019-09-03 12:56:32 -07003068 ASSERT_TRUE(TestUpdateCheck());
3069
Amin Hassani2cbb0692019-10-30 13:36:17 -07003070 string eol_date;
Amin Hassani538bd592020-11-04 20:46:08 -08003071 EXPECT_TRUE(FakeSystemState::Get()->prefs()->GetString(kPrefsOmahaEolDate,
3072 &eol_date));
Jae Hoon Kimb3146742019-11-07 13:24:24 -08003073 EXPECT_EQ(kDate, eol_date);
Jae Hoon Kim051627a2019-09-03 12:56:32 -07003074}
3075
Amin Hassani2cbb0692019-10-30 13:36:17 -07003076TEST_F(OmahaRequestActionTest, PersistEolBadDateTest) {
Jae Hoon Kim051627a2019-09-03 12:56:32 -07003077 tuc_params_.http_response =
3078 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
3079 "protocol=\"3.0\"><app appid=\"foo\" status=\"ok\">"
3080 "<ping status=\"ok\"/><updatecheck status=\"noupdate\" "
Amin Hassani2cbb0692019-10-30 13:36:17 -07003081 "_eol_date=\"bad\" foo=\"bar\"/></app></response>";
Jae Hoon Kim051627a2019-09-03 12:56:32 -07003082 tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
3083 tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
3084
3085 ASSERT_TRUE(TestUpdateCheck());
3086
Amin Hassani2cbb0692019-10-30 13:36:17 -07003087 string eol_date;
Amin Hassani538bd592020-11-04 20:46:08 -08003088 EXPECT_TRUE(FakeSystemState::Get()->prefs()->GetString(kPrefsOmahaEolDate,
3089 &eol_date));
Jae Hoon Kim051627a2019-09-03 12:56:32 -07003090 EXPECT_EQ(kEolDateInvalid, StringToEolDate(eol_date));
3091}
3092
Andrew065d78d2020-04-07 15:43:07 -07003093TEST_F(OmahaRequestActionDlcPingTest, StorePingReplyNoPing) {
3094 OmahaRequestParams::AppParams app_param = {.name = dlc_id_};
Andrewe045aef2020-01-08 16:29:22 -08003095 request_params_.set_dlc_apps_params(
Andrew065d78d2020-04-07 15:43:07 -07003096 {{request_params_.GetDlcAppId(dlc_id_), app_param}});
Andrewe045aef2020-01-08 16:29:22 -08003097
3098 ASSERT_TRUE(TestUpdateCheck());
Andrew065d78d2020-04-07 15:43:07 -07003099
3100 int64_t temp_int;
Andrewe045aef2020-01-08 16:29:22 -08003101 // If there was no ping, the metadata files shouldn't exist yet.
Andrew065d78d2020-04-07 15:43:07 -07003102 EXPECT_FALSE(fake_prefs_.GetInt64(active_key_, &temp_int));
3103 EXPECT_FALSE(fake_prefs_.GetInt64(last_active_key_, &temp_int));
3104 EXPECT_FALSE(fake_prefs_.GetInt64(last_rollcall_key_, &temp_int));
Andrewe045aef2020-01-08 16:29:22 -08003105}
3106
Andrew065d78d2020-04-07 15:43:07 -07003107TEST_F(OmahaRequestActionDlcPingTest, StorePingReplyActiveTest) {
Andrewe045aef2020-01-08 16:29:22 -08003108 // Create Active value
Andrew065d78d2020-04-07 15:43:07 -07003109 fake_prefs_.SetInt64(active_key_, 0);
Andrewe045aef2020-01-08 16:29:22 -08003110
3111 OmahaRequestParams::AppParams app_param = {
3112 .active_counting_type = OmahaRequestParams::kDateBased,
Andrew065d78d2020-04-07 15:43:07 -07003113 .name = dlc_id_,
Andrewe045aef2020-01-08 16:29:22 -08003114 .ping_active = 1,
3115 .send_ping = true};
3116 request_params_.set_dlc_apps_params(
Andrew065d78d2020-04-07 15:43:07 -07003117 {{request_params_.GetDlcAppId(dlc_id_), app_param}});
Andrewe045aef2020-01-08 16:29:22 -08003118
Andrew065d78d2020-04-07 15:43:07 -07003119 int64_t temp_int;
3120 string temp_str;
Andrewe045aef2020-01-08 16:29:22 -08003121 ASSERT_TRUE(TestUpdateCheck());
Andrew065d78d2020-04-07 15:43:07 -07003122 EXPECT_TRUE(fake_prefs_.GetInt64(active_key_, &temp_int));
Andrewe045aef2020-01-08 16:29:22 -08003123 EXPECT_EQ(temp_int, kPingInactiveValue);
Andrew065d78d2020-04-07 15:43:07 -07003124 EXPECT_TRUE(fake_prefs_.GetString(last_active_key_, &temp_str));
3125 EXPECT_EQ(temp_str, "4763");
3126 EXPECT_TRUE(fake_prefs_.GetString(last_rollcall_key_, &temp_str));
3127 EXPECT_EQ(temp_str, "4763");
Andrewe045aef2020-01-08 16:29:22 -08003128}
3129
Andrew065d78d2020-04-07 15:43:07 -07003130TEST_F(OmahaRequestActionDlcPingTest, StorePingReplyInactiveTest) {
Andrewe045aef2020-01-08 16:29:22 -08003131 // Create Active value
Andrew065d78d2020-04-07 15:43:07 -07003132 fake_prefs_.SetInt64(active_key_, 0);
Andrewe045aef2020-01-08 16:29:22 -08003133
3134 OmahaRequestParams::AppParams app_param = {
3135 .active_counting_type = OmahaRequestParams::kDateBased,
Andrew065d78d2020-04-07 15:43:07 -07003136 .name = dlc_id_,
Andrewe045aef2020-01-08 16:29:22 -08003137 .ping_active = 0,
3138 .send_ping = true};
3139 request_params_.set_dlc_apps_params(
Andrew065d78d2020-04-07 15:43:07 -07003140 {{request_params_.GetDlcAppId(dlc_id_), app_param}});
Andrewe045aef2020-01-08 16:29:22 -08003141
3142 // Set the previous active value to an older value than 4763.
Andrew065d78d2020-04-07 15:43:07 -07003143 fake_prefs_.SetString(last_active_key_, "555");
Andrewe045aef2020-01-08 16:29:22 -08003144
Andrew065d78d2020-04-07 15:43:07 -07003145 int64_t temp_int;
Andrewe045aef2020-01-08 16:29:22 -08003146 ASSERT_TRUE(TestUpdateCheck());
Andrew065d78d2020-04-07 15:43:07 -07003147 EXPECT_TRUE(fake_prefs_.GetInt64(active_key_, &temp_int));
Andrewe045aef2020-01-08 16:29:22 -08003148 EXPECT_EQ(temp_int, kPingInactiveValue);
Andrew065d78d2020-04-07 15:43:07 -07003149 string temp_str;
3150 EXPECT_TRUE(fake_prefs_.GetString(last_active_key_, &temp_str));
3151 EXPECT_EQ(temp_str, "555");
3152 EXPECT_TRUE(fake_prefs_.GetString(last_rollcall_key_, &temp_str));
3153 EXPECT_EQ(temp_str, "4763");
Andrewe045aef2020-01-08 16:29:22 -08003154}
3155
Jae Hoon Kim694eeb02020-06-01 14:24:08 -07003156TEST_F(OmahaRequestActionTest, OmahaResponseUpdateCanExcludeCheck) {
3157 request_params_.set_dlc_apps_params(
3158 {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}}});
3159 fake_update_response_.dlc_app_update = true;
3160 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
3161
3162 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
3163 ASSERT_TRUE(TestUpdateCheck());
3164 ASSERT_TRUE(delegate_.omaha_response_);
3165 const auto& packages = delegate_.omaha_response_->packages;
3166 ASSERT_EQ(packages.size(), 2);
3167
3168 EXPECT_FALSE(packages[0].can_exclude);
3169 EXPECT_TRUE(packages[1].can_exclude);
3170}
3171
3172TEST_F(OmahaRequestActionTest, OmahaResponseInstallCannotExcludeCheck) {
3173 request_params_.set_is_install(true);
3174 request_params_.set_dlc_apps_params(
3175 {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}}});
3176 fake_update_response_.dlc_app_update = true;
3177 tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
3178
3179 EXPECT_CALL(mock_excluder_, IsExcluded(_)).WillRepeatedly(Return(false));
3180 ASSERT_TRUE(TestUpdateCheck());
3181 ASSERT_TRUE(delegate_.omaha_response_);
3182 const auto& packages = delegate_.omaha_response_->packages;
3183 ASSERT_EQ(packages.size(), 2);
3184
3185 EXPECT_FALSE(packages[0].can_exclude);
3186 EXPECT_FALSE(packages[1].can_exclude);
3187}
3188
Darin Petkov6a5b3222010-07-13 14:55:28 -07003189} // namespace chromeos_update_engine