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)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 210 | EXPECT_EQ("", install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 211 | EXPECT_EQ("", install_plan.payload_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 212 | EXPECT_EQ("", install_plan.install_path); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 213 | EXPECT_EQ("", install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 216 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpTest) { |
| 217 | OmahaResponse in; |
| 218 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 219 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 220 | in.payload_urls.push_back("http://test.should/need/hash.checks.signed"); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 221 | in.more_info_url = "http://more/info"; |
| 222 | in.hash = "HASHj+"; |
| 223 | in.size = 12; |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 224 | // Hash checks are always skipped for non-official update URLs. |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 225 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 226 | IsUpdateUrlOfficial()) |
| 227 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 228 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 229 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 230 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 231 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 232 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 233 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 234 | } |
| 235 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 236 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForUnofficialUpdateUrl) { |
| 237 | OmahaResponse in; |
| 238 | in.update_exists = true; |
| 239 | in.version = "a.b.c.d"; |
| 240 | in.payload_urls.push_back("http://url.normally/needs/hash.checks.signed"); |
| 241 | in.more_info_url = "http://more/info"; |
| 242 | in.hash = "HASHj+"; |
| 243 | in.size = 12; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 244 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 245 | IsUpdateUrlOfficial()) |
| 246 | .WillRepeatedly(Return(false)); |
| 247 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 248 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 249 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 250 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 251 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 252 | EXPECT_EQ(in.version, install_plan.version); |
| 253 | } |
| 254 | |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 255 | TEST_F(OmahaResponseHandlerActionTest, |
| 256 | HashChecksForOfficialUrlUnofficialBuildTest) { |
| 257 | // Official URLs for unofficial builds (dev/test images) don't require hash. |
| 258 | OmahaResponse in; |
| 259 | in.update_exists = true; |
| 260 | in.version = "a.b.c.d"; |
| 261 | in.payload_urls.push_back("http://url.normally/needs/hash.checks.signed"); |
| 262 | in.more_info_url = "http://more/info"; |
| 263 | in.hash = "HASHj+"; |
| 264 | in.size = 12; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 265 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 266 | IsUpdateUrlOfficial()) |
| 267 | .WillRepeatedly(Return(true)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 268 | fake_system_state_.fake_hardware()->SetIsOfficialBuild(false); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 269 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 270 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 271 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 272 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 273 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 274 | EXPECT_EQ(in.version, install_plan.version); |
| 275 | } |
| 276 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 277 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpsTest) { |
| 278 | OmahaResponse in; |
| 279 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 280 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 281 | 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] | 282 | in.more_info_url = "http://more/info"; |
| 283 | in.hash = "HASHj+"; |
| 284 | in.size = 12; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 285 | EXPECT_CALL(*(fake_system_state_.mock_request_params()), |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 286 | IsUpdateUrlOfficial()) |
| 287 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 288 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 289 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 290 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 291 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 292 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 293 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 296 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForBothHttpAndHttpsTest) { |
| 297 | OmahaResponse in; |
| 298 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 299 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 300 | in.payload_urls.push_back("http://test.should.still/need/hash.checks"); |
| 301 | in.payload_urls.push_back("https://test.should.still/need/hash.checks"); |
| 302 | in.more_info_url = "http://more/info"; |
| 303 | in.hash = "HASHj+"; |
| 304 | in.size = 12; |
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 | 6f6ea00 | 2012-12-14 11:26:28 -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)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 310 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 311 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 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 | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 316 | TEST_F(OmahaResponseHandlerActionTest, ChangeToMoreStableChannelTest) { |
| 317 | OmahaResponse in; |
| 318 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 319 | in.version = "a.b.c.d"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 320 | in.payload_urls.push_back("https://MoreStableChannelTest"); |
| 321 | in.more_info_url = "http://more/info"; |
| 322 | in.hash = "HASHjk"; |
| 323 | in.size = 15; |
| 324 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 325 | // Create a uniquely named test directory. |
| 326 | string test_dir; |
| 327 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 328 | "omaha_response_handler_action-test-XXXXXX", &test_dir)); |
| 329 | |
| 330 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc")); |
| 331 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 332 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 333 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 334 | test_dir + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 335 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 336 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 337 | test_dir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 338 | "CHROMEOS_IS_POWERWASH_ALLOWED=true\n" |
| 339 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 340 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 341 | OmahaRequestParams params(&fake_system_state_); |
Gilad Arnold | d04f8e2 | 2014-01-09 13:13:40 -0800 | [diff] [blame] | 342 | params.set_root(test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 343 | params.SetLockDown(false); |
| 344 | params.Init("1.2.3.4", "", 0); |
| 345 | EXPECT_EQ("canary-channel", params.current_channel()); |
| 346 | EXPECT_EQ("stable-channel", params.target_channel()); |
| 347 | EXPECT_TRUE(params.to_more_stable_channel()); |
| 348 | EXPECT_TRUE(params.is_powerwash_allowed()); |
| 349 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 350 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [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)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 353 | EXPECT_TRUE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 354 | |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 355 | ASSERT_TRUE(test_utils::RecursiveUnlinkDir(test_dir)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | TEST_F(OmahaResponseHandlerActionTest, ChangeToLessStableChannelTest) { |
| 359 | OmahaResponse in; |
| 360 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 361 | in.version = "a.b.c.d"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 362 | in.payload_urls.push_back("https://LessStableChannelTest"); |
| 363 | in.more_info_url = "http://more/info"; |
| 364 | in.hash = "HASHjk"; |
| 365 | in.size = 15; |
| 366 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 367 | // Create a uniquely named test directory. |
| 368 | string test_dir; |
| 369 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 370 | "omaha_response_handler_action-test-XXXXXX", &test_dir)); |
| 371 | |
| 372 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc")); |
| 373 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 374 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 375 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 376 | test_dir + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 377 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 378 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 379 | test_dir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 380 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 381 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 382 | OmahaRequestParams params(&fake_system_state_); |
Gilad Arnold | d04f8e2 | 2014-01-09 13:13:40 -0800 | [diff] [blame] | 383 | params.set_root(test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 384 | params.SetLockDown(false); |
| 385 | params.Init("5.6.7.8", "", 0); |
| 386 | EXPECT_EQ("stable-channel", params.current_channel()); |
| 387 | params.SetTargetChannel("canary-channel", false); |
| 388 | EXPECT_EQ("canary-channel", params.target_channel()); |
| 389 | EXPECT_FALSE(params.to_more_stable_channel()); |
| 390 | EXPECT_FALSE(params.is_powerwash_allowed()); |
| 391 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 392 | fake_system_state_.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 393 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 394 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 395 | EXPECT_FALSE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 396 | |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 397 | ASSERT_TRUE(test_utils::RecursiveUnlinkDir(test_dir)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 398 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 399 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 400 | TEST_F(OmahaResponseHandlerActionTest, P2PUrlIsUsedAndHashChecksMandatory) { |
| 401 | OmahaResponse in; |
| 402 | in.update_exists = true; |
| 403 | in.version = "a.b.c.d"; |
| 404 | in.payload_urls.push_back("https://would.not/cause/hash/checks"); |
| 405 | in.more_info_url = "http://more/info"; |
| 406 | in.hash = "HASHj+"; |
| 407 | in.size = 12; |
| 408 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 409 | OmahaRequestParams params(&fake_system_state_); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 410 | // We're using a real OmahaRequestParams object here so we can't mock |
| 411 | // IsUpdateUrlOfficial(), but setting the update URL to the AutoUpdate test |
| 412 | // server will cause IsUpdateUrlOfficial() to return true. |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 413 | params.set_update_url(constants::kOmahaDefaultAUTestURL); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 414 | fake_system_state_.set_request_params(¶ms); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 415 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 416 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 417 | SetUsingP2PForDownloading(true)); |
| 418 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 419 | string p2p_url = "http://9.8.7.6/p2p"; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 420 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), GetP2PUrl()) |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 421 | .WillRepeatedly(Return(p2p_url)); |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 422 | EXPECT_CALL(*fake_system_state_.mock_payload_state(), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 423 | GetUsingP2PForDownloading()).WillRepeatedly(Return(true)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 424 | |
| 425 | InstallPlan install_plan; |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 426 | EXPECT_TRUE(DoTest(in, "", &install_plan)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 427 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 428 | EXPECT_EQ(install_plan.download_url, p2p_url); |
| 429 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
| 430 | } |
| 431 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 432 | } // namespace chromeos_update_engine |