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