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