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