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