OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 #include <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
8 #include "update_engine/install_plan.h" | 8 #include "update_engine/install_plan.h" |
9 #include "update_engine/omaha_request_prep_action.h" | 9 #include "update_engine/omaha_request_prep_action.h" |
10 #include "update_engine/test_utils.h" | 10 #include "update_engine/test_utils.h" |
11 #include "update_engine/utils.h" | 11 #include "update_engine/utils.h" |
12 | 12 |
13 using std::string; | 13 using std::string; |
14 | 14 |
15 namespace chromeos_update_engine { | 15 namespace chromeos_update_engine { |
16 | 16 |
17 class OmahaRequestPrepActionTest : public ::testing::Test { | 17 class OmahaRequestPrepActionTest : public ::testing::Test { |
18 public: | 18 public: |
19 // Return true iff the OmahaResponseHandlerAction succeeded. | 19 // Return true iff the OmahaResponseHandlerAction succeeded. |
20 // if out is non-NULL, it's set w/ the response from the action. | 20 // if out is non-NULL, it's set w/ the response from the action. |
21 bool DoTest(bool force_full_update, UpdateCheckParams* out); | 21 bool DoTest(bool force_full_update, OmahaRequestParams* out); |
22 static const string kTestDir; | 22 static const string kTestDir; |
23 }; | 23 }; |
24 | 24 |
25 const string OmahaRequestPrepActionTest::kTestDir = "request_prep_action-test"; | 25 const string OmahaRequestPrepActionTest::kTestDir = "request_prep_action-test"; |
26 | 26 |
27 class OmahaRequestPrepActionProcessorDelegate | 27 class OmahaRequestPrepActionProcessorDelegate |
28 : public ActionProcessorDelegate { | 28 : public ActionProcessorDelegate { |
29 public: | 29 public: |
30 OmahaRequestPrepActionProcessorDelegate() | 30 OmahaRequestPrepActionProcessorDelegate() |
31 : success_(false), | 31 : success_(false), |
32 success_set_(false) {} | 32 success_set_(false) {} |
33 void ActionCompleted(ActionProcessor* processor, | 33 void ActionCompleted(ActionProcessor* processor, |
34 AbstractAction* action, | 34 AbstractAction* action, |
35 bool success) { | 35 bool success) { |
36 if (action->Type() == OmahaRequestPrepAction::StaticType()) { | 36 if (action->Type() == OmahaRequestPrepAction::StaticType()) { |
37 success_ = success; | 37 success_ = success; |
38 success_set_ = true; | 38 success_set_ = true; |
39 } | 39 } |
40 } | 40 } |
41 bool success_; | 41 bool success_; |
42 bool success_set_; | 42 bool success_set_; |
43 }; | 43 }; |
44 | 44 |
45 bool OmahaRequestPrepActionTest::DoTest(bool force_full_update, | 45 bool OmahaRequestPrepActionTest::DoTest(bool force_full_update, |
46 UpdateCheckParams* out) { | 46 OmahaRequestParams* out) { |
47 ActionProcessor processor; | 47 ActionProcessor processor; |
48 OmahaRequestPrepActionProcessorDelegate delegate; | 48 OmahaRequestPrepActionProcessorDelegate delegate; |
49 processor.set_delegate(&delegate); | 49 processor.set_delegate(&delegate); |
50 | 50 |
51 OmahaRequestPrepAction request_prep_action(force_full_update); | 51 OmahaRequestPrepAction request_prep_action(force_full_update); |
52 request_prep_action.set_root(string("./") + kTestDir); | 52 request_prep_action.set_root(string("./") + kTestDir); |
53 ObjectCollectorAction<UpdateCheckParams> collector_action; | 53 ObjectCollectorAction<OmahaRequestParams> collector_action; |
54 BondActions(&request_prep_action, &collector_action); | 54 BondActions(&request_prep_action, &collector_action); |
55 processor.EnqueueAction(&request_prep_action); | 55 processor.EnqueueAction(&request_prep_action); |
56 processor.EnqueueAction(&collector_action); | 56 processor.EnqueueAction(&collector_action); |
57 processor.StartProcessing(); | 57 processor.StartProcessing(); |
58 EXPECT_TRUE(!processor.IsRunning()) | 58 EXPECT_TRUE(!processor.IsRunning()) |
59 << "Update test to handle non-asynch actions"; | 59 << "Update test to handle non-asynch actions"; |
60 if (out) | 60 if (out) |
61 *out = collector_action.object(); | 61 *out = collector_action.object(); |
62 EXPECT_TRUE(delegate.success_set_); | 62 EXPECT_TRUE(delegate.success_set_); |
63 return delegate.success_; | 63 return delegate.success_; |
64 } | 64 } |
65 | 65 |
66 namespace { | 66 namespace { |
67 bool IsHexDigit(char c) { | 67 bool IsHexDigit(char c) { |
68 return ((c >= '0') && (c <= '9')) || | 68 return ((c >= '0') && (c <= '9')) || |
69 ((c >= 'a') && (c <= 'f')) || | 69 ((c >= 'a') && (c <= 'f')) || |
70 ((c >= 'A') && (c <= 'F')); | 70 ((c >= 'A') && (c <= 'F')); |
71 } | 71 } |
72 | 72 |
73 // Returns true iff str is formatted as a GUID. Example GUID: | 73 // Returns true iff str is formatted as a GUID. Example GUID: |
74 // "{2251FFAD-DBAB-4E53-8B3A-18F98BB4EB80}" | 74 // "{2251FFAD-DBAB-4E53-8B3A-18F98BB4EB80}" |
75 bool IsValidGuid(const string& str) { | 75 bool IsValidGuid(const string& str) { |
76 TEST_AND_RETURN_FALSE(str.size() == 38); | 76 TEST_AND_RETURN_FALSE(str.size() == 38); |
77 TEST_AND_RETURN_FALSE((*str.begin() == '{') && (*str.rbegin() == '}')); | 77 TEST_AND_RETURN_FALSE((*str.begin() == '{') && (*str.rbegin() == '}')); |
78 for (string::size_type i = 1; i < (str.size() - 1); ++i) { | 78 for (string::size_type i = 1; i < (str.size() - 1); ++i) { |
79 if ((i == 9) || (i == 14) || (i == 19) || (i == 24)) { | 79 if ((i == 9) || (i == 14) || (i == 19) || (i == 24)) { |
80 TEST_AND_RETURN_FALSE(str[i] == '-'); | 80 TEST_AND_RETURN_FALSE(str[i] == '-'); |
81 } else { | 81 } else { |
82 TEST_AND_RETURN_FALSE(IsHexDigit(str[i])); | 82 TEST_AND_RETURN_FALSE(IsHexDigit(str[i])); |
(...skipping 25 matching lines...) Expand all Loading... |
108 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | 108 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
109 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | 109 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
110 utils::kStatefulPartition + "/etc")); | 110 utils::kStatefulPartition + "/etc")); |
111 { | 111 { |
112 ASSERT_TRUE(WriteFileString( | 112 ASSERT_TRUE(WriteFileString( |
113 kTestDir + "/etc/lsb-release", | 113 kTestDir + "/etc/lsb-release", |
114 "CHROMEOS_RELEASE_BOARD=arm-generic\n" | 114 "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
115 "CHROMEOS_RELEASE_FOO=bar\n" | 115 "CHROMEOS_RELEASE_FOO=bar\n" |
116 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 116 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
117 "CHROMEOS_RELEASE_TRACK=footrack")); | 117 "CHROMEOS_RELEASE_TRACK=footrack")); |
118 UpdateCheckParams out; | 118 OmahaRequestParams out; |
119 EXPECT_TRUE(DoTest(false, &out)); | 119 EXPECT_TRUE(DoTest(false, &out)); |
120 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; | 120 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; |
121 // for now we're just using the machine id here | 121 // for now we're just using the machine id here |
122 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; | 122 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; |
123 EXPECT_EQ("Chrome OS", out.os_platform); | 123 EXPECT_EQ("Chrome OS", out.os_platform); |
124 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); | 124 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
125 EXPECT_EQ("arm-generic", out.os_board); | 125 EXPECT_EQ("arm-generic", out.os_board); |
126 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); | 126 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
127 EXPECT_EQ("0.2.2.3", out.app_version); | 127 EXPECT_EQ("0.2.2.3", out.app_version); |
128 EXPECT_EQ("en-US", out.app_lang); | 128 EXPECT_EQ("en-US", out.app_lang); |
129 EXPECT_EQ("footrack", out.app_track); | 129 EXPECT_EQ("footrack", out.app_track); |
130 } | 130 } |
131 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | 131 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
132 } | 132 } |
133 | 133 |
134 TEST_F(OmahaRequestPrepActionTest, MissingTrackTest) { | 134 TEST_F(OmahaRequestPrepActionTest, MissingTrackTest) { |
135 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | 135 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
136 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | 136 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
137 utils::kStatefulPartition + "/etc")); | 137 utils::kStatefulPartition + "/etc")); |
138 { | 138 { |
139 ASSERT_TRUE(WriteFileString( | 139 ASSERT_TRUE(WriteFileString( |
140 kTestDir + "/etc/lsb-release", | 140 kTestDir + "/etc/lsb-release", |
141 "CHROMEOS_RELEASE_FOO=bar\n" | 141 "CHROMEOS_RELEASE_FOO=bar\n" |
142 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 142 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
143 "CHROMEOS_RELEASE_TRXCK=footrack")); | 143 "CHROMEOS_RELEASE_TRXCK=footrack")); |
144 UpdateCheckParams out; | 144 OmahaRequestParams out; |
145 EXPECT_TRUE(DoTest(false, &out)); | 145 EXPECT_TRUE(DoTest(false, &out)); |
146 EXPECT_TRUE(IsValidGuid(out.machine_id)); | 146 EXPECT_TRUE(IsValidGuid(out.machine_id)); |
147 // for now we're just using the machine id here | 147 // for now we're just using the machine id here |
148 EXPECT_TRUE(IsValidGuid(out.user_id)); | 148 EXPECT_TRUE(IsValidGuid(out.user_id)); |
149 EXPECT_EQ("Chrome OS", out.os_platform); | 149 EXPECT_EQ("Chrome OS", out.os_platform); |
150 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); | 150 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
151 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); | 151 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
152 EXPECT_EQ("0.2.2.3", out.app_version); | 152 EXPECT_EQ("0.2.2.3", out.app_version); |
153 EXPECT_EQ("en-US", out.app_lang); | 153 EXPECT_EQ("en-US", out.app_lang); |
154 EXPECT_EQ("", out.app_track); | 154 EXPECT_EQ("", out.app_track); |
155 } | 155 } |
156 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | 156 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
157 } | 157 } |
158 | 158 |
159 TEST_F(OmahaRequestPrepActionTest, ConfusingReleaseTest) { | 159 TEST_F(OmahaRequestPrepActionTest, ConfusingReleaseTest) { |
160 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | 160 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
161 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | 161 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
162 utils::kStatefulPartition + "/etc")); | 162 utils::kStatefulPartition + "/etc")); |
163 { | 163 { |
164 ASSERT_TRUE(WriteFileString( | 164 ASSERT_TRUE(WriteFileString( |
165 kTestDir + "/etc/lsb-release", | 165 kTestDir + "/etc/lsb-release", |
166 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" | 166 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
167 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 167 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
168 "CHROMEOS_RELEASE_TRXCK=footrack")); | 168 "CHROMEOS_RELEASE_TRXCK=footrack")); |
169 UpdateCheckParams out; | 169 OmahaRequestParams out; |
170 EXPECT_TRUE(DoTest(false, &out)); | 170 EXPECT_TRUE(DoTest(false, &out)); |
171 EXPECT_TRUE(IsValidGuid(out.machine_id)) << out.machine_id; | 171 EXPECT_TRUE(IsValidGuid(out.machine_id)) << out.machine_id; |
172 // for now we're just using the machine id here | 172 // for now we're just using the machine id here |
173 EXPECT_TRUE(IsValidGuid(out.user_id)); | 173 EXPECT_TRUE(IsValidGuid(out.user_id)); |
174 EXPECT_EQ("Chrome OS", out.os_platform); | 174 EXPECT_EQ("Chrome OS", out.os_platform); |
175 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); | 175 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
176 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); | 176 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
177 EXPECT_EQ("0.2.2.3", out.app_version); | 177 EXPECT_EQ("0.2.2.3", out.app_version); |
178 EXPECT_EQ("en-US", out.app_lang); | 178 EXPECT_EQ("en-US", out.app_lang); |
179 EXPECT_EQ("", out.app_track); | 179 EXPECT_EQ("", out.app_track); |
180 } | 180 } |
181 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | 181 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
182 } | 182 } |
183 | 183 |
184 TEST_F(OmahaRequestPrepActionTest, MachineIdPersistsTest) { | 184 TEST_F(OmahaRequestPrepActionTest, MachineIdPersistsTest) { |
185 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | 185 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
186 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | 186 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
187 utils::kStatefulPartition + "/etc")); | 187 utils::kStatefulPartition + "/etc")); |
188 ASSERT_TRUE(WriteFileString( | 188 ASSERT_TRUE(WriteFileString( |
189 kTestDir + "/etc/lsb-release", | 189 kTestDir + "/etc/lsb-release", |
190 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" | 190 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
191 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 191 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
192 "CHROMEOS_RELEASE_TRXCK=footrack")); | 192 "CHROMEOS_RELEASE_TRXCK=footrack")); |
193 UpdateCheckParams out1; | 193 OmahaRequestParams out1; |
194 EXPECT_TRUE(DoTest(false, &out1)); | 194 EXPECT_TRUE(DoTest(false, &out1)); |
195 string machine_id; | 195 string machine_id; |
196 EXPECT_TRUE(utils::ReadFileToString( | 196 EXPECT_TRUE(utils::ReadFileToString( |
197 kTestDir + | 197 kTestDir + |
198 utils::kStatefulPartition + "/etc/omaha_id", | 198 utils::kStatefulPartition + "/etc/omaha_id", |
199 &machine_id)); | 199 &machine_id)); |
200 EXPECT_EQ(machine_id, out1.machine_id); | 200 EXPECT_EQ(machine_id, out1.machine_id); |
201 UpdateCheckParams out2; | 201 OmahaRequestParams out2; |
202 EXPECT_TRUE(DoTest(false, &out2)); | 202 EXPECT_TRUE(DoTest(false, &out2)); |
203 EXPECT_EQ(machine_id, out2.machine_id); | 203 EXPECT_EQ(machine_id, out2.machine_id); |
204 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | 204 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
205 } | 205 } |
206 | 206 |
207 } // namespace chromeos_update_engine | 207 } // namespace chromeos_update_engine |
OLD | NEW |