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