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