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> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 21 | |
Alex Deymo | 110e030 | 2015-10-19 20:35:21 -0700 | [diff] [blame] | 22 | #include <base/files/file_util.h> |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 23 | #include <base/files/scoped_temp_dir.h> |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 24 | #include <brillo/message_loops/fake_message_loop.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 26 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 27 | #include "update_engine/common/constants.h" |
| 28 | #include "update_engine/common/platform_constants.h" |
| 29 | #include "update_engine/common/test_utils.h" |
| 30 | #include "update_engine/common/utils.h" |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 31 | #include "update_engine/fake_system_state.h" |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 32 | #include "update_engine/mock_payload_state.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 33 | #include "update_engine/payload_consumer/payload_constants.h" |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 34 | #include "update_engine/update_manager/mock_policy.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 35 | |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 36 | using chromeos_update_engine::test_utils::System; |
| 37 | using chromeos_update_engine::test_utils::WriteFileString; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 38 | using chromeos_update_manager::EvalStatus; |
| 39 | using chromeos_update_manager::FakeUpdateManager; |
| 40 | using chromeos_update_manager::MockPolicy; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 41 | using std::string; |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 42 | using testing::_; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 43 | using testing::DoAll; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 44 | using testing::Return; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 45 | using testing::SetArgPointee; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | |
| 47 | namespace chromeos_update_engine { |
| 48 | |
| 49 | class OmahaResponseHandlerActionTest : public ::testing::Test { |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 50 | protected: |
| 51 | void SetUp() override { |
| 52 | FakeBootControl* fake_boot_control = fake_system_state_.fake_boot_control(); |
| 53 | fake_boot_control->SetPartitionDevice( |
Tudor Brindus | dda79e2 | 2018-06-28 18:03:21 -0700 | [diff] [blame] | 54 | kPartitionNameKernel, 0, "/dev/sdz2"); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 55 | fake_boot_control->SetPartitionDevice( |
Tudor Brindus | dda79e2 | 2018-06-28 18:03:21 -0700 | [diff] [blame] | 56 | kPartitionNameRoot, 0, "/dev/sdz3"); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 57 | fake_boot_control->SetPartitionDevice( |
Tudor Brindus | dda79e2 | 2018-06-28 18:03:21 -0700 | [diff] [blame] | 58 | kPartitionNameKernel, 1, "/dev/sdz4"); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 59 | fake_boot_control->SetPartitionDevice( |
Tudor Brindus | dda79e2 | 2018-06-28 18:03:21 -0700 | [diff] [blame] | 60 | kPartitionNameRoot, 1, "/dev/sdz5"); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 61 | } |
| 62 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 63 | // Return true iff the OmahaResponseHandlerAction succeeded. |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 64 | // If out is non-null, it's set w/ the response from the action. |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 65 | bool DoTest(const OmahaResponse& in, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 66 | const string& deadline_file, |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 67 | InstallPlan* out); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 68 | |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 69 | // Pointer to the Action, valid after |DoTest|, released when the test is |
| 70 | // finished. |
| 71 | std::unique_ptr<OmahaResponseHandlerAction> action_; |
| 72 | // Captures the action's result code, for tests that need to directly verify |
| 73 | // it in non-success cases. |
| 74 | ErrorCode action_result_code_; |
| 75 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 76 | FakeSystemState fake_system_state_; |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 77 | // "Hash+" |
| 78 | const brillo::Blob expected_hash_ = {0x48, 0x61, 0x73, 0x68, 0x2b}; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | class OmahaResponseHandlerActionProcessorDelegate |
| 82 | : public ActionProcessorDelegate { |
| 83 | public: |
| 84 | OmahaResponseHandlerActionProcessorDelegate() |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 85 | : code_(ErrorCode::kError), code_set_(false) {} |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 86 | void ActionCompleted(ActionProcessor* processor, |
| 87 | AbstractAction* action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 88 | ErrorCode code) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 89 | if (action->Type() == OmahaResponseHandlerAction::StaticType()) { |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 90 | code_ = code; |
| 91 | code_set_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 94 | ErrorCode code_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 95 | bool code_set_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | namespace { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 99 | const char* const kLongName = |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 100 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 101 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 102 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 103 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 104 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 105 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 106 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 107 | "-the_update_a.b.c.d_DELTA_.tgz"; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 108 | const char* const kBadVersion = "don't update me"; |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 109 | const char* const kPayloadHashHex = "486173682b"; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 110 | } // namespace |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 111 | |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 112 | bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in, |
| 113 | const string& test_deadline_file, |
| 114 | InstallPlan* out) { |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 115 | brillo::FakeMessageLoop loop(nullptr); |
| 116 | loop.SetAsCurrent(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 117 | ActionProcessor processor; |
| 118 | OmahaResponseHandlerActionProcessorDelegate delegate; |
| 119 | processor.set_delegate(&delegate); |
| 120 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 121 | ObjectFeederAction<OmahaResponse> feeder_action; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 122 | feeder_action.set_obj(in); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 123 | if (in.update_exists && in.version != kBadVersion) { |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 124 | string expected_hash; |
| 125 | for (const auto& package : in.packages) |
| 126 | expected_hash += package.hash + ":"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 127 | EXPECT_CALL(*(fake_system_state_.mock_prefs()), |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 128 | SetString(kPrefsUpdateCheckResponseHash, expected_hash)) |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 129 | .WillOnce(Return(true)); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 130 | |
| 131 | int slot = 1 - fake_system_state_.fake_boot_control()->GetCurrentSlot(); |
| 132 | string key = kPrefsChannelOnSlotPrefix + std::to_string(slot); |
| 133 | EXPECT_CALL(*(fake_system_state_.mock_prefs()), SetString(key, testing::_)) |
| 134 | .WillOnce(Return(true)); |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 135 | } |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 136 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 137 | string current_url = in.packages.size() ? in.packages[0].payload_urls[0] : ""; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 138 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), GetCurrentUrl()) |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 139 | .WillRepeatedly(Return(current_url)); |
| 140 | |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 141 | action_.reset(new OmahaResponseHandlerAction( |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 142 | &fake_system_state_, |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 143 | (test_deadline_file.empty() ? constants::kOmahaResponseDeadlineFile |
| 144 | : test_deadline_file))); |
| 145 | BondActions(&feeder_action, action_.get()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 146 | ObjectCollectorAction<InstallPlan> collector_action; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 147 | BondActions(action_.get(), &collector_action); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 148 | processor.EnqueueAction(&feeder_action); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 149 | processor.EnqueueAction(action_.get()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 150 | processor.EnqueueAction(&collector_action); |
| 151 | processor.StartProcessing(); |
| 152 | EXPECT_TRUE(!processor.IsRunning()) |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 153 | << "Update test to handle non-async actions"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 154 | if (out) |
| 155 | *out = collector_action.object(); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 156 | EXPECT_TRUE(delegate.code_set_); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 157 | action_result_code_ = delegate.code_; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 158 | return delegate.code_ == ErrorCode::kSuccess; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | TEST_F(OmahaResponseHandlerActionTest, SimpleTest) { |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 162 | string test_deadline_file; |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 163 | CHECK(utils::MakeTempFile("omaha_response_handler_action_unittest-XXXXXX", |
| 164 | &test_deadline_file, |
| 165 | nullptr)); |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 166 | ScopedPathUnlinker deadline_unlinker(test_deadline_file); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 167 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 168 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 169 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 170 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 171 | in.packages.push_back( |
| 172 | {.payload_urls = {"http://foo/the_update_a.b.c.d.tgz"}, |
| 173 | .size = 12, |
| 174 | .hash = kPayloadHashHex}); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 175 | in.more_info_url = "http://more/info"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 176 | in.prompt = false; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 177 | in.deadline = "20101020"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 178 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 179 | EXPECT_TRUE(DoTest(in, test_deadline_file, &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 180 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 181 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 182 | EXPECT_EQ(1U, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 183 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 184 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 185 | EXPECT_EQ("20101020", deadline); |
| 186 | struct stat deadline_stat; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 187 | EXPECT_EQ(0, stat(test_deadline_file.c_str(), &deadline_stat)); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 188 | EXPECT_EQ( |
| 189 | static_cast<mode_t>(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), |
| 190 | deadline_stat.st_mode); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 191 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 192 | } |
| 193 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 194 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 195 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 196 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 197 | in.packages.push_back( |
| 198 | {.payload_urls = {"http://foo/the_update_a.b.c.d.tgz"}, |
| 199 | .size = 12, |
| 200 | .hash = kPayloadHashHex}); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 201 | in.more_info_url = "http://more/info"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 202 | in.prompt = true; |
| 203 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 204 | // Set the other slot as current. |
| 205 | fake_system_state_.fake_boot_control()->SetCurrentSlot(1); |
| 206 | EXPECT_TRUE(DoTest(in, test_deadline_file, &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 207 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 208 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 209 | EXPECT_EQ(0U, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 210 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 211 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline) && |
| 212 | deadline.empty()); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 213 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 214 | } |
| 215 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 216 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 217 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 218 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 219 | in.packages.push_back( |
| 220 | {.payload_urls = {kLongName}, .size = 12, .hash = kPayloadHashHex}); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 221 | in.more_info_url = "http://more/info"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 222 | in.prompt = true; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 223 | in.deadline = "some-deadline"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 224 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 225 | fake_system_state_.fake_boot_control()->SetCurrentSlot(0); |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 226 | // Because rollback happened, the deadline shouldn't be written into the |
| 227 | // file. |
| 228 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), |
| 229 | GetRollbackHappened()) |
| 230 | .WillOnce(Return(true)); |
| 231 | EXPECT_TRUE(DoTest(in, test_deadline_file, &install_plan)); |
| 232 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 233 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 234 | EXPECT_EQ(1U, install_plan.target_slot); |
| 235 | string deadline; |
| 236 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
| 237 | EXPECT_TRUE(deadline.empty()); |
| 238 | EXPECT_EQ(in.version, install_plan.version); |
| 239 | } |
| 240 | { |
| 241 | OmahaResponse in; |
| 242 | in.update_exists = true; |
| 243 | in.version = "a.b.c.d"; |
| 244 | in.packages.push_back( |
| 245 | {.payload_urls = {kLongName}, .size = 12, .hash = kPayloadHashHex}); |
| 246 | in.more_info_url = "http://more/info"; |
| 247 | in.prompt = true; |
| 248 | in.deadline = "some-deadline"; |
| 249 | InstallPlan install_plan; |
| 250 | fake_system_state_.fake_boot_control()->SetCurrentSlot(0); |
| 251 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), |
| 252 | GetRollbackHappened()) |
| 253 | .WillOnce(Return(false)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 254 | EXPECT_TRUE(DoTest(in, test_deadline_file, &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 255 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 256 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 257 | EXPECT_EQ(1U, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 258 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 259 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 260 | EXPECT_EQ("some-deadline", deadline); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 261 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 266 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 267 | in.update_exists = false; |
| 268 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 269 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 270 | EXPECT_TRUE(install_plan.partitions.empty()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 273 | TEST_F(OmahaResponseHandlerActionTest, MultiPackageTest) { |
| 274 | OmahaResponse in; |
| 275 | in.update_exists = true; |
| 276 | in.version = "a.b.c.d"; |
| 277 | in.packages.push_back({.payload_urls = {"http://package/1"}, |
| 278 | .size = 1, |
| 279 | .hash = kPayloadHashHex}); |
| 280 | in.packages.push_back({.payload_urls = {"http://package/2"}, |
| 281 | .size = 2, |
| 282 | .hash = kPayloadHashHex}); |
| 283 | in.more_info_url = "http://more/info"; |
| 284 | InstallPlan install_plan; |
| 285 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 286 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 287 | EXPECT_EQ(2u, install_plan.payloads.size()); |
| 288 | EXPECT_EQ(in.packages[0].size, install_plan.payloads[0].size); |
| 289 | EXPECT_EQ(in.packages[1].size, install_plan.payloads[1].size); |
| 290 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 291 | EXPECT_EQ(expected_hash_, install_plan.payloads[1].hash); |
| 292 | EXPECT_EQ(in.version, install_plan.version); |
| 293 | } |
| 294 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 295 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpTest) { |
| 296 | OmahaResponse in; |
| 297 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 298 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 299 | in.packages.push_back( |
| 300 | {.payload_urls = {"http://test.should/need/hash.checks.signed"}, |
| 301 | .size = 12, |
| 302 | .hash = kPayloadHashHex}); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 303 | in.more_info_url = "http://more/info"; |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 304 | // Hash checks are always skipped for non-official update URLs. |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 305 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 306 | IsUpdateUrlOfficial()) |
| 307 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 308 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 309 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 310 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 311 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 312 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 313 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 314 | } |
| 315 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 316 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForUnofficialUpdateUrl) { |
| 317 | OmahaResponse in; |
| 318 | in.update_exists = true; |
| 319 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 320 | in.packages.push_back( |
| 321 | {.payload_urls = {"http://url.normally/needs/hash.checks.signed"}, |
| 322 | .size = 12, |
| 323 | .hash = kPayloadHashHex}); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 324 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 325 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 326 | IsUpdateUrlOfficial()) |
| 327 | .WillRepeatedly(Return(false)); |
| 328 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 329 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 330 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 331 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 332 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 333 | EXPECT_EQ(in.version, install_plan.version); |
| 334 | } |
| 335 | |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 336 | TEST_F(OmahaResponseHandlerActionTest, |
| 337 | HashChecksForOfficialUrlUnofficialBuildTest) { |
| 338 | // Official URLs for unofficial builds (dev/test images) don't require hash. |
| 339 | OmahaResponse in; |
| 340 | in.update_exists = true; |
| 341 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 342 | in.packages.push_back( |
| 343 | {.payload_urls = {"http://url.normally/needs/hash.checks.signed"}, |
| 344 | .size = 12, |
| 345 | .hash = kPayloadHashHex}); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 346 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 347 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 348 | IsUpdateUrlOfficial()) |
| 349 | .WillRepeatedly(Return(true)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 350 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 351 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 352 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 353 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 354 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 355 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 356 | EXPECT_EQ(in.version, install_plan.version); |
| 357 | } |
| 358 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 359 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpsTest) { |
| 360 | OmahaResponse in; |
| 361 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 362 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 363 | in.packages.push_back( |
| 364 | {.payload_urls = {"https://test.should/need/hash.checks.signed"}, |
| 365 | .size = 12, |
| 366 | .hash = kPayloadHashHex}); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 367 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 368 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 369 | IsUpdateUrlOfficial()) |
| 370 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 371 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 372 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 373 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 374 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 375 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 376 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 379 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForBothHttpAndHttpsTest) { |
| 380 | OmahaResponse in; |
| 381 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 382 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 383 | in.packages.push_back( |
| 384 | {.payload_urls = {"http://test.should.still/need/hash.checks", |
| 385 | "https://test.should.still/need/hash.checks"}, |
| 386 | .size = 12, |
| 387 | .hash = kPayloadHashHex}); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 388 | in.more_info_url = "http://more/info"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 389 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 390 | IsUpdateUrlOfficial()) |
| 391 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 392 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 393 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 394 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 395 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 396 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 397 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 400 | TEST_F(OmahaResponseHandlerActionTest, ChangeToMoreStableChannelTest) { |
| 401 | OmahaResponse in; |
| 402 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 403 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 404 | in.packages.push_back({.payload_urls = {"https://MoreStableChannelTest"}, |
| 405 | .size = 1, |
| 406 | .hash = kPayloadHashHex}); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 407 | in.more_info_url = "http://more/info"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 408 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 409 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 410 | base::ScopedTempDir tempdir; |
| 411 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 412 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 413 | OmahaRequestParams params(&fake_system_state_); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 414 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
Hidehiko Abe | 2b9d241 | 2017-12-13 18:56:18 +0900 | [diff] [blame] | 415 | params.set_root(tempdir.GetPath().value()); |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 416 | params.set_current_channel("canary-channel"); |
| 417 | // The ImageProperties in Android uses prefs to store MutableImageProperties. |
| 418 | #ifdef __ANDROID__ |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 419 | EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, true)) |
| 420 | .WillOnce(Return(true)); |
| 421 | #endif // __ANDROID__ |
| 422 | EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr)); |
| 423 | params.UpdateDownloadChannel(); |
Sen Jiang | 8500d3a | 2018-02-08 12:04:05 -0800 | [diff] [blame] | 424 | EXPECT_TRUE(params.ShouldPowerwash()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 425 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 426 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 427 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 428 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 429 | EXPECT_TRUE(install_plan.powerwash_required); |
| 430 | } |
| 431 | |
| 432 | TEST_F(OmahaResponseHandlerActionTest, ChangeToLessStableChannelTest) { |
| 433 | OmahaResponse in; |
| 434 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 435 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 436 | in.packages.push_back({.payload_urls = {"https://LessStableChannelTest"}, |
| 437 | .size = 15, |
| 438 | .hash = kPayloadHashHex}); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 439 | in.more_info_url = "http://more/info"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 440 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 441 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 442 | base::ScopedTempDir tempdir; |
| 443 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 444 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 445 | OmahaRequestParams params(&fake_system_state_); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 446 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
Hidehiko Abe | 2b9d241 | 2017-12-13 18:56:18 +0900 | [diff] [blame] | 447 | params.set_root(tempdir.GetPath().value()); |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 448 | params.set_current_channel("stable-channel"); |
| 449 | // The ImageProperties in Android uses prefs to store MutableImageProperties. |
| 450 | #ifdef __ANDROID__ |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 451 | EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, false)) |
| 452 | .WillOnce(Return(true)); |
| 453 | #endif // __ANDROID__ |
| 454 | EXPECT_TRUE(params.SetTargetChannel("canary-channel", false, nullptr)); |
| 455 | params.UpdateDownloadChannel(); |
Sen Jiang | 8500d3a | 2018-02-08 12:04:05 -0800 | [diff] [blame] | 456 | EXPECT_FALSE(params.ShouldPowerwash()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 457 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 458 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 459 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 460 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 461 | EXPECT_FALSE(install_plan.powerwash_required); |
| 462 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 463 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 464 | TEST_F(OmahaResponseHandlerActionTest, P2PUrlIsUsedAndHashChecksMandatory) { |
| 465 | OmahaResponse in; |
| 466 | in.update_exists = true; |
| 467 | in.version = "a.b.c.d"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 468 | in.packages.push_back( |
| 469 | {.payload_urls = {"https://would.not/cause/hash/checks"}, |
| 470 | .size = 12, |
| 471 | .hash = kPayloadHashHex}); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 472 | in.more_info_url = "http://more/info"; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 473 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 474 | OmahaRequestParams params(&fake_system_state_); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 475 | // We're using a real OmahaRequestParams object here so we can't mock |
| 476 | // IsUpdateUrlOfficial(), but setting the update URL to the AutoUpdate test |
| 477 | // server will cause IsUpdateUrlOfficial() to return true. |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 478 | params.set_update_url(constants::kOmahaDefaultAUTestURL); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 479 | fake_system_state_.set_request_params(¶ms); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 480 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 481 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 482 | SetUsingP2PForDownloading(true)); |
| 483 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 484 | string p2p_url = "http://9.8.7.6/p2p"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 485 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), GetP2PUrl()) |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 486 | .WillRepeatedly(Return(p2p_url)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 487 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
Aaron Wood | c73fdc1 | 2017-12-06 11:09:15 -0800 | [diff] [blame] | 488 | GetUsingP2PForDownloading()) |
| 489 | .WillRepeatedly(Return(true)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 490 | |
| 491 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 492 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 493 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 494 | EXPECT_EQ(p2p_url, install_plan.download_url); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 495 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
| 496 | } |
| 497 | |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 498 | TEST_F(OmahaResponseHandlerActionTest, RollbackTest) { |
| 499 | OmahaResponse in; |
| 500 | in.update_exists = true; |
| 501 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 502 | .size = 1, |
| 503 | .hash = kPayloadHashHex}); |
| 504 | in.is_rollback = true; |
Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame^] | 505 | in.rollback_key_version.kernel = 1; |
| 506 | in.rollback_key_version.kernel = 2; |
| 507 | in.rollback_key_version.firmware_key = 3; |
| 508 | in.rollback_key_version.firmware = 4; |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 509 | |
| 510 | fake_system_state_.fake_hardware()->SetMinKernelKeyVersion(0x00010002); |
| 511 | fake_system_state_.fake_hardware()->SetMinFirmwareKeyVersion(0x00030004); |
| 512 | |
| 513 | OmahaRequestParams params(&fake_system_state_); |
| 514 | params.set_rollback_allowed(true); |
| 515 | |
| 516 | fake_system_state_.set_request_params(¶ms); |
| 517 | InstallPlan install_plan; |
| 518 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 519 | EXPECT_TRUE(install_plan.is_rollback); |
| 520 | } |
| 521 | |
| 522 | TEST_F(OmahaResponseHandlerActionTest, RollbackKernelVersionErrorTest) { |
| 523 | OmahaResponse in; |
| 524 | in.update_exists = true; |
| 525 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 526 | .size = 1, |
| 527 | .hash = kPayloadHashHex}); |
| 528 | in.is_rollback = true; |
Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame^] | 529 | in.rollback_key_version.kernel_key = 1; |
| 530 | in.rollback_key_version.kernel = 1; // This is lower than the minimum. |
| 531 | in.rollback_key_version.firmware_key = 3; |
| 532 | in.rollback_key_version.firmware = 4; |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 533 | |
| 534 | fake_system_state_.fake_hardware()->SetMinKernelKeyVersion(0x00010002); |
| 535 | fake_system_state_.fake_hardware()->SetMinFirmwareKeyVersion(0x00030004); |
| 536 | |
| 537 | OmahaRequestParams params(&fake_system_state_); |
| 538 | params.set_rollback_allowed(true); |
| 539 | |
| 540 | fake_system_state_.set_request_params(¶ms); |
| 541 | InstallPlan install_plan; |
| 542 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
| 543 | } |
| 544 | |
| 545 | TEST_F(OmahaResponseHandlerActionTest, RollbackFirmwareVersionErrorTest) { |
| 546 | OmahaResponse in; |
| 547 | in.update_exists = true; |
| 548 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 549 | .size = 1, |
| 550 | .hash = kPayloadHashHex}); |
| 551 | in.is_rollback = true; |
Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame^] | 552 | in.rollback_key_version.kernel_key = 1; |
| 553 | in.rollback_key_version.kernel = 2; |
| 554 | in.rollback_key_version.firmware_key = 3; |
| 555 | in.rollback_key_version.firmware = 3; // This is lower than the minimum. |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 556 | |
| 557 | fake_system_state_.fake_hardware()->SetMinKernelKeyVersion(0x00010002); |
| 558 | fake_system_state_.fake_hardware()->SetMinFirmwareKeyVersion(0x00030004); |
| 559 | |
| 560 | OmahaRequestParams params(&fake_system_state_); |
| 561 | params.set_rollback_allowed(true); |
| 562 | |
| 563 | fake_system_state_.set_request_params(¶ms); |
| 564 | InstallPlan install_plan; |
| 565 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
| 566 | } |
| 567 | |
| 568 | TEST_F(OmahaResponseHandlerActionTest, RollbackNotRollbackTest) { |
| 569 | OmahaResponse in; |
| 570 | in.update_exists = true; |
| 571 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 572 | .size = 1, |
| 573 | .hash = kPayloadHashHex}); |
| 574 | in.is_rollback = false; |
| 575 | |
| 576 | OmahaRequestParams params(&fake_system_state_); |
| 577 | params.set_rollback_allowed(true); |
| 578 | |
| 579 | fake_system_state_.set_request_params(¶ms); |
| 580 | InstallPlan install_plan; |
| 581 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 582 | EXPECT_FALSE(install_plan.is_rollback); |
| 583 | } |
| 584 | |
| 585 | TEST_F(OmahaResponseHandlerActionTest, RollbackNotAllowedTest) { |
| 586 | OmahaResponse in; |
| 587 | in.update_exists = true; |
| 588 | in.packages.push_back({.payload_urls = {"https://RollbackTest"}, |
| 589 | .size = 1, |
| 590 | .hash = kPayloadHashHex}); |
| 591 | in.is_rollback = true; |
| 592 | |
| 593 | OmahaRequestParams params(&fake_system_state_); |
| 594 | params.set_rollback_allowed(false); |
| 595 | |
| 596 | fake_system_state_.set_request_params(¶ms); |
| 597 | InstallPlan install_plan; |
| 598 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
| 599 | } |
| 600 | |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 601 | TEST_F(OmahaResponseHandlerActionTest, SystemVersionTest) { |
| 602 | OmahaResponse in; |
| 603 | in.update_exists = true; |
| 604 | in.version = "a.b.c.d"; |
| 605 | in.system_version = "b.c.d.e"; |
| 606 | in.packages.push_back({.payload_urls = {"http://package/1"}, |
| 607 | .size = 1, |
| 608 | .hash = kPayloadHashHex}); |
| 609 | in.packages.push_back({.payload_urls = {"http://package/2"}, |
| 610 | .size = 2, |
| 611 | .hash = kPayloadHashHex}); |
| 612 | in.more_info_url = "http://more/info"; |
| 613 | InstallPlan install_plan; |
| 614 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
| 615 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 616 | EXPECT_EQ(2u, install_plan.payloads.size()); |
| 617 | EXPECT_EQ(in.packages[0].size, install_plan.payloads[0].size); |
| 618 | EXPECT_EQ(in.packages[1].size, install_plan.payloads[1].size); |
| 619 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 620 | EXPECT_EQ(expected_hash_, install_plan.payloads[1].hash); |
| 621 | EXPECT_EQ(in.version, install_plan.version); |
| 622 | EXPECT_EQ(in.system_version, install_plan.system_version); |
| 623 | } |
| 624 | |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 625 | TEST_F(OmahaResponseHandlerActionTest, TestDeferredByPolicy) { |
| 626 | OmahaResponse in; |
| 627 | in.update_exists = true; |
| 628 | in.version = "a.b.c.d"; |
| 629 | in.packages.push_back({.payload_urls = {"http://foo/the_update_a.b.c.d.tgz"}, |
| 630 | .size = 12, |
| 631 | .hash = kPayloadHashHex}); |
| 632 | // Setup the UpdateManager to disallow the update. |
| 633 | FakeClock fake_clock; |
| 634 | MockPolicy* mock_policy = new MockPolicy(&fake_clock); |
| 635 | FakeUpdateManager* fake_update_manager = |
| 636 | fake_system_state_.fake_update_manager(); |
| 637 | fake_update_manager->set_policy(mock_policy); |
| 638 | EXPECT_CALL(*mock_policy, UpdateCanBeApplied(_, _, _, _, _)) |
| 639 | .WillOnce( |
| 640 | DoAll(SetArgPointee<3>(ErrorCode::kOmahaUpdateDeferredPerPolicy), |
| 641 | Return(EvalStatus::kSucceeded))); |
| 642 | // Perform the Action. It should "fail" with kOmahaUpdateDeferredPerPolicy. |
| 643 | InstallPlan install_plan; |
| 644 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
| 645 | EXPECT_EQ(ErrorCode::kOmahaUpdateDeferredPerPolicy, action_result_code_); |
| 646 | // Verify that DoTest() didn't set the output install plan. |
| 647 | EXPECT_EQ("", install_plan.version); |
| 648 | // Copy the underlying InstallPlan from the Action (like a real Delegate). |
| 649 | install_plan = action_->install_plan(); |
| 650 | // Now verify the InstallPlan that was generated. |
| 651 | EXPECT_EQ(in.packages[0].payload_urls[0], install_plan.download_url); |
| 652 | EXPECT_EQ(expected_hash_, install_plan.payloads[0].hash); |
| 653 | EXPECT_EQ(1U, install_plan.target_slot); |
| 654 | EXPECT_EQ(in.version, install_plan.version); |
| 655 | } |
| 656 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 657 | } // namespace chromeos_update_engine |