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