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