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