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