Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: omaha_response_handler_action_unittest.cc

Issue 6574009: If a public key is present, disallow old style full payloads. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « omaha_response_handler_action.cc ('k') | update_attempter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
8 8
9 #include "update_engine/omaha_response_handler_action.h" 9 #include "update_engine/omaha_response_handler_action.h"
10 #include "update_engine/prefs_mock.h" 10 #include "update_engine/prefs_mock.h"
11 #include "update_engine/test_utils.h" 11 #include "update_engine/test_utils.h"
12 #include "update_engine/utils.h" 12 #include "update_engine/utils.h"
13 13
14 using std::string; 14 using std::string;
15 using testing::NiceMock; 15 using testing::NiceMock;
16 using testing::Return; 16 using testing::Return;
17 17
18 namespace chromeos_update_engine { 18 namespace chromeos_update_engine {
19 19
20 class OmahaResponseHandlerActionTest : public ::testing::Test { 20 class OmahaResponseHandlerActionTest : public ::testing::Test {
21 public: 21 public:
22 // Return true iff the OmahaResponseHandlerAction succeeded. 22 // Return true iff the OmahaResponseHandlerAction succeeded.
23 // If out is non-NULL, it's set w/ the response from the action. 23 // If out is non-NULL, it's set w/ the response from the action.
24 bool DoTest(const OmahaResponse& in, 24 bool DoTest(const OmahaResponse& in,
25 const string& boot_dev, 25 const string& boot_dev,
26 bool test_key,
26 InstallPlan* out); 27 InstallPlan* out);
27 }; 28 };
28 29
29 class OmahaResponseHandlerActionProcessorDelegate 30 class OmahaResponseHandlerActionProcessorDelegate
30 : public ActionProcessorDelegate { 31 : public ActionProcessorDelegate {
31 public: 32 public:
32 OmahaResponseHandlerActionProcessorDelegate() 33 OmahaResponseHandlerActionProcessorDelegate()
33 : code_(kActionCodeError), 34 : code_(kActionCodeError),
34 code_set_(false) {} 35 code_set_(false) {}
35 void ActionCompleted(ActionProcessor* processor, 36 void ActionCompleted(ActionProcessor* processor,
(...skipping 15 matching lines...) Expand all
51 "very_long_name_and_no_slashes-very_long_name_and_no_slashes" 52 "very_long_name_and_no_slashes-very_long_name_and_no_slashes"
52 "very_long_name_and_no_slashes-very_long_name_and_no_slashes" 53 "very_long_name_and_no_slashes-very_long_name_and_no_slashes"
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"
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"
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"
56 "-the_update_a.b.c.d_DELTA_.tgz"; 57 "-the_update_a.b.c.d_DELTA_.tgz";
57 } // namespace {} 58 } // namespace {}
58 59
59 bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in, 60 bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in,
60 const string& boot_dev, 61 const string& boot_dev,
62 bool test_key,
61 InstallPlan* out) { 63 InstallPlan* out) {
62 ActionProcessor processor; 64 ActionProcessor processor;
63 OmahaResponseHandlerActionProcessorDelegate delegate; 65 OmahaResponseHandlerActionProcessorDelegate delegate;
64 processor.set_delegate(&delegate); 66 processor.set_delegate(&delegate);
65 67
66 ObjectFeederAction<OmahaResponse> feeder_action; 68 ObjectFeederAction<OmahaResponse> feeder_action;
67 feeder_action.set_obj(in); 69 feeder_action.set_obj(in);
68 NiceMock<PrefsMock> prefs; 70 NiceMock<PrefsMock> prefs;
69 if (in.update_exists) { 71 if (in.update_exists) {
70 EXPECT_CALL(prefs, SetString(kPrefsUpdateCheckResponseHash, in.hash)) 72 EXPECT_CALL(prefs, SetString(kPrefsUpdateCheckResponseHash, in.hash))
71 .WillOnce(Return(true)); 73 .WillOnce(Return(true));
72 } 74 }
73 OmahaResponseHandlerAction response_handler_action(&prefs); 75 OmahaResponseHandlerAction response_handler_action(&prefs);
76 if (test_key) {
77 response_handler_action.set_key_path("/dev/null");
78 }
74 response_handler_action.set_boot_device(boot_dev); 79 response_handler_action.set_boot_device(boot_dev);
75 BondActions(&feeder_action, &response_handler_action); 80 BondActions(&feeder_action, &response_handler_action);
76 ObjectCollectorAction<InstallPlan> collector_action; 81 ObjectCollectorAction<InstallPlan> collector_action;
77 BondActions(&response_handler_action, &collector_action); 82 BondActions(&response_handler_action, &collector_action);
78 processor.EnqueueAction(&feeder_action); 83 processor.EnqueueAction(&feeder_action);
79 processor.EnqueueAction(&response_handler_action); 84 processor.EnqueueAction(&response_handler_action);
80 processor.EnqueueAction(&collector_action); 85 processor.EnqueueAction(&collector_action);
81 processor.StartProcessing(); 86 processor.StartProcessing();
82 EXPECT_TRUE(!processor.IsRunning()) 87 EXPECT_TRUE(!processor.IsRunning())
83 << "Update test to handle non-asynch actions"; 88 << "Update test to handle non-asynch actions";
84 if (out) 89 if (out)
85 *out = collector_action.object(); 90 *out = collector_action.object();
86 EXPECT_TRUE(delegate.code_set_); 91 EXPECT_TRUE(delegate.code_set_);
87 return delegate.code_ == kActionCodeSuccess; 92 ActionExitCode expected_code = test_key ?
93 kActionCodeSignedDeltaPayloadExpectedError : kActionCodeSuccess;
94 return delegate.code_ == expected_code;
88 } 95 }
89 96
90 TEST_F(OmahaResponseHandlerActionTest, SimpleTest) { 97 TEST_F(OmahaResponseHandlerActionTest, SimpleTest) {
91 ScopedPathUnlinker deadline_unlinker( 98 ScopedPathUnlinker deadline_unlinker(
92 OmahaResponseHandlerAction::kDeadlineFile); 99 OmahaResponseHandlerAction::kDeadlineFile);
93 { 100 {
94 OmahaResponse in; 101 OmahaResponse in;
95 in.update_exists = true; 102 in.update_exists = true;
96 in.display_version = "a.b.c.d"; 103 in.display_version = "a.b.c.d";
97 in.codebase = "http://foo/the_update_a.b.c.d.tgz"; 104 in.codebase = "http://foo/the_update_a.b.c.d.tgz";
98 in.more_info_url = "http://more/info"; 105 in.more_info_url = "http://more/info";
99 in.hash = "HASH+"; 106 in.hash = "HASH+";
100 in.size = 12; 107 in.size = 12;
101 in.needs_admin = true; 108 in.needs_admin = true;
102 in.prompt = false; 109 in.prompt = false;
103 in.is_delta = false; 110 in.is_delta = false;
104 in.deadline = "20101020"; 111 in.deadline = "20101020";
105 InstallPlan install_plan; 112 InstallPlan install_plan;
106 EXPECT_TRUE(DoTest(in, "/dev/sda3", &install_plan)); 113 EXPECT_TRUE(DoTest(in, "/dev/sda3", false, &install_plan));
107 EXPECT_TRUE(install_plan.is_full_update); 114 EXPECT_TRUE(install_plan.is_full_update);
108 EXPECT_EQ(in.codebase, install_plan.download_url); 115 EXPECT_EQ(in.codebase, install_plan.download_url);
109 EXPECT_EQ(in.hash, install_plan.download_hash); 116 EXPECT_EQ(in.hash, install_plan.download_hash);
110 EXPECT_EQ("/dev/sda5", install_plan.install_path); 117 EXPECT_EQ("/dev/sda5", install_plan.install_path);
111 string deadline; 118 string deadline;
112 EXPECT_TRUE(utils::ReadFileToString( 119 EXPECT_TRUE(utils::ReadFileToString(
113 OmahaResponseHandlerAction::kDeadlineFile, 120 OmahaResponseHandlerAction::kDeadlineFile,
114 &deadline)); 121 &deadline));
115 EXPECT_EQ("20101020", deadline); 122 EXPECT_EQ("20101020", deadline);
116 struct stat deadline_stat; 123 struct stat deadline_stat;
117 EXPECT_EQ(0, stat(OmahaResponseHandlerAction::kDeadlineFile, 124 EXPECT_EQ(0, stat(OmahaResponseHandlerAction::kDeadlineFile,
118 &deadline_stat)); 125 &deadline_stat));
119 EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, 126 EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
120 deadline_stat.st_mode); 127 deadline_stat.st_mode);
121 } 128 }
122 { 129 {
123 OmahaResponse in; 130 OmahaResponse in;
124 in.update_exists = true; 131 in.update_exists = true;
125 in.display_version = "a.b.c.d"; 132 in.display_version = "a.b.c.d";
126 in.codebase = "http://foo/the_update_a.b.c.d.tgz"; 133 in.codebase = "http://foo/the_update_a.b.c.d.tgz";
127 in.more_info_url = "http://more/info"; 134 in.more_info_url = "http://more/info";
128 in.hash = "HASHj+"; 135 in.hash = "HASHj+";
129 in.size = 12; 136 in.size = 12;
130 in.needs_admin = true; 137 in.needs_admin = true;
131 in.prompt = true; 138 in.prompt = true;
132 in.is_delta = true; 139 in.is_delta = true;
133 InstallPlan install_plan; 140 InstallPlan install_plan;
134 EXPECT_TRUE(DoTest(in, "/dev/sda5", &install_plan)); 141 EXPECT_TRUE(DoTest(in, "/dev/sda5", false, &install_plan));
135 EXPECT_FALSE(install_plan.is_full_update); 142 EXPECT_FALSE(install_plan.is_full_update);
136 EXPECT_EQ(in.codebase, install_plan.download_url); 143 EXPECT_EQ(in.codebase, install_plan.download_url);
137 EXPECT_EQ(in.hash, install_plan.download_hash); 144 EXPECT_EQ(in.hash, install_plan.download_hash);
138 EXPECT_EQ("/dev/sda3", install_plan.install_path); 145 EXPECT_EQ("/dev/sda3", install_plan.install_path);
139 string deadline; 146 string deadline;
140 EXPECT_TRUE(utils::ReadFileToString( 147 EXPECT_TRUE(utils::ReadFileToString(
141 OmahaResponseHandlerAction::kDeadlineFile, 148 OmahaResponseHandlerAction::kDeadlineFile,
142 &deadline) && deadline.empty()); 149 &deadline) && deadline.empty());
143 } 150 }
144 { 151 {
145 OmahaResponse in; 152 OmahaResponse in;
146 in.update_exists = true; 153 in.update_exists = true;
147 in.display_version = "a.b.c.d"; 154 in.display_version = "a.b.c.d";
148 in.codebase = kLongName; 155 in.codebase = kLongName;
149 in.more_info_url = "http://more/info"; 156 in.more_info_url = "http://more/info";
150 in.hash = "HASHj+"; 157 in.hash = "HASHj+";
151 in.size = 12; 158 in.size = 12;
152 in.needs_admin = true; 159 in.needs_admin = true;
153 in.prompt = true; 160 in.prompt = true;
154 in.is_delta = false; 161 in.is_delta = false;
155 in.deadline = "some-deadline"; 162 in.deadline = "some-deadline";
156 InstallPlan install_plan; 163 InstallPlan install_plan;
157 EXPECT_TRUE(DoTest(in, "/dev/sda3", &install_plan)); 164 EXPECT_TRUE(DoTest(in, "/dev/sda3", false, &install_plan));
158 EXPECT_TRUE(install_plan.is_full_update); 165 EXPECT_TRUE(install_plan.is_full_update);
159 EXPECT_EQ(in.codebase, install_plan.download_url); 166 EXPECT_EQ(in.codebase, install_plan.download_url);
160 EXPECT_EQ(in.hash, install_plan.download_hash); 167 EXPECT_EQ(in.hash, install_plan.download_hash);
161 EXPECT_EQ("/dev/sda5", install_plan.install_path); 168 EXPECT_EQ("/dev/sda5", install_plan.install_path);
162 string deadline; 169 string deadline;
163 EXPECT_TRUE(utils::ReadFileToString( 170 EXPECT_TRUE(utils::ReadFileToString(
164 OmahaResponseHandlerAction::kDeadlineFile, 171 OmahaResponseHandlerAction::kDeadlineFile,
165 &deadline)); 172 &deadline));
166 EXPECT_EQ("some-deadline", deadline); 173 EXPECT_EQ("some-deadline", deadline);
167 } 174 }
168 } 175 }
169 176
177 TEST_F(OmahaResponseHandlerActionTest, PublicKeyOldStyleTest) {
178 OmahaResponse in;
179 in.update_exists = true;
180 in.codebase = "http://foo/the_update_a.b.c.d.tgz";
181 in.is_delta = false;
182 InstallPlan install_plan;
183 EXPECT_TRUE(DoTest(in, "/dev/sda3", true, &install_plan));
184 }
185
170 TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) { 186 TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) {
171 OmahaResponse in; 187 OmahaResponse in;
172 in.update_exists = false; 188 in.update_exists = false;
173 InstallPlan install_plan; 189 InstallPlan install_plan;
174 EXPECT_FALSE(DoTest(in, "/dev/sda1", &install_plan)); 190 EXPECT_FALSE(DoTest(in, "/dev/sda1", false, &install_plan));
175 EXPECT_FALSE(install_plan.is_full_update); 191 EXPECT_FALSE(install_plan.is_full_update);
176 EXPECT_EQ("", install_plan.download_url); 192 EXPECT_EQ("", install_plan.download_url);
177 EXPECT_EQ("", install_plan.download_hash); 193 EXPECT_EQ("", install_plan.download_hash);
178 EXPECT_EQ("", install_plan.install_path); 194 EXPECT_EQ("", install_plan.install_path);
179 } 195 }
180 196
181 } // namespace chromeos_update_engine 197 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « omaha_response_handler_action.cc ('k') | update_attempter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698