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