Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 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 Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 17 | #include "update_engine/omaha_request_action.h" |
| 18 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 21 | #include <memory> |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 22 | #include <string> |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 23 | #include <utility> |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 24 | #include <vector> |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 25 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 26 | #include <base/bind.h> |
Alex Deymo | 110e030 | 2015-10-19 20:35:21 -0700 | [diff] [blame] | 27 | #include <base/files/file_util.h> |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 28 | #include <base/files/scoped_temp_dir.h> |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 29 | #include <base/memory/ptr_util.h> |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 30 | #include <base/strings/string_number_conversions.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 31 | #include <base/strings/string_util.h> |
| 32 | #include <base/strings/stringprintf.h> |
| 33 | #include <base/time/time.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 34 | #include <brillo/bind_lambda.h> |
| 35 | #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> |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 38 | #include <gtest/gtest.h> |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 39 | #include <policy/libpolicy.h> |
| 40 | #include <policy/mock_libpolicy.h> |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 41 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 42 | #include "update_engine/common/action_pipe.h" |
| 43 | #include "update_engine/common/constants.h" |
| 44 | #include "update_engine/common/fake_prefs.h" |
| 45 | #include "update_engine/common/hash_calculator.h" |
| 46 | #include "update_engine/common/mock_http_fetcher.h" |
| 47 | #include "update_engine/common/platform_constants.h" |
| 48 | #include "update_engine/common/prefs.h" |
| 49 | #include "update_engine/common/test_utils.h" |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 50 | #include "update_engine/fake_system_state.h" |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 51 | #include "update_engine/metrics_reporter_interface.h" |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 52 | #include "update_engine/mock_connection_manager.h" |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 53 | #include "update_engine/mock_payload_state.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 54 | #include "update_engine/omaha_request_params.h" |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 55 | #include "update_engine/update_manager/rollback_prefs.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 56 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 57 | using base::Time; |
| 58 | using base::TimeDelta; |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 59 | using chromeos_update_manager::kRollforwardInfinity; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 60 | using std::string; |
| 61 | using std::vector; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 62 | using testing::AllOf; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 63 | using testing::AnyNumber; |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 64 | using testing::DoAll; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 65 | using testing::Ge; |
| 66 | using testing::Le; |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 67 | using testing::NiceMock; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 68 | using testing::Return; |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 69 | using testing::ReturnRef; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 70 | using testing::ReturnPointee; |
| 71 | using testing::SaveArg; |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 72 | using testing::SetArgPointee; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 73 | using testing::_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 74 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 75 | namespace { |
| 76 | |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 77 | static_assert(kRollforwardInfinity == 0xfffffffe, |
| 78 | "Don't change the value of kRollforward infinity unless its " |
| 79 | "size has been changed in firmware."); |
| 80 | |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 81 | const char kTestAppId[] = "test-app-id"; |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 82 | const char kTestAppId2[] = "test-app2-id"; |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 83 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 84 | // This is a helper struct to allow unit tests build an update response with the |
| 85 | // values they care about. |
| 86 | struct FakeUpdateResponse { |
| 87 | string GetNoUpdateResponse() const { |
| 88 | string entity_str; |
| 89 | if (include_entity) |
| 90 | entity_str = "<!DOCTYPE response [<!ENTITY CrOS \"ChromeOS\">]>"; |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 91 | return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + entity_str + |
| 92 | "<response protocol=\"3.0\">" |
| 93 | "<daystart elapsed_seconds=\"100\"/>" |
| 94 | "<app appid=\"" + |
| 95 | app_id + "\" " + |
| 96 | (include_cohorts |
| 97 | ? "cohort=\"" + cohort + "\" cohorthint=\"" + cohorthint + |
| 98 | "\" cohortname=\"" + cohortname + "\" " |
| 99 | : "") + |
| 100 | " status=\"ok\">" |
| 101 | "<ping status=\"ok\"/>" |
| 102 | "<updatecheck status=\"noupdate\"/></app>" + |
| 103 | (multi_app_no_update |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 104 | ? "<app appid=\"" + app_id2 + |
| 105 | "\"><updatecheck status=\"noupdate\"/></app>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 106 | : "") + |
| 107 | "</response>"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | string GetUpdateResponse() const { |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 111 | return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 112 | "protocol=\"3.0\">" |
| 113 | "<daystart elapsed_seconds=\"100\"" + |
| 114 | (elapsed_days.empty() ? "" |
| 115 | : (" elapsed_days=\"" + elapsed_days + "\"")) + |
| 116 | "/>" |
| 117 | "<app appid=\"" + |
| 118 | app_id + "\" " + |
| 119 | (include_cohorts |
| 120 | ? "cohort=\"" + cohort + "\" cohorthint=\"" + cohorthint + |
| 121 | "\" cohortname=\"" + cohortname + "\" " |
| 122 | : "") + |
| 123 | " status=\"ok\">" |
| 124 | "<ping status=\"ok\"/><updatecheck status=\"ok\">" |
| 125 | "<urls><url codebase=\"" + |
| 126 | codebase + |
| 127 | "\"/></urls>" |
| 128 | "<manifest version=\"" + |
| 129 | version + |
| 130 | "\">" |
| 131 | "<packages><package hash=\"not-used\" name=\"" + |
| 132 | filename + "\" size=\"" + base::Int64ToString(size) + |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 133 | "\" hash_sha256=\"" + hash + "\"/>" + |
| 134 | (multi_package ? "<package name=\"package2\" size=\"222\" " |
| 135 | "hash_sha256=\"hash2\"/>" |
| 136 | : "") + |
| 137 | "</packages>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 138 | "<actions><action event=\"postinstall\" MetadataSize=\"11" + |
| 139 | (multi_package ? ":22" : "") + "\" ChromeOSVersion=\"" + version + |
| 140 | "\" MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 141 | "\" " |
| 142 | "IsDelta=\"true\" " |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 143 | "IsDeltaPayload=\"true" + |
| 144 | (multi_package ? ":false" : "") + |
| 145 | "\" " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 146 | "MaxDaysToScatter=\"" + |
| 147 | max_days_to_scatter + |
| 148 | "\" " |
| 149 | "sha256=\"not-used\" " |
| 150 | "needsadmin=\"" + |
| 151 | needsadmin + "\" " + |
| 152 | (deadline.empty() ? "" : ("deadline=\"" + deadline + "\" ")) + |
| 153 | (disable_p2p_for_downloading ? "DisableP2PForDownloading=\"true\" " |
| 154 | : "") + |
| 155 | (disable_p2p_for_sharing ? "DisableP2PForSharing=\"true\" " : "") + |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 156 | "/></actions></manifest></updatecheck></app>" + |
| 157 | (multi_app |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 158 | ? "<app appid=\"" + app_id2 + "\"" + |
| 159 | (include_cohorts ? " cohort=\"cohort2\"" : "") + |
| 160 | "><updatecheck status=\"ok\"><urls><url codebase=\"" + |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 161 | codebase2 + "\"/></urls><manifest version=\"" + version2 + |
| 162 | "\"><packages>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 163 | "<package name=\"package3\" size=\"333\" " |
| 164 | "hash_sha256=\"hash3\"/></packages>" |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 165 | "<actions><action event=\"postinstall\" " + |
| 166 | (multi_app_self_update |
| 167 | ? "noupdate=\"true\" IsDeltaPayload=\"true\" " |
| 168 | : "IsDeltaPayload=\"false\" ") + |
| 169 | "MetadataSize=\"33\"/></actions>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 170 | "</manifest></updatecheck></app>" |
| 171 | : "") + |
| 172 | (multi_app_no_update |
| 173 | ? "<app><updatecheck status=\"noupdate\"/></app>" |
| 174 | : "") + |
| 175 | "</response>"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // Return the payload URL, which is split in two fields in the XML response. |
| 179 | string GetPayloadUrl() { |
| 180 | return codebase + filename; |
| 181 | } |
| 182 | |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 183 | string app_id = kTestAppId; |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 184 | string app_id2 = kTestAppId2; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 185 | string version = "1.2.3.4"; |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 186 | string version2 = "2.3.4.5"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 187 | string more_info_url = "http://more/info"; |
| 188 | string prompt = "true"; |
| 189 | string codebase = "http://code/base/"; |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 190 | string codebase2 = "http://code/base/2/"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 191 | string filename = "file.signed"; |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 192 | string hash = "4841534831323334"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 193 | string needsadmin = "false"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 194 | uint64_t size = 123; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 195 | string deadline = ""; |
| 196 | string max_days_to_scatter = "7"; |
| 197 | string elapsed_days = "42"; |
| 198 | |
| 199 | // P2P setting defaults to allowed. |
| 200 | bool disable_p2p_for_downloading = false; |
| 201 | bool disable_p2p_for_sharing = false; |
| 202 | |
| 203 | // Omaha cohorts settings. |
| 204 | bool include_cohorts = false; |
| 205 | string cohort = ""; |
| 206 | string cohorthint = ""; |
| 207 | string cohortname = ""; |
| 208 | |
| 209 | // Whether to include the CrOS <!ENTITY> in the XML response. |
| 210 | bool include_entity = false; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 211 | |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 212 | // Whether to include more than one app. |
| 213 | bool multi_app = false; |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 214 | // Whether to include an app with noupdate="true". |
| 215 | bool multi_app_self_update = false; |
| 216 | // Whether to include an additional app with status="noupdate". |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 217 | bool multi_app_no_update = false; |
| 218 | // Whether to include more than one package in an app. |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 219 | bool multi_package = false; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | } // namespace |
| 223 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 224 | namespace chromeos_update_engine { |
| 225 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 226 | class OmahaRequestActionTest : public ::testing::Test { |
| 227 | protected: |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 228 | void SetUp() override { |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 229 | request_params_.set_os_sp("service_pack"); |
| 230 | request_params_.set_os_board("x86-generic"); |
| 231 | request_params_.set_app_id(kTestAppId); |
| 232 | request_params_.set_app_version("0.1.0.0"); |
| 233 | request_params_.set_app_lang("en-US"); |
| 234 | request_params_.set_current_channel("unittest"); |
| 235 | request_params_.set_target_channel("unittest"); |
| 236 | request_params_.set_hwid("OEM MODEL 09235 7471"); |
| 237 | request_params_.set_fw_version("ChromeOSFirmware.1.0"); |
| 238 | request_params_.set_ec_version("0X0A1"); |
| 239 | request_params_.set_delta_okay(true); |
| 240 | request_params_.set_interactive(false); |
| 241 | request_params_.set_update_url("http://url"); |
| 242 | request_params_.set_target_version_prefix(""); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 243 | request_params_.set_rollback_allowed(false); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 244 | request_params_.set_is_powerwash_allowed(false); |
| 245 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 246 | fake_system_state_.set_request_params(&request_params_); |
| 247 | fake_system_state_.set_prefs(&fake_prefs_); |
| 248 | } |
| 249 | |
| 250 | // Returns true iff an output response was obtained from the |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 251 | // OmahaRequestAction. |prefs| may be null, in which case a local MockPrefs |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 252 | // is used. |payload_state| may be null, in which case a local mock is used. |
| 253 | // |p2p_manager| may be null, in which case a local mock is used. |
| 254 | // |connection_manager| may be null, in which case a local mock is used. |
| 255 | // out_response may be null. If |fail_http_response_code| is non-negative, |
| 256 | // the transfer will fail with that code. |ping_only| is passed through to the |
| 257 | // OmahaRequestAction constructor. out_post_data may be null; if non-null, the |
| 258 | // post-data received by the mock HttpFetcher is returned. |
| 259 | // |
| 260 | // The |expected_check_result|, |expected_check_reaction| and |
| 261 | // |expected_error_code| parameters are for checking expectations |
| 262 | // about reporting UpdateEngine.Check.{Result,Reaction,DownloadError} |
| 263 | // UMA statistics. Use the appropriate ::kUnset value to specify that |
| 264 | // the given metric should not be reported. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 265 | bool TestUpdateCheck(const string& http_response, |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 266 | int fail_http_response_code, |
| 267 | bool ping_only, |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 268 | bool is_consumer_device, |
| 269 | int rollback_allowed_milestones, |
| 270 | bool is_policy_loaded, |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 271 | ErrorCode expected_code, |
| 272 | metrics::CheckResult expected_check_result, |
| 273 | metrics::CheckReaction expected_check_reaction, |
| 274 | metrics::DownloadErrorCode expected_download_error_code, |
| 275 | OmahaResponse* out_response, |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 276 | brillo::Blob* out_post_data); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 277 | |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 278 | // Overload of TestUpdateCheck that does not supply |is_consumer_device| or |
| 279 | // |rollback_allowed_milestones| which are only required for rollback tests. |
| 280 | bool TestUpdateCheck(const string& http_response, |
| 281 | int fail_http_response_code, |
| 282 | bool ping_only, |
| 283 | ErrorCode expected_code, |
| 284 | metrics::CheckResult expected_check_result, |
| 285 | metrics::CheckReaction expected_check_reaction, |
| 286 | metrics::DownloadErrorCode expected_download_error_code, |
| 287 | OmahaResponse* out_response, |
| 288 | brillo::Blob* out_post_data); |
| 289 | |
| 290 | void TestRollbackCheck(bool is_consumer_device, |
| 291 | int rollback_allowed_milestones, |
| 292 | bool is_policy_loaded); |
| 293 | |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 294 | // Runs and checks a ping test. |ping_only| indicates whether it should send |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 295 | // only a ping or also an updatecheck. |
| 296 | void PingTest(bool ping_only); |
| 297 | |
| 298 | // InstallDate test helper function. |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 299 | bool InstallDateParseHelper(const string &elapsed_days, |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 300 | OmahaResponse *response); |
| 301 | |
| 302 | // P2P test helper function. |
| 303 | void P2PTest( |
| 304 | bool initial_allow_p2p_for_downloading, |
| 305 | bool initial_allow_p2p_for_sharing, |
| 306 | bool omaha_disable_p2p_for_downloading, |
| 307 | bool omaha_disable_p2p_for_sharing, |
| 308 | bool payload_state_allow_p2p_attempt, |
| 309 | bool expect_p2p_client_lookup, |
| 310 | const string& p2p_client_result_url, |
| 311 | bool expected_allow_p2p_for_downloading, |
| 312 | bool expected_allow_p2p_for_sharing, |
| 313 | const string& expected_p2p_url); |
| 314 | |
| 315 | FakeSystemState fake_system_state_; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 316 | FakeUpdateResponse fake_update_response_; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 317 | // Used by all tests. |
| 318 | OmahaRequestParams request_params_{&fake_system_state_}; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 319 | |
| 320 | FakePrefs fake_prefs_; |
| 321 | }; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 322 | |
| 323 | namespace { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 324 | class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { |
| 325 | public: |
| 326 | OmahaRequestActionTestProcessorDelegate() |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 327 | : expected_code_(ErrorCode::kSuccess) {} |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 328 | ~OmahaRequestActionTestProcessorDelegate() override { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 329 | } |
Yunlian Jiang | 35866ed | 2015-01-29 13:09:20 -0800 | [diff] [blame] | 330 | void ProcessingDone(const ActionProcessor* processor, |
| 331 | ErrorCode code) override { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 332 | brillo::MessageLoop::current()->BreakLoop(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Yunlian Jiang | 35866ed | 2015-01-29 13:09:20 -0800 | [diff] [blame] | 335 | void ActionCompleted(ActionProcessor* processor, |
| 336 | AbstractAction* action, |
| 337 | ErrorCode code) override { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 338 | // make sure actions always succeed |
| 339 | if (action->Type() == OmahaRequestAction::StaticType()) |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 340 | EXPECT_EQ(expected_code_, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 341 | else |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 342 | EXPECT_EQ(ErrorCode::kSuccess, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 343 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 344 | ErrorCode expected_code_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 345 | }; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 346 | } // namespace |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 347 | |
| 348 | class OutputObjectCollectorAction; |
| 349 | |
| 350 | template<> |
| 351 | class ActionTraits<OutputObjectCollectorAction> { |
| 352 | public: |
| 353 | // Does not take an object for input |
| 354 | typedef OmahaResponse InputObjectType; |
| 355 | // On success, puts the output path on output |
| 356 | typedef NoneType OutputObjectType; |
| 357 | }; |
| 358 | |
| 359 | class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
| 360 | public: |
| 361 | OutputObjectCollectorAction() : has_input_object_(false) {} |
| 362 | void PerformAction() { |
| 363 | // copy input object |
| 364 | has_input_object_ = HasInputObject(); |
| 365 | if (has_input_object_) |
| 366 | omaha_response_ = GetInputObject(); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 367 | processor_->ActionComplete(this, ErrorCode::kSuccess); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 368 | } |
| 369 | // Should never be called |
| 370 | void TerminateProcessing() { |
| 371 | CHECK(false); |
| 372 | } |
| 373 | // Debugging/logging |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 374 | static string StaticType() { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 375 | return "OutputObjectCollectorAction"; |
| 376 | } |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 377 | string Type() const { return StaticType(); } |
Alex Vakulenko | 0057daa | 2016-01-23 16:22:50 -0800 | [diff] [blame] | 378 | using InputObjectType = |
| 379 | ActionTraits<OutputObjectCollectorAction>::InputObjectType; |
| 380 | using OutputObjectType = |
| 381 | ActionTraits<OutputObjectCollectorAction>::OutputObjectType; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 382 | bool has_input_object_; |
| 383 | OmahaResponse omaha_response_; |
| 384 | }; |
| 385 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 386 | bool OmahaRequestActionTest::TestUpdateCheck( |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 387 | const string& http_response, |
| 388 | int fail_http_response_code, |
| 389 | bool ping_only, |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 390 | bool is_consumer_device, |
| 391 | int rollback_allowed_milestones, |
| 392 | bool is_policy_loaded, |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 393 | ErrorCode expected_code, |
| 394 | metrics::CheckResult expected_check_result, |
| 395 | metrics::CheckReaction expected_check_reaction, |
| 396 | metrics::DownloadErrorCode expected_download_error_code, |
| 397 | OmahaResponse* out_response, |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 398 | brillo::Blob* out_post_data) { |
| 399 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 400 | loop.SetAsCurrent(); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 401 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 402 | http_response.size(), |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 403 | nullptr); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 404 | if (fail_http_response_code >= 0) { |
| 405 | fetcher->FailTransfer(fail_http_response_code); |
| 406 | } |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 407 | // This ensures the tests didn't forget to update fake_system_state_ if they |
| 408 | // are not using the default request_params_. |
| 409 | EXPECT_EQ(&request_params_, fake_system_state_.request_params()); |
| 410 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 411 | OmahaRequestAction action(&fake_system_state_, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 412 | nullptr, |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 413 | base::WrapUnique(fetcher), |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 414 | ping_only); |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 415 | auto mock_policy_provider = |
| 416 | std::make_unique<NiceMock<policy::MockPolicyProvider>>(); |
| 417 | EXPECT_CALL(*mock_policy_provider, IsConsumerDevice()) |
| 418 | .WillRepeatedly(Return(is_consumer_device)); |
| 419 | |
| 420 | EXPECT_CALL(*mock_policy_provider, device_policy_is_loaded()) |
| 421 | .WillRepeatedly(Return(is_policy_loaded)); |
| 422 | |
| 423 | const policy::MockDevicePolicy device_policy; |
| 424 | const bool get_allowed_milestone_succeeds = rollback_allowed_milestones >= 0; |
| 425 | EXPECT_CALL(device_policy, GetRollbackAllowedMilestones(_)) |
| 426 | .WillRepeatedly(DoAll(SetArgPointee<0>(rollback_allowed_milestones), |
| 427 | Return(get_allowed_milestone_succeeds))); |
| 428 | |
| 429 | EXPECT_CALL(*mock_policy_provider, GetDevicePolicy()) |
| 430 | .WillRepeatedly(ReturnRef(device_policy)); |
| 431 | |
| 432 | action.policy_provider_ = std::move(mock_policy_provider); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 433 | OmahaRequestActionTestProcessorDelegate delegate; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 434 | delegate.expected_code_ = expected_code; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 435 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 436 | ActionProcessor processor; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 437 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 438 | processor.EnqueueAction(&action); |
| 439 | |
| 440 | OutputObjectCollectorAction collector_action; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 441 | BondActions(&action, &collector_action); |
| 442 | processor.EnqueueAction(&collector_action); |
| 443 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 444 | EXPECT_CALL(*fake_system_state_.mock_metrics_reporter(), |
| 445 | ReportUpdateCheckMetrics(_, _, _, _)) |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 446 | .Times(AnyNumber()); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 447 | |
| 448 | EXPECT_CALL(*fake_system_state_.mock_metrics_reporter(), |
| 449 | ReportUpdateCheckMetrics(_, |
| 450 | expected_check_result, |
| 451 | expected_check_reaction, |
| 452 | expected_download_error_code)) |
| 453 | .Times(ping_only ? 0 : 1); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 454 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 455 | loop.PostTask(base::Bind( |
| 456 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 457 | base::Unretained(&processor))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 458 | loop.Run(); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 459 | EXPECT_FALSE(loop.PendingTasks()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 460 | if (collector_action.has_input_object_ && out_response) |
| 461 | *out_response = collector_action.omaha_response_; |
| 462 | if (out_post_data) |
| 463 | *out_post_data = fetcher->post_data(); |
| 464 | return collector_action.has_input_object_; |
| 465 | } |
| 466 | |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 467 | bool OmahaRequestActionTest::TestUpdateCheck( |
| 468 | const string& http_response, |
| 469 | int fail_http_response_code, |
| 470 | bool ping_only, |
| 471 | ErrorCode expected_code, |
| 472 | metrics::CheckResult expected_check_result, |
| 473 | metrics::CheckReaction expected_check_reaction, |
| 474 | metrics::DownloadErrorCode expected_download_error_code, |
| 475 | OmahaResponse* out_response, |
| 476 | brillo::Blob* out_post_data) { |
| 477 | return TestUpdateCheck(http_response, |
| 478 | fail_http_response_code, |
| 479 | ping_only, |
| 480 | true, // is_consumer_device |
| 481 | 0, // rollback_allowed_milestones |
| 482 | false, // is_policy_loaded |
| 483 | expected_code, |
| 484 | expected_check_result, |
| 485 | expected_check_reaction, |
| 486 | expected_download_error_code, |
| 487 | out_response, |
| 488 | out_post_data); |
| 489 | } |
| 490 | |
| 491 | void OmahaRequestActionTest::TestRollbackCheck(bool is_consumer_device, |
| 492 | int rollback_allowed_milestones, |
| 493 | bool is_policy_loaded) { |
| 494 | OmahaResponse response; |
| 495 | fake_update_response_.deadline = "20101020"; |
| 496 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 497 | -1, |
| 498 | false, // ping_only |
| 499 | is_consumer_device, |
| 500 | rollback_allowed_milestones, |
| 501 | is_policy_loaded, |
| 502 | ErrorCode::kSuccess, |
| 503 | metrics::CheckResult::kUpdateAvailable, |
| 504 | metrics::CheckReaction::kUpdating, |
| 505 | metrics::DownloadErrorCode::kUnset, |
| 506 | &response, |
| 507 | nullptr)); |
| 508 | ASSERT_TRUE(response.update_exists); |
| 509 | } |
| 510 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 511 | // Tests Event requests -- they should always succeed. |out_post_data| |
| 512 | // may be null; if non-null, the post-data received by the mock |
| 513 | // HttpFetcher is returned. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 514 | void TestEvent(OmahaEvent* event, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 515 | const string& http_response, |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 516 | brillo::Blob* out_post_data) { |
| 517 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 518 | loop.SetAsCurrent(); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 519 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 520 | http_response.size(), |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 521 | nullptr); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 522 | FakeSystemState fake_system_state; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 523 | OmahaRequestAction action(&fake_system_state, |
| 524 | event, |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 525 | base::WrapUnique(fetcher), |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 526 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 527 | OmahaRequestActionTestProcessorDelegate delegate; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 528 | ActionProcessor processor; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 529 | processor.set_delegate(&delegate); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 530 | processor.EnqueueAction(&action); |
| 531 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 532 | loop.PostTask(base::Bind( |
| 533 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 534 | base::Unretained(&processor))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 535 | loop.Run(); |
Alex Deymo | 72a2567 | 2016-03-23 15:44:39 -0700 | [diff] [blame] | 536 | EXPECT_FALSE(loop.PendingTasks()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 537 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 538 | if (out_post_data) |
| 539 | *out_post_data = fetcher->post_data(); |
| 540 | } |
| 541 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 542 | TEST_F(OmahaRequestActionTest, RejectEntities) { |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 543 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 544 | fake_update_response_.include_entity = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 545 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 546 | -1, |
| 547 | false, // ping_only |
| 548 | ErrorCode::kOmahaRequestXMLHasEntityDecl, |
| 549 | metrics::CheckResult::kParsingError, |
| 550 | metrics::CheckReaction::kUnset, |
| 551 | metrics::DownloadErrorCode::kUnset, |
| 552 | &response, |
| 553 | nullptr)); |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 554 | EXPECT_FALSE(response.update_exists); |
| 555 | } |
| 556 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 557 | TEST_F(OmahaRequestActionTest, NoUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 558 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 559 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 560 | -1, |
| 561 | false, // ping_only |
| 562 | ErrorCode::kSuccess, |
| 563 | metrics::CheckResult::kNoUpdateAvailable, |
| 564 | metrics::CheckReaction::kUnset, |
| 565 | metrics::DownloadErrorCode::kUnset, |
| 566 | &response, |
| 567 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 568 | EXPECT_FALSE(response.update_exists); |
| 569 | } |
| 570 | |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 571 | TEST_F(OmahaRequestActionTest, MultiAppNoUpdateTest) { |
| 572 | OmahaResponse response; |
| 573 | fake_update_response_.multi_app_no_update = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 574 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 575 | -1, |
| 576 | false, // ping_only |
| 577 | ErrorCode::kSuccess, |
| 578 | metrics::CheckResult::kNoUpdateAvailable, |
| 579 | metrics::CheckReaction::kUnset, |
| 580 | metrics::DownloadErrorCode::kUnset, |
| 581 | &response, |
| 582 | nullptr)); |
| 583 | EXPECT_FALSE(response.update_exists); |
| 584 | } |
| 585 | |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 586 | TEST_F(OmahaRequestActionTest, MultiAppNoPartialUpdateTest) { |
| 587 | OmahaResponse response; |
| 588 | fake_update_response_.multi_app_no_update = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 589 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 590 | -1, |
| 591 | false, // ping_only |
| 592 | ErrorCode::kSuccess, |
| 593 | metrics::CheckResult::kNoUpdateAvailable, |
| 594 | metrics::CheckReaction::kUnset, |
| 595 | metrics::DownloadErrorCode::kUnset, |
| 596 | &response, |
| 597 | nullptr)); |
| 598 | EXPECT_FALSE(response.update_exists); |
| 599 | } |
| 600 | |
| 601 | TEST_F(OmahaRequestActionTest, NoSelfUpdateTest) { |
| 602 | OmahaResponse response; |
| 603 | ASSERT_TRUE(TestUpdateCheck( |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 604 | "<response><app><updatecheck status=\"ok\"><manifest><actions><action " |
| 605 | "event=\"postinstall\" noupdate=\"true\"/></actions>" |
| 606 | "</manifest></updatecheck></app></response>", |
| 607 | -1, |
| 608 | false, // ping_only |
| 609 | ErrorCode::kSuccess, |
| 610 | metrics::CheckResult::kNoUpdateAvailable, |
| 611 | metrics::CheckReaction::kUnset, |
| 612 | metrics::DownloadErrorCode::kUnset, |
| 613 | &response, |
| 614 | nullptr)); |
| 615 | EXPECT_FALSE(response.update_exists); |
| 616 | } |
| 617 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 618 | // Test that all the values in the response are parsed in a normal update |
| 619 | // response. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 620 | TEST_F(OmahaRequestActionTest, ValidUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 621 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 622 | fake_update_response_.deadline = "20101020"; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 623 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 624 | -1, |
| 625 | false, // ping_only |
| 626 | ErrorCode::kSuccess, |
| 627 | metrics::CheckResult::kUpdateAvailable, |
| 628 | metrics::CheckReaction::kUpdating, |
| 629 | metrics::DownloadErrorCode::kUnset, |
| 630 | &response, |
| 631 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 632 | EXPECT_TRUE(response.update_exists); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 633 | EXPECT_EQ(fake_update_response_.version, response.version); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 634 | EXPECT_EQ("", response.system_version); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 635 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 636 | response.packages[0].payload_urls[0]); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 637 | EXPECT_EQ(fake_update_response_.more_info_url, response.more_info_url); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 638 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 639 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 640 | EXPECT_EQ(true, response.packages[0].is_delta); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 641 | EXPECT_EQ(fake_update_response_.prompt == "true", response.prompt); |
| 642 | EXPECT_EQ(fake_update_response_.deadline, response.deadline); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 643 | // Omaha cohort attributes are not set in the response, so they should not be |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 644 | // persisted. |
| 645 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohort)); |
| 646 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortHint)); |
| 647 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortName)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 650 | TEST_F(OmahaRequestActionTest, MultiPackageUpdateTest) { |
| 651 | OmahaResponse response; |
| 652 | fake_update_response_.multi_package = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 653 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 654 | -1, |
| 655 | false, // ping_only |
| 656 | ErrorCode::kSuccess, |
| 657 | metrics::CheckResult::kUpdateAvailable, |
| 658 | metrics::CheckReaction::kUpdating, |
| 659 | metrics::DownloadErrorCode::kUnset, |
| 660 | &response, |
| 661 | nullptr)); |
| 662 | EXPECT_TRUE(response.update_exists); |
| 663 | EXPECT_EQ(fake_update_response_.version, response.version); |
| 664 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 665 | response.packages[0].payload_urls[0]); |
| 666 | EXPECT_EQ(fake_update_response_.codebase + "package2", |
| 667 | response.packages[1].payload_urls[0]); |
| 668 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 669 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 670 | EXPECT_EQ(true, response.packages[0].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 671 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 672 | ASSERT_EQ(2u, response.packages.size()); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 673 | EXPECT_EQ(string("hash2"), response.packages[1].hash); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 674 | EXPECT_EQ(222u, response.packages[1].size); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 675 | EXPECT_EQ(22u, response.packages[1].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 676 | EXPECT_EQ(false, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | TEST_F(OmahaRequestActionTest, MultiAppUpdateTest) { |
| 680 | OmahaResponse response; |
| 681 | fake_update_response_.multi_app = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 682 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 683 | -1, |
| 684 | false, // ping_only |
| 685 | ErrorCode::kSuccess, |
| 686 | metrics::CheckResult::kUpdateAvailable, |
| 687 | metrics::CheckReaction::kUpdating, |
| 688 | metrics::DownloadErrorCode::kUnset, |
| 689 | &response, |
| 690 | nullptr)); |
| 691 | EXPECT_TRUE(response.update_exists); |
| 692 | EXPECT_EQ(fake_update_response_.version, response.version); |
| 693 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 694 | response.packages[0].payload_urls[0]); |
| 695 | EXPECT_EQ(fake_update_response_.codebase2 + "package3", |
| 696 | response.packages[1].payload_urls[0]); |
| 697 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 698 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 699 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 700 | EXPECT_EQ(true, response.packages[0].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 701 | ASSERT_EQ(2u, response.packages.size()); |
| 702 | EXPECT_EQ(string("hash3"), response.packages[1].hash); |
| 703 | EXPECT_EQ(333u, response.packages[1].size); |
| 704 | EXPECT_EQ(33u, response.packages[1].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 705 | EXPECT_EQ(false, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 708 | TEST_F(OmahaRequestActionTest, MultiAppAndSystemUpdateTest) { |
| 709 | OmahaResponse response; |
| 710 | fake_update_response_.multi_app = true; |
| 711 | // trigger the lining up of the app and system versions |
| 712 | request_params_.set_system_app_id(fake_update_response_.app_id2); |
| 713 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 714 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 715 | -1, |
| 716 | false, // ping_only |
| 717 | ErrorCode::kSuccess, |
| 718 | metrics::CheckResult::kUpdateAvailable, |
| 719 | metrics::CheckReaction::kUpdating, |
| 720 | metrics::DownloadErrorCode::kUnset, |
| 721 | &response, |
| 722 | nullptr)); |
| 723 | EXPECT_TRUE(response.update_exists); |
| 724 | EXPECT_EQ(fake_update_response_.version, response.version); |
| 725 | EXPECT_EQ(fake_update_response_.version2, response.system_version); |
| 726 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 727 | response.packages[0].payload_urls[0]); |
| 728 | EXPECT_EQ(fake_update_response_.codebase2 + "package3", |
| 729 | response.packages[1].payload_urls[0]); |
| 730 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 731 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 732 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
| 733 | EXPECT_EQ(true, response.packages[0].is_delta); |
| 734 | ASSERT_EQ(2u, response.packages.size()); |
| 735 | EXPECT_EQ(string("hash3"), response.packages[1].hash); |
| 736 | EXPECT_EQ(333u, response.packages[1].size); |
| 737 | EXPECT_EQ(33u, response.packages[1].metadata_size); |
| 738 | EXPECT_EQ(false, response.packages[1].is_delta); |
| 739 | } |
| 740 | |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 741 | TEST_F(OmahaRequestActionTest, MultiAppPartialUpdateTest) { |
| 742 | OmahaResponse response; |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 743 | fake_update_response_.multi_app = true; |
| 744 | fake_update_response_.multi_app_self_update = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 745 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 746 | -1, |
| 747 | false, // ping_only |
| 748 | ErrorCode::kSuccess, |
| 749 | metrics::CheckResult::kUpdateAvailable, |
| 750 | metrics::CheckReaction::kUpdating, |
| 751 | metrics::DownloadErrorCode::kUnset, |
| 752 | &response, |
| 753 | nullptr)); |
| 754 | EXPECT_TRUE(response.update_exists); |
| 755 | EXPECT_EQ(fake_update_response_.version, response.version); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 756 | EXPECT_EQ("", response.system_version); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 757 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 758 | response.packages[0].payload_urls[0]); |
| 759 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 760 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 761 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 762 | ASSERT_EQ(2u, response.packages.size()); |
| 763 | EXPECT_EQ(string("hash3"), response.packages[1].hash); |
| 764 | EXPECT_EQ(333u, response.packages[1].size); |
| 765 | EXPECT_EQ(33u, response.packages[1].metadata_size); |
| 766 | EXPECT_EQ(true, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | TEST_F(OmahaRequestActionTest, MultiAppMultiPackageUpdateTest) { |
| 770 | OmahaResponse response; |
| 771 | fake_update_response_.multi_app = true; |
| 772 | fake_update_response_.multi_package = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 773 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 774 | -1, |
| 775 | false, // ping_only |
| 776 | ErrorCode::kSuccess, |
| 777 | metrics::CheckResult::kUpdateAvailable, |
| 778 | metrics::CheckReaction::kUpdating, |
| 779 | metrics::DownloadErrorCode::kUnset, |
| 780 | &response, |
| 781 | nullptr)); |
| 782 | EXPECT_TRUE(response.update_exists); |
| 783 | EXPECT_EQ(fake_update_response_.version, response.version); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 784 | EXPECT_EQ("", response.system_version); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 785 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 786 | response.packages[0].payload_urls[0]); |
| 787 | EXPECT_EQ(fake_update_response_.codebase + "package2", |
| 788 | response.packages[1].payload_urls[0]); |
| 789 | EXPECT_EQ(fake_update_response_.codebase2 + "package3", |
| 790 | response.packages[2].payload_urls[0]); |
| 791 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 792 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 793 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 794 | EXPECT_EQ(true, response.packages[0].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 795 | ASSERT_EQ(3u, response.packages.size()); |
| 796 | EXPECT_EQ(string("hash2"), response.packages[1].hash); |
| 797 | EXPECT_EQ(222u, response.packages[1].size); |
| 798 | EXPECT_EQ(22u, response.packages[1].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 799 | EXPECT_EQ(false, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 800 | EXPECT_EQ(string("hash3"), response.packages[2].hash); |
| 801 | EXPECT_EQ(333u, response.packages[2].size); |
| 802 | EXPECT_EQ(33u, response.packages[2].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 803 | EXPECT_EQ(false, response.packages[2].is_delta); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 804 | } |
| 805 | |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 806 | TEST_F(OmahaRequestActionTest, ExtraHeadersSentTest) { |
| 807 | const string http_response = "<?xml invalid response"; |
| 808 | request_params_.set_interactive(true); |
| 809 | |
| 810 | brillo::FakeMessageLoop loop(nullptr); |
| 811 | loop.SetAsCurrent(); |
| 812 | |
| 813 | MockHttpFetcher* fetcher = |
| 814 | new MockHttpFetcher(http_response.data(), http_response.size(), nullptr); |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 815 | OmahaRequestAction action(&fake_system_state_, nullptr, |
| 816 | base::WrapUnique(fetcher), false); |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 817 | ActionProcessor processor; |
| 818 | processor.EnqueueAction(&action); |
| 819 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 820 | loop.PostTask(base::Bind( |
| 821 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 822 | base::Unretained(&processor))); |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 823 | loop.Run(); |
| 824 | EXPECT_FALSE(loop.PendingTasks()); |
| 825 | |
| 826 | // Check that the headers were set in the fetcher during the action. Note that |
| 827 | // we set this request as "interactive". |
Sen Jiang | 42fa45e | 2018-03-12 11:02:14 -0700 | [diff] [blame] | 828 | EXPECT_EQ("fg", fetcher->GetHeader("X-Goog-Update-Interactivity")); |
| 829 | EXPECT_EQ(kTestAppId, fetcher->GetHeader("X-Goog-Update-AppId")); |
| 830 | EXPECT_NE("", fetcher->GetHeader("X-Goog-Update-Updater")); |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 833 | TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByConnection) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 834 | OmahaResponse response; |
| 835 | // Set up a connection manager that doesn't allow a valid update over |
| 836 | // the current ethernet connection. |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 837 | MockConnectionManager mock_cm; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 838 | fake_system_state_.set_connection_manager(&mock_cm); |
| 839 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 840 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 841 | .WillRepeatedly( |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 842 | DoAll(SetArgPointee<0>(ConnectionType::kEthernet), |
| 843 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 844 | Return(true))); |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 845 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kEthernet, _)) |
| 846 | .WillRepeatedly(Return(false)); |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 847 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 848 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 849 | -1, |
| 850 | false, // ping_only |
| 851 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
| 852 | metrics::CheckResult::kUpdateAvailable, |
| 853 | metrics::CheckReaction::kIgnored, |
| 854 | metrics::DownloadErrorCode::kUnset, |
| 855 | &response, |
| 856 | nullptr)); |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 857 | EXPECT_FALSE(response.update_exists); |
| 858 | } |
| 859 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 860 | TEST_F(OmahaRequestActionTest, ValidUpdateOverCellularAllowedByDevicePolicy) { |
| 861 | // This test tests that update over cellular is allowed as device policy |
| 862 | // says yes. |
| 863 | OmahaResponse response; |
| 864 | MockConnectionManager mock_cm; |
| 865 | |
| 866 | fake_system_state_.set_connection_manager(&mock_cm); |
| 867 | |
| 868 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 869 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 870 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 871 | Return(true))); |
| 872 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 873 | .WillRepeatedly(Return(true)); |
| 874 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 875 | .WillRepeatedly(Return(true)); |
| 876 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 877 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 878 | -1, |
| 879 | false, // ping_only |
| 880 | ErrorCode::kSuccess, |
| 881 | metrics::CheckResult::kUpdateAvailable, |
| 882 | metrics::CheckReaction::kUpdating, |
| 883 | metrics::DownloadErrorCode::kUnset, |
| 884 | &response, |
| 885 | nullptr)); |
| 886 | EXPECT_TRUE(response.update_exists); |
| 887 | } |
| 888 | |
| 889 | TEST_F(OmahaRequestActionTest, ValidUpdateOverCellularBlockedByDevicePolicy) { |
| 890 | // This test tests that update over cellular is blocked as device policy |
| 891 | // says no. |
| 892 | OmahaResponse response; |
| 893 | MockConnectionManager mock_cm; |
| 894 | |
| 895 | fake_system_state_.set_connection_manager(&mock_cm); |
| 896 | |
| 897 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 898 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 899 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 900 | Return(true))); |
| 901 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 902 | .WillRepeatedly(Return(true)); |
| 903 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 904 | .WillRepeatedly(Return(false)); |
| 905 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 906 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 907 | -1, |
| 908 | false, // ping_only |
| 909 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
| 910 | metrics::CheckResult::kUpdateAvailable, |
| 911 | metrics::CheckReaction::kIgnored, |
| 912 | metrics::DownloadErrorCode::kUnset, |
| 913 | &response, |
| 914 | nullptr)); |
| 915 | EXPECT_FALSE(response.update_exists); |
| 916 | } |
| 917 | |
| 918 | TEST_F(OmahaRequestActionTest, |
| 919 | ValidUpdateOverCellularAllowedByUserPermissionTrue) { |
| 920 | // This test tests that, when device policy is not set, update over cellular |
| 921 | // is allowed as permission for update over cellular is set to true. |
| 922 | OmahaResponse response; |
| 923 | MockConnectionManager mock_cm; |
| 924 | |
| 925 | fake_prefs_.SetBoolean(kPrefsUpdateOverCellularPermission, true); |
| 926 | fake_system_state_.set_connection_manager(&mock_cm); |
| 927 | |
| 928 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 929 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 930 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 931 | Return(true))); |
| 932 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 933 | .WillRepeatedly(Return(false)); |
| 934 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 935 | .WillRepeatedly(Return(true)); |
| 936 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 937 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 938 | -1, |
| 939 | false, // ping_only |
| 940 | ErrorCode::kSuccess, |
| 941 | metrics::CheckResult::kUpdateAvailable, |
| 942 | metrics::CheckReaction::kUpdating, |
| 943 | metrics::DownloadErrorCode::kUnset, |
| 944 | &response, |
| 945 | nullptr)); |
| 946 | EXPECT_TRUE(response.update_exists); |
| 947 | } |
| 948 | |
| 949 | TEST_F(OmahaRequestActionTest, |
| 950 | ValidUpdateOverCellularBlockedByUpdateTargetNotMatch) { |
| 951 | // This test tests that, when device policy is not set and permission for |
| 952 | // update over cellular is set to false or does not exist, update over |
| 953 | // cellular is blocked as update target does not match the omaha response. |
| 954 | OmahaResponse response; |
| 955 | MockConnectionManager mock_cm; |
| 956 | // A version different from the version in omaha response. |
| 957 | string diff_version = "99.99.99"; |
| 958 | // A size different from the size in omaha response. |
| 959 | int64_t diff_size = 999; |
| 960 | |
| 961 | fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, diff_version); |
| 962 | fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, diff_size); |
| 963 | // This test tests cellular (3G) being the only connection type being allowed. |
| 964 | fake_system_state_.set_connection_manager(&mock_cm); |
| 965 | |
| 966 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 967 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 968 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 969 | Return(true))); |
| 970 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 971 | .WillRepeatedly(Return(false)); |
| 972 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 973 | .WillRepeatedly(Return(true)); |
| 974 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 975 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 976 | -1, |
| 977 | false, // ping_only |
| 978 | ErrorCode::kOmahaUpdateIgnoredOverCellular, |
| 979 | metrics::CheckResult::kUpdateAvailable, |
| 980 | metrics::CheckReaction::kIgnored, |
| 981 | metrics::DownloadErrorCode::kUnset, |
| 982 | &response, |
| 983 | nullptr)); |
| 984 | EXPECT_FALSE(response.update_exists); |
| 985 | } |
| 986 | |
| 987 | TEST_F(OmahaRequestActionTest, |
| 988 | ValidUpdateOverCellularAllowedByUpdateTargetMatch) { |
| 989 | // This test tests that, when device policy is not set and permission for |
| 990 | // update over cellular is set to false or does not exist, update over |
| 991 | // cellular is allowed as update target matches the omaha response. |
| 992 | OmahaResponse response; |
| 993 | MockConnectionManager mock_cm; |
| 994 | // A version same as the version in omaha response. |
| 995 | string new_version = fake_update_response_.version; |
| 996 | // A size same as the size in omaha response. |
| 997 | int64_t new_size = fake_update_response_.size; |
| 998 | |
| 999 | fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, new_version); |
| 1000 | fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, new_size); |
| 1001 | fake_system_state_.set_connection_manager(&mock_cm); |
| 1002 | |
| 1003 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 1004 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 1005 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 1006 | Return(true))); |
| 1007 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 1008 | .WillRepeatedly(Return(false)); |
| 1009 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 1010 | .WillRepeatedly(Return(true)); |
| 1011 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1012 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 1013 | -1, |
| 1014 | false, // ping_only |
| 1015 | ErrorCode::kSuccess, |
| 1016 | metrics::CheckResult::kUpdateAvailable, |
| 1017 | metrics::CheckReaction::kUpdating, |
| 1018 | metrics::DownloadErrorCode::kUnset, |
| 1019 | &response, |
| 1020 | nullptr)); |
| 1021 | EXPECT_TRUE(response.update_exists); |
| 1022 | } |
| 1023 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1024 | TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByRollback) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1025 | string rollback_version = "1234.0.0"; |
| 1026 | OmahaResponse response; |
| 1027 | |
| 1028 | MockPayloadState mock_payload_state; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1029 | fake_system_state_.set_payload_state(&mock_payload_state); |
| 1030 | |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1031 | EXPECT_CALL(mock_payload_state, GetRollbackVersion()) |
| 1032 | .WillRepeatedly(Return(rollback_version)); |
| 1033 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1034 | fake_update_response_.version = rollback_version; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1035 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1036 | -1, |
| 1037 | false, // ping_only |
| 1038 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
| 1039 | metrics::CheckResult::kUpdateAvailable, |
| 1040 | metrics::CheckReaction::kIgnored, |
| 1041 | metrics::DownloadErrorCode::kUnset, |
| 1042 | &response, |
| 1043 | nullptr)); |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1044 | EXPECT_FALSE(response.update_exists); |
| 1045 | } |
| 1046 | |
Marton Hunyady | c288206 | 2018-05-14 17:28:25 +0200 | [diff] [blame] | 1047 | // Verify that update checks called during OOBE will not try to download an |
| 1048 | // update if the response doesn't include the deadline field. |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 1049 | TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBE) { |
| 1050 | OmahaResponse response; |
Marton Hunyady | c288206 | 2018-05-14 17:28:25 +0200 | [diff] [blame] | 1051 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 1052 | |
Sen Jiang | 8cd4234 | 2018-01-31 12:06:59 -0800 | [diff] [blame] | 1053 | // TODO(senj): set better default value for metrics::checkresult in |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 1054 | // OmahaRequestAction::ActionCompleted. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1055 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 1056 | -1, |
| 1057 | false, // ping_only |
| 1058 | ErrorCode::kNonCriticalUpdateInOOBE, |
| 1059 | metrics::CheckResult::kParsingError, |
| 1060 | metrics::CheckReaction::kUnset, |
| 1061 | metrics::DownloadErrorCode::kUnset, |
| 1062 | &response, |
| 1063 | nullptr)); |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 1064 | EXPECT_FALSE(response.update_exists); |
Marton Hunyady | c288206 | 2018-05-14 17:28:25 +0200 | [diff] [blame] | 1065 | } |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 1066 | |
Marton Hunyady | c288206 | 2018-05-14 17:28:25 +0200 | [diff] [blame] | 1067 | // Verify that the IsOOBEComplete() value is ignored when the OOBE flow is not |
| 1068 | // enabled. |
| 1069 | TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBEDisabled) { |
| 1070 | OmahaResponse response; |
| 1071 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 1072 | fake_system_state_.fake_hardware()->SetIsOOBEEnabled(false); |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 1073 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1074 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1075 | -1, |
| 1076 | false, // ping_only |
| 1077 | ErrorCode::kSuccess, |
| 1078 | metrics::CheckResult::kUpdateAvailable, |
| 1079 | metrics::CheckReaction::kUpdating, |
| 1080 | metrics::DownloadErrorCode::kUnset, |
| 1081 | &response, |
| 1082 | nullptr)); |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 1083 | EXPECT_TRUE(response.update_exists); |
| 1084 | } |
| 1085 | |
Marton Hunyady | c288206 | 2018-05-14 17:28:25 +0200 | [diff] [blame] | 1086 | // Verify that update checks called during OOBE will still try to download an |
| 1087 | // update if the response includes the deadline field. |
| 1088 | TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBEDeadlineSet) { |
| 1089 | OmahaResponse response; |
| 1090 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
| 1091 | fake_update_response_.deadline = "20101020"; |
| 1092 | |
| 1093 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1094 | -1, |
| 1095 | false, // ping_only |
| 1096 | ErrorCode::kSuccess, |
| 1097 | metrics::CheckResult::kUpdateAvailable, |
| 1098 | metrics::CheckReaction::kUpdating, |
| 1099 | metrics::DownloadErrorCode::kUnset, |
| 1100 | &response, |
| 1101 | nullptr)); |
| 1102 | EXPECT_TRUE(response.update_exists); |
| 1103 | } |
| 1104 | |
| 1105 | // Verify that update checks called during OOBE will not try to download an |
| 1106 | // update if a rollback happened, even when the response includes the deadline |
| 1107 | // field. |
| 1108 | TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBERollback) { |
| 1109 | OmahaResponse response; |
| 1110 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
| 1111 | fake_update_response_.deadline = "20101020"; |
| 1112 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), GetRollbackHappened()) |
| 1113 | .WillOnce(Return(true)); |
| 1114 | |
| 1115 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1116 | -1, |
| 1117 | false, // ping_only |
| 1118 | ErrorCode::kNonCriticalUpdateInOOBE, |
| 1119 | metrics::CheckResult::kParsingError, |
| 1120 | metrics::CheckReaction::kUnset, |
| 1121 | metrics::DownloadErrorCode::kUnset, |
| 1122 | &response, |
| 1123 | nullptr)); |
| 1124 | EXPECT_FALSE(response.update_exists); |
| 1125 | } |
| 1126 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1127 | TEST_F(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1128 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1129 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1130 | request_params_.set_update_check_count_wait_enabled(false); |
| 1131 | request_params_.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1132 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1133 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1134 | -1, |
| 1135 | false, // ping_only |
| 1136 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
| 1137 | metrics::CheckResult::kUpdateAvailable, |
| 1138 | metrics::CheckReaction::kDeferring, |
| 1139 | metrics::DownloadErrorCode::kUnset, |
| 1140 | &response, |
| 1141 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1142 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1143 | |
| 1144 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1145 | request_params_.set_interactive(true); |
| 1146 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1147 | -1, |
| 1148 | false, // ping_only |
| 1149 | ErrorCode::kSuccess, |
| 1150 | metrics::CheckResult::kUpdateAvailable, |
| 1151 | metrics::CheckReaction::kUpdating, |
| 1152 | metrics::DownloadErrorCode::kUnset, |
| 1153 | &response, |
| 1154 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1155 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1158 | TEST_F(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1159 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1160 | request_params_.set_wall_clock_based_wait_enabled(false); |
| 1161 | request_params_.set_waiting_period(TimeDelta::FromDays(2)); |
| 1162 | request_params_.set_update_check_count_wait_enabled(true); |
| 1163 | request_params_.set_min_update_checks_needed(1); |
| 1164 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1165 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1166 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1167 | -1, |
| 1168 | false, // ping_only |
| 1169 | ErrorCode::kSuccess, |
| 1170 | metrics::CheckResult::kUpdateAvailable, |
| 1171 | metrics::CheckReaction::kUpdating, |
| 1172 | metrics::DownloadErrorCode::kUnset, |
| 1173 | &response, |
| 1174 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1175 | EXPECT_TRUE(response.update_exists); |
| 1176 | } |
| 1177 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1178 | TEST_F(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1179 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1180 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1181 | request_params_.set_waiting_period(TimeDelta::FromDays(2)); |
| 1182 | request_params_.set_update_check_count_wait_enabled(true); |
| 1183 | request_params_.set_min_update_checks_needed(1); |
| 1184 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1185 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1186 | fake_update_response_.max_days_to_scatter = "0"; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1187 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1188 | -1, |
| 1189 | false, // ping_only |
| 1190 | ErrorCode::kSuccess, |
| 1191 | metrics::CheckResult::kUpdateAvailable, |
| 1192 | metrics::CheckReaction::kUpdating, |
| 1193 | metrics::DownloadErrorCode::kUnset, |
| 1194 | &response, |
| 1195 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1196 | EXPECT_TRUE(response.update_exists); |
| 1197 | } |
| 1198 | |
| 1199 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1200 | TEST_F(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1201 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1202 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1203 | request_params_.set_waiting_period(TimeDelta()); |
| 1204 | request_params_.set_update_check_count_wait_enabled(true); |
| 1205 | request_params_.set_min_update_checks_needed(0); |
| 1206 | request_params_.set_max_update_checks_allowed(0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1207 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1208 | ASSERT_TRUE(TestUpdateCheck( |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1209 | fake_update_response_.GetUpdateResponse(), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1210 | -1, |
| 1211 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1212 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1213 | metrics::CheckResult::kUpdateAvailable, |
| 1214 | metrics::CheckReaction::kUpdating, |
| 1215 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1216 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1217 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1218 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1219 | int64_t count; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1220 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count)); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1221 | ASSERT_EQ(count, 0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1222 | EXPECT_TRUE(response.update_exists); |
| 1223 | } |
| 1224 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1225 | TEST_F(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1226 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1227 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1228 | request_params_.set_waiting_period(TimeDelta()); |
| 1229 | request_params_.set_update_check_count_wait_enabled(true); |
| 1230 | request_params_.set_min_update_checks_needed(1); |
| 1231 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1232 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1233 | ASSERT_FALSE(TestUpdateCheck( |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1234 | fake_update_response_.GetUpdateResponse(), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1235 | -1, |
| 1236 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1237 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1238 | metrics::CheckResult::kUpdateAvailable, |
| 1239 | metrics::CheckReaction::kDeferring, |
| 1240 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1241 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1242 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1243 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1244 | int64_t count; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1245 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count)); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1246 | ASSERT_GT(count, 0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1247 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1248 | |
| 1249 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1250 | request_params_.set_interactive(true); |
| 1251 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1252 | -1, |
| 1253 | false, // ping_only |
| 1254 | ErrorCode::kSuccess, |
| 1255 | metrics::CheckResult::kUpdateAvailable, |
| 1256 | metrics::CheckReaction::kUpdating, |
| 1257 | metrics::DownloadErrorCode::kUnset, |
| 1258 | &response, |
| 1259 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1260 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1263 | TEST_F(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1264 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1265 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1266 | request_params_.set_waiting_period(TimeDelta()); |
| 1267 | request_params_.set_update_check_count_wait_enabled(true); |
| 1268 | request_params_.set_min_update_checks_needed(1); |
| 1269 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1270 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1271 | ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1272 | |
| 1273 | ASSERT_FALSE(TestUpdateCheck( |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1274 | fake_update_response_.GetUpdateResponse(), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1275 | -1, |
| 1276 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1277 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1278 | metrics::CheckResult::kUpdateAvailable, |
| 1279 | metrics::CheckReaction::kDeferring, |
| 1280 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1281 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1282 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1283 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1284 | int64_t count; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1285 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1286 | // count remains the same, as the decrementing happens in update_attempter |
| 1287 | // which this test doesn't exercise. |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1288 | ASSERT_EQ(count, 5); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1289 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1290 | |
| 1291 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1292 | request_params_.set_interactive(true); |
| 1293 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1294 | -1, |
| 1295 | false, // ping_only |
| 1296 | ErrorCode::kSuccess, |
| 1297 | metrics::CheckResult::kUpdateAvailable, |
| 1298 | metrics::CheckReaction::kUpdating, |
| 1299 | metrics::DownloadErrorCode::kUnset, |
| 1300 | &response, |
| 1301 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1302 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1303 | } |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1304 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1305 | TEST_F(OmahaRequestActionTest, CohortsArePersisted) { |
| 1306 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1307 | fake_update_response_.include_cohorts = true; |
| 1308 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1309 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1310 | fake_update_response_.cohortname = "stable"; |
| 1311 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1312 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1313 | -1, |
| 1314 | false, // ping_only |
| 1315 | ErrorCode::kSuccess, |
| 1316 | metrics::CheckResult::kUpdateAvailable, |
| 1317 | metrics::CheckReaction::kUpdating, |
| 1318 | metrics::DownloadErrorCode::kUnset, |
| 1319 | &response, |
| 1320 | nullptr)); |
| 1321 | |
| 1322 | string value; |
| 1323 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1324 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1325 | |
| 1326 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1327 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1328 | |
| 1329 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1330 | EXPECT_EQ(fake_update_response_.cohortname, value); |
| 1331 | } |
| 1332 | |
| 1333 | TEST_F(OmahaRequestActionTest, CohortsAreUpdated) { |
| 1334 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1335 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value")); |
| 1336 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortHint, "old_hint")); |
| 1337 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortName, "old_name")); |
| 1338 | fake_update_response_.include_cohorts = true; |
| 1339 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1340 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1341 | fake_update_response_.cohortname = ""; |
| 1342 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1343 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1344 | -1, |
| 1345 | false, // ping_only |
| 1346 | ErrorCode::kSuccess, |
| 1347 | metrics::CheckResult::kUpdateAvailable, |
| 1348 | metrics::CheckReaction::kUpdating, |
| 1349 | metrics::DownloadErrorCode::kUnset, |
| 1350 | &response, |
| 1351 | nullptr)); |
| 1352 | |
| 1353 | string value; |
| 1354 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1355 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1356 | |
| 1357 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1358 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1359 | |
| 1360 | EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1361 | } |
| 1362 | |
| 1363 | TEST_F(OmahaRequestActionTest, CohortsAreNotModifiedWhenMissing) { |
| 1364 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1365 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value")); |
| 1366 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1367 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1368 | -1, |
| 1369 | false, // ping_only |
| 1370 | ErrorCode::kSuccess, |
| 1371 | metrics::CheckResult::kUpdateAvailable, |
| 1372 | metrics::CheckReaction::kUpdating, |
| 1373 | metrics::DownloadErrorCode::kUnset, |
| 1374 | &response, |
| 1375 | nullptr)); |
| 1376 | |
| 1377 | string value; |
| 1378 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1379 | EXPECT_EQ("old_value", value); |
| 1380 | |
| 1381 | EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1382 | EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1383 | } |
| 1384 | |
Alex Deymo | 00d79ac | 2015-06-29 15:41:49 -0700 | [diff] [blame] | 1385 | TEST_F(OmahaRequestActionTest, CohortsArePersistedWhenNoUpdate) { |
| 1386 | OmahaResponse response; |
Alex Deymo | 00d79ac | 2015-06-29 15:41:49 -0700 | [diff] [blame] | 1387 | fake_update_response_.include_cohorts = true; |
| 1388 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1389 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1390 | fake_update_response_.cohortname = "stable"; |
| 1391 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1392 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
Alex Deymo | 00d79ac | 2015-06-29 15:41:49 -0700 | [diff] [blame] | 1393 | -1, |
| 1394 | false, // ping_only |
| 1395 | ErrorCode::kSuccess, |
| 1396 | metrics::CheckResult::kNoUpdateAvailable, |
| 1397 | metrics::CheckReaction::kUnset, |
| 1398 | metrics::DownloadErrorCode::kUnset, |
| 1399 | &response, |
| 1400 | nullptr)); |
| 1401 | |
| 1402 | string value; |
| 1403 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1404 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1405 | |
| 1406 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1407 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1408 | |
| 1409 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1410 | EXPECT_EQ(fake_update_response_.cohortname, value); |
| 1411 | } |
| 1412 | |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 1413 | TEST_F(OmahaRequestActionTest, MultiAppCohortTest) { |
| 1414 | OmahaResponse response; |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 1415 | fake_update_response_.multi_app = true; |
| 1416 | fake_update_response_.include_cohorts = true; |
| 1417 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1418 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1419 | fake_update_response_.cohortname = "stable"; |
| 1420 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1421 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 1422 | -1, |
| 1423 | false, // ping_only |
| 1424 | ErrorCode::kSuccess, |
| 1425 | metrics::CheckResult::kUpdateAvailable, |
| 1426 | metrics::CheckReaction::kUpdating, |
| 1427 | metrics::DownloadErrorCode::kUnset, |
| 1428 | &response, |
| 1429 | nullptr)); |
| 1430 | |
| 1431 | string value; |
| 1432 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1433 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1434 | |
| 1435 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1436 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1437 | |
| 1438 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1439 | EXPECT_EQ(fake_update_response_.cohortname, value); |
| 1440 | } |
| 1441 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1442 | TEST_F(OmahaRequestActionTest, NoOutputPipeTest) { |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1443 | const string http_response(fake_update_response_.GetNoUpdateResponse()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1444 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1445 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1446 | loop.SetAsCurrent(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1447 | |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1448 | OmahaRequestAction action( |
| 1449 | &fake_system_state_, |
| 1450 | nullptr, |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1451 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1452 | http_response.size(), |
| 1453 | nullptr), |
| 1454 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1455 | OmahaRequestActionTestProcessorDelegate delegate; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1456 | ActionProcessor processor; |
| 1457 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1458 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1459 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 1460 | loop.PostTask(base::Bind( |
| 1461 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 1462 | base::Unretained(&processor))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1463 | loop.Run(); |
| 1464 | EXPECT_FALSE(loop.PendingTasks()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1465 | EXPECT_FALSE(processor.IsRunning()); |
| 1466 | } |
| 1467 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1468 | TEST_F(OmahaRequestActionTest, InvalidXmlTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1469 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1470 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
| 1471 | -1, |
| 1472 | false, // ping_only |
| 1473 | ErrorCode::kOmahaRequestXMLParseError, |
| 1474 | metrics::CheckResult::kParsingError, |
| 1475 | metrics::CheckReaction::kUnset, |
| 1476 | metrics::DownloadErrorCode::kUnset, |
| 1477 | &response, |
| 1478 | nullptr)); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1479 | EXPECT_FALSE(response.update_exists); |
| 1480 | } |
| 1481 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1482 | TEST_F(OmahaRequestActionTest, EmptyResponseTest) { |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1483 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1484 | ASSERT_FALSE(TestUpdateCheck("", |
| 1485 | -1, |
| 1486 | false, // ping_only |
| 1487 | ErrorCode::kOmahaRequestEmptyResponseError, |
| 1488 | metrics::CheckResult::kParsingError, |
| 1489 | metrics::CheckReaction::kUnset, |
| 1490 | metrics::DownloadErrorCode::kUnset, |
| 1491 | &response, |
| 1492 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1493 | EXPECT_FALSE(response.update_exists); |
| 1494 | } |
| 1495 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1496 | TEST_F(OmahaRequestActionTest, MissingStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1497 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1498 | ASSERT_FALSE(TestUpdateCheck( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1499 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1500 | "<daystart elapsed_seconds=\"100\"/>" |
| 1501 | "<app appid=\"foo\" status=\"ok\">" |
| 1502 | "<ping status=\"ok\"/>" |
| 1503 | "<updatecheck/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1504 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1505 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1506 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1507 | metrics::CheckResult::kParsingError, |
| 1508 | metrics::CheckReaction::kUnset, |
| 1509 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1510 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1511 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1512 | EXPECT_FALSE(response.update_exists); |
| 1513 | } |
| 1514 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1515 | TEST_F(OmahaRequestActionTest, InvalidStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1516 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1517 | ASSERT_FALSE(TestUpdateCheck( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1518 | "<?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\"/>" |
| 1522 | "<updatecheck status=\"InvalidStatusTest\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1523 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1524 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1525 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1526 | metrics::CheckResult::kParsingError, |
| 1527 | metrics::CheckReaction::kUnset, |
| 1528 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1529 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1530 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1531 | EXPECT_FALSE(response.update_exists); |
| 1532 | } |
| 1533 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1534 | TEST_F(OmahaRequestActionTest, MissingNodesetTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1535 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1536 | ASSERT_FALSE(TestUpdateCheck( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1537 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1538 | "<daystart elapsed_seconds=\"100\"/>" |
| 1539 | "<app appid=\"foo\" status=\"ok\">" |
| 1540 | "<ping status=\"ok\"/>" |
| 1541 | "</app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1542 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1543 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1544 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1545 | metrics::CheckResult::kParsingError, |
| 1546 | metrics::CheckReaction::kUnset, |
| 1547 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1548 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1549 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1550 | EXPECT_FALSE(response.update_exists); |
| 1551 | } |
| 1552 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1553 | TEST_F(OmahaRequestActionTest, MissingFieldTest) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1554 | string input_response = |
| 1555 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1556 | "<daystart elapsed_seconds=\"100\"/>" |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 1557 | // the appid needs to match that in the request params |
| 1558 | "<app appid=\"" + |
| 1559 | fake_update_response_.app_id + |
| 1560 | "\" status=\"ok\">" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1561 | "<updatecheck status=\"ok\">" |
| 1562 | "<urls><url codebase=\"http://missing/field/test/\"/></urls>" |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 1563 | "<manifest version=\"10.2.3.4\">" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1564 | "<packages><package hash=\"not-used\" name=\"f\" " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 1565 | "size=\"587\" hash_sha256=\"lkq34j5345\"/></packages>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1566 | "<actions><action event=\"postinstall\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1567 | "ChromeOSVersion=\"10.2.3.4\" " |
| 1568 | "Prompt=\"false\" " |
| 1569 | "IsDelta=\"true\" " |
Jay Srinivasan | d671e97 | 2013-01-11 17:17:19 -0800 | [diff] [blame] | 1570 | "IsDeltaPayload=\"false\" " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 1571 | "sha256=\"not-used\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1572 | "needsadmin=\"true\" " |
| 1573 | "/></actions></manifest></updatecheck></app></response>"; |
| 1574 | LOG(INFO) << "Input Response = " << input_response; |
| 1575 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1576 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1577 | ASSERT_TRUE(TestUpdateCheck(input_response, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1578 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1579 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1580 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1581 | metrics::CheckResult::kUpdateAvailable, |
| 1582 | metrics::CheckReaction::kUpdating, |
| 1583 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1584 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1585 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1586 | EXPECT_TRUE(response.update_exists); |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 1587 | EXPECT_EQ("10.2.3.4", response.version); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1588 | EXPECT_EQ("http://missing/field/test/f", |
| 1589 | response.packages[0].payload_urls[0]); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1590 | EXPECT_EQ("", response.more_info_url); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1591 | EXPECT_EQ("lkq34j5345", response.packages[0].hash); |
| 1592 | EXPECT_EQ(587u, response.packages[0].size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1593 | EXPECT_FALSE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 1594 | EXPECT_TRUE(response.deadline.empty()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | namespace { |
| 1598 | class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate { |
| 1599 | public: |
| 1600 | void ProcessingStopped(const ActionProcessor* processor) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1601 | brillo::MessageLoop::current()->BreakLoop(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1602 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1603 | }; |
| 1604 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1605 | void TerminateTransferTestStarter(ActionProcessor* processor) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1606 | processor->StartProcessing(); |
| 1607 | CHECK(processor->IsRunning()); |
| 1608 | processor->StopProcessing(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1609 | } |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1610 | } // namespace |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1611 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1612 | TEST_F(OmahaRequestActionTest, TerminateTransferTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1613 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1614 | loop.SetAsCurrent(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1615 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1616 | string http_response("doesn't matter"); |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1617 | OmahaRequestAction action( |
| 1618 | &fake_system_state_, |
| 1619 | nullptr, |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1620 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1621 | http_response.size(), |
| 1622 | nullptr), |
| 1623 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1624 | TerminateEarlyTestProcessorDelegate delegate; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1625 | ActionProcessor processor; |
| 1626 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1627 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1628 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1629 | loop.PostTask(base::Bind(&TerminateTransferTestStarter, &processor)); |
| 1630 | loop.Run(); |
| 1631 | EXPECT_FALSE(loop.PendingTasks()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1634 | TEST_F(OmahaRequestActionTest, XmlEncodeTest) { |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1635 | string output; |
| 1636 | EXPECT_TRUE(XmlEncode("ab", &output)); |
| 1637 | EXPECT_EQ("ab", output); |
| 1638 | EXPECT_TRUE(XmlEncode("a<b", &output)); |
| 1639 | EXPECT_EQ("a<b", output); |
Alex Deymo | cc45785 | 2015-06-18 18:35:50 -0700 | [diff] [blame] | 1640 | EXPECT_TRUE(XmlEncode("<&>\"\'\\", &output)); |
| 1641 | EXPECT_EQ("<&>"'\\", output); |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1642 | EXPECT_TRUE(XmlEncode("<&>", &output)); |
| 1643 | EXPECT_EQ("&lt;&amp;&gt;", output); |
Alex Deymo | cc45785 | 2015-06-18 18:35:50 -0700 | [diff] [blame] | 1644 | // Check that unterminated UTF-8 strings are handled properly. |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1645 | EXPECT_FALSE(XmlEncode("\xc2", &output)); |
| 1646 | // Fail with invalid ASCII-7 chars. |
| 1647 | EXPECT_FALSE(XmlEncode("This is an 'n' with a tilde: \xc3\xb1", &output)); |
| 1648 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1649 | |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1650 | TEST_F(OmahaRequestActionTest, XmlEncodeWithDefaultTest) { |
| 1651 | EXPECT_EQ("<&>", XmlEncodeWithDefault("<&>", "something else")); |
| 1652 | EXPECT_EQ("<not escaped>", XmlEncodeWithDefault("\xc2", "<not escaped>")); |
| 1653 | } |
| 1654 | |
| 1655 | TEST_F(OmahaRequestActionTest, XmlEncodeIsUsedForParams) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1656 | brillo::Blob post_data; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1657 | |
| 1658 | // Make sure XML Encode is being called on the params |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1659 | request_params_.set_os_sp("testtheservice_pack>"); |
| 1660 | request_params_.set_os_board("x86 generic<id"); |
| 1661 | request_params_.set_current_channel("unittest_track<"); |
| 1662 | request_params_.set_target_channel("unittest_track<"); |
| 1663 | request_params_.set_hwid("<OEM MODEL>"); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1664 | fake_prefs_.SetString(kPrefsOmahaCohort, "evil\nstring"); |
| 1665 | fake_prefs_.SetString(kPrefsOmahaCohortHint, "evil&string\\"); |
| 1666 | fake_prefs_.SetString(kPrefsOmahaCohortName, |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 1667 | base::JoinString( |
| 1668 | vector<string>(100, "My spoon is too big."), " ")); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1669 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1670 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
| 1671 | -1, |
| 1672 | false, // ping_only |
| 1673 | ErrorCode::kOmahaRequestXMLParseError, |
| 1674 | metrics::CheckResult::kParsingError, |
| 1675 | metrics::CheckReaction::kUnset, |
| 1676 | metrics::DownloadErrorCode::kUnset, |
| 1677 | &response, |
| 1678 | &post_data)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1679 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1680 | string post_str(post_data.begin(), post_data.end()); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1681 | EXPECT_NE(string::npos, post_str.find("testtheservice_pack>")); |
| 1682 | EXPECT_EQ(string::npos, post_str.find("testtheservice_pack>")); |
| 1683 | EXPECT_NE(string::npos, post_str.find("x86 generic<id")); |
| 1684 | EXPECT_EQ(string::npos, post_str.find("x86 generic<id")); |
| 1685 | EXPECT_NE(string::npos, post_str.find("unittest_track&lt;")); |
| 1686 | EXPECT_EQ(string::npos, post_str.find("unittest_track<")); |
| 1687 | EXPECT_NE(string::npos, post_str.find("<OEM MODEL>")); |
| 1688 | EXPECT_EQ(string::npos, post_str.find("<OEM MODEL>")); |
| 1689 | EXPECT_NE(string::npos, post_str.find("cohort=\"evil\nstring\"")); |
| 1690 | EXPECT_EQ(string::npos, post_str.find("cohorthint=\"evil&string\\\"")); |
| 1691 | EXPECT_NE(string::npos, post_str.find("cohorthint=\"evil&string\\\"")); |
| 1692 | // Values from Prefs that are too big are removed from the XML instead of |
| 1693 | // encoded. |
| 1694 | EXPECT_EQ(string::npos, post_str.find("cohortname=")); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1697 | TEST_F(OmahaRequestActionTest, XmlDecodeTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1698 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1699 | fake_update_response_.deadline = "<20110101"; |
| 1700 | fake_update_response_.more_info_url = "testthe<url"; |
| 1701 | fake_update_response_.codebase = "testthe&codebase/"; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1702 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1703 | -1, |
| 1704 | false, // ping_only |
| 1705 | ErrorCode::kSuccess, |
| 1706 | metrics::CheckResult::kUpdateAvailable, |
| 1707 | metrics::CheckReaction::kUpdating, |
| 1708 | metrics::DownloadErrorCode::kUnset, |
| 1709 | &response, |
| 1710 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1711 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1712 | EXPECT_EQ("testthe<url", response.more_info_url); |
| 1713 | EXPECT_EQ("testthe&codebase/file.signed", |
| 1714 | response.packages[0].payload_urls[0]); |
| 1715 | EXPECT_EQ("<20110101", response.deadline); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1718 | TEST_F(OmahaRequestActionTest, ParseIntTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1719 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1720 | // overflows int32_t: |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1721 | fake_update_response_.size = 123123123123123ull; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1722 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1723 | -1, |
| 1724 | false, // ping_only |
| 1725 | ErrorCode::kSuccess, |
| 1726 | metrics::CheckResult::kUpdateAvailable, |
| 1727 | metrics::CheckReaction::kUpdating, |
| 1728 | metrics::DownloadErrorCode::kUnset, |
| 1729 | &response, |
| 1730 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1731 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1732 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1735 | TEST_F(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1736 | brillo::Blob post_data; |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1737 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1738 | fake_system_state_.set_prefs(&prefs); |
| 1739 | |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 1740 | EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1741 | .WillOnce(DoAll(SetArgPointee<1>(string("")), Return(true))); |
Alex Deymo | efb9d83 | 2015-11-02 18:39:02 -0800 | [diff] [blame] | 1742 | // An existing but empty previous version means that we didn't reboot to a new |
| 1743 | // update, therefore, no need to update the previous version. |
| 1744 | EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1745 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1746 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1747 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1748 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1749 | metrics::CheckResult::kParsingError, |
| 1750 | metrics::CheckReaction::kUnset, |
| 1751 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1752 | nullptr, // response |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1753 | &post_data)); |
| 1754 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1755 | string post_str(post_data.begin(), post_data.end()); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1756 | EXPECT_NE( |
| 1757 | post_str.find(" <ping active=\"1\" a=\"-1\" r=\"-1\"></ping>\n" |
| 1758 | " <updatecheck></updatecheck>\n"), |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1759 | string::npos); |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 1760 | EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 1761 | string::npos); |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 1762 | EXPECT_NE(post_str.find("fw_version=\"ChromeOSFirmware.1.0\""), |
| 1763 | string::npos); |
| 1764 | EXPECT_NE(post_str.find("ec_version=\"0X0A1\""), |
| 1765 | string::npos); |
Alex Deymo | efb9d83 | 2015-11-02 18:39:02 -0800 | [diff] [blame] | 1766 | // No <event> tag should be sent if we didn't reboot to an update. |
| 1767 | EXPECT_EQ(post_str.find("<event"), string::npos); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1770 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1771 | TEST_F(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1772 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1773 | TestEvent(new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1774 | "invalid xml>", |
| 1775 | &post_data); |
| 1776 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1777 | string post_str(post_data.begin(), post_data.end()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 1778 | string expected_event = base::StringPrintf( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1779 | " <event eventtype=\"%d\" eventresult=\"%d\"></event>\n", |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1780 | OmahaEvent::kTypeUpdateDownloadStarted, |
| 1781 | OmahaEvent::kResultSuccess); |
| 1782 | EXPECT_NE(post_str.find(expected_event), string::npos); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1783 | EXPECT_EQ(post_str.find("ping"), string::npos); |
| 1784 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1787 | TEST_F(OmahaRequestActionTest, FormatErrorEventOutputTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1788 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1789 | TestEvent(new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1790 | OmahaEvent::kResultError, |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1791 | ErrorCode::kError), |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1792 | "invalid xml>", |
| 1793 | &post_data); |
| 1794 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1795 | string post_str(post_data.begin(), post_data.end()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 1796 | string expected_event = base::StringPrintf( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1797 | " <event eventtype=\"%d\" eventresult=\"%d\" " |
| 1798 | "errorcode=\"%d\"></event>\n", |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1799 | OmahaEvent::kTypeDownloadComplete, |
| 1800 | OmahaEvent::kResultError, |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1801 | static_cast<int>(ErrorCode::kError)); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1802 | EXPECT_NE(post_str.find(expected_event), string::npos); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1803 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1806 | TEST_F(OmahaRequestActionTest, IsEventTest) { |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1807 | string http_response("doesn't matter"); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1808 | OmahaRequestAction update_check_action( |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1809 | &fake_system_state_, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1810 | nullptr, |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1811 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1812 | http_response.size(), |
| 1813 | nullptr), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1814 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1815 | EXPECT_FALSE(update_check_action.IsEvent()); |
| 1816 | |
| 1817 | OmahaRequestAction event_action( |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1818 | &fake_system_state_, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1819 | new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1820 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1821 | http_response.size(), |
| 1822 | nullptr), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1823 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1824 | EXPECT_TRUE(event_action.IsEvent()); |
| 1825 | } |
| 1826 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1827 | TEST_F(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1828 | for (int i = 0; i < 2; i++) { |
| 1829 | bool delta_okay = i == 1; |
| 1830 | const char* delta_okay_str = delta_okay ? "true" : "false"; |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1831 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1832 | |
| 1833 | request_params_.set_delta_okay(delta_okay); |
| 1834 | |
| 1835 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1836 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1837 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1838 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1839 | metrics::CheckResult::kParsingError, |
| 1840 | metrics::CheckReaction::kUnset, |
| 1841 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1842 | nullptr, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1843 | &post_data)); |
| 1844 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1845 | string post_str(post_data.begin(), post_data.end()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 1846 | EXPECT_NE(post_str.find(base::StringPrintf(" delta_okay=\"%s\"", |
| 1847 | delta_okay_str)), |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1848 | string::npos) |
| 1849 | << "i = " << i; |
| 1850 | } |
| 1851 | } |
| 1852 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1853 | TEST_F(OmahaRequestActionTest, FormatInteractiveOutputTest) { |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1854 | for (int i = 0; i < 2; i++) { |
| 1855 | bool interactive = i == 1; |
Gilad Arnold | 8a659d8 | 2013-01-24 11:26:00 -0800 | [diff] [blame] | 1856 | const char* interactive_str = interactive ? "ondemandupdate" : "scheduler"; |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1857 | brillo::Blob post_data; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 1858 | FakeSystemState fake_system_state; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1859 | |
| 1860 | request_params_.set_interactive(interactive); |
| 1861 | |
| 1862 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1863 | -1, |
| 1864 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1865 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1866 | metrics::CheckResult::kParsingError, |
| 1867 | metrics::CheckReaction::kUnset, |
| 1868 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1869 | nullptr, |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1870 | &post_data)); |
| 1871 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1872 | string post_str(post_data.begin(), post_data.end()); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1873 | EXPECT_NE(post_str.find( |
| 1874 | base::StringPrintf("installsource=\"%s\"", interactive_str)), |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1875 | string::npos) |
| 1876 | << "i = " << i; |
| 1877 | } |
| 1878 | } |
| 1879 | |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1880 | TEST_F(OmahaRequestActionTest, FormatTargetVersionPrefixOutputTest) { |
| 1881 | for (int i = 0; i < 2; i++) { |
| 1882 | bool target_version_set = i == 1; |
| 1883 | const char* target_version_prefix = target_version_set ? "10032." : ""; |
| 1884 | brillo::Blob post_data; |
| 1885 | FakeSystemState fake_system_state; |
| 1886 | |
| 1887 | request_params_.set_target_version_prefix(target_version_prefix); |
| 1888 | |
| 1889 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
| 1890 | -1, |
| 1891 | false, // ping_only |
| 1892 | ErrorCode::kOmahaRequestXMLParseError, |
| 1893 | metrics::CheckResult::kParsingError, |
| 1894 | metrics::CheckReaction::kUnset, |
| 1895 | metrics::DownloadErrorCode::kUnset, |
| 1896 | nullptr, |
| 1897 | &post_data)); |
| 1898 | // convert post_data to string |
| 1899 | string post_str(post_data.begin(), post_data.end()); |
| 1900 | if (target_version_set) { |
| 1901 | EXPECT_NE(post_str.find("<updatecheck targetversionprefix=\"10032.\">"), |
| 1902 | string::npos) |
| 1903 | << "i = " << i; |
| 1904 | } else { |
| 1905 | EXPECT_EQ(post_str.find("targetversionprefix"), string::npos) |
| 1906 | << "i = " << i; |
| 1907 | } |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | TEST_F(OmahaRequestActionTest, FormatRollbackAllowedOutputTest) { |
| 1912 | for (int i = 0; i < 4; i++) { |
| 1913 | bool rollback_allowed = i / 2 == 0; |
| 1914 | bool target_version_set = i % 2 == 0; |
| 1915 | brillo::Blob post_data; |
| 1916 | FakeSystemState fake_system_state; |
| 1917 | |
| 1918 | request_params_.set_target_version_prefix(target_version_set ? "10032." |
| 1919 | : ""); |
| 1920 | request_params_.set_rollback_allowed(rollback_allowed); |
| 1921 | |
| 1922 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
| 1923 | -1, |
| 1924 | false, // ping_only |
| 1925 | ErrorCode::kOmahaRequestXMLParseError, |
| 1926 | metrics::CheckResult::kParsingError, |
| 1927 | metrics::CheckReaction::kUnset, |
| 1928 | metrics::DownloadErrorCode::kUnset, |
| 1929 | nullptr, |
| 1930 | &post_data)); |
| 1931 | // convert post_data to string |
| 1932 | string post_str(post_data.begin(), post_data.end()); |
| 1933 | if (rollback_allowed && target_version_set) { |
| 1934 | EXPECT_NE(post_str.find("rollback_allowed=\"true\""), string::npos) |
| 1935 | << "i = " << i; |
| 1936 | } else { |
| 1937 | EXPECT_EQ(post_str.find("rollback_allowed"), string::npos) << "i = " << i; |
| 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1942 | TEST_F(OmahaRequestActionTest, OmahaEventTest) { |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1943 | OmahaEvent default_event; |
| 1944 | EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type); |
| 1945 | EXPECT_EQ(OmahaEvent::kResultError, default_event.result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1946 | EXPECT_EQ(ErrorCode::kError, default_event.error_code); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1947 | |
| 1948 | OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted); |
| 1949 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type); |
| 1950 | EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1951 | EXPECT_EQ(ErrorCode::kSuccess, success_event.error_code); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1952 | |
| 1953 | OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, |
| 1954 | OmahaEvent::kResultError, |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1955 | ErrorCode::kError); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1956 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); |
| 1957 | EXPECT_EQ(OmahaEvent::kResultError, error_event.result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1958 | EXPECT_EQ(ErrorCode::kError, error_event.error_code); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1961 | void OmahaRequestActionTest::PingTest(bool ping_only) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1962 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1963 | fake_system_state_.set_prefs(&prefs); |
| 1964 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 1965 | .Times(AnyNumber()); |
| 1966 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
| 1967 | // Add a few hours to the day difference to test no rounding, etc. |
| 1968 | int64_t five_days_ago = |
| 1969 | (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue(); |
| 1970 | int64_t six_days_ago = |
| 1971 | (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue(); |
| 1972 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1973 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1974 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1975 | .WillOnce(DoAll(SetArgPointee<1>(six_days_ago), Return(true))); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1976 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1977 | .WillOnce(DoAll(SetArgPointee<1>(five_days_ago), Return(true))); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1978 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 1979 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 1980 | -1, |
| 1981 | ping_only, |
| 1982 | ErrorCode::kSuccess, |
| 1983 | metrics::CheckResult::kNoUpdateAvailable, |
| 1984 | metrics::CheckReaction::kUnset, |
| 1985 | metrics::DownloadErrorCode::kUnset, |
| 1986 | nullptr, |
| 1987 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1988 | string post_str(post_data.begin(), post_data.end()); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1989 | EXPECT_NE(post_str.find("<ping active=\"1\" a=\"6\" r=\"5\"></ping>"), |
| 1990 | string::npos); |
| 1991 | if (ping_only) { |
| 1992 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
| 1993 | EXPECT_EQ(post_str.find("previousversion"), string::npos); |
| 1994 | } else { |
| 1995 | EXPECT_NE(post_str.find("updatecheck"), string::npos); |
| 1996 | EXPECT_NE(post_str.find("previousversion"), string::npos); |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1997 | } |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2000 | TEST_F(OmahaRequestActionTest, PingTestSendOnlyAPing) { |
| 2001 | PingTest(true /* ping_only */); |
| 2002 | } |
| 2003 | |
| 2004 | TEST_F(OmahaRequestActionTest, PingTestSendAlsoAnUpdateCheck) { |
| 2005 | PingTest(false /* ping_only */); |
| 2006 | } |
| 2007 | |
| 2008 | TEST_F(OmahaRequestActionTest, ActivePingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2009 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2010 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2011 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 2012 | .Times(AnyNumber()); |
| 2013 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2014 | int64_t three_days_ago = |
| 2015 | (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue(); |
| 2016 | int64_t now = Time::Now().ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2017 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2018 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2019 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2020 | .WillOnce(DoAll(SetArgPointee<1>(three_days_ago), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2021 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2022 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2023 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2024 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2025 | -1, |
| 2026 | false, // ping_only |
| 2027 | ErrorCode::kSuccess, |
| 2028 | metrics::CheckResult::kNoUpdateAvailable, |
| 2029 | metrics::CheckReaction::kUnset, |
| 2030 | metrics::DownloadErrorCode::kUnset, |
| 2031 | nullptr, |
| 2032 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2033 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2034 | EXPECT_NE(post_str.find("<ping active=\"1\" a=\"3\"></ping>"), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 2035 | string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2038 | TEST_F(OmahaRequestActionTest, RollCallPingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2039 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2040 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2041 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 2042 | .Times(AnyNumber()); |
| 2043 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2044 | int64_t four_days_ago = |
| 2045 | (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue(); |
| 2046 | int64_t now = Time::Now().ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2047 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2048 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2049 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2050 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2051 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2052 | .WillOnce(DoAll(SetArgPointee<1>(four_days_ago), Return(true))); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2053 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2054 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2055 | -1, |
| 2056 | false, // ping_only |
| 2057 | ErrorCode::kSuccess, |
| 2058 | metrics::CheckResult::kNoUpdateAvailable, |
| 2059 | metrics::CheckReaction::kUnset, |
| 2060 | metrics::DownloadErrorCode::kUnset, |
| 2061 | nullptr, |
| 2062 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2063 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2064 | EXPECT_NE(post_str.find("<ping active=\"1\" r=\"4\"></ping>\n"), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 2065 | string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2068 | TEST_F(OmahaRequestActionTest, NoPingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2069 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2070 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2071 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 2072 | .Times(AnyNumber()); |
| 2073 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2074 | int64_t one_hour_ago = |
| 2075 | (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2076 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2077 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2078 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2079 | .WillOnce(DoAll(SetArgPointee<1>(one_hour_ago), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2080 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2081 | .WillOnce(DoAll(SetArgPointee<1>(one_hour_ago), Return(true))); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2082 | // LastActivePingDay and PrefsLastRollCallPingDay are set even if we didn't |
| 2083 | // send a ping. |
| 2084 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) |
| 2085 | .WillOnce(Return(true)); |
| 2086 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) |
| 2087 | .WillOnce(Return(true)); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2088 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2089 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2090 | -1, |
| 2091 | false, // ping_only |
| 2092 | ErrorCode::kSuccess, |
| 2093 | metrics::CheckResult::kNoUpdateAvailable, |
| 2094 | metrics::CheckReaction::kUnset, |
| 2095 | metrics::DownloadErrorCode::kUnset, |
| 2096 | nullptr, |
| 2097 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2098 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2099 | EXPECT_EQ(post_str.find("ping"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2102 | TEST_F(OmahaRequestActionTest, IgnoreEmptyPingTest) { |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 2103 | // This test ensures that we ignore empty ping only requests. |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2104 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2105 | fake_system_state_.set_prefs(&prefs); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 2106 | int64_t now = Time::Now().ToInternalValue(); |
| 2107 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2108 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 2109 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2110 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 2111 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 2112 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2113 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2114 | EXPECT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2115 | -1, |
| 2116 | true, // ping_only |
| 2117 | ErrorCode::kSuccess, |
| 2118 | metrics::CheckResult::kUnset, |
| 2119 | metrics::CheckReaction::kUnset, |
| 2120 | metrics::DownloadErrorCode::kUnset, |
| 2121 | nullptr, |
| 2122 | &post_data)); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 2123 | EXPECT_EQ(0U, post_data.size()); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2126 | TEST_F(OmahaRequestActionTest, BackInTimePingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2127 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2128 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2129 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 2130 | .Times(AnyNumber()); |
| 2131 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2132 | int64_t future = |
| 2133 | (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2134 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2135 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2136 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2137 | .WillOnce(DoAll(SetArgPointee<1>(future), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2138 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 2139 | .WillOnce(DoAll(SetArgPointee<1>(future), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2140 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) |
| 2141 | .WillOnce(Return(true)); |
| 2142 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) |
| 2143 | .WillOnce(Return(true)); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2144 | brillo::Blob post_data; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2145 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2146 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2147 | "protocol=\"3.0\"><daystart elapsed_seconds=\"100\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2148 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2149 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2150 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2151 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2152 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2153 | metrics::CheckResult::kNoUpdateAvailable, |
| 2154 | metrics::CheckReaction::kUnset, |
| 2155 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2156 | nullptr, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2157 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2158 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2159 | EXPECT_EQ(post_str.find("ping"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2162 | TEST_F(OmahaRequestActionTest, LastPingDayUpdateTest) { |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2163 | // This test checks that the action updates the last ping day to now |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 2164 | // minus 200 seconds with a slack of 5 seconds. Therefore, the test |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2165 | // may fail if it runs for longer than 5 seconds. It shouldn't run |
| 2166 | // that long though. |
| 2167 | int64_t midnight = |
| 2168 | (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue(); |
| 2169 | int64_t midnight_slack = |
| 2170 | (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue(); |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2171 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2172 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2173 | EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber()); |
| 2174 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2175 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, |
| 2176 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 2177 | .WillOnce(Return(true)); |
| 2178 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, |
| 2179 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 2180 | .WillOnce(Return(true)); |
| 2181 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2182 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2183 | "protocol=\"3.0\"><daystart elapsed_seconds=\"200\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2184 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2185 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2186 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2187 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2188 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2189 | metrics::CheckResult::kNoUpdateAvailable, |
| 2190 | metrics::CheckReaction::kUnset, |
| 2191 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2192 | nullptr, |
| 2193 | nullptr)); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2196 | TEST_F(OmahaRequestActionTest, NoElapsedSecondsTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2197 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2198 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2199 | EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber()); |
| 2200 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2201 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 2202 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 2203 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2204 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2205 | "protocol=\"3.0\"><daystart blah=\"200\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2206 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2207 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2208 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2209 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2210 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2211 | metrics::CheckResult::kNoUpdateAvailable, |
| 2212 | metrics::CheckReaction::kUnset, |
| 2213 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2214 | nullptr, |
| 2215 | nullptr)); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2218 | TEST_F(OmahaRequestActionTest, BadElapsedSecondsTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2219 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2220 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2221 | EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber()); |
| 2222 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2223 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 2224 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 2225 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2226 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2227 | "protocol=\"3.0\"><daystart elapsed_seconds=\"x\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2228 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2229 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2230 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2231 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2232 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2233 | metrics::CheckResult::kNoUpdateAvailable, |
| 2234 | metrics::CheckReaction::kUnset, |
| 2235 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2236 | nullptr, |
| 2237 | nullptr)); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 2240 | TEST_F(OmahaRequestActionTest, ParseUpdateCheckAttributesTest) { |
| 2241 | // Test that the "eol" flags is only parsed from the "_eol" attribute and not |
| 2242 | // the "eol" attribute. |
| 2243 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2244 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 2245 | "protocol=\"3.0\"><app appid=\"foo\" status=\"ok\">" |
| 2246 | "<ping status=\"ok\"/><updatecheck status=\"noupdate\" " |
| 2247 | "_eol=\"security-only\" eol=\"eol\" _foo=\"bar\"/>" |
| 2248 | "</app></response>", |
| 2249 | -1, |
| 2250 | false, // ping_only |
| 2251 | ErrorCode::kSuccess, |
| 2252 | metrics::CheckResult::kNoUpdateAvailable, |
| 2253 | metrics::CheckReaction::kUnset, |
| 2254 | metrics::DownloadErrorCode::kUnset, |
| 2255 | nullptr, |
| 2256 | nullptr)); |
| 2257 | string eol_pref; |
| 2258 | EXPECT_TRUE( |
| 2259 | fake_system_state_.prefs()->GetString(kPrefsOmahaEolStatus, &eol_pref)); |
| 2260 | // Note that the eol="eol" attribute should be ignored and the _eol should be |
| 2261 | // used instead. |
| 2262 | EXPECT_EQ("security-only", eol_pref); |
| 2263 | } |
| 2264 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2265 | TEST_F(OmahaRequestActionTest, NoUniqueIDTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2266 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2267 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2268 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2269 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2270 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2271 | metrics::CheckResult::kParsingError, |
| 2272 | metrics::CheckReaction::kUnset, |
| 2273 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2274 | nullptr, // response |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 2275 | &post_data)); |
| 2276 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2277 | string post_str(post_data.begin(), post_data.end()); |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 2278 | EXPECT_EQ(post_str.find("machineid="), string::npos); |
| 2279 | EXPECT_EQ(post_str.find("userid="), string::npos); |
| 2280 | } |
| 2281 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2282 | TEST_F(OmahaRequestActionTest, NetworkFailureTest) { |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2283 | OmahaResponse response; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2284 | const int http_error_code = |
| 2285 | static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 501; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2286 | ASSERT_FALSE(TestUpdateCheck("", |
| 2287 | 501, |
| 2288 | false, // ping_only |
| 2289 | static_cast<ErrorCode>(http_error_code), |
| 2290 | metrics::CheckResult::kDownloadError, |
| 2291 | metrics::CheckReaction::kUnset, |
| 2292 | static_cast<metrics::DownloadErrorCode>(501), |
| 2293 | &response, |
| 2294 | nullptr)); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2295 | EXPECT_FALSE(response.update_exists); |
| 2296 | } |
| 2297 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2298 | TEST_F(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) { |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2299 | OmahaResponse response; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2300 | const int http_error_code = |
| 2301 | static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 999; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2302 | ASSERT_FALSE(TestUpdateCheck("", |
| 2303 | 1500, |
| 2304 | false, // ping_only |
| 2305 | static_cast<ErrorCode>(http_error_code), |
| 2306 | metrics::CheckResult::kDownloadError, |
| 2307 | metrics::CheckReaction::kUnset, |
| 2308 | metrics::DownloadErrorCode::kHttpStatusOther, |
| 2309 | &response, |
| 2310 | nullptr)); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2311 | EXPECT_FALSE(response.update_exists); |
| 2312 | } |
| 2313 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2314 | TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsPersistedFirstTime) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2315 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2316 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 2317 | request_params_.set_waiting_period(TimeDelta().FromDays(1)); |
| 2318 | request_params_.set_update_check_count_wait_enabled(false); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2319 | |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2320 | Time arbitrary_date; |
Eric Caruso | 761be2c | 2018-05-22 16:23:33 -0700 | [diff] [blame^] | 2321 | ASSERT_TRUE(Time::FromString("6/4/1989", &arbitrary_date)); |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2322 | fake_system_state_.fake_clock()->SetWallclockTime(arbitrary_date); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2323 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2324 | -1, |
| 2325 | false, // ping_only |
| 2326 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
| 2327 | metrics::CheckResult::kUpdateAvailable, |
| 2328 | metrics::CheckReaction::kDeferring, |
| 2329 | metrics::DownloadErrorCode::kUnset, |
| 2330 | &response, |
| 2331 | nullptr)); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2332 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 2333 | int64_t timestamp = 0; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2334 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp)); |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2335 | EXPECT_EQ(arbitrary_date.ToInternalValue(), timestamp); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2336 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 2337 | |
| 2338 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2339 | request_params_.set_interactive(true); |
| 2340 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2341 | -1, |
| 2342 | false, // ping_only |
| 2343 | ErrorCode::kSuccess, |
| 2344 | metrics::CheckResult::kUpdateAvailable, |
| 2345 | metrics::CheckReaction::kUpdating, |
| 2346 | metrics::DownloadErrorCode::kUnset, |
| 2347 | &response, |
| 2348 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 2349 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2352 | TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsUsedIfAlreadyPresent) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2353 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2354 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 2355 | request_params_.set_waiting_period(TimeDelta().FromDays(1)); |
| 2356 | request_params_.set_update_check_count_wait_enabled(false); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2357 | |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2358 | Time t1, t2; |
Eric Caruso | 761be2c | 2018-05-22 16:23:33 -0700 | [diff] [blame^] | 2359 | ASSERT_TRUE(Time::FromString("1/1/2012", &t1)); |
| 2360 | ASSERT_TRUE(Time::FromString("1/3/2012", &t2)); |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2361 | ASSERT_TRUE( |
| 2362 | fake_prefs_.SetInt64(kPrefsUpdateFirstSeenAt, t1.ToInternalValue())); |
| 2363 | fake_system_state_.fake_clock()->SetWallclockTime(t2); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2364 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2365 | -1, |
| 2366 | false, // ping_only |
| 2367 | ErrorCode::kSuccess, |
| 2368 | metrics::CheckResult::kUpdateAvailable, |
| 2369 | metrics::CheckReaction::kUpdating, |
| 2370 | metrics::DownloadErrorCode::kUnset, |
| 2371 | &response, |
| 2372 | nullptr)); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2373 | |
| 2374 | EXPECT_TRUE(response.update_exists); |
| 2375 | |
| 2376 | // Make sure the timestamp t1 is unchanged showing that it was reused. |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 2377 | int64_t timestamp = 0; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2378 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp)); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2379 | ASSERT_TRUE(timestamp == t1.ToInternalValue()); |
| 2380 | } |
| 2381 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2382 | TEST_F(OmahaRequestActionTest, TestChangingToMoreStableChannel) { |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2383 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 2384 | base::ScopedTempDir tempdir; |
| 2385 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2386 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2387 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2388 | request_params_.set_root(tempdir.GetPath().value()); |
| 2389 | request_params_.set_app_id("{22222222-2222-2222-2222-222222222222}"); |
| 2390 | request_params_.set_app_version("1.2.3.4"); |
| 2391 | request_params_.set_product_components("o.bundle=1"); |
| 2392 | request_params_.set_current_channel("canary-channel"); |
| 2393 | EXPECT_TRUE( |
| 2394 | request_params_.SetTargetChannel("stable-channel", true, nullptr)); |
| 2395 | request_params_.UpdateDownloadChannel(); |
| 2396 | EXPECT_TRUE(request_params_.ShouldPowerwash()); |
| 2397 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2398 | -1, |
| 2399 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2400 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2401 | metrics::CheckResult::kParsingError, |
| 2402 | metrics::CheckReaction::kUnset, |
| 2403 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2404 | nullptr, // response |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2405 | &post_data)); |
| 2406 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2407 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2408 | EXPECT_NE(string::npos, post_str.find( |
| 2409 | "appid=\"{22222222-2222-2222-2222-222222222222}\" " |
| 2410 | "version=\"0.0.0.0\" from_version=\"1.2.3.4\" " |
| 2411 | "track=\"stable-channel\" from_track=\"canary-channel\" ")); |
Sen Jiang | 8cd4234 | 2018-01-31 12:06:59 -0800 | [diff] [blame] | 2412 | EXPECT_EQ(string::npos, post_str.find("o.bundle")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2415 | TEST_F(OmahaRequestActionTest, TestChangingToLessStableChannel) { |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2416 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 2417 | base::ScopedTempDir tempdir; |
| 2418 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2419 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2420 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2421 | request_params_.set_root(tempdir.GetPath().value()); |
| 2422 | request_params_.set_app_id("{11111111-1111-1111-1111-111111111111}"); |
| 2423 | request_params_.set_app_version("5.6.7.8"); |
| 2424 | request_params_.set_product_components("o.bundle=1"); |
| 2425 | request_params_.set_current_channel("stable-channel"); |
| 2426 | EXPECT_TRUE( |
| 2427 | request_params_.SetTargetChannel("canary-channel", false, nullptr)); |
| 2428 | request_params_.UpdateDownloadChannel(); |
| 2429 | EXPECT_FALSE(request_params_.ShouldPowerwash()); |
| 2430 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2431 | -1, |
| 2432 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2433 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2434 | metrics::CheckResult::kParsingError, |
| 2435 | metrics::CheckReaction::kUnset, |
| 2436 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2437 | nullptr, // response |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2438 | &post_data)); |
| 2439 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2440 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2441 | EXPECT_NE(string::npos, post_str.find( |
| 2442 | "appid=\"{11111111-1111-1111-1111-111111111111}\" " |
| 2443 | "version=\"5.6.7.8\" " |
| 2444 | "track=\"canary-channel\" from_track=\"stable-channel\"")); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2445 | EXPECT_EQ(string::npos, post_str.find("from_version")); |
Sen Jiang | 8cd4234 | 2018-01-31 12:06:59 -0800 | [diff] [blame] | 2446 | EXPECT_NE(string::npos, post_str.find("o.bundle.version=\"1\"")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2449 | // Checks that the initial ping with a=-1 r=-1 is not send when the device |
| 2450 | // was powerwashed. |
| 2451 | TEST_F(OmahaRequestActionTest, PingWhenPowerwashed) { |
| 2452 | fake_prefs_.SetString(kPrefsPreviousVersion, ""); |
| 2453 | |
| 2454 | // Flag that the device was powerwashed in the past. |
| 2455 | fake_system_state_.fake_hardware()->SetPowerwashCount(1); |
| 2456 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2457 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2458 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2459 | -1, |
| 2460 | false, // ping_only |
| 2461 | ErrorCode::kSuccess, |
| 2462 | metrics::CheckResult::kNoUpdateAvailable, |
| 2463 | metrics::CheckReaction::kUnset, |
| 2464 | metrics::DownloadErrorCode::kUnset, |
| 2465 | nullptr, |
| 2466 | &post_data)); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2467 | // We shouldn't send a ping in this case since powerwash > 0. |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2468 | string post_str(post_data.begin(), post_data.end()); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2469 | EXPECT_EQ(string::npos, post_str.find("<ping")); |
| 2470 | } |
| 2471 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 2472 | // Checks that the initial ping with a=-1 r=-1 is not send when the device |
| 2473 | // first_active_omaha_ping_sent is set. |
| 2474 | TEST_F(OmahaRequestActionTest, PingWhenFirstActiveOmahaPingIsSent) { |
| 2475 | fake_prefs_.SetString(kPrefsPreviousVersion, ""); |
| 2476 | |
| 2477 | // Flag that the device was not powerwashed in the past. |
| 2478 | fake_system_state_.fake_hardware()->SetPowerwashCount(0); |
| 2479 | |
| 2480 | // Flag that the device has sent first active ping in the past. |
| 2481 | fake_system_state_.fake_hardware()->SetFirstActiveOmahaPingSent(); |
| 2482 | |
| 2483 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2484 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2485 | -1, |
| 2486 | false, // ping_only |
| 2487 | ErrorCode::kSuccess, |
| 2488 | metrics::CheckResult::kNoUpdateAvailable, |
| 2489 | metrics::CheckReaction::kUnset, |
| 2490 | metrics::DownloadErrorCode::kUnset, |
| 2491 | nullptr, |
| 2492 | &post_data)); |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 2493 | // We shouldn't send a ping in this case since |
| 2494 | // first_active_omaha_ping_sent=true |
| 2495 | string post_str(post_data.begin(), post_data.end()); |
| 2496 | EXPECT_EQ(string::npos, post_str.find("<ping")); |
| 2497 | } |
| 2498 | |
Alex Deymo | 9fded1e | 2015-11-05 12:31:19 -0800 | [diff] [blame] | 2499 | // Checks that the event 54 is sent on a reboot to a new update. |
| 2500 | TEST_F(OmahaRequestActionTest, RebootAfterUpdateEvent) { |
| 2501 | // Flag that the device was updated in a previous boot. |
| 2502 | fake_prefs_.SetString(kPrefsPreviousVersion, "1.2.3.4"); |
| 2503 | |
| 2504 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2505 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2506 | -1, |
| 2507 | false, // ping_only |
| 2508 | ErrorCode::kSuccess, |
| 2509 | metrics::CheckResult::kNoUpdateAvailable, |
| 2510 | metrics::CheckReaction::kUnset, |
| 2511 | metrics::DownloadErrorCode::kUnset, |
| 2512 | nullptr, |
| 2513 | &post_data)); |
Alex Deymo | 9fded1e | 2015-11-05 12:31:19 -0800 | [diff] [blame] | 2514 | string post_str(post_data.begin(), post_data.end()); |
| 2515 | |
| 2516 | // An event 54 is included and has the right version. |
| 2517 | EXPECT_NE(string::npos, |
| 2518 | post_str.find(base::StringPrintf( |
| 2519 | "<event eventtype=\"%d\"", |
| 2520 | OmahaEvent::kTypeRebootedAfterUpdate))); |
| 2521 | EXPECT_NE(string::npos, |
| 2522 | post_str.find("previousversion=\"1.2.3.4\"></event>")); |
| 2523 | |
| 2524 | // The previous version flag should have been removed. |
| 2525 | EXPECT_TRUE(fake_prefs_.Exists(kPrefsPreviousVersion)); |
| 2526 | string prev_version; |
| 2527 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsPreviousVersion, &prev_version)); |
| 2528 | EXPECT_TRUE(prev_version.empty()); |
| 2529 | } |
| 2530 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2531 | void OmahaRequestActionTest::P2PTest( |
| 2532 | bool initial_allow_p2p_for_downloading, |
| 2533 | bool initial_allow_p2p_for_sharing, |
| 2534 | bool omaha_disable_p2p_for_downloading, |
| 2535 | bool omaha_disable_p2p_for_sharing, |
| 2536 | bool payload_state_allow_p2p_attempt, |
| 2537 | bool expect_p2p_client_lookup, |
| 2538 | const string& p2p_client_result_url, |
| 2539 | bool expected_allow_p2p_for_downloading, |
| 2540 | bool expected_allow_p2p_for_sharing, |
| 2541 | const string& expected_p2p_url) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2542 | OmahaResponse response; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2543 | bool actual_allow_p2p_for_downloading = initial_allow_p2p_for_downloading; |
| 2544 | bool actual_allow_p2p_for_sharing = initial_allow_p2p_for_sharing; |
| 2545 | string actual_p2p_url; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2546 | |
| 2547 | MockPayloadState mock_payload_state; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2548 | fake_system_state_.set_payload_state(&mock_payload_state); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2549 | EXPECT_CALL(mock_payload_state, P2PAttemptAllowed()) |
| 2550 | .WillRepeatedly(Return(payload_state_allow_p2p_attempt)); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2551 | EXPECT_CALL(mock_payload_state, GetUsingP2PForDownloading()) |
| 2552 | .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_downloading)); |
| 2553 | EXPECT_CALL(mock_payload_state, GetUsingP2PForSharing()) |
| 2554 | .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_sharing)); |
| 2555 | EXPECT_CALL(mock_payload_state, SetUsingP2PForDownloading(_)) |
| 2556 | .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_downloading)); |
| 2557 | EXPECT_CALL(mock_payload_state, SetUsingP2PForSharing(_)) |
| 2558 | .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_sharing)); |
| 2559 | EXPECT_CALL(mock_payload_state, SetP2PUrl(_)) |
| 2560 | .WillRepeatedly(SaveArg<0>(&actual_p2p_url)); |
| 2561 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2562 | MockP2PManager mock_p2p_manager; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2563 | fake_system_state_.set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2564 | mock_p2p_manager.fake().SetLookupUrlForFileResult(p2p_client_result_url); |
| 2565 | |
David Zeuthen | 4cc5ed2 | 2014-01-15 12:35:03 -0800 | [diff] [blame] | 2566 | TimeDelta timeout = TimeDelta::FromSeconds(kMaxP2PNetworkWaitTimeSeconds); |
| 2567 | EXPECT_CALL(mock_p2p_manager, LookupUrlForFile(_, _, timeout, _)) |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2568 | .Times(expect_p2p_client_lookup ? 1 : 0); |
| 2569 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 2570 | fake_update_response_.disable_p2p_for_downloading = |
| 2571 | omaha_disable_p2p_for_downloading; |
| 2572 | fake_update_response_.disable_p2p_for_sharing = omaha_disable_p2p_for_sharing; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2573 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 2574 | -1, |
| 2575 | false, // ping_only |
| 2576 | ErrorCode::kSuccess, |
| 2577 | metrics::CheckResult::kUpdateAvailable, |
| 2578 | metrics::CheckReaction::kUpdating, |
| 2579 | metrics::DownloadErrorCode::kUnset, |
| 2580 | &response, |
| 2581 | nullptr)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2582 | EXPECT_TRUE(response.update_exists); |
| 2583 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2584 | EXPECT_EQ(omaha_disable_p2p_for_downloading, |
| 2585 | response.disable_p2p_for_downloading); |
| 2586 | EXPECT_EQ(omaha_disable_p2p_for_sharing, |
| 2587 | response.disable_p2p_for_sharing); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2588 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2589 | EXPECT_EQ(expected_allow_p2p_for_downloading, |
| 2590 | actual_allow_p2p_for_downloading); |
| 2591 | EXPECT_EQ(expected_allow_p2p_for_sharing, actual_allow_p2p_for_sharing); |
| 2592 | EXPECT_EQ(expected_p2p_url, actual_p2p_url); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2595 | TEST_F(OmahaRequestActionTest, P2PWithPeer) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2596 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2597 | true, // initial_allow_p2p_for_sharing |
| 2598 | false, // omaha_disable_p2p_for_downloading |
| 2599 | false, // omaha_disable_p2p_for_sharing |
| 2600 | true, // payload_state_allow_p2p_attempt |
| 2601 | true, // expect_p2p_client_lookup |
| 2602 | "http://1.3.5.7/p2p", // p2p_client_result_url |
| 2603 | true, // expected_allow_p2p_for_downloading |
| 2604 | true, // expected_allow_p2p_for_sharing |
| 2605 | "http://1.3.5.7/p2p"); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2608 | TEST_F(OmahaRequestActionTest, P2PWithoutPeer) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2609 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2610 | true, // initial_allow_p2p_for_sharing |
| 2611 | false, // omaha_disable_p2p_for_downloading |
| 2612 | false, // omaha_disable_p2p_for_sharing |
| 2613 | true, // payload_state_allow_p2p_attempt |
| 2614 | true, // expect_p2p_client_lookup |
| 2615 | "", // p2p_client_result_url |
| 2616 | false, // expected_allow_p2p_for_downloading |
| 2617 | true, // expected_allow_p2p_for_sharing |
| 2618 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2621 | TEST_F(OmahaRequestActionTest, P2PDownloadNotAllowed) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2622 | P2PTest(false, // initial_allow_p2p_for_downloading |
| 2623 | true, // initial_allow_p2p_for_sharing |
| 2624 | false, // omaha_disable_p2p_for_downloading |
| 2625 | false, // omaha_disable_p2p_for_sharing |
| 2626 | true, // payload_state_allow_p2p_attempt |
| 2627 | false, // expect_p2p_client_lookup |
| 2628 | "unset", // p2p_client_result_url |
| 2629 | false, // expected_allow_p2p_for_downloading |
| 2630 | true, // expected_allow_p2p_for_sharing |
| 2631 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2634 | TEST_F(OmahaRequestActionTest, P2PWithPeerDownloadDisabledByOmaha) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2635 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2636 | true, // initial_allow_p2p_for_sharing |
| 2637 | true, // omaha_disable_p2p_for_downloading |
| 2638 | false, // omaha_disable_p2p_for_sharing |
| 2639 | true, // payload_state_allow_p2p_attempt |
| 2640 | false, // expect_p2p_client_lookup |
| 2641 | "unset", // p2p_client_result_url |
| 2642 | false, // expected_allow_p2p_for_downloading |
| 2643 | true, // expected_allow_p2p_for_sharing |
| 2644 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2647 | TEST_F(OmahaRequestActionTest, P2PWithPeerSharingDisabledByOmaha) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2648 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2649 | true, // initial_allow_p2p_for_sharing |
| 2650 | false, // omaha_disable_p2p_for_downloading |
| 2651 | true, // omaha_disable_p2p_for_sharing |
| 2652 | true, // payload_state_allow_p2p_attempt |
| 2653 | true, // expect_p2p_client_lookup |
| 2654 | "http://1.3.5.7/p2p", // p2p_client_result_url |
| 2655 | true, // expected_allow_p2p_for_downloading |
| 2656 | false, // expected_allow_p2p_for_sharing |
| 2657 | "http://1.3.5.7/p2p"); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2660 | TEST_F(OmahaRequestActionTest, P2PWithPeerBothDisabledByOmaha) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2661 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2662 | true, // initial_allow_p2p_for_sharing |
| 2663 | true, // omaha_disable_p2p_for_downloading |
| 2664 | true, // omaha_disable_p2p_for_sharing |
| 2665 | true, // payload_state_allow_p2p_attempt |
| 2666 | false, // expect_p2p_client_lookup |
| 2667 | "unset", // p2p_client_result_url |
| 2668 | false, // expected_allow_p2p_for_downloading |
| 2669 | false, // expected_allow_p2p_for_sharing |
| 2670 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 2673 | bool OmahaRequestActionTest::InstallDateParseHelper(const string &elapsed_days, |
| 2674 | OmahaResponse *response) { |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 2675 | fake_update_response_.elapsed_days = elapsed_days; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame] | 2676 | return TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 2677 | -1, |
| 2678 | false, // ping_only |
| 2679 | ErrorCode::kSuccess, |
| 2680 | metrics::CheckResult::kUpdateAvailable, |
| 2681 | metrics::CheckReaction::kUpdating, |
| 2682 | metrics::DownloadErrorCode::kUnset, |
| 2683 | response, |
| 2684 | nullptr); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2685 | } |
| 2686 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2687 | TEST_F(OmahaRequestActionTest, ParseInstallDateFromResponse) { |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2688 | OmahaResponse response; |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2689 | |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 2690 | // Simulate a successful update check that happens during OOBE. The |
| 2691 | // deadline in the response is needed to force the update attempt to |
| 2692 | // occur; responses without a deadline seen during OOBE will normally |
| 2693 | // return ErrorCode::kNonCriticalUpdateInOOBE. |
| 2694 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
| 2695 | fake_update_response_.deadline = "20101020"; |
| 2696 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2697 | // Check that we parse elapsed_days in the Omaha Response correctly. |
| 2698 | // and that the kPrefsInstallDateDays value is written to. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2699 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
| 2700 | EXPECT_TRUE(InstallDateParseHelper("42", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2701 | EXPECT_TRUE(response.update_exists); |
| 2702 | EXPECT_EQ(42, response.install_date_days); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2703 | EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2704 | int64_t prefs_days; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2705 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2706 | EXPECT_EQ(prefs_days, 42); |
| 2707 | |
| 2708 | // If there already is a value set, we shouldn't do anything. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2709 | EXPECT_TRUE(InstallDateParseHelper("7", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2710 | EXPECT_TRUE(response.update_exists); |
| 2711 | EXPECT_EQ(7, response.install_date_days); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2712 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2713 | EXPECT_EQ(prefs_days, 42); |
| 2714 | |
| 2715 | // Note that elapsed_days is not necessarily divisible by 7 so check |
| 2716 | // that we round down correctly when populating kPrefsInstallDateDays. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2717 | EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays)); |
| 2718 | EXPECT_TRUE(InstallDateParseHelper("23", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2719 | EXPECT_TRUE(response.update_exists); |
| 2720 | EXPECT_EQ(23, response.install_date_days); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2721 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2722 | EXPECT_EQ(prefs_days, 21); |
| 2723 | |
| 2724 | // Check that we correctly handle elapsed_days not being included in |
| 2725 | // the Omaha Response. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2726 | EXPECT_TRUE(InstallDateParseHelper("", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2727 | EXPECT_TRUE(response.update_exists); |
| 2728 | EXPECT_EQ(-1, response.install_date_days); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2729 | } |
| 2730 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2731 | // If there is no prefs and OOBE is not complete, we should not |
| 2732 | // report anything to Omaha. |
| 2733 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE) { |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 2734 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2735 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1); |
| 2736 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
| 2737 | } |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2738 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2739 | // If OOBE is complete and happened on a valid date (e.g. after Jan |
| 2740 | // 1 2007 0:00 PST), that date should be used and written to |
| 2741 | // prefs. However, first try with an invalid date and check we do |
| 2742 | // nothing. |
| 2743 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithInvalidDate) { |
| 2744 | Time oobe_date = Time::FromTimeT(42); // Dec 31, 1969 16:00:42 PST. |
| 2745 | fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date); |
| 2746 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1); |
| 2747 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
| 2748 | } |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2749 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2750 | // Then check with a valid date. The date Jan 20, 2007 0:00 PST |
| 2751 | // should yield an InstallDate of 14. |
| 2752 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithValidDate) { |
| 2753 | Time oobe_date = Time::FromTimeT(1169280000); // Jan 20, 2007 0:00 PST. |
| 2754 | fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date); |
| 2755 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14); |
| 2756 | EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2757 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2758 | int64_t prefs_days; |
| 2759 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
| 2760 | EXPECT_EQ(prefs_days, 14); |
| 2761 | } |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2762 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2763 | // Now that we have a valid date in prefs, check that we keep using |
| 2764 | // that even if OOBE date reports something else. The date Jan 30, |
| 2765 | // 2007 0:00 PST should yield an InstallDate of 28... but since |
| 2766 | // there's a prefs file, we should still get 14. |
| 2767 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedDateChanges) { |
| 2768 | // Set a valid date in the prefs first. |
| 2769 | EXPECT_TRUE(fake_prefs_.SetInt64(kPrefsInstallDateDays, 14)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2770 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2771 | Time oobe_date = Time::FromTimeT(1170144000); // Jan 30, 2007 0:00 PST. |
| 2772 | fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date); |
| 2773 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2774 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2775 | int64_t prefs_days; |
| 2776 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
| 2777 | EXPECT_EQ(prefs_days, 14); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2778 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2779 | // If we delete the prefs file, we should get 28 days. |
| 2780 | EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays)); |
| 2781 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 28); |
| 2782 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
| 2783 | EXPECT_EQ(prefs_days, 28); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2784 | } |
| 2785 | |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 2786 | // Verifies that a device with no device policy, and is not a consumer |
| 2787 | // device sets the max kernel key version to the current version. |
| 2788 | // ie. the same behavior as if rollback is enabled. |
| 2789 | TEST_F(OmahaRequestActionTest, NoPolicyEnterpriseDevicesSetMaxRollback) { |
| 2790 | FakeHardware* fake_hw = fake_system_state_.fake_hardware(); |
| 2791 | |
| 2792 | // Setup and verify some initial default values for the kernel TPM |
| 2793 | // values that control verified boot and rollback. |
| 2794 | const int min_kernel_version = 4; |
| 2795 | fake_hw->SetMinKernelKeyVersion(min_kernel_version); |
| 2796 | fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity); |
| 2797 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2798 | EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward()); |
| 2799 | |
| 2800 | TestRollbackCheck(false /* is_consumer_device */, |
| 2801 | 3 /* rollback_allowed_milestones */, |
| 2802 | false /* is_policy_loaded */); |
| 2803 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 2804 | // Verify kernel_max_rollforward was set to the current minimum |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 2805 | // kernel key version. This has the effect of freezing roll |
| 2806 | // forwards indefinitely. This will hold the rollback window |
| 2807 | // open until a future change will be able to move this forward |
| 2808 | // relative the configured window. |
| 2809 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2810 | EXPECT_EQ(min_kernel_version, fake_hw->GetMaxKernelKeyRollforward()); |
| 2811 | } |
| 2812 | |
| 2813 | // Verifies that a conmsumer device with no device policy sets the |
| 2814 | // max kernel key version to the current version. ie. the same |
| 2815 | // behavior as if rollback is enabled. |
| 2816 | TEST_F(OmahaRequestActionTest, NoPolicyConsumerDevicesSetMaxRollback) { |
| 2817 | FakeHardware* fake_hw = fake_system_state_.fake_hardware(); |
| 2818 | |
| 2819 | // Setup and verify some initial default values for the kernel TPM |
| 2820 | // values that control verified boot and rollback. |
| 2821 | const int min_kernel_version = 3; |
| 2822 | fake_hw->SetMinKernelKeyVersion(min_kernel_version); |
| 2823 | fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity); |
| 2824 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2825 | EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward()); |
| 2826 | |
| 2827 | TestRollbackCheck(true /* is_consumer_device */, |
| 2828 | 3 /* rollback_allowed_milestones */, |
| 2829 | false /* is_policy_loaded */); |
| 2830 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 2831 | // Verify that with rollback disabled that kernel_max_rollforward |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 2832 | // was set to logical infinity. This is the expected behavior for |
| 2833 | // consumer devices and matches the existing behavior prior to the |
| 2834 | // rollback features. |
| 2835 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2836 | EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward()); |
| 2837 | } |
| 2838 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 2839 | // Verifies that a device with rollback enabled sets kernel_max_rollforward |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 2840 | // in the TPM to prevent roll forward. |
| 2841 | TEST_F(OmahaRequestActionTest, RollbackEnabledDevicesSetMaxRollback) { |
| 2842 | FakeHardware* fake_hw = fake_system_state_.fake_hardware(); |
| 2843 | |
| 2844 | // Setup and verify some initial default values for the kernel TPM |
| 2845 | // values that control verified boot and rollback. |
| 2846 | const int allowed_milestones = 4; |
| 2847 | const int min_kernel_version = 3; |
| 2848 | fake_hw->SetMinKernelKeyVersion(min_kernel_version); |
| 2849 | fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity); |
| 2850 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2851 | EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward()); |
| 2852 | |
| 2853 | TestRollbackCheck(false /* is_consumer_device */, |
| 2854 | allowed_milestones, |
| 2855 | true /* is_policy_loaded */); |
| 2856 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 2857 | // Verify that with rollback enabled that kernel_max_rollforward |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 2858 | // was set to the current minimum kernel key version. This has |
| 2859 | // the effect of freezing roll forwards indefinitely. This will |
| 2860 | // hold the rollback window open until a future change will |
| 2861 | // be able to move this forward relative the configured window. |
| 2862 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2863 | EXPECT_EQ(min_kernel_version, fake_hw->GetMaxKernelKeyRollforward()); |
| 2864 | } |
| 2865 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 2866 | // Verifies that a device with rollback disabled sets kernel_max_rollforward |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 2867 | // in the TPM to logical infinity, to allow roll forward. |
| 2868 | TEST_F(OmahaRequestActionTest, RollbackDisabledDevicesSetMaxRollback) { |
| 2869 | FakeHardware* fake_hw = fake_system_state_.fake_hardware(); |
| 2870 | |
| 2871 | // Setup and verify some initial default values for the kernel TPM |
| 2872 | // values that control verified boot and rollback. |
| 2873 | const int allowed_milestones = 0; |
| 2874 | const int min_kernel_version = 3; |
| 2875 | fake_hw->SetMinKernelKeyVersion(min_kernel_version); |
| 2876 | fake_hw->SetMaxKernelKeyRollforward(kRollforwardInfinity); |
| 2877 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2878 | EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward()); |
| 2879 | |
| 2880 | TestRollbackCheck(false /* is_consumer_device */, |
| 2881 | allowed_milestones, |
| 2882 | true /* is_policy_loaded */); |
| 2883 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 2884 | // Verify that with rollback disabled that kernel_max_rollforward |
Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 2885 | // was set to logical infinity. |
| 2886 | EXPECT_EQ(min_kernel_version, fake_hw->GetMinKernelKeyVersion()); |
| 2887 | EXPECT_EQ(kRollforwardInfinity, fake_hw->GetMaxKernelKeyRollforward()); |
| 2888 | } |
| 2889 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 2890 | } // namespace chromeos_update_engine |