Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2011 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 | // |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | |
Alex Deymo | aab50e3 | 2014-11-10 19:55:35 -0800 | [diff] [blame] | 17 | #include "update_engine/omaha_response_handler_action.h" |
| 18 | |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 19 | #include <memory> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 20 | #include <string> |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 21 | #include <utility> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 22 | |
Alex Deymo | 110e030 | 2015-10-19 20:35:21 -0700 | [diff] [blame] | 23 | #include <base/files/file_util.h> |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 24 | #include <base/files/scoped_temp_dir.h> |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 25 | #include <brillo/message_loops/fake_message_loop.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 26 | #include <gtest/gtest.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 27 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 28 | #include "update_engine/common/constants.h" |
| 29 | #include "update_engine/common/platform_constants.h" |
| 30 | #include "update_engine/common/test_utils.h" |
| 31 | #include "update_engine/common/utils.h" |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 32 | #include "update_engine/fake_system_state.h" |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 33 | #include "update_engine/mock_payload_state.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 34 | #include "update_engine/payload_consumer/payload_constants.h" |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 35 | #include "update_engine/update_manager/mock_policy.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 37 | using chromeos_update_engine::test_utils::System; |
| 38 | using chromeos_update_engine::test_utils::WriteFileString; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 39 | using chromeos_update_manager::EvalStatus; |
| 40 | using chromeos_update_manager::FakeUpdateManager; |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 41 | using chromeos_update_manager::kRollforwardInfinity; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 42 | using chromeos_update_manager::MockPolicy; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 43 | using std::string; |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 44 | using testing::_; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 45 | using testing::DoAll; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 46 | using testing::Return; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 47 | using testing::SetArgPointee; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 48 | |
| 49 | namespace chromeos_update_engine { |
| 50 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 51 | class OmahaResponseHandlerActionProcessorDelegate |
| 52 | : public ActionProcessorDelegate { |
| 53 | public: |
| 54 | OmahaResponseHandlerActionProcessorDelegate() |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 55 | : code_(ErrorCode::kError), code_set_(false) {} |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 56 | void ActionCompleted(ActionProcessor* processor, |
| 57 | AbstractAction* action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 58 | ErrorCode code) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 59 | if (action->Type() == OmahaResponseHandlerAction::StaticType()) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 60 | auto response_handler_action = |
| 61 | static_cast<OmahaResponseHandlerAction*>(action); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 62 | code_ = code; |
| 63 | code_set_ = true; |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 64 | response_handler_action_install_plan_.reset( |
| 65 | new InstallPlan(response_handler_action->install_plan_)); |
| 66 | } else if (action->Type() == |
| 67 | ObjectCollectorAction<InstallPlan>::StaticType()) { |
| 68 | auto collector_action = |
| 69 | static_cast<ObjectCollectorAction<InstallPlan>*>(action); |
| 70 | collector_action_install_plan_.reset( |
| 71 | new InstallPlan(collector_action->object())); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 74 | ErrorCode code_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 75 | bool code_set_; |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 76 | std::unique_ptr<InstallPlan> collector_action_install_plan_; |
| 77 | std::unique_ptr<InstallPlan> response_handler_action_install_plan_; |
| 78 | }; |
| 79 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 80 | class OmahaResponseHandlerActionTest : public ::testing::Test { |
| 81 | protected: |
| 82 | void SetUp() override { |
| 83 | FakeBootControl* fake_boot_control = fake_system_state_.fake_boot_control(); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 84 | fake_boot_control->SetPartitionDevice(kPartitionNameKernel, 0, "/dev/sdz2"); |
| 85 | fake_boot_control->SetPartitionDevice(kPartitionNameRoot, 0, "/dev/sdz3"); |
| 86 | fake_boot_control->SetPartitionDevice(kPartitionNameKernel, 1, "/dev/sdz4"); |
| 87 | fake_boot_control->SetPartitionDevice(kPartitionNameRoot, 1, "/dev/sdz5"); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // Return true iff the OmahaResponseHandlerAction succeeded. |
| 91 | // If out is non-null, it's set w/ the response from the action. |
| 92 | bool DoTest(const OmahaResponse& in, |
| 93 | const string& deadline_file, |
| 94 | InstallPlan* out); |
| 95 | |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 96 | // Delegate passed to the ActionProcessor. |
| 97 | OmahaResponseHandlerActionProcessorDelegate delegate_; |
| 98 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 99 | // Captures the action's result code, for tests that need to directly verify |
| 100 | // it in non-success cases. |
| 101 | ErrorCode action_result_code_; |
| 102 | |
| 103 | FakeSystemState fake_system_state_; |
| 104 | // "Hash+" |
| 105 | const brillo::Blob expected_hash_ = {0x48, 0x61, 0x73, 0x68, 0x2b}; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | namespace { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 109 | const char* const kLongName = |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 110 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 111 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 112 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 113 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 114 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 115 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 116 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 117 | "-the_update_a.b.c.d_DELTA_.tgz"; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 118 | const char* const kBadVersion = "don't update me"; |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 119 | const char* const kPayloadHashHex = "486173682b"; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 120 | } // namespace |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 121 | |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 122 | bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in, |
| 123 | const string& test_deadline_file, |
| 124 | InstallPlan* out) { |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 125 | brillo::FakeMessageLoop loop(nullptr); |
| 126 | loop.SetAsCurrent(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 127 | ActionProcessor processor; |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 128 | processor.set_delegate(&delegate_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 129 | |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 130 | auto feeder_action = std::make_unique<ObjectFeederAction<OmahaResponse>>(); |
| 131 | feeder_action->set_obj(in); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 132 | if (in.update_exists && in.version != kBadVersion) { |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 133 | string expected_hash; |
| 134 | for (const auto& package : in.packages) |
| 135 | expected_hash += package.hash + ":"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 136 | EXPECT_CALL(*(fake_system_state_.mock_prefs()), |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 137 | SetString(kPrefsUpdateCheckResponseHash, expected_hash)) |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 138 | .WillOnce(Return(true)); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 139 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 140 | int slot = |
| 141 | fake_system_state_.request_params()->is_install() |
| 142 | ? fake_system_state_.fake_boot_control()->GetCurrentSlot() |
| 143 | : 1 - fake_system_state_.fake_boot_control()->GetCurrentSlot(); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 144 | string key = kPrefsChannelOnSlotPrefix + std::to_string(slot); |
| 145 | EXPECT_CALL(*(fake_system_state_.mock_prefs()), SetString(key, testing::_)) |
| 146 | .WillOnce(Return(true)); |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 147 | } |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 148 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 149 | string current_url = in.packages.size() ? in.packages[0].payload_urls[0] : ""; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 150 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), GetCurrentUrl()) |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 151 | .WillRepeatedly(Return(current_url)); |
| 152 | |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 153 | auto response_handler_action = |
| 154 | std::make_unique<OmahaResponseHandlerAction>(&fake_system_state_); |
| 155 | if (!test_deadline_file.empty()) |
| 156 | response_handler_action->deadline_file_ = test_deadline_file; |
| 157 | |
| 158 | auto collector_action = |
| 159 | std::make_unique<ObjectCollectorAction<InstallPlan>>(); |
| 160 | |
| 161 | BondActions(feeder_action.get(), response_handler_action.get()); |
| 162 | BondActions(response_handler_action.get(), collector_action.get()); |
| 163 | processor.EnqueueAction(std::move(feeder_action)); |
| 164 | processor.EnqueueAction(std::move(response_handler_action)); |
| 165 | processor.EnqueueAction(std::move(collector_action)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 166 | processor.StartProcessing(); |
| 167 | EXPECT_TRUE(!processor.IsRunning()) |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 168 | << "Update test to handle non-async actions"; |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 169 | |
| 170 | if (out && delegate_.collector_action_install_plan_) |
| 171 | *out = *delegate_.collector_action_install_plan_; |
| 172 | |
| 173 | EXPECT_TRUE(delegate_.code_set_); |
| 174 | action_result_code_ = delegate_.code_; |
| 175 | return delegate_.code_ == ErrorCode::kSuccess; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | TEST_F(OmahaResponseHandlerActionTest, SimpleTest) { |
Amin Hassani | ed03b44 | 2020-10-26 17:21:29 -0700 | [diff] [blame] | 179 | ScopedTempFile test_deadline_file( |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 180 | "omaha_response_handler_action_unittest-XXXXXX"); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 181 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 182 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 183 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 184 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 185 | in.packages.push_back( |
| 186 | {.payload_urls = {"http://foo/the_update_a.b.c.d.tgz"}, |
| 187 | .size = 12, |
| 188 | .hash = kPayloadHashHex}); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 189 | in.more_info_url = "http://more/info"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 190 | in.prompt = false; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 191 | in.deadline = "20101020"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 192 | InstallPlan install_plan; |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 193 | EXPECT_TRUE(DoTest(in, test_deadline_file.path(), &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 194 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 195 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 196 | EXPECT_EQ(1U, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 197 | string deadline; |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 198 | EXPECT_TRUE(utils::ReadFile(test_deadline_file.path(), &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 199 | EXPECT_EQ("20101020", deadline); |
| 200 | struct stat deadline_stat; |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 201 | EXPECT_EQ(0, stat(test_deadline_file.path().c_str(), &deadline_stat)); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 202 | EXPECT_EQ( |
| 203 | static_cast<mode_t>(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), |
| 204 | deadline_stat.st_mode); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 205 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 206 | } |
| 207 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 208 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 209 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 210 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 211 | in.packages.push_back( |
| 212 | {.payload_urls = {"http://foo/the_update_a.b.c.d.tgz"}, |
| 213 | .size = 12, |
| 214 | .hash = kPayloadHashHex}); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 215 | in.more_info_url = "http://more/info"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 216 | in.prompt = true; |
| 217 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 218 | // Set the other slot as current. |
| 219 | fake_system_state_.fake_boot_control()->SetCurrentSlot(1); |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 220 | EXPECT_TRUE(DoTest(in, test_deadline_file.path(), &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 221 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 222 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 223 | EXPECT_EQ(0U, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 224 | string deadline; |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 225 | EXPECT_TRUE(utils::ReadFile(test_deadline_file.path(), &deadline) && |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 226 | deadline.empty()); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 227 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 228 | } |
| 229 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 230 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 231 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 232 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 233 | in.packages.push_back( |
| 234 | {.payload_urls = {kLongName}, .size = 12, .hash = kPayloadHashHex}); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 235 | in.more_info_url = "http://more/info"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 236 | in.prompt = true; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 237 | in.deadline = "some-deadline"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 238 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 239 | fake_system_state_.fake_boot_control()->SetCurrentSlot(0); |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 240 | // Because rollback happened, the deadline shouldn't be written into the |
| 241 | // file. |
| 242 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), |
| 243 | GetRollbackHappened()) |
| 244 | .WillOnce(Return(true)); |
Sen Jiang | 456853f | 2018-08-13 15:41:43 -0700 | [diff] [blame] | 245 | EXPECT_TRUE(DoTest(in, test_deadline_file.path(), &install_plan)); |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 246 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 247 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 248 | EXPECT_EQ(1U, install_plan.target_slot); |
| 249 | string deadline; |
Sen Jiang | 456853f | 2018-08-13 15:41:43 -0700 | [diff] [blame] | 250 | EXPECT_TRUE(utils::ReadFile(test_deadline_file.path(), &deadline)); |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 251 | EXPECT_TRUE(deadline.empty()); |
| 252 | EXPECT_EQ(in.version, install_plan.version); |
| 253 | } |
| 254 | { |
| 255 | OmahaResponse in; |
| 256 | in.update_exists = true; |
| 257 | in.version = "a.b.c.d"; |
| 258 | in.packages.push_back( |
| 259 | {.payload_urls = {kLongName}, .size = 12, .hash = kPayloadHashHex}); |
| 260 | in.more_info_url = "http://more/info"; |
| 261 | in.prompt = true; |
| 262 | in.deadline = "some-deadline"; |
| 263 | InstallPlan install_plan; |
| 264 | fake_system_state_.fake_boot_control()->SetCurrentSlot(0); |
| 265 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), |
| 266 | GetRollbackHappened()) |
| 267 | .WillOnce(Return(false)); |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 268 | EXPECT_TRUE(DoTest(in, test_deadline_file.path(), &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 269 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 270 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 271 | EXPECT_EQ(1U, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 272 | string deadline; |
Sen Jiang | 0779a15 | 2018-07-02 17:34:56 -0700 | [diff] [blame] | 273 | EXPECT_TRUE(utils::ReadFile(test_deadline_file.path(), &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 274 | EXPECT_EQ("some-deadline", deadline); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 275 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 280 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 281 | in.update_exists = false; |
| 282 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 283 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 284 | EXPECT_TRUE(install_plan.partitions.empty()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 287 | TEST_F(OmahaResponseHandlerActionTest, InstallTest) { |
| 288 | OmahaResponse in; |
| 289 | in.update_exists = true; |
| 290 | in.version = "a.b.c.d"; |
| 291 | in.packages.push_back( |
| 292 | {.payload_urls = {kLongName}, .size = 1, .hash = kPayloadHashHex}); |
| 293 | in.packages.push_back( |
| 294 | {.payload_urls = {kLongName}, .size = 2, .hash = kPayloadHashHex}); |
| 295 | in.more_info_url = "http://more/info"; |
| 296 | |
| 297 | OmahaRequestParams params(&fake_system_state_); |
| 298 | params.set_is_install(true); |
| 299 | |
| 300 | fake_system_state_.set_request_params(¶ms); |
| 301 | InstallPlan install_plan; |
| 302 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 303 | EXPECT_EQ(install_plan.source_slot, UINT_MAX); |
| 304 | } |
| 305 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 306 | TEST_F(OmahaResponseHandlerActionTest, MultiPackageTest) { |
| 307 | OmahaResponse in; |
| 308 | in.update_exists = true; |
| 309 | in.version = "a.b.c.d"; |
| 310 | in.packages.push_back({.payload_urls = {"http://package/1"}, |
| 311 | .size = 1, |
| 312 | .hash = kPayloadHashHex}); |
| 313 | in.packages.push_back({.payload_urls = {"http://package/2"}, |
| 314 | .size = 2, |
| 315 | .hash = kPayloadHashHex}); |
| 316 | in.more_info_url = "http://more/info"; |
| 317 | InstallPlan install_plan; |
| 318 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 319 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 320 | EXPECT_EQ(2u, install_plan.payloads.size()); |
| 321 | EXPECT_EQ(in.packages[0].size, install_plan.payloads[0].size); |
| 322 | EXPECT_EQ(in.packages[1].size, install_plan.payloads[1].size); |
| 323 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 324 | EXPECT_EQ(expected_hash_, install_plan.payloads[1].hash); |
| 325 | EXPECT_EQ(in.version, install_plan.version); |
| 326 | } |
| 327 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 328 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpTest) { |
| 329 | OmahaResponse in; |
| 330 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 331 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 332 | in.packages.push_back( |
| 333 | {.payload_urls = {"http://test.should/need/hash.checks.signed"}, |
| 334 | .size = 12, |
| 335 | .hash = kPayloadHashHex}); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 336 | in.more_info_url = "http://more/info"; |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 337 | // Hash checks are always skipped for non-official update URLs. |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 338 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 339 | IsUpdateUrlOfficial()) |
| 340 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 341 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 342 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 343 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 344 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 345 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 346 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 347 | } |
| 348 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 349 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForUnofficialUpdateUrl) { |
| 350 | OmahaResponse in; |
| 351 | in.update_exists = true; |
| 352 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 353 | in.packages.push_back( |
| 354 | {.payload_urls = {"http://url.normally/needs/hash.checks.signed"}, |
| 355 | .size = 12, |
| 356 | .hash = kPayloadHashHex}); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 357 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 358 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 359 | IsUpdateUrlOfficial()) |
| 360 | .WillRepeatedly(Return(false)); |
| 361 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 362 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 363 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 364 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 365 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 366 | EXPECT_EQ(in.version, install_plan.version); |
| 367 | } |
| 368 | |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 369 | TEST_F(OmahaResponseHandlerActionTest, |
| 370 | HashChecksForOfficialUrlUnofficialBuildTest) { |
| 371 | // Official URLs for unofficial builds (dev/test images) don't require hash. |
| 372 | OmahaResponse in; |
| 373 | in.update_exists = true; |
| 374 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 375 | in.packages.push_back( |
| 376 | {.payload_urls = {"http://url.normally/needs/hash.checks.signed"}, |
| 377 | .size = 12, |
| 378 | .hash = kPayloadHashHex}); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 379 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 380 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 381 | IsUpdateUrlOfficial()) |
| 382 | .WillRepeatedly(Return(true)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 383 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 384 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 385 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 386 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 387 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 388 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 389 | EXPECT_EQ(in.version, install_plan.version); |
| 390 | } |
| 391 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 392 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpsTest) { |
| 393 | OmahaResponse in; |
| 394 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 395 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 396 | in.packages.push_back( |
| 397 | {.payload_urls = {"https://test.should/need/hash.checks.signed"}, |
| 398 | .size = 12, |
| 399 | .hash = kPayloadHashHex}); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 400 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 401 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 402 | IsUpdateUrlOfficial()) |
| 403 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 404 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 405 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 406 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 407 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Sen Jiang | 81c705b | 2018-10-04 14:15:05 -0700 | [diff] [blame] | 408 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 409 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 412 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForBothHttpAndHttpsTest) { |
| 413 | OmahaResponse in; |
| 414 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 415 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 416 | in.packages.push_back( |
| 417 | {.payload_urls = {"http://test.should.still/need/hash.checks", |
| 418 | "https://test.should.still/need/hash.checks"}, |
| 419 | .size = 12, |
| 420 | .hash = kPayloadHashHex}); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 421 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 422 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 423 | IsUpdateUrlOfficial()) |
| 424 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 425 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 426 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 427 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 428 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 429 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 430 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 433 | TEST_F(OmahaResponseHandlerActionTest, |
| 434 | ChangeToMoreStableVersionAndChannelTest) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 435 | OmahaResponse in; |
| 436 | in.update_exists = true; |
Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 437 | in.version = "1.0.0.0"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 438 | in.packages.push_back({.payload_urls = {"https://MoreStableChannelTest"}, |
| 439 | .size = 1, |
| 440 | .hash = kPayloadHashHex}); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 441 | in.more_info_url = "http://more/info"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 442 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 443 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 444 | base::ScopedTempDir tempdir; |
| 445 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 446 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 447 | OmahaRequestParams params(&fake_system_state_); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 448 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
Hidehiko Abe | 2b9d241 | 2017-12-13 18:56:18 +0900 | [diff] [blame] | 449 | params.set_root(tempdir.GetPath().value()); |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 450 | params.set_current_channel("canary-channel"); |
| 451 | // The ImageProperties in Android uses prefs to store MutableImageProperties. |
| 452 | #ifdef __ANDROID__ |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 453 | EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, true)) |
| 454 | .WillOnce(Return(true)); |
| 455 | #endif // __ANDROID__ |
| 456 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr)); |
| 457 | params.UpdateDownloadChannel(); |
Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 458 | params.set_app_version("2.0.0.0"); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 459 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 460 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 461 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 462 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 463 | EXPECT_TRUE(install_plan.powerwash_required); |
| 464 | } |
| 465 | |
Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 466 | TEST_F(OmahaResponseHandlerActionTest, |
| 467 | ChangeToMoreStableVersionAndChannelPowerwashNotAllowedTest) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 468 | OmahaResponse in; |
| 469 | in.update_exists = true; |
Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 470 | in.version = "1.0.0.0"; |
| 471 | in.packages.push_back({.payload_urls = {"https://MoreStableChannelTest"}, |
| 472 | .size = 1, |
| 473 | .hash = kPayloadHashHex}); |
| 474 | in.more_info_url = "http://more/info"; |
| 475 | |
| 476 | // Create a uniquely named test directory. |
| 477 | base::ScopedTempDir tempdir; |
| 478 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
| 479 | |
| 480 | OmahaRequestParams params(&fake_system_state_); |
| 481 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
| 482 | params.set_root(tempdir.GetPath().value()); |
| 483 | params.set_current_channel("canary-channel"); |
| 484 | // The |ImageProperties| in Android uses prefs to store |
| 485 | // |MutableImageProperties|. |
| 486 | #ifdef __ANDROID__ |
| 487 | EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, true)) |
| 488 | .WillOnce(Return(true)); |
| 489 | #endif // __ANDROID__ |
| 490 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", false, nullptr)); |
| 491 | params.UpdateDownloadChannel(); |
| 492 | params.set_app_version("2.0.0.0"); |
| 493 | |
| 494 | fake_system_state_.set_request_params(¶ms); |
| 495 | InstallPlan install_plan; |
| 496 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 497 | EXPECT_FALSE(install_plan.powerwash_required); |
| 498 | } |
| 499 | |
| 500 | TEST_F(OmahaResponseHandlerActionTest, |
| 501 | ChangeToMoreStableChannelButNewerVersionTest) { |
| 502 | OmahaResponse in; |
| 503 | in.update_exists = true; |
| 504 | in.version = "12345.96.0.0"; |
| 505 | in.packages.push_back({.payload_urls = {"https://ChannelDownVersionUp"}, |
| 506 | .size = 1, |
| 507 | .hash = kPayloadHashHex}); |
| 508 | in.more_info_url = "http://more/info"; |
| 509 | |
| 510 | // Create a uniquely named test directory. |
| 511 | base::ScopedTempDir tempdir; |
| 512 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
| 513 | |
| 514 | OmahaRequestParams params(&fake_system_state_); |
| 515 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
| 516 | params.set_root(tempdir.GetPath().value()); |
| 517 | params.set_current_channel("beta-channel"); |
| 518 | // The |ImageProperties| in Android uses prefs to store |
| 519 | // |MutableImageProperties|. |
| 520 | #ifdef __ANDROID__ |
| 521 | EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, true)) |
| 522 | .WillOnce(Return(true)); |
| 523 | #endif // __ANDROID__ |
| 524 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr)); |
| 525 | params.UpdateDownloadChannel(); |
| 526 | params.set_app_version("12345.48.0.0"); |
| 527 | |
| 528 | fake_system_state_.set_request_params(¶ms); |
| 529 | InstallPlan install_plan; |
| 530 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 531 | EXPECT_FALSE(install_plan.powerwash_required); |
| 532 | } |
| 533 | |
| 534 | TEST_F(OmahaResponseHandlerActionTest, |
Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 535 | ChangeToMoreStableChannelButSameVersionTest) { |
| 536 | OmahaResponse in; |
| 537 | in.update_exists = true; |
| 538 | in.version = "12345.0.0.0"; |
| 539 | in.packages.push_back({.payload_urls = {"https://ChannelDownVersionUp"}, |
| 540 | .size = 1, |
| 541 | .hash = kPayloadHashHex}); |
| 542 | in.more_info_url = "http://more/info"; |
| 543 | |
| 544 | // Create a uniquely named test directory. |
| 545 | base::ScopedTempDir tempdir; |
| 546 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
| 547 | |
| 548 | OmahaRequestParams params(&fake_system_state_); |
| 549 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
| 550 | params.set_root(tempdir.GetPath().value()); |
| 551 | params.set_current_channel("beta-channel"); |
| 552 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr)); |
| 553 | params.UpdateDownloadChannel(); |
| 554 | params.set_app_version("12345.0.0.0"); |
| 555 | |
| 556 | fake_system_state_.set_request_params(¶ms); |
| 557 | InstallPlan install_plan; |
| 558 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 559 | EXPECT_FALSE(install_plan.powerwash_required); |
| 560 | EXPECT_FALSE(install_plan.rollback_data_save_requested); |
| 561 | } |
| 562 | |
| 563 | // On an enrolled device, the rollback data restore should be attempted when |
| 564 | // doing a powerwash and channel downgrade. |
| 565 | TEST_F(OmahaResponseHandlerActionTest, |
| 566 | ChangeToMoreStableChannelEnrolledDataRestore) { |
| 567 | OmahaResponse in; |
| 568 | in.update_exists = true; |
| 569 | in.version = "12345.96.0.0"; |
| 570 | in.packages.push_back({.payload_urls = {"https://ChannelDownEnrolled"}, |
| 571 | .size = 1, |
| 572 | .hash = kPayloadHashHex}); |
| 573 | in.more_info_url = "http://more/info"; |
| 574 | |
| 575 | // Create a uniquely named test directory. |
| 576 | base::ScopedTempDir tempdir; |
| 577 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
| 578 | |
| 579 | OmahaRequestParams params(&fake_system_state_); |
| 580 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(true); |
| 581 | params.set_root(tempdir.GetPath().value()); |
| 582 | params.set_current_channel("beta-channel"); |
| 583 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr)); |
| 584 | params.UpdateDownloadChannel(); |
| 585 | params.set_app_version("12347.48.0.0"); |
| 586 | |
| 587 | testing::NiceMock<policy::MockDevicePolicy> mock_device_policy; |
| 588 | EXPECT_CALL(mock_device_policy, IsEnterpriseEnrolled()) |
| 589 | .WillOnce(Return(true)); |
| 590 | fake_system_state_.set_device_policy(&mock_device_policy); |
| 591 | |
| 592 | fake_system_state_.set_request_params(¶ms); |
| 593 | InstallPlan install_plan; |
| 594 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 595 | EXPECT_TRUE(install_plan.rollback_data_save_requested); |
| 596 | } |
| 597 | |
| 598 | // Never attempt rollback data restore if the device is not enrolled. |
| 599 | TEST_F(OmahaResponseHandlerActionTest, |
| 600 | ChangeToMoreStableChannelUnenrolledNoDataRestore) { |
| 601 | OmahaResponse in; |
| 602 | in.update_exists = true; |
| 603 | in.version = "12345.96.0.0"; |
| 604 | in.packages.push_back({.payload_urls = {"https://ChannelDownEnrolled"}, |
| 605 | .size = 1, |
| 606 | .hash = kPayloadHashHex}); |
| 607 | in.more_info_url = "http://more/info"; |
| 608 | |
| 609 | // Create a uniquely named test directory. |
| 610 | base::ScopedTempDir tempdir; |
| 611 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
| 612 | |
| 613 | OmahaRequestParams params(&fake_system_state_); |
| 614 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(true); |
| 615 | params.set_root(tempdir.GetPath().value()); |
| 616 | params.set_current_channel("beta-channel"); |
| 617 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr)); |
| 618 | params.UpdateDownloadChannel(); |
| 619 | params.set_app_version("12347.48.0.0"); |
| 620 | |
| 621 | testing::NiceMock<policy::MockDevicePolicy> mock_device_policy; |
| 622 | EXPECT_CALL(mock_device_policy, IsEnterpriseEnrolled()) |
| 623 | .WillOnce(Return(false)); |
| 624 | fake_system_state_.set_device_policy(&mock_device_policy); |
| 625 | |
| 626 | fake_system_state_.set_request_params(¶ms); |
| 627 | InstallPlan install_plan; |
| 628 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 629 | EXPECT_FALSE(install_plan.rollback_data_save_requested); |
| 630 | } |
| 631 | |
| 632 | // Never attempt rollback data restore if powerwash is not allowed. |
| 633 | TEST_F(OmahaResponseHandlerActionTest, |
| 634 | ChangeToMoreStableChannelNoPowerwashNoDataRestore) { |
| 635 | OmahaResponse in; |
| 636 | in.update_exists = true; |
| 637 | in.version = "12345.96.0.0"; |
| 638 | in.packages.push_back( |
| 639 | {.payload_urls = {"https://URL"}, .size = 1, .hash = kPayloadHashHex}); |
| 640 | in.more_info_url = "http://more/info"; |
| 641 | |
| 642 | // Create a uniquely named test directory. |
| 643 | base::ScopedTempDir tempdir; |
| 644 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
| 645 | |
| 646 | OmahaRequestParams params(&fake_system_state_); |
| 647 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(true); |
| 648 | params.set_root(tempdir.GetPath().value()); |
| 649 | params.set_current_channel("beta-channel"); |
| 650 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", false, nullptr)); |
| 651 | params.UpdateDownloadChannel(); |
| 652 | params.set_app_version("12347.48.0.0"); |
| 653 | |
| 654 | fake_system_state_.set_request_params(¶ms); |
| 655 | InstallPlan install_plan; |
| 656 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 657 | EXPECT_FALSE(install_plan.rollback_data_save_requested); |
| 658 | } |
| 659 | |
| 660 | TEST_F(OmahaResponseHandlerActionTest, |
Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 661 | ChangeToLessStableVersionAndChannelTest) { |
| 662 | OmahaResponse in; |
| 663 | in.update_exists = true; |
| 664 | in.version = "2.0.0.0"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 665 | in.packages.push_back({.payload_urls = {"https://LessStableChannelTest"}, |
| 666 | .size = 15, |
| 667 | .hash = kPayloadHashHex}); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 668 | in.more_info_url = "http://more/info"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 669 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 670 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 671 | base::ScopedTempDir tempdir; |
| 672 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 673 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 674 | OmahaRequestParams params(&fake_system_state_); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 675 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
Hidehiko Abe | 2b9d241 | 2017-12-13 18:56:18 +0900 | [diff] [blame] | 676 | params.set_root(tempdir.GetPath().value()); |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 677 | params.set_current_channel("stable-channel"); |
| 678 | // The ImageProperties in Android uses prefs to store MutableImageProperties. |
| 679 | #ifdef __ANDROID__ |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 680 | EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, false)) |
| 681 | .WillOnce(Return(true)); |
| 682 | #endif // __ANDROID__ |
| 683 | EXPECT_TRUE(params.SetTargetChannel("canary-channel", false, nullptr)); |
| 684 | params.UpdateDownloadChannel(); |
Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 685 | params.set_app_version("1.0.0.0"); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 686 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 687 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 688 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 689 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 690 | EXPECT_FALSE(install_plan.powerwash_required); |
| 691 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 692 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 693 | TEST_F(OmahaResponseHandlerActionTest, P2PUrlIsUsedAndHashChecksMandatory) { |
| 694 | OmahaResponse in; |
| 695 | in.update_exists = true; |
| 696 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 697 | in.packages.push_back( |
| 698 | {.payload_urls = {"https://would.not/cause/hash/checks"}, |
| 699 | .size = 12, |
| 700 | .hash = kPayloadHashHex}); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 701 | in.more_info_url = "http://more/info"; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 702 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 703 | OmahaRequestParams params(&fake_system_state_); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 704 | // We're using a real OmahaRequestParams object here so we can't mock |
| 705 | // IsUpdateUrlOfficial(), but setting the update URL to the AutoUpdate test |
| 706 | // server will cause IsUpdateUrlOfficial() to return true. |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 707 | params.set_update_url(constants::kOmahaDefaultAUTestURL); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 708 | fake_system_state_.set_request_params(¶ms); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 709 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 710 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 711 | SetUsingP2PForDownloading(true)); |
| 712 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 713 | string p2p_url = "http://9.8.7.6/p2p"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 714 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), GetP2PUrl()) |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 715 | .WillRepeatedly(Return(p2p_url)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 716 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 717 | GetUsingP2PForDownloading()) |
| 718 | .WillRepeatedly(Return(true)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 719 | |
| 720 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 721 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 722 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 723 | EXPECT_EQ(p2p_url, install_plan.download_url); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 724 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
| 725 | } |
| 726 | |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 727 | TEST_F(OmahaResponseHandlerActionTest, RollbackTest) { |
| 728 | OmahaResponse in; |
| 729 | in.update_exists = true; |
| 730 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 731 | .size = 1, |
| 732 | .hash = kPayloadHashHex}); |
| 733 | in.is_rollback = true; |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 734 | |
| 735 | // The rollback payload is 2 versions behind stable. |
| 736 | in.rollback_key_version.kernel = 24; |
| 737 | in.rollback_key_version.kernel = 23; |
| 738 | in.rollback_key_version.firmware_key = 22; |
| 739 | in.rollback_key_version.firmware = 21; |
| 740 | |
| 741 | OmahaResponse::RollbackKeyVersion m4; |
| 742 | m4.firmware_key = 16; |
| 743 | m4.firmware = 15; |
| 744 | m4.kernel_key = 14; |
| 745 | m4.kernel = 13; |
| 746 | |
| 747 | in.past_rollback_key_version = m4; |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 748 | |
| 749 | fake_system_state_.fake_hardware()->SetMinKernelKeyVersion(0x00010002); |
| 750 | fake_system_state_.fake_hardware()->SetMinFirmwareKeyVersion(0x00030004); |
| 751 | |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 752 | fake_system_state_.fake_hardware()->SetMaxKernelKeyRollforward(0xaaaaaaaa); |
| 753 | // TODO(crbug/783998): Add support for firmware when implemented. |
| 754 | |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 755 | OmahaRequestParams params(&fake_system_state_); |
| 756 | params.set_rollback_allowed(true); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 757 | params.set_rollback_allowed_milestones(4); |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 758 | |
| 759 | fake_system_state_.set_request_params(¶ms); |
| 760 | InstallPlan install_plan; |
| 761 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 762 | EXPECT_TRUE(install_plan.is_rollback); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 763 | |
| 764 | // The max rollforward should be set the values of the image |
| 765 | // rollback_allowed_milestones (4 for this test) in the past. |
| 766 | const uint32_t expected_max_kernel_rollforward = |
| 767 | static_cast<uint32_t>(m4.kernel_key) << 16 | |
| 768 | static_cast<uint32_t>(m4.kernel); |
| 769 | EXPECT_EQ(expected_max_kernel_rollforward, |
| 770 | fake_system_state_.fake_hardware()->GetMaxKernelKeyRollforward()); |
| 771 | // TODO(crbug/783998): Add support for firmware when implemented. |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | TEST_F(OmahaResponseHandlerActionTest, RollbackKernelVersionErrorTest) { |
| 775 | OmahaResponse in; |
| 776 | in.update_exists = true; |
| 777 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 778 | .size = 1, |
| 779 | .hash = kPayloadHashHex}); |
| 780 | in.is_rollback = true; |
Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame] | 781 | in.rollback_key_version.kernel_key = 1; |
| 782 | in.rollback_key_version.kernel = 1; // This is lower than the minimum. |
| 783 | in.rollback_key_version.firmware_key = 3; |
| 784 | in.rollback_key_version.firmware = 4; |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 785 | |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 786 | OmahaResponse::RollbackKeyVersion m4; |
| 787 | m4.firmware_key = 16; |
| 788 | m4.firmware = 15; |
| 789 | m4.kernel_key = 14; |
| 790 | m4.kernel = 13; |
| 791 | in.past_rollback_key_version = m4; |
| 792 | |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 793 | fake_system_state_.fake_hardware()->SetMinKernelKeyVersion(0x00010002); |
| 794 | fake_system_state_.fake_hardware()->SetMinFirmwareKeyVersion(0x00030004); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 795 | const uint32_t current_kernel_max_rollforward = 0xaaaaaaaa; |
| 796 | fake_system_state_.fake_hardware()->SetMaxKernelKeyRollforward( |
| 797 | current_kernel_max_rollforward); |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 798 | |
| 799 | OmahaRequestParams params(&fake_system_state_); |
| 800 | params.set_rollback_allowed(true); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 801 | params.set_rollback_allowed_milestones(4); |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 802 | |
| 803 | fake_system_state_.set_request_params(¶ms); |
| 804 | InstallPlan install_plan; |
| 805 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 806 | |
| 807 | // Max rollforward is not changed in error cases. |
| 808 | EXPECT_EQ(current_kernel_max_rollforward, |
| 809 | fake_system_state_.fake_hardware()->GetMaxKernelKeyRollforward()); |
| 810 | // TODO(crbug/783998): Add support for firmware when implemented. |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | TEST_F(OmahaResponseHandlerActionTest, RollbackFirmwareVersionErrorTest) { |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 814 | // TODO(crbug/783998): Add handling for max_firmware_rollforward when |
| 815 | // implemented. |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 816 | OmahaResponse in; |
| 817 | in.update_exists = true; |
| 818 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 819 | .size = 1, |
| 820 | .hash = kPayloadHashHex}); |
| 821 | in.is_rollback = true; |
Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame] | 822 | in.rollback_key_version.kernel_key = 1; |
| 823 | in.rollback_key_version.kernel = 2; |
| 824 | in.rollback_key_version.firmware_key = 3; |
| 825 | in.rollback_key_version.firmware = 3; // This is lower than the minimum. |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 826 | |
| 827 | fake_system_state_.fake_hardware()->SetMinKernelKeyVersion(0x00010002); |
| 828 | fake_system_state_.fake_hardware()->SetMinFirmwareKeyVersion(0x00030004); |
| 829 | |
| 830 | OmahaRequestParams params(&fake_system_state_); |
| 831 | params.set_rollback_allowed(true); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 832 | params.set_rollback_allowed_milestones(4); |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 833 | |
| 834 | fake_system_state_.set_request_params(¶ms); |
| 835 | InstallPlan install_plan; |
| 836 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
| 837 | } |
| 838 | |
| 839 | TEST_F(OmahaResponseHandlerActionTest, RollbackNotRollbackTest) { |
| 840 | OmahaResponse in; |
| 841 | in.update_exists = true; |
| 842 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 843 | .size = 1, |
| 844 | .hash = kPayloadHashHex}); |
| 845 | in.is_rollback = false; |
| 846 | |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 847 | const uint32_t current_kernel_max_rollforward = 0xaaaaaaaa; |
| 848 | fake_system_state_.fake_hardware()->SetMaxKernelKeyRollforward( |
| 849 | current_kernel_max_rollforward); |
| 850 | |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 851 | OmahaRequestParams params(&fake_system_state_); |
| 852 | params.set_rollback_allowed(true); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 853 | params.set_rollback_allowed_milestones(4); |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 854 | |
| 855 | fake_system_state_.set_request_params(¶ms); |
| 856 | InstallPlan install_plan; |
| 857 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 858 | EXPECT_FALSE(install_plan.is_rollback); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 859 | |
| 860 | // Max rollforward is not changed for non-rollback cases. |
| 861 | EXPECT_EQ(current_kernel_max_rollforward, |
| 862 | fake_system_state_.fake_hardware()->GetMaxKernelKeyRollforward()); |
| 863 | // TODO(crbug/783998): Add support for firmware when implemented. |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | TEST_F(OmahaResponseHandlerActionTest, RollbackNotAllowedTest) { |
| 867 | OmahaResponse in; |
| 868 | in.update_exists = true; |
| 869 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 870 | .size = 1, |
| 871 | .hash = kPayloadHashHex}); |
| 872 | in.is_rollback = true; |
| 873 | |
| 874 | OmahaRequestParams params(&fake_system_state_); |
| 875 | params.set_rollback_allowed(false); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 876 | params.set_rollback_allowed_milestones(4); |
| 877 | |
| 878 | const uint32_t current_kernel_max_rollforward = 0xaaaaaaaa; |
| 879 | fake_system_state_.fake_hardware()->SetMaxKernelKeyRollforward( |
| 880 | current_kernel_max_rollforward); |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 881 | |
| 882 | fake_system_state_.set_request_params(¶ms); |
| 883 | InstallPlan install_plan; |
| 884 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 885 | |
| 886 | // This case generates an error so, do not update max rollforward. |
| 887 | EXPECT_EQ(current_kernel_max_rollforward, |
| 888 | fake_system_state_.fake_hardware()->GetMaxKernelKeyRollforward()); |
| 889 | // TODO(crbug/783998): Add support for firmware when implemented. |
| 890 | } |
| 891 | |
| 892 | TEST_F(OmahaResponseHandlerActionTest, NormalUpdateWithZeroMilestonesAllowed) { |
| 893 | OmahaResponse in; |
| 894 | in.update_exists = true; |
| 895 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 896 | .size = 1, |
| 897 | .hash = kPayloadHashHex}); |
| 898 | in.is_rollback = false; |
| 899 | |
| 900 | OmahaRequestParams params(&fake_system_state_); |
| 901 | params.set_rollback_allowed(true); |
| 902 | params.set_rollback_allowed_milestones(0); |
| 903 | |
| 904 | const uint32_t current_kernel_max_rollforward = 0xaaaaaaaa; |
| 905 | fake_system_state_.fake_hardware()->SetMaxKernelKeyRollforward( |
| 906 | current_kernel_max_rollforward); |
| 907 | |
| 908 | fake_system_state_.set_request_params(¶ms); |
| 909 | InstallPlan install_plan; |
| 910 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 911 | |
| 912 | // When allowed_milestones is 0, this is set to infinity. |
| 913 | EXPECT_EQ(kRollforwardInfinity, |
| 914 | fake_system_state_.fake_hardware()->GetMaxKernelKeyRollforward()); |
| 915 | // TODO(crbug/783998): Add support for firmware when implemented. |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 916 | } |
| 917 | |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 918 | TEST_F(OmahaResponseHandlerActionTest, SystemVersionTest) { |
| 919 | OmahaResponse in; |
| 920 | in.update_exists = true; |
| 921 | in.version = "a.b.c.d"; |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 922 | in.packages.push_back({.payload_urls = {"http://package/1"}, |
| 923 | .size = 1, |
| 924 | .hash = kPayloadHashHex}); |
| 925 | in.packages.push_back({.payload_urls = {"http://package/2"}, |
| 926 | .size = 2, |
| 927 | .hash = kPayloadHashHex}); |
| 928 | in.more_info_url = "http://more/info"; |
| 929 | InstallPlan install_plan; |
| 930 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 931 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 932 | EXPECT_EQ(2u, install_plan.payloads.size()); |
| 933 | EXPECT_EQ(in.packages[0].size, install_plan.payloads[0].size); |
| 934 | EXPECT_EQ(in.packages[1].size, install_plan.payloads[1].size); |
| 935 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 936 | EXPECT_EQ(expected_hash_, install_plan.payloads[1].hash); |
| 937 | EXPECT_EQ(in.version, install_plan.version); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 940 | TEST_F(OmahaResponseHandlerActionTest, TestDeferredByPolicy) { |
| 941 | OmahaResponse in; |
| 942 | in.update_exists = true; |
| 943 | in.version = "a.b.c.d"; |
| 944 | in.packages.push_back({.payload_urls = {"http://foo/the_update_a.b.c.d.tgz"}, |
| 945 | .size = 12, |
| 946 | .hash = kPayloadHashHex}); |
| 947 | // Setup the UpdateManager to disallow the update. |
| 948 | FakeClock fake_clock; |
| 949 | MockPolicy* mock_policy = new MockPolicy(&fake_clock); |
| 950 | FakeUpdateManager* fake_update_manager = |
| 951 | fake_system_state_.fake_update_manager(); |
| 952 | fake_update_manager->set_policy(mock_policy); |
| 953 | EXPECT_CALL(*mock_policy, UpdateCanBeApplied(_, _, _, _, _)) |
| 954 | .WillOnce( |
| 955 | DoAll(SetArgPointee<3>(ErrorCode::kOmahaUpdateDeferredPerPolicy), |
| 956 | Return(EvalStatus::kSucceeded))); |
| 957 | // Perform the Action. It should "fail" with kOmahaUpdateDeferredPerPolicy. |
| 958 | InstallPlan install_plan; |
| 959 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
| 960 | EXPECT_EQ(ErrorCode::kOmahaUpdateDeferredPerPolicy, action_result_code_); |
| 961 | // Verify that DoTest() didn't set the output install plan. |
| 962 | EXPECT_EQ("", install_plan.version); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 963 | // Now verify the InstallPlan that was generated. |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 964 | install_plan = *delegate_.response_handler_action_install_plan_; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 965 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 966 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 967 | EXPECT_EQ(1U, install_plan.target_slot); |
| 968 | EXPECT_EQ(in.version, install_plan.version); |
| 969 | } |
| 970 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 971 | } // namespace chromeos_update_engine |