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" |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 10 | #include "update_engine/fake_system_state.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 11 | #include "update_engine/omaha_response_handler_action.h" |
| 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. |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 25 | bool DoTestCommon(FakeSystemState* fake_system_state, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 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() |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 40 | : code_(ErrorCode::kError), |
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 { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 55 | const char* const kLongName = |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 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"; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 64 | const char* const kBadVersion = "don't update me"; |
| 65 | } // namespace |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 66 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 67 | bool OmahaResponseHandlerActionTest::DoTestCommon( |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 68 | FakeSystemState* fake_system_state, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 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); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 79 | if (in.update_exists && in.version != kBadVersion) { |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 80 | EXPECT_CALL(*(fake_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] : ""; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 86 | EXPECT_CALL(*(fake_system_state->mock_payload_state()), GetCurrentUrl()) |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 87 | .WillRepeatedly(Return(current_url)); |
| 88 | |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 89 | OmahaResponseHandlerAction response_handler_action( |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 90 | fake_system_state, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 91 | (test_deadline_file.empty() ? |
| 92 | OmahaResponseHandlerAction::kDeadlineFile : test_deadline_file)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 93 | response_handler_action.set_boot_device(boot_dev); |
| 94 | BondActions(&feeder_action, &response_handler_action); |
| 95 | ObjectCollectorAction<InstallPlan> collector_action; |
| 96 | BondActions(&response_handler_action, &collector_action); |
| 97 | processor.EnqueueAction(&feeder_action); |
| 98 | processor.EnqueueAction(&response_handler_action); |
| 99 | processor.EnqueueAction(&collector_action); |
| 100 | processor.StartProcessing(); |
| 101 | EXPECT_TRUE(!processor.IsRunning()) |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame^] | 102 | << "Update test to handle non-async actions"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 103 | if (out) |
| 104 | *out = collector_action.object(); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 105 | EXPECT_TRUE(delegate.code_set_); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 106 | return delegate.code_ == ErrorCode::kSuccess; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 109 | bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in, |
| 110 | const string& boot_dev, |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 111 | const string& deadline_file, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 112 | InstallPlan* out) { |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 113 | FakeSystemState fake_system_state; |
| 114 | return DoTestCommon(&fake_system_state, in, boot_dev, deadline_file, out); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 115 | } |
| 116 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 117 | TEST_F(OmahaResponseHandlerActionTest, SimpleTest) { |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 118 | string test_deadline_file; |
| 119 | CHECK(utils::MakeTempFile( |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 120 | "omaha_response_handler_action_unittest-XXXXXX", |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 121 | &test_deadline_file, NULL)); |
| 122 | ScopedPathUnlinker deadline_unlinker(test_deadline_file); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 123 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 124 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 125 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 126 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 127 | 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] | 128 | in.more_info_url = "http://more/info"; |
| 129 | in.hash = "HASH+"; |
| 130 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 131 | in.prompt = false; |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 132 | in.deadline = "20101020"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 133 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 134 | EXPECT_TRUE(DoTest(in, "/dev/sda3", test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 135 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 136 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 137 | EXPECT_EQ("/dev/sda5", install_plan.install_path); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 138 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 139 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 140 | EXPECT_EQ("20101020", deadline); |
| 141 | struct stat deadline_stat; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 142 | EXPECT_EQ(0, stat(test_deadline_file.c_str(), &deadline_stat)); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 143 | EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, |
| 144 | deadline_stat.st_mode); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 145 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 146 | } |
| 147 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 148 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 149 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 150 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 151 | 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] | 152 | in.more_info_url = "http://more/info"; |
| 153 | in.hash = "HASHj+"; |
| 154 | in.size = 12; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 155 | in.prompt = true; |
| 156 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 157 | EXPECT_TRUE(DoTest(in, "/dev/sda5", test_deadline_file, &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 158 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 159 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 160 | EXPECT_EQ("/dev/sda3", install_plan.install_path); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 161 | string deadline; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 162 | EXPECT_TRUE(utils::ReadFile(test_deadline_file, &deadline) && |
| 163 | deadline.empty()); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 164 | EXPECT_EQ(in.version, install_plan.version); |
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); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 184 | EXPECT_EQ(in.version, install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 189 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 190 | in.update_exists = false; |
| 191 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 192 | EXPECT_FALSE(DoTest(in, "/dev/sda1", "", &install_plan)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 193 | EXPECT_EQ("", install_plan.download_url); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 194 | EXPECT_EQ("", install_plan.payload_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 195 | EXPECT_EQ("", install_plan.install_path); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 196 | EXPECT_EQ("", install_plan.version); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 199 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpTest) { |
| 200 | OmahaResponse in; |
| 201 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 202 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 203 | in.payload_urls.push_back("http://test.should/need/hash.checks.signed"); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 204 | in.more_info_url = "http://more/info"; |
| 205 | in.hash = "HASHj+"; |
| 206 | in.size = 12; |
| 207 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 208 | EXPECT_TRUE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 209 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 210 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 211 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 212 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpsTest) { |
| 216 | OmahaResponse in; |
| 217 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 218 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 219 | 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] | 220 | in.more_info_url = "http://more/info"; |
| 221 | in.hash = "HASHj+"; |
| 222 | in.size = 12; |
| 223 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 224 | EXPECT_TRUE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 225 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 226 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 227 | EXPECT_FALSE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 228 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 231 | TEST_F(OmahaResponseHandlerActionTest, HashChecksForBothHttpAndHttpsTest) { |
| 232 | OmahaResponse in; |
| 233 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 234 | in.version = "a.b.c.d"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 235 | in.payload_urls.push_back("http://test.should.still/need/hash.checks"); |
| 236 | in.payload_urls.push_back("https://test.should.still/need/hash.checks"); |
| 237 | in.more_info_url = "http://more/info"; |
| 238 | in.hash = "HASHj+"; |
| 239 | in.size = 12; |
| 240 | InstallPlan install_plan; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 241 | EXPECT_TRUE(DoTest(in, "/dev/sda5", "", &install_plan)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 242 | EXPECT_EQ(in.payload_urls[0], install_plan.download_url); |
| 243 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 244 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 245 | EXPECT_EQ(in.version, install_plan.version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 248 | TEST_F(OmahaResponseHandlerActionTest, ChangeToMoreStableChannelTest) { |
| 249 | OmahaResponse in; |
| 250 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 251 | in.version = "a.b.c.d"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 252 | in.payload_urls.push_back("https://MoreStableChannelTest"); |
| 253 | in.more_info_url = "http://more/info"; |
| 254 | in.hash = "HASHjk"; |
| 255 | in.size = 15; |
| 256 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 257 | // Create a uniquely named test directory. |
| 258 | string test_dir; |
| 259 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 260 | "omaha_response_handler_action-test-XXXXXX", &test_dir)); |
| 261 | |
| 262 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc")); |
| 263 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 264 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 265 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 266 | test_dir + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 267 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 268 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 269 | test_dir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 270 | "CHROMEOS_IS_POWERWASH_ALLOWED=true\n" |
| 271 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 272 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 273 | FakeSystemState fake_system_state; |
| 274 | OmahaRequestParams params(&fake_system_state); |
Gilad Arnold | d04f8e2 | 2014-01-09 13:13:40 -0800 | [diff] [blame] | 275 | params.set_root(test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 276 | params.SetLockDown(false); |
| 277 | params.Init("1.2.3.4", "", 0); |
| 278 | EXPECT_EQ("canary-channel", params.current_channel()); |
| 279 | EXPECT_EQ("stable-channel", params.target_channel()); |
| 280 | EXPECT_TRUE(params.to_more_stable_channel()); |
| 281 | EXPECT_TRUE(params.is_powerwash_allowed()); |
| 282 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 283 | fake_system_state.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 284 | InstallPlan install_plan; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 285 | EXPECT_TRUE(DoTestCommon(&fake_system_state, in, "/dev/sda5", "", |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 286 | &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 287 | EXPECT_TRUE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 288 | |
| 289 | ASSERT_TRUE(utils::RecursiveUnlinkDir(test_dir)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | TEST_F(OmahaResponseHandlerActionTest, ChangeToLessStableChannelTest) { |
| 293 | OmahaResponse in; |
| 294 | in.update_exists = true; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 295 | in.version = "a.b.c.d"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 296 | in.payload_urls.push_back("https://LessStableChannelTest"); |
| 297 | in.more_info_url = "http://more/info"; |
| 298 | in.hash = "HASHjk"; |
| 299 | in.size = 15; |
| 300 | |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 301 | // Create a uniquely named test directory. |
| 302 | string test_dir; |
| 303 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 304 | "omaha_response_handler_action-test-XXXXXX", &test_dir)); |
| 305 | |
| 306 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc")); |
| 307 | ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 308 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 309 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 310 | test_dir + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 311 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 312 | ASSERT_TRUE(WriteFileString( |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 313 | test_dir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 314 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 315 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 316 | FakeSystemState fake_system_state; |
| 317 | OmahaRequestParams params(&fake_system_state); |
Gilad Arnold | d04f8e2 | 2014-01-09 13:13:40 -0800 | [diff] [blame] | 318 | params.set_root(test_dir); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 319 | params.SetLockDown(false); |
| 320 | params.Init("5.6.7.8", "", 0); |
| 321 | EXPECT_EQ("stable-channel", params.current_channel()); |
| 322 | params.SetTargetChannel("canary-channel", false); |
| 323 | EXPECT_EQ("canary-channel", params.target_channel()); |
| 324 | EXPECT_FALSE(params.to_more_stable_channel()); |
| 325 | EXPECT_FALSE(params.is_powerwash_allowed()); |
| 326 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 327 | fake_system_state.set_request_params(¶ms); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 328 | InstallPlan install_plan; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 329 | EXPECT_TRUE(DoTestCommon(&fake_system_state, in, "/dev/sda5", "", |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 330 | &install_plan)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 331 | EXPECT_FALSE(install_plan.powerwash_required); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 332 | |
| 333 | ASSERT_TRUE(utils::RecursiveUnlinkDir(test_dir)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 334 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 335 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 336 | TEST_F(OmahaResponseHandlerActionTest, P2PUrlIsUsedAndHashChecksMandatory) { |
| 337 | OmahaResponse in; |
| 338 | in.update_exists = true; |
| 339 | in.version = "a.b.c.d"; |
| 340 | in.payload_urls.push_back("https://would.not/cause/hash/checks"); |
| 341 | in.more_info_url = "http://more/info"; |
| 342 | in.hash = "HASHj+"; |
| 343 | in.size = 12; |
| 344 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 345 | FakeSystemState fake_system_state; |
| 346 | OmahaRequestParams params(&fake_system_state); |
| 347 | fake_system_state.set_request_params(¶ms); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 348 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 349 | EXPECT_CALL(*fake_system_state.mock_payload_state(), |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 350 | SetUsingP2PForDownloading(true)); |
| 351 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 352 | string p2p_url = "http://9.8.7.6/p2p"; |
| 353 | params.set_p2p_url(p2p_url); |
| 354 | params.set_use_p2p_for_downloading(true); |
| 355 | |
| 356 | InstallPlan install_plan; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 357 | EXPECT_TRUE(DoTestCommon(&fake_system_state, in, "/dev/sda5", "", |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 358 | &install_plan)); |
| 359 | EXPECT_EQ(in.hash, install_plan.payload_hash); |
| 360 | EXPECT_EQ(install_plan.download_url, p2p_url); |
| 361 | EXPECT_TRUE(install_plan.hash_checks_mandatory); |
| 362 | } |
| 363 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 364 | } // namespace chromeos_update_engine |