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