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