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