OLD | NEW |
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 <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_params.h" | 9 #include "update_engine/omaha_request_params.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 OmahaRequestDeviceParamsTest : public ::testing::Test { | 17 class OmahaRequestDeviceParamsTest : public ::testing::Test { |
18 public: | 18 protected: |
19 // Return true iff the OmahaRequestDeviceParams::Init succeeded. If | 19 // Return true iff the OmahaRequestDeviceParams::Init succeeded. If |
20 // out is non-NULL, it's set w/ the generated data. | 20 // out is non-NULL, it's set w/ the generated data. |
21 bool DoTest(OmahaRequestParams* out); | 21 bool DoTest(OmahaRequestParams* out, const string& app_version, |
| 22 const string& omaha_url); |
| 23 |
| 24 virtual void SetUp() { |
| 25 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
| 26 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
| 27 utils::kStatefulPartition + "/etc")); |
| 28 } |
| 29 |
| 30 virtual void TearDown() { |
| 31 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
| 32 } |
| 33 |
22 static const string kTestDir; | 34 static const string kTestDir; |
23 }; | 35 }; |
24 | 36 |
25 const string OmahaRequestDeviceParamsTest::kTestDir = | 37 const string OmahaRequestDeviceParamsTest::kTestDir = |
26 "omaha_request_device_params-test"; | 38 "omaha_request_device_params-test"; |
27 | 39 |
28 bool OmahaRequestDeviceParamsTest::DoTest(OmahaRequestParams* out) { | 40 bool OmahaRequestDeviceParamsTest::DoTest(OmahaRequestParams* out, |
| 41 const string& app_version, |
| 42 const string& omaha_url) { |
29 OmahaRequestDeviceParams params; | 43 OmahaRequestDeviceParams params; |
30 params.set_root(string("./") + kTestDir); | 44 params.set_root(string("./") + kTestDir); |
31 bool success = params.Init(); | 45 bool success = params.Init(app_version, omaha_url); |
32 if (out) | 46 if (out) |
33 *out = params; | 47 *out = params; |
34 return success; | 48 return success; |
35 } | 49 } |
36 | 50 |
37 namespace { | 51 namespace { |
38 bool IsHexDigit(char c) { | 52 bool IsHexDigit(char c) { |
39 return ((c >= '0') && (c <= '9')) || | 53 return ((c >= '0') && (c <= '9')) || |
40 ((c >= 'a') && (c <= 'f')) || | 54 ((c >= 'a') && (c <= 'f')) || |
41 ((c >= 'A') && (c <= 'F')); | 55 ((c >= 'A') && (c <= 'F')); |
(...skipping 28 matching lines...) Expand all Loading... |
70 } | 84 } |
71 // strip trailing '\n' if it exists | 85 // strip trailing '\n' if it exists |
72 if ((*ret.rbegin()) == '\n') | 86 if ((*ret.rbegin()) == '\n') |
73 ret.resize(ret.size() - 1); | 87 ret.resize(ret.size() - 1); |
74 fclose(fp); | 88 fclose(fp); |
75 return ret; | 89 return ret; |
76 } | 90 } |
77 } // namespace {} | 91 } // namespace {} |
78 | 92 |
79 TEST_F(OmahaRequestDeviceParamsTest, SimpleTest) { | 93 TEST_F(OmahaRequestDeviceParamsTest, SimpleTest) { |
80 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | 94 ASSERT_TRUE(WriteFileString( |
81 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | 95 kTestDir + "/etc/lsb-release", |
82 utils::kStatefulPartition + "/etc")); | 96 "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
83 { | 97 "CHROMEOS_RELEASE_FOO=bar\n" |
84 ASSERT_TRUE(WriteFileString( | 98 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
85 kTestDir + "/etc/lsb-release", | 99 "CHROMEOS_RELEASE_TRACK=footrack\n" |
86 "CHROMEOS_RELEASE_BOARD=arm-generic\n" | 100 "CHROMEOS_AUSERVER=http://www.google.com")); |
87 "CHROMEOS_RELEASE_FOO=bar\n" | 101 OmahaRequestParams out; |
88 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 102 EXPECT_TRUE(DoTest(&out, "", "")); |
89 "CHROMEOS_RELEASE_TRACK=footrack")); | 103 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; |
90 OmahaRequestParams out; | 104 // for now we're just using the machine id here |
91 EXPECT_TRUE(DoTest(&out)); | 105 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; |
92 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; | 106 EXPECT_EQ("Chrome OS", out.os_platform); |
93 // for now we're just using the machine id here | 107 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
94 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; | 108 EXPECT_EQ("arm-generic", out.os_board); |
95 EXPECT_EQ("Chrome OS", out.os_platform); | 109 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
96 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); | 110 EXPECT_EQ("0.2.2.3", out.app_version); |
97 EXPECT_EQ("arm-generic", out.os_board); | 111 EXPECT_EQ("en-US", out.app_lang); |
98 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); | 112 EXPECT_TRUE(out.delta_okay); |
99 EXPECT_EQ("0.2.2.3", out.app_version); | 113 EXPECT_EQ("footrack", out.app_track); |
100 EXPECT_EQ("en-US", out.app_lang); | 114 EXPECT_EQ("http://www.google.com", out.update_url); |
101 EXPECT_TRUE(out.delta_okay); | |
102 EXPECT_EQ("footrack", out.app_track); | |
103 } | |
104 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | |
105 } | 115 } |
106 | 116 |
107 TEST_F(OmahaRequestDeviceParamsTest, MissingTrackTest) { | 117 TEST_F(OmahaRequestDeviceParamsTest, MissingTrackTest) { |
108 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | 118 ASSERT_TRUE(WriteFileString( |
109 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | 119 kTestDir + "/etc/lsb-release", |
110 utils::kStatefulPartition + "/etc")); | 120 "CHROMEOS_RELEASE_FOO=bar\n" |
111 { | 121 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
112 ASSERT_TRUE(WriteFileString( | 122 "CHROMEOS_RELEASE_TRXCK=footrack")); |
113 kTestDir + "/etc/lsb-release", | 123 OmahaRequestParams out; |
114 "CHROMEOS_RELEASE_FOO=bar\n" | 124 EXPECT_TRUE(DoTest(&out, "", "")); |
115 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 125 EXPECT_TRUE(IsValidGuid(out.machine_id)); |
116 "CHROMEOS_RELEASE_TRXCK=footrack")); | 126 // for now we're just using the machine id here |
117 OmahaRequestParams out; | 127 EXPECT_TRUE(IsValidGuid(out.user_id)); |
118 EXPECT_TRUE(DoTest(&out)); | 128 EXPECT_EQ("Chrome OS", out.os_platform); |
119 EXPECT_TRUE(IsValidGuid(out.machine_id)); | 129 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
120 // for now we're just using the machine id here | 130 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
121 EXPECT_TRUE(IsValidGuid(out.user_id)); | 131 EXPECT_EQ("0.2.2.3", out.app_version); |
122 EXPECT_EQ("Chrome OS", out.os_platform); | 132 EXPECT_EQ("en-US", out.app_lang); |
123 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); | 133 EXPECT_EQ("", out.app_track); |
124 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); | |
125 EXPECT_EQ("0.2.2.3", out.app_version); | |
126 EXPECT_EQ("en-US", out.app_lang); | |
127 EXPECT_EQ("", out.app_track); | |
128 } | |
129 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | |
130 } | 134 } |
131 | 135 |
132 TEST_F(OmahaRequestDeviceParamsTest, ConfusingReleaseTest) { | 136 TEST_F(OmahaRequestDeviceParamsTest, ConfusingReleaseTest) { |
133 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | 137 ASSERT_TRUE(WriteFileString( |
134 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | 138 kTestDir + "/etc/lsb-release", |
135 utils::kStatefulPartition + "/etc")); | 139 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
136 { | 140 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
137 ASSERT_TRUE(WriteFileString( | 141 "CHROMEOS_RELEASE_TRXCK=footrack")); |
138 kTestDir + "/etc/lsb-release", | 142 OmahaRequestParams out; |
139 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" | 143 EXPECT_TRUE(DoTest(&out, "", "")); |
140 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 144 EXPECT_TRUE(IsValidGuid(out.machine_id)) << out.machine_id; |
141 "CHROMEOS_RELEASE_TRXCK=footrack")); | 145 // for now we're just using the machine id here |
142 OmahaRequestParams out; | 146 EXPECT_TRUE(IsValidGuid(out.user_id)); |
143 EXPECT_TRUE(DoTest(&out)); | 147 EXPECT_EQ("Chrome OS", out.os_platform); |
144 EXPECT_TRUE(IsValidGuid(out.machine_id)) << out.machine_id; | 148 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
145 // for now we're just using the machine id here | 149 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
146 EXPECT_TRUE(IsValidGuid(out.user_id)); | 150 EXPECT_EQ("0.2.2.3", out.app_version); |
147 EXPECT_EQ("Chrome OS", out.os_platform); | 151 EXPECT_EQ("en-US", out.app_lang); |
148 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); | 152 EXPECT_EQ("", out.app_track); |
149 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); | |
150 EXPECT_EQ("0.2.2.3", out.app_version); | |
151 EXPECT_EQ("en-US", out.app_lang); | |
152 EXPECT_EQ("", out.app_track); | |
153 } | |
154 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | |
155 } | 153 } |
156 | 154 |
157 TEST_F(OmahaRequestDeviceParamsTest, MachineIdPersistsTest) { | 155 TEST_F(OmahaRequestDeviceParamsTest, MachineIdPersistsTest) { |
158 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | |
159 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | |
160 utils::kStatefulPartition + "/etc")); | |
161 ASSERT_TRUE(WriteFileString( | 156 ASSERT_TRUE(WriteFileString( |
162 kTestDir + "/etc/lsb-release", | 157 kTestDir + "/etc/lsb-release", |
163 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" | 158 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
164 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 159 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
165 "CHROMEOS_RELEASE_TRXCK=footrack")); | 160 "CHROMEOS_RELEASE_TRXCK=footrack")); |
166 OmahaRequestParams out1; | 161 OmahaRequestParams out1; |
167 EXPECT_TRUE(DoTest(&out1)); | 162 EXPECT_TRUE(DoTest(&out1, "", "")); |
168 string machine_id; | 163 string machine_id; |
169 EXPECT_TRUE(utils::ReadFileToString( | 164 EXPECT_TRUE(utils::ReadFileToString( |
170 kTestDir + | 165 kTestDir + |
171 utils::kStatefulPartition + "/etc/omaha_id", | 166 utils::kStatefulPartition + "/etc/omaha_id", |
172 &machine_id)); | 167 &machine_id)); |
173 EXPECT_EQ(machine_id, out1.machine_id); | 168 EXPECT_EQ(machine_id, out1.machine_id); |
174 OmahaRequestParams out2; | 169 OmahaRequestParams out2; |
175 EXPECT_TRUE(DoTest(&out2)); | 170 EXPECT_TRUE(DoTest(&out2, "", "")); |
176 EXPECT_EQ(machine_id, out2.machine_id); | 171 EXPECT_EQ(machine_id, out2.machine_id); |
177 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | 172 } |
| 173 |
| 174 TEST_F(OmahaRequestDeviceParamsTest, MissingVersionTest) { |
| 175 ASSERT_TRUE(WriteFileString( |
| 176 kTestDir + "/etc/lsb-release", |
| 177 "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 178 "CHROMEOS_RELEASE_FOO=bar\n" |
| 179 "CHROMEOS_RELEASE_TRACK=footrack")); |
| 180 OmahaRequestParams out; |
| 181 EXPECT_TRUE(DoTest(&out, "", "")); |
| 182 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; |
| 183 // for now we're just using the machine id here |
| 184 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; |
| 185 EXPECT_EQ("Chrome OS", out.os_platform); |
| 186 EXPECT_EQ(string("_") + GetMachineType(), out.os_sp); |
| 187 EXPECT_EQ("arm-generic", out.os_board); |
| 188 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 189 EXPECT_EQ("", out.app_version); |
| 190 EXPECT_EQ("en-US", out.app_lang); |
| 191 EXPECT_TRUE(out.delta_okay); |
| 192 EXPECT_EQ("footrack", out.app_track); |
| 193 } |
| 194 |
| 195 TEST_F(OmahaRequestDeviceParamsTest, ForceVersionTest) { |
| 196 ASSERT_TRUE(WriteFileString( |
| 197 kTestDir + "/etc/lsb-release", |
| 198 "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 199 "CHROMEOS_RELEASE_FOO=bar\n" |
| 200 "CHROMEOS_RELEASE_TRACK=footrack")); |
| 201 OmahaRequestParams out; |
| 202 EXPECT_TRUE(DoTest(&out, "ForcedVersion", "")); |
| 203 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; |
| 204 // for now we're just using the machine id here |
| 205 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; |
| 206 EXPECT_EQ("Chrome OS", out.os_platform); |
| 207 EXPECT_EQ(string("ForcedVersion_") + GetMachineType(), out.os_sp); |
| 208 EXPECT_EQ("arm-generic", out.os_board); |
| 209 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 210 EXPECT_EQ("ForcedVersion", out.app_version); |
| 211 EXPECT_EQ("en-US", out.app_lang); |
| 212 EXPECT_TRUE(out.delta_okay); |
| 213 EXPECT_EQ("footrack", out.app_track); |
| 214 } |
| 215 |
| 216 TEST_F(OmahaRequestDeviceParamsTest, ForcedURLTest) { |
| 217 ASSERT_TRUE(WriteFileString( |
| 218 kTestDir + "/etc/lsb-release", |
| 219 "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 220 "CHROMEOS_RELEASE_FOO=bar\n" |
| 221 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 222 "CHROMEOS_RELEASE_TRACK=footrack")); |
| 223 OmahaRequestParams out; |
| 224 EXPECT_TRUE(DoTest(&out, "", "http://forced.google.com")); |
| 225 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; |
| 226 // for now we're just using the machine id here |
| 227 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; |
| 228 EXPECT_EQ("Chrome OS", out.os_platform); |
| 229 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 230 EXPECT_EQ("arm-generic", out.os_board); |
| 231 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 232 EXPECT_EQ("0.2.2.3", out.app_version); |
| 233 EXPECT_EQ("en-US", out.app_lang); |
| 234 EXPECT_TRUE(out.delta_okay); |
| 235 EXPECT_EQ("footrack", out.app_track); |
| 236 EXPECT_EQ("http://forced.google.com", out.update_url); |
| 237 } |
| 238 |
| 239 TEST_F(OmahaRequestDeviceParamsTest, MissingURLTest) { |
| 240 ASSERT_TRUE(WriteFileString( |
| 241 kTestDir + "/etc/lsb-release", |
| 242 "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 243 "CHROMEOS_RELEASE_FOO=bar\n" |
| 244 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 245 "CHROMEOS_RELEASE_TRACK=footrack")); |
| 246 OmahaRequestParams out; |
| 247 EXPECT_TRUE(DoTest(&out, "", "")); |
| 248 EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id; |
| 249 // for now we're just using the machine id here |
| 250 EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id; |
| 251 EXPECT_EQ("Chrome OS", out.os_platform); |
| 252 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 253 EXPECT_EQ("arm-generic", out.os_board); |
| 254 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 255 EXPECT_EQ("0.2.2.3", out.app_version); |
| 256 EXPECT_EQ("en-US", out.app_lang); |
| 257 EXPECT_TRUE(out.delta_okay); |
| 258 EXPECT_EQ("footrack", out.app_track); |
| 259 EXPECT_EQ(OmahaRequestParams::kUpdateUrl, out.update_url); |
178 } | 260 } |
179 | 261 |
180 TEST_F(OmahaRequestDeviceParamsTest, NoDeltasTest) { | 262 TEST_F(OmahaRequestDeviceParamsTest, NoDeltasTest) { |
181 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); | |
182 ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + | |
183 utils::kStatefulPartition + "/etc")); | |
184 ASSERT_TRUE(WriteFileString( | 263 ASSERT_TRUE(WriteFileString( |
185 kTestDir + "/etc/lsb-release", | 264 kTestDir + "/etc/lsb-release", |
186 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" | 265 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
187 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" | 266 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
188 "CHROMEOS_RELEASE_TRXCK=footrack")); | 267 "CHROMEOS_RELEASE_TRXCK=footrack")); |
189 ASSERT_TRUE(WriteFileString(kTestDir + "/.nodelta", "")); | 268 ASSERT_TRUE(WriteFileString(kTestDir + "/.nodelta", "")); |
190 OmahaRequestParams out; | 269 OmahaRequestParams out; |
191 EXPECT_TRUE(DoTest(&out)); | 270 EXPECT_TRUE(DoTest(&out, "", "")); |
192 EXPECT_FALSE(out.delta_okay); | 271 EXPECT_FALSE(out.delta_okay); |
193 EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); | |
194 } | 272 } |
195 | 273 |
196 } // namespace chromeos_update_engine | 274 } // namespace chromeos_update_engine |
OLD | NEW |