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