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 | |
| 5 | #include <string> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 6 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 7 | #include <gtest/gtest.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 8 | |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 9 | #include "update_engine/constants.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 10 | #include "update_engine/omaha_response_handler_action.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 11 | #include "update_engine/mock_system_state.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 12 | #include "update_engine/test_utils.h" |
| 13 | #include "update_engine/utils.h" |
| 14 | |
| 15 | using std::string; |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 16 | using testing::NiceMock; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 17 | using testing::Return; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 18 | |
| 19 | namespace chromeos_update_engine { |
| 20 | |
| 21 | class OmahaResponseHandlerActionTest : public ::testing::Test { |
| 22 | public: |
| 23 | // Return true iff the OmahaResponseHandlerAction succeeded. |
| 24 | // If out is non-NULL, it's set w/ the response from the action. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 25 | bool DoTestCommon(MockSystemState* mock_system_state, |
| 26 | const OmahaResponse& in, |
| 27 | const string& boot_dev, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 28 | const string& deadline_file, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 29 | InstallPlan* out); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 30 | bool DoTest(const OmahaResponse& in, |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 31 | const string& boot_dev, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 32 | const string& deadline_file, |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 33 | InstallPlan* out); |
| 34 | }; |
| 35 | |
| 36 | class OmahaResponseHandlerActionProcessorDelegate |
| 37 | : public ActionProcessorDelegate { |
| 38 | public: |
| 39 | OmahaResponseHandlerActionProcessorDelegate() |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 40 | : code_(kErrorCodeError), |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 41 | code_set_(false) {} |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 42 | void ActionCompleted(ActionProcessor* processor, |
| 43 | AbstractAction* action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 44 | ErrorCode code) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 45 | if (action->Type() == OmahaResponseHandlerAction::StaticType()) { |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 46 | code_ = code; |
| 47 | code_set_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 50 | ErrorCode code_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 51 | bool code_set_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | namespace { |
| 55 | const string kLongName = |
| 56 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 57 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 58 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 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 | "-the_update_a.b.c.d_DELTA_.tgz"; |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 64 | const string kBadVersion = "don't update me"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 65 | } // namespace {} |
| 66 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 67 | bool OmahaResponseHandlerActionTest::DoTestCommon( |
| 68 | MockSystemState* mock_system_state, |
| 69 | const OmahaResponse& in, |
| 70 | const string& boot_dev, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 71 | const string& test_deadline_file, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 72 | InstallPlan* out) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 73 | ActionProcessor processor; |
| 74 | OmahaResponseHandlerActionProcessorDelegate delegate; |
| 75 | processor.set_delegate(&delegate); |
| 76 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 77 | ObjectFeederAction<OmahaResponse> feeder_action; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 78 | feeder_action.set_obj(in); |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 79 | if (in.update_exists and in.version != kBadVersion) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 80 | EXPECT_CALL(*(mock_system_state->mock_prefs()), |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 81 | SetString(kPrefsUpdateCheckResponseHash, in.hash)) |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 82 | .WillOnce(Return(true)); |
| 83 | } |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 84 | |
| 85 | string current_url = in.payload_urls.size() ? in.payload_urls[0] : ""; |
| 86 | EXPECT_CALL(*(mock_system_state->mock_payload_state()), GetCurrentUrl()) |
| 87 | .WillRepeatedly(Return(current_url)); |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 88 | EXPECT_CALL(*(mock_system_state->mock_payload_state()), GetRollbackVersion()) |
| 89 | .WillRepeatedly(Return(kBadVersion)); |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 90 | |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 91 | OmahaResponseHandlerAction response_handler_action( |
| 92 | mock_system_state, |
| 93 | (test_deadline_file.empty() ? |
| 94 | OmahaResponseHandlerAction::kDeadlineFile : test_deadline_file)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 95 | response_handler_action.set_boot_device(boot_dev); |
| 96 | BondActions(&feeder_action, &response_handler_action); |
| 97 | ObjectCollectorAction<InstallPlan> collector_action; |
| 98 | BondActions(&response_handler_action, &collector_action); |
| 99 | processor.EnqueueAction(&feeder_action); |
| 100 | processor.EnqueueAction(&response_handler_action); |
| 101 | processor.EnqueueAction(&collector_action); |
| 102 | processor.StartProcessing(); |
| 103 | EXPECT_TRUE(!processor.IsRunning()) |
| 104 | << "Update test to handle non-asynch actions"; |
| 105 | if (out) |
| 106 | *out = collector_action.object(); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 107 | EXPECT_TRUE(delegate.code_set_); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 108 | return delegate.code_ == kErrorCodeSuccess; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 111 | bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in, |
| 112 | const string& boot_dev, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 113 | const string& deadline_file, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 114 | InstallPlan* out) { |
| 115 | MockSystemState mock_system_state; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 116 | return DoTestCommon(&mock_system_state, in, boot_dev, deadline_file, out); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 117 | } |
| 118 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 119 | TEST_F(OmahaResponseHandlerActionTest, SimpleTest) { |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 120 | string test_deadline_file; |
| 121 | CHECK(utils::MakeTempFile( |
| 122 | "/tmp/omaha_response_handler_action_unittest-XXXXXX", |
| 123 | &test_deadline_file, NULL)); |
| 124 | ScopedPathUnlinker deadline_unlinker(test_deadline_file); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 125 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 126 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 127 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 128 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 129 | 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] | 130 | in.more_info_url = "http://more/info"; |
| 131 | in.hash = "HASH+"; |
| 132 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 133 | in.prompt = false; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 134 | in.deadline = "20101020"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 135 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 136 | EXPECT_TRUE(DoTest(in, "/dev/sda3", test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 137 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 138 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 139 | EXPECT_EQ("/dev/sda5", install_plan.install_path); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 140 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 141 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 142 | EXPECT_EQ("20101020", deadline); |
| 143 | struct stat deadline_stat; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 144 | EXPECT_EQ(0, stat(test_deadline_file.c_str(), &deadline_stat)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 145 | EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, |
| 146 | deadline_stat.st_mode); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 147 | } |
| 148 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 149 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 150 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 151 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 152 | 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] | 153 | in.more_info_url = "http://more/info"; |
| 154 | in.hash = "HASHj+"; |
| 155 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 156 | in.prompt = true; |
| 157 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 158 | EXPECT_TRUE(DoTest(in, "/dev/sda5", test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 159 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 160 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 161 | EXPECT_EQ("/dev/sda3", install_plan.install_path); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 162 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 163 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline) && |
| 164 | deadline.empty()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 165 | } |
| 166 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 167 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 168 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 169 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 170 | in.payload_urls.push_back(kLongName); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 171 | in.more_info_url = "http://more/info"; |
| 172 | in.hash = "HASHj+"; |
| 173 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 174 | in.prompt = true; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 175 | in.deadline = "some-deadline"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 176 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 177 | EXPECT_TRUE(DoTest(in, "/dev/sda3", test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 178 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 179 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 180 | EXPECT_EQ("/dev/sda5", install_plan.install_path); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 181 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 182 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 183 | EXPECT_EQ("some-deadline", deadline); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
| 187 | TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 188 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 189 | in.update_exists = false; |
| 190 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 191 | EXPECT_FALSE(DoTest(in, "/dev/sda1", "", &install_plan)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 192 | EXPECT_EQ("", install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 193 | EXPECT_EQ("", install_plan.payload_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 194 | EXPECT_EQ("", install_plan.install_path); |
| 195 | } |
| 196 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 197 | TEST_F(OmahaResponseHandlerActionTest, RollbackVersionTest) { |
| 198 | string version_ok = "124.0.0"; |
| 199 | |
| 200 | InstallPlan install_plan; |
| 201 | OmahaResponse in; |
| 202 | in.update_exists = true; |
| 203 | in.version = kBadVersion; |
| 204 | in.payload_urls.push_back("http://foo/the_update_a.b.c.d.tgz"); |
| 205 | in.more_info_url = "http://more/info"; |
| 206 | in.hash = "HASHj+"; |
| 207 | in.size = 12; |
| 208 | in.prompt = true; |
| 209 | |
| 210 | // Version is blacklisted for first call so no update. |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 211 | EXPECT_FALSE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 212 | EXPECT_EQ("", install_plan.download_url); |
| 213 | EXPECT_EQ("", install_plan.payload_hash); |
| 214 | EXPECT_EQ("", install_plan.install_path); |
| 215 | |
| 216 | // Version isn't blacklisted. |
| 217 | in.version = version_ok; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 218 | EXPECT_TRUE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 219 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 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; |
| 230 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 231 | EXPECT_TRUE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 232 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 233 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 234 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
| 235 | } |
| 236 | |
| 237 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpsTest) { |
| 238 | OmahaResponse in; |
| 239 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 240 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 241 | 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] | 242 | in.more_info_url = "http://more/info"; |
| 243 | in.hash = "HASHj+"; |
| 244 | in.size = 12; |
| 245 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 246 | EXPECT_TRUE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 247 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 248 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 249 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
| 250 | } |
| 251 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 252 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForBothHttpAndHttpsTest) { |
| 253 | OmahaResponse in; |
| 254 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 255 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 256 | in.payload_urls.push_back("http://test.should.still/need/hash.checks"); |
| 257 | in.payload_urls.push_back("https://test.should.still/need/hash.checks"); |
| 258 | in.more_info_url = "http://more/info"; |
| 259 | in.hash = "HASHj+"; |
| 260 | in.size = 12; |
| 261 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 262 | EXPECT_TRUE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 263 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 264 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 265 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
| 266 | } |
| 267 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 268 | TEST_F(OmahaResponseHandlerActionTest, ChangeToMoreStableChannelTest) { |
| 269 | OmahaResponse in; |
| 270 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 271 | in.version = "a.b.c.d"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 272 | in.payload_urls.push_back("https://MoreStableChannelTest"); |
| 273 | in.more_info_url = "http://more/info"; |
| 274 | in.hash = "HASHjk"; |
| 275 | in.size = 15; |
| 276 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame^] | 277 | // Create a uniquely named test directory. |
| 278 | string test_dir; |
| 279 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 280 | "omaha_response_handler_action-test-XXXXXX", &test_dir)); |
| 281 | |
| 282 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc")); |
| 283 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 284 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 285 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame^] | 286 | test_dir + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 287 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 288 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame^] | 289 | test_dir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 290 | "CHROMEOS_IS_POWERWASH_ALLOWED=true\n" |
| 291 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 292 | |
| 293 | MockSystemState mock_system_state; |
| 294 | OmahaRequestParams params(&mock_system_state); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame^] | 295 | params.set_root(string("./") + test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 296 | params.SetLockDown(false); |
| 297 | params.Init("1.2.3.4", "", 0); |
| 298 | EXPECT_EQ("canary-channel", params.current_channel()); |
| 299 | EXPECT_EQ("stable-channel", params.target_channel()); |
| 300 | EXPECT_TRUE(params.to_more_stable_channel()); |
| 301 | EXPECT_TRUE(params.is_powerwash_allowed()); |
| 302 | |
| 303 | mock_system_state.set_request_params(¶ms); |
| 304 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 305 | EXPECT_TRUE(DoTestCommon(&mock_system_state, in, "/dev/sda5", "", |
| 306 | &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 307 | EXPECT_TRUE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame^] | 308 | |
| 309 | ASSERT_TRUE(utils::RecursiveUnlinkDir(test_dir)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | TEST_F(OmahaResponseHandlerActionTest, ChangeToLessStableChannelTest) { |
| 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://LessStableChannelTest"); |
| 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=stable-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_RELEASE_TRACK=canary-channel\n")); |
| 335 | |
| 336 | MockSystemState mock_system_state; |
| 337 | OmahaRequestParams params(&mock_system_state); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame^] | 338 | params.set_root(string("./") + test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 339 | params.SetLockDown(false); |
| 340 | params.Init("5.6.7.8", "", 0); |
| 341 | EXPECT_EQ("stable-channel", params.current_channel()); |
| 342 | params.SetTargetChannel("canary-channel", false); |
| 343 | EXPECT_EQ("canary-channel", params.target_channel()); |
| 344 | EXPECT_FALSE(params.to_more_stable_channel()); |
| 345 | EXPECT_FALSE(params.is_powerwash_allowed()); |
| 346 | |
| 347 | mock_system_state.set_request_params(¶ms); |
| 348 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 349 | EXPECT_TRUE(DoTestCommon(&mock_system_state, in, "/dev/sda5", "", |
| 350 | &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 351 | EXPECT_FALSE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame^] | 352 | |
| 353 | ASSERT_TRUE(utils::RecursiveUnlinkDir(test_dir)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 354 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 355 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 356 | } // namespace chromeos_update_engine |