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 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | #include <string> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 20 | |
Alex Deymo | 110e030 | 2015-10-19 20:35:21 -0700 | [diff] [blame] | 21 | #include <base/files/file_util.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 23 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 24 | #include "update_engine/common/constants.h" |
| 25 | #include "update_engine/common/platform_constants.h" |
| 26 | #include "update_engine/common/test_utils.h" |
| 27 | #include "update_engine/common/utils.h" |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 28 | #include "update_engine/fake_system_state.h" |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 29 | #include "update_engine/mock_payload_state.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 30 | #include "update_engine/payload_consumer/payload_constants.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 31 | |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 32 | using chromeos_update_engine::test_utils::System; |
| 33 | using chromeos_update_engine::test_utils::WriteFileString; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 34 | using std::string; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 35 | using testing::Return; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | |
| 37 | namespace chromeos_update_engine { |
| 38 | |
| 39 | class OmahaResponseHandlerActionTest : public ::testing::Test { |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 40 | protected: |
| 41 | void SetUp() override { |
| 42 | FakeBootControl* fake_boot_control = fake_system_state_.fake_boot_control(); |
| 43 | fake_boot_control->SetPartitionDevice( |
| 44 | kLegacyPartitionNameKernel, 0, "/dev/sdz2"); |
| 45 | fake_boot_control->SetPartitionDevice( |
| 46 | kLegacyPartitionNameRoot, 0, "/dev/sdz3"); |
| 47 | fake_boot_control->SetPartitionDevice( |
| 48 | kLegacyPartitionNameKernel, 1, "/dev/sdz4"); |
| 49 | fake_boot_control->SetPartitionDevice( |
| 50 | kLegacyPartitionNameRoot, 1, "/dev/sdz5"); |
| 51 | } |
| 52 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 53 | // Return true iff the OmahaResponseHandlerAction succeeded. |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 54 | // 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] | 55 | bool DoTest(const OmahaResponse& in, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 56 | const string& deadline_file, |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 57 | InstallPlan* out); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 58 | |
| 59 | FakeSystemState fake_system_state_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | class OmahaResponseHandlerActionProcessorDelegate |
| 63 | : public ActionProcessorDelegate { |
| 64 | public: |
| 65 | OmahaResponseHandlerActionProcessorDelegate() |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 66 | : code_(ErrorCode::kError), |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 67 | code_set_(false) {} |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 68 | void ActionCompleted(ActionProcessor* processor, |
| 69 | AbstractAction* action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 70 | ErrorCode code) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 71 | if (action->Type() == OmahaResponseHandlerAction::StaticType()) { |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 72 | code_ = code; |
| 73 | code_set_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 76 | ErrorCode code_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 77 | bool code_set_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | namespace { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 81 | const char* const kLongName = |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 82 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 83 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 84 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 85 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 86 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 87 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 88 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 89 | "-the_update_a.b.c.d_DELTA_.tgz"; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 90 | const char* const kBadVersion = "don't update me"; |
| 91 | } // namespace |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 92 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 93 | bool OmahaResponseHandlerActionTest::DoTest( |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 94 | const OmahaResponse& in, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 95 | const string& test_deadline_file, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 96 | InstallPlan* out) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 97 | ActionProcessor processor; |
| 98 | OmahaResponseHandlerActionProcessorDelegate delegate; |
| 99 | processor.set_delegate(&delegate); |
| 100 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 101 | ObjectFeederAction<OmahaResponse> feeder_action; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 102 | feeder_action.set_obj(in); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 103 | if (in.update_exists && in.version != kBadVersion) { |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 104 | EXPECT_CALL(*(fake_system_state_.mock_prefs()), |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 105 | SetString(kPrefsUpdateCheckResponseHash, in.hash)) |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 106 | .WillOnce(Return(true)); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 107 | |
| 108 | int slot = 1 - fake_system_state_.fake_boot_control()->GetCurrentSlot(); |
| 109 | string key = kPrefsChannelOnSlotPrefix + std::to_string(slot); |
| 110 | EXPECT_CALL(*(fake_system_state_.mock_prefs()), SetString(key, testing::_)) |
| 111 | .WillOnce(Return(true)); |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 112 | } |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 113 | |
| 114 | string current_url = in.payload_urls.size() ? in.payload_urls[0] : ""; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 115 | EXPECT_CALL(*(fake_system_state_.mock_payload_state()), GetCurrentUrl()) |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 116 | .WillRepeatedly(Return(current_url)); |
| 117 | |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 118 | OmahaResponseHandlerAction response_handler_action( |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 119 | &fake_system_state_, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 120 | (test_deadline_file.empty() ? |
Alex Deymo | 6dd160a | 2015-10-09 18:45:14 -0700 | [diff] [blame] | 121 | constants::kOmahaResponseDeadlineFile : test_deadline_file)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 122 | BondActions(&feeder_action, &response_handler_action); |
| 123 | ObjectCollectorAction<InstallPlan> collector_action; |
| 124 | BondActions(&response_handler_action, &collector_action); |
| 125 | processor.EnqueueAction(&feeder_action); |
| 126 | processor.EnqueueAction(&response_handler_action); |
| 127 | processor.EnqueueAction(&collector_action); |
| 128 | processor.StartProcessing(); |
| 129 | EXPECT_TRUE(!processor.IsRunning()) |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 130 | << "Update test to handle non-async actions"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 131 | if (out) |
| 132 | *out = collector_action.object(); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 133 | EXPECT_TRUE(delegate.code_set_); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 134 | return delegate.code_ == ErrorCode::kSuccess; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | TEST_F(OmahaResponseHandlerActionTest, SimpleTest) { |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 138 | string test_deadline_file; |
| 139 | CHECK(utils::MakeTempFile( |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 140 | "omaha_response_handler_action_unittest-XXXXXX", |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 141 | &test_deadline_file, nullptr)); |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 142 | ScopedPathUnlinker deadline_unlinker(test_deadline_file); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 143 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 144 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 145 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 146 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 147 | in.payload_urls.push_back("http://foo/the_update_a.b.c.d.tgz"); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 148 | in.more_info_url = "http://more/info"; |
| 149 | in.hash = "HASH+"; |
| 150 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 151 | in.prompt = false; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 152 | in.deadline = "20101020"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 153 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 154 | EXPECT_TRUE(DoTest(in, test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 155 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 156 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 157 | EXPECT_EQ(1, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 158 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 159 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 160 | EXPECT_EQ("20101020", deadline); |
| 161 | struct stat deadline_stat; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 162 | EXPECT_EQ(0, stat(test_deadline_file.c_str(), &deadline_stat)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 163 | EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, |
| 164 | deadline_stat.st_mode); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 165 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 166 | } |
| 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"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 171 | in.payload_urls.push_back("http://foo/the_update_a.b.c.d.tgz"); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 172 | in.more_info_url = "http://more/info"; |
| 173 | in.hash = "HASHj+"; |
| 174 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 175 | in.prompt = true; |
| 176 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 177 | // Set the other slot as current. |
| 178 | fake_system_state_.fake_boot_control()->SetCurrentSlot(1); |
| 179 | EXPECT_TRUE(DoTest(in, test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 180 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 181 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 182 | EXPECT_EQ(0, 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) && |
| 185 | deadline.empty()); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 186 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 187 | } |
| 188 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 189 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 190 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 191 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 192 | in.payload_urls.push_back(kLongName); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 193 | in.more_info_url = "http://more/info"; |
| 194 | in.hash = "HASHj+"; |
| 195 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 196 | in.prompt = true; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 197 | in.deadline = "some-deadline"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 198 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 199 | fake_system_state_.fake_boot_control()->SetCurrentSlot(0); |
| 200 | EXPECT_TRUE(DoTest(in, test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 201 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 202 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 203 | EXPECT_EQ(1, install_plan.target_slot); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 204 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 205 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 206 | EXPECT_EQ("some-deadline", deadline); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 207 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 212 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 213 | in.update_exists = false; |
| 214 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 215 | EXPECT_FALSE(DoTest(in, "", &install_plan)); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 216 | EXPECT_TRUE(install_plan.partitions.empty()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 219 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpTest) { |
| 220 | OmahaResponse in; |
| 221 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 222 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 223 | in.payload_urls.push_back("http://test.should/need/hash.checks.signed"); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 224 | in.more_info_url = "http://more/info"; |
| 225 | in.hash = "HASHj+"; |
| 226 | in.size = 12; |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 227 | // Hash checks are always skipped for non-official update URLs. |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 228 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 229 | IsUpdateUrlOfficial()) |
| 230 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 231 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 232 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 233 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 234 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 235 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 236 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 237 | } |
| 238 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 239 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForUnofficialUpdateUrl) { |
| 240 | OmahaResponse in; |
| 241 | in.update_exists = true; |
| 242 | in.version = "a.b.c.d"; |
| 243 | in.payload_urls.push_back("http://url.normally/needs/hash.checks.signed"); |
| 244 | in.more_info_url = "http://more/info"; |
| 245 | in.hash = "HASHj+"; |
| 246 | in.size = 12; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 247 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 248 | IsUpdateUrlOfficial()) |
| 249 | .WillRepeatedly(Return(false)); |
| 250 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 251 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 252 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 253 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 254 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 255 | EXPECT_EQ(in.version, install_plan.version); |
| 256 | } |
| 257 | |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 258 | TEST_F(OmahaResponseHandlerActionTest, |
| 259 | HashChecksForOfficialUrlUnofficialBuildTest) { |
| 260 | // Official URLs for unofficial builds (dev/test images) don't require hash. |
| 261 | OmahaResponse in; |
| 262 | in.update_exists = true; |
| 263 | in.version = "a.b.c.d"; |
| 264 | in.payload_urls.push_back("http://url.normally/needs/hash.checks.signed"); |
| 265 | in.more_info_url = "http://more/info"; |
| 266 | in.hash = "HASHj+"; |
| 267 | in.size = 12; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 268 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 269 | IsUpdateUrlOfficial()) |
| 270 | .WillRepeatedly(Return(true)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 271 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 272 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 273 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 274 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 275 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 276 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 277 | EXPECT_EQ(in.version, install_plan.version); |
| 278 | } |
| 279 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 280 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpsTest) { |
| 281 | OmahaResponse in; |
| 282 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 283 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 284 | in.payload_urls.push_back("https://test.should.not/need/hash.checks.signed"); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 285 | in.more_info_url = "http://more/info"; |
| 286 | in.hash = "HASHj+"; |
| 287 | in.size = 12; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 288 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 289 | IsUpdateUrlOfficial()) |
| 290 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 291 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 292 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 293 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 294 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 295 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 296 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 299 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForBothHttpAndHttpsTest) { |
| 300 | OmahaResponse in; |
| 301 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 302 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 303 | in.payload_urls.push_back("http://test.should.still/need/hash.checks"); |
| 304 | in.payload_urls.push_back("https://test.should.still/need/hash.checks"); |
| 305 | in.more_info_url = "http://more/info"; |
| 306 | in.hash = "HASHj+"; |
| 307 | in.size = 12; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 308 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 309 | IsUpdateUrlOfficial()) |
| 310 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 311 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 312 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 313 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 314 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 315 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 316 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 319 | TEST_F(OmahaResponseHandlerActionTest, ChangeToMoreStableChannelTest) { |
| 320 | OmahaResponse in; |
| 321 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 322 | in.version = "a.b.c.d"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 323 | in.payload_urls.push_back("https://MoreStableChannelTest"); |
| 324 | in.more_info_url = "http://more/info"; |
| 325 | in.hash = "HASHjk"; |
| 326 | in.size = 15; |
| 327 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 328 | // Create a uniquely named test directory. |
| 329 | string test_dir; |
| 330 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 331 | "omaha_response_handler_action-test-XXXXXX", &test_dir)); |
| 332 | |
| 333 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc")); |
| 334 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 335 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 336 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 337 | test_dir + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 338 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 339 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 340 | test_dir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 341 | "CHROMEOS_IS_POWERWASH_ALLOWED=true\n" |
| 342 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 343 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 344 | OmahaRequestParams params(&fake_system_state_); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 345 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
Gilad Arnold | d04f8e2 | 2014-01-09 13:13:40 -0800 | [diff] [blame] | 346 | params.set_root(test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 347 | params.Init("1.2.3.4", "", 0); |
| 348 | EXPECT_EQ("canary-channel", params.current_channel()); |
| 349 | EXPECT_EQ("stable-channel", params.target_channel()); |
| 350 | EXPECT_TRUE(params.to_more_stable_channel()); |
| 351 | EXPECT_TRUE(params.is_powerwash_allowed()); |
| 352 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 353 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 354 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 355 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 356 | EXPECT_TRUE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 357 | |
Alex Deymo | 110e030 | 2015-10-19 20:35:21 -0700 | [diff] [blame] | 358 | ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | TEST_F(OmahaResponseHandlerActionTest, ChangeToLessStableChannelTest) { |
| 362 | OmahaResponse in; |
| 363 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 364 | in.version = "a.b.c.d"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 365 | in.payload_urls.push_back("https://LessStableChannelTest"); |
| 366 | in.more_info_url = "http://more/info"; |
| 367 | in.hash = "HASHjk"; |
| 368 | in.size = 15; |
| 369 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 370 | // Create a uniquely named test directory. |
| 371 | string test_dir; |
| 372 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 373 | "omaha_response_handler_action-test-XXXXXX", &test_dir)); |
| 374 | |
| 375 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc")); |
| 376 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 377 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 378 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 379 | test_dir + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 380 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 381 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 382 | test_dir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 383 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 384 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 385 | OmahaRequestParams params(&fake_system_state_); |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 386 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
Gilad Arnold | d04f8e2 | 2014-01-09 13:13:40 -0800 | [diff] [blame] | 387 | params.set_root(test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 388 | params.Init("5.6.7.8", "", 0); |
| 389 | EXPECT_EQ("stable-channel", params.current_channel()); |
Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 390 | params.SetTargetChannel("canary-channel", false, nullptr); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 391 | EXPECT_EQ("canary-channel", params.target_channel()); |
| 392 | EXPECT_FALSE(params.to_more_stable_channel()); |
| 393 | EXPECT_FALSE(params.is_powerwash_allowed()); |
| 394 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 395 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 396 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 397 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 398 | EXPECT_FALSE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 399 | |
Alex Deymo | 110e030 | 2015-10-19 20:35:21 -0700 | [diff] [blame] | 400 | ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 401 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 402 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 403 | TEST_F(OmahaResponseHandlerActionTest, P2PUrlIsUsedAndHashChecksMandatory) { |
| 404 | OmahaResponse in; |
| 405 | in.update_exists = true; |
| 406 | in.version = "a.b.c.d"; |
| 407 | in.payload_urls.push_back("https://would.not/cause/hash/checks"); |
| 408 | in.more_info_url = "http://more/info"; |
| 409 | in.hash = "HASHj+"; |
| 410 | in.size = 12; |
| 411 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 412 | OmahaRequestParams params(&fake_system_state_); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 413 | // We're using a real OmahaRequestParams object here so we can't mock |
| 414 | // IsUpdateUrlOfficial(), but setting the update URL to the AutoUpdate test |
| 415 | // server will cause IsUpdateUrlOfficial() to return true. |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 416 | params.set_update_url(constants::kOmahaDefaultAUTestURL); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 417 | fake_system_state_.set_request_params(¶ms); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 418 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 419 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 420 | SetUsingP2PForDownloading(true)); |
| 421 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 422 | string p2p_url = "http://9.8.7.6/p2p"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 423 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), GetP2PUrl()) |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 424 | .WillRepeatedly(Return(p2p_url)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 425 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 426 | GetUsingP2PForDownloading()).WillRepeatedly(Return(true)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 427 | |
| 428 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 429 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 430 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 431 | EXPECT_EQ(install_plan.download_url, p2p_url); |
| 432 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
| 433 | } |
| 434 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 435 | } // namespace chromeos_update_engine |