| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include <vector> | 6 #include <vector> |
| 7 |
| 7 #include <glib.h> | 8 #include <glib.h> |
| 8 #include <gtest/gtest.h> | 9 |
| 10 #include "base/string_util.h" |
| 11 #include "gtest/gtest.h" |
| 9 #include "update_engine/action_pipe.h" | 12 #include "update_engine/action_pipe.h" |
| 10 #include "update_engine/mock_http_fetcher.h" | 13 #include "update_engine/mock_http_fetcher.h" |
| 11 #include "update_engine/omaha_hash_calculator.h" | 14 #include "update_engine/omaha_hash_calculator.h" |
| 12 #include "update_engine/omaha_request_action.h" | 15 #include "update_engine/omaha_request_action.h" |
| 13 #include "update_engine/test_utils.h" | 16 #include "update_engine/test_utils.h" |
| 14 | 17 |
| 15 using std::string; | 18 using std::string; |
| 16 using std::vector; | 19 using std::vector; |
| 17 | 20 |
| 18 namespace chromeos_update_engine { | 21 namespace chromeos_update_engine { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 114 } |
| 112 std::string Type() const { return StaticType(); } | 115 std::string Type() const { return StaticType(); } |
| 113 bool has_input_object_; | 116 bool has_input_object_; |
| 114 OmahaResponse omaha_response_; | 117 OmahaResponse omaha_response_; |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 // returns true iff an output response was obtained from the | 120 // returns true iff an output response was obtained from the |
| 118 // OmahaRequestAction. out_response may be NULL. | 121 // OmahaRequestAction. out_response may be NULL. |
| 119 // out_post_data may be null; if non-null, the post-data received by the | 122 // out_post_data may be null; if non-null, the post-data received by the |
| 120 // mock HttpFetcher is returned. | 123 // mock HttpFetcher is returned. |
| 121 bool TestOmahaRequestAction(const OmahaRequestParams& params, | 124 bool TestUpdateCheck(const OmahaRequestParams& params, |
| 122 const string& http_response, | 125 const string& http_response, |
| 123 bool expected_success, | 126 bool expected_success, |
| 124 OmahaResponse* out_response, | 127 OmahaResponse* out_response, |
| 125 vector<char> *out_post_data) { | 128 vector<char>* out_post_data) { |
| 126 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 129 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 127 MockHttpFetcher *fetcher = new MockHttpFetcher(http_response.data(), | 130 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
| 128 http_response.size()); | 131 http_response.size()); |
| 129 ObjectFeederAction<OmahaRequestParams> feeder_action; | 132 ObjectFeederAction<OmahaRequestParams> feeder_action; |
| 130 OmahaRequestAction action(fetcher); // takes ownership of fetcher | 133 OmahaRequestAction action(NULL, fetcher); // takes ownership of fetcher |
| 131 OmahaRequestActionTestProcessorDelegate delegate; | 134 OmahaRequestActionTestProcessorDelegate delegate; |
| 132 delegate.loop_ = loop; | 135 delegate.loop_ = loop; |
| 133 delegate.expected_success_ = expected_success; | 136 delegate.expected_success_ = expected_success; |
| 134 ActionProcessor processor; | 137 ActionProcessor processor; |
| 135 feeder_action.set_obj(params); | 138 feeder_action.set_obj(params); |
| 136 processor.set_delegate(&delegate); | 139 processor.set_delegate(&delegate); |
| 137 processor.EnqueueAction(&feeder_action); | 140 processor.EnqueueAction(&feeder_action); |
| 138 processor.EnqueueAction(&action); | 141 processor.EnqueueAction(&action); |
| 139 | 142 |
| 140 OutputObjectCollectorAction collector_action; | 143 OutputObjectCollectorAction collector_action; |
| 141 | 144 |
| 142 BondActions(&feeder_action, &action); | 145 BondActions(&feeder_action, &action); |
| 143 BondActions(&action, &collector_action); | 146 BondActions(&action, &collector_action); |
| 144 processor.EnqueueAction(&collector_action); | 147 processor.EnqueueAction(&collector_action); |
| 145 | 148 |
| 146 g_timeout_add(0, &StartProcessorInRunLoop, &processor); | 149 g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 147 g_main_loop_run(loop); | 150 g_main_loop_run(loop); |
| 148 g_main_loop_unref(loop); | 151 g_main_loop_unref(loop); |
| 149 if (collector_action.has_input_object_ && out_response) | 152 if (collector_action.has_input_object_ && out_response) |
| 150 *out_response = collector_action.omaha_response_; | 153 *out_response = collector_action.omaha_response_; |
| 151 if (out_post_data) | 154 if (out_post_data) |
| 152 *out_post_data = fetcher->post_data(); | 155 *out_post_data = fetcher->post_data(); |
| 153 return collector_action.has_input_object_; | 156 return collector_action.has_input_object_; |
| 154 } | 157 } |
| 155 | 158 |
| 159 // Tests Event requests -- they should always succeed. |out_post_data| |
| 160 // may be null; if non-null, the post-data received by the mock |
| 161 // HttpFetcher is returned. |
| 162 void TestEvent(const OmahaRequestParams& params, |
| 163 OmahaEvent* event, |
| 164 const string& http_response, |
| 165 vector<char>* out_post_data) { |
| 166 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 167 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
| 168 http_response.size()); |
| 169 ObjectFeederAction<OmahaRequestParams> feeder_action; |
| 170 OmahaRequestAction action(event, fetcher); // takes ownership of fetcher |
| 171 OmahaRequestActionTestProcessorDelegate delegate; |
| 172 delegate.loop_ = loop; |
| 173 ActionProcessor processor; |
| 174 feeder_action.set_obj(params); |
| 175 processor.set_delegate(&delegate); |
| 176 processor.EnqueueAction(&feeder_action); |
| 177 processor.EnqueueAction(&action); |
| 178 |
| 179 BondActions(&feeder_action, &action); |
| 180 |
| 181 g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 182 g_main_loop_run(loop); |
| 183 g_main_loop_unref(loop); |
| 184 if (out_post_data) |
| 185 *out_post_data = fetcher->post_data(); |
| 186 } |
| 187 |
| 156 TEST(OmahaRequestActionTest, NoUpdateTest) { | 188 TEST(OmahaRequestActionTest, NoUpdateTest) { |
| 157 OmahaRequestParams params("", // machine_id | 189 OmahaRequestParams params("", // machine_id |
| 158 "", // user_id | 190 "", // user_id |
| 159 OmahaRequestParams::kOsPlatform, | 191 OmahaRequestParams::kOsPlatform, |
| 160 OmahaRequestParams::kOsVersion, | 192 OmahaRequestParams::kOsVersion, |
| 161 "", // os_sp | 193 "", // os_sp |
| 162 "x86-generic", | 194 "x86-generic", |
| 163 OmahaRequestParams::kAppId, | 195 OmahaRequestParams::kAppId, |
| 164 "0.1.0.0", | 196 "0.1.0.0", |
| 165 "en-US", | 197 "en-US", |
| 166 "unittest", | 198 "unittest", |
| 167 ""); // url | 199 ""); // url |
| 168 OmahaResponse response; | 200 OmahaResponse response; |
| 169 ASSERT_TRUE( | 201 ASSERT_TRUE( |
| 170 TestOmahaRequestAction(params, | 202 TestUpdateCheck(params, |
| 171 GetNoUpdateResponse(OmahaRequestParams::kAppId), | 203 GetNoUpdateResponse(OmahaRequestParams::kAppId), |
| 172 true, | 204 true, |
| 173 &response, | 205 &response, |
| 174 NULL)); | 206 NULL)); |
| 175 EXPECT_FALSE(response.update_exists); | 207 EXPECT_FALSE(response.update_exists); |
| 176 } | 208 } |
| 177 | 209 |
| 178 TEST(OmahaRequestActionTest, ValidUpdateTest) { | 210 TEST(OmahaRequestActionTest, ValidUpdateTest) { |
| 179 OmahaRequestParams params("machine_id", | 211 OmahaRequestParams params("machine_id", |
| 180 "user_id", | 212 "user_id", |
| 181 OmahaRequestParams::kOsPlatform, | 213 OmahaRequestParams::kOsPlatform, |
| 182 OmahaRequestParams::kOsVersion, | 214 OmahaRequestParams::kOsVersion, |
| 183 "service_pack", | 215 "service_pack", |
| 184 "arm-generic", | 216 "arm-generic", |
| 185 OmahaRequestParams::kAppId, | 217 OmahaRequestParams::kAppId, |
| 186 "0.1.0.0", | 218 "0.1.0.0", |
| 187 "en-US", | 219 "en-US", |
| 188 "unittest_track", | 220 "unittest_track", |
| 189 ""); // url | 221 ""); // url |
| 190 OmahaResponse response; | 222 OmahaResponse response; |
| 191 ASSERT_TRUE( | 223 ASSERT_TRUE( |
| 192 TestOmahaRequestAction(params, | 224 TestUpdateCheck(params, |
| 193 GetUpdateResponse(OmahaRequestParams::kAppId, | 225 GetUpdateResponse(OmahaRequestParams::kAppId, |
| 194 "1.2.3.4", // version | 226 "1.2.3.4", // version |
| 195 "http://more/info", | 227 "http://more/info", |
| 196 "true", // prompt | 228 "true", // prompt |
| 197 "http://code/base", // dl url | 229 "http://code/base", // dl url |
| 198 "HASH1234=", // checksum | 230 "HASH1234=", // checksum |
| 199 "false", // needs admin | 231 "false", // needs admin |
| 200 "123"), // size | 232 "123"), // size |
| 201 true, | 233 true, |
| 202 &response, | 234 &response, |
| 203 NULL)); | 235 NULL)); |
| 204 EXPECT_TRUE(response.update_exists); | 236 EXPECT_TRUE(response.update_exists); |
| 205 EXPECT_EQ("1.2.3.4", response.display_version); | 237 EXPECT_EQ("1.2.3.4", response.display_version); |
| 206 EXPECT_EQ("http://code/base", response.codebase); | 238 EXPECT_EQ("http://code/base", response.codebase); |
| 207 EXPECT_EQ("http://more/info", response.more_info_url); | 239 EXPECT_EQ("http://more/info", response.more_info_url); |
| 208 EXPECT_EQ("HASH1234=", response.hash); | 240 EXPECT_EQ("HASH1234=", response.hash); |
| 209 EXPECT_EQ(123, response.size); | 241 EXPECT_EQ(123, response.size); |
| 210 EXPECT_FALSE(response.needs_admin); | 242 EXPECT_FALSE(response.needs_admin); |
| 211 EXPECT_TRUE(response.prompt); | 243 EXPECT_TRUE(response.prompt); |
| 212 } | 244 } |
| 213 | 245 |
| 214 TEST(OmahaRequestActionTest, NoOutputPipeTest) { | 246 TEST(OmahaRequestActionTest, NoOutputPipeTest) { |
| 215 OmahaRequestParams params("", // machine_id | 247 OmahaRequestParams params("", // machine_id |
| 216 "", // usr_id | 248 "", // usr_id |
| 217 OmahaRequestParams::kOsPlatform, | 249 OmahaRequestParams::kOsPlatform, |
| 218 OmahaRequestParams::kOsVersion, | 250 OmahaRequestParams::kOsVersion, |
| 219 "", // os_sp | 251 "", // os_sp |
| 220 "", // os_board | 252 "", // os_board |
| 221 OmahaRequestParams::kAppId, | 253 OmahaRequestParams::kAppId, |
| 222 "0.1.0.0", | 254 "0.1.0.0", |
| 223 "en-US", | 255 "en-US", |
| 224 "unittest", | 256 "unittest", |
| 225 ""); // url | 257 ""); // url |
| 226 const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); | 258 const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); |
| 227 | 259 |
| 228 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 260 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 229 | 261 |
| 230 ObjectFeederAction<OmahaRequestParams> feeder_action; | 262 ObjectFeederAction<OmahaRequestParams> feeder_action; |
| 231 feeder_action.set_obj(params); | 263 feeder_action.set_obj(params); |
| 232 OmahaRequestAction action(new MockHttpFetcher(http_response.data(), | 264 OmahaRequestAction action(NULL, |
| 265 new MockHttpFetcher(http_response.data(), |
| 233 http_response.size())); | 266 http_response.size())); |
| 234 OmahaRequestActionTestProcessorDelegate delegate; | 267 OmahaRequestActionTestProcessorDelegate delegate; |
| 235 delegate.loop_ = loop; | 268 delegate.loop_ = loop; |
| 236 ActionProcessor processor; | 269 ActionProcessor processor; |
| 237 processor.set_delegate(&delegate); | 270 processor.set_delegate(&delegate); |
| 238 processor.EnqueueAction(&feeder_action); | 271 processor.EnqueueAction(&feeder_action); |
| 239 processor.EnqueueAction(&action); | 272 processor.EnqueueAction(&action); |
| 240 BondActions(&feeder_action, &action); | 273 BondActions(&feeder_action, &action); |
| 241 | 274 |
| 242 g_timeout_add(0, &StartProcessorInRunLoop, &processor); | 275 g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 243 g_main_loop_run(loop); | 276 g_main_loop_run(loop); |
| 244 g_main_loop_unref(loop); | 277 g_main_loop_unref(loop); |
| 245 EXPECT_FALSE(processor.IsRunning()); | 278 EXPECT_FALSE(processor.IsRunning()); |
| 246 } | 279 } |
| 247 | 280 |
| 248 TEST(OmahaRequestActionTest, InvalidXmlTest) { | 281 TEST(OmahaRequestActionTest, InvalidXmlTest) { |
| 249 OmahaRequestParams params("machine_id", | 282 OmahaRequestParams params("machine_id", |
| 250 "user_id", | 283 "user_id", |
| 251 OmahaRequestParams::kOsPlatform, | 284 OmahaRequestParams::kOsPlatform, |
| 252 OmahaRequestParams::kOsVersion, | 285 OmahaRequestParams::kOsVersion, |
| 253 "service_pack", | 286 "service_pack", |
| 254 "x86-generic", | 287 "x86-generic", |
| 255 OmahaRequestParams::kAppId, | 288 OmahaRequestParams::kAppId, |
| 256 "0.1.0.0", | 289 "0.1.0.0", |
| 257 "en-US", | 290 "en-US", |
| 258 "unittest_track", | 291 "unittest_track", |
| 259 "http://url"); | 292 "http://url"); |
| 260 OmahaResponse response; | 293 OmahaResponse response; |
| 261 ASSERT_FALSE( | 294 ASSERT_FALSE( |
| 262 TestOmahaRequestAction(params, | 295 TestUpdateCheck(params, |
| 263 "invalid xml>", | 296 "invalid xml>", |
| 264 false, | 297 false, |
| 265 &response, | 298 &response, |
| 266 NULL)); | 299 NULL)); |
| 267 EXPECT_FALSE(response.update_exists); | 300 EXPECT_FALSE(response.update_exists); |
| 268 } | 301 } |
| 269 | 302 |
| 270 TEST(OmahaRequestActionTest, MissingStatusTest) { | 303 TEST(OmahaRequestActionTest, MissingStatusTest) { |
| 271 OmahaRequestParams params("machine_id", | 304 OmahaRequestParams params("machine_id", |
| 272 "user_id", | 305 "user_id", |
| 273 OmahaRequestParams::kOsPlatform, | 306 OmahaRequestParams::kOsPlatform, |
| 274 OmahaRequestParams::kOsVersion, | 307 OmahaRequestParams::kOsVersion, |
| 275 "service_pack", | 308 "service_pack", |
| 276 "x86-generic", | 309 "x86-generic", |
| 277 OmahaRequestParams::kAppId, | 310 OmahaRequestParams::kAppId, |
| 278 "0.1.0.0", | 311 "0.1.0.0", |
| 279 "en-US", | 312 "en-US", |
| 280 "unittest_track", | 313 "unittest_track", |
| 281 "http://url"); | 314 "http://url"); |
| 282 OmahaResponse response; | 315 OmahaResponse response; |
| 283 ASSERT_FALSE(TestOmahaRequestAction( | 316 ASSERT_FALSE(TestUpdateCheck( |
| 284 params, | 317 params, |
| 285 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 318 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 286 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 319 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 287 "appid=\"foo\" status=\"ok\"><ping " | 320 "appid=\"foo\" status=\"ok\"><ping " |
| 288 "status=\"ok\"/><updatecheck/></app></gupdate>", | 321 "status=\"ok\"/><updatecheck/></app></gupdate>", |
| 289 false, | 322 false, |
| 290 &response, | 323 &response, |
| 291 NULL)); | 324 NULL)); |
| 292 EXPECT_FALSE(response.update_exists); | 325 EXPECT_FALSE(response.update_exists); |
| 293 } | 326 } |
| 294 | 327 |
| 295 TEST(OmahaRequestActionTest, InvalidStatusTest) { | 328 TEST(OmahaRequestActionTest, InvalidStatusTest) { |
| 296 OmahaRequestParams params("machine_id", | 329 OmahaRequestParams params("machine_id", |
| 297 "user_id", | 330 "user_id", |
| 298 OmahaRequestParams::kOsPlatform, | 331 OmahaRequestParams::kOsPlatform, |
| 299 OmahaRequestParams::kOsVersion, | 332 OmahaRequestParams::kOsVersion, |
| 300 "service_pack", | 333 "service_pack", |
| 301 "x86-generic", | 334 "x86-generic", |
| 302 OmahaRequestParams::kAppId, | 335 OmahaRequestParams::kAppId, |
| 303 "0.1.0.0", | 336 "0.1.0.0", |
| 304 "en-US", | 337 "en-US", |
| 305 "unittest_track", | 338 "unittest_track", |
| 306 "http://url"); | 339 "http://url"); |
| 307 OmahaResponse response; | 340 OmahaResponse response; |
| 308 ASSERT_FALSE(TestOmahaRequestAction( | 341 ASSERT_FALSE(TestUpdateCheck( |
| 309 params, | 342 params, |
| 310 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 343 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 311 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 344 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 312 "appid=\"foo\" status=\"ok\"><ping " | 345 "appid=\"foo\" status=\"ok\"><ping " |
| 313 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", | 346 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", |
| 314 false, | 347 false, |
| 315 &response, | 348 &response, |
| 316 NULL)); | 349 NULL)); |
| 317 EXPECT_FALSE(response.update_exists); | 350 EXPECT_FALSE(response.update_exists); |
| 318 } | 351 } |
| 319 | 352 |
| 320 TEST(OmahaRequestActionTest, MissingNodesetTest) { | 353 TEST(OmahaRequestActionTest, MissingNodesetTest) { |
| 321 OmahaRequestParams params("machine_id", | 354 OmahaRequestParams params("machine_id", |
| 322 "user_id", | 355 "user_id", |
| 323 OmahaRequestParams::kOsPlatform, | 356 OmahaRequestParams::kOsPlatform, |
| 324 OmahaRequestParams::kOsVersion, | 357 OmahaRequestParams::kOsVersion, |
| 325 "service_pack", | 358 "service_pack", |
| 326 "x86-generic", | 359 "x86-generic", |
| 327 OmahaRequestParams::kAppId, | 360 OmahaRequestParams::kAppId, |
| 328 "0.1.0.0", | 361 "0.1.0.0", |
| 329 "en-US", | 362 "en-US", |
| 330 "unittest_track", | 363 "unittest_track", |
| 331 "http://url"); | 364 "http://url"); |
| 332 OmahaResponse response; | 365 OmahaResponse response; |
| 333 ASSERT_FALSE(TestOmahaRequestAction( | 366 ASSERT_FALSE(TestUpdateCheck( |
| 334 params, | 367 params, |
| 335 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 368 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 336 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 369 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 337 "appid=\"foo\" status=\"ok\"><ping " | 370 "appid=\"foo\" status=\"ok\"><ping " |
| 338 "status=\"ok\"/></app></gupdate>", | 371 "status=\"ok\"/></app></gupdate>", |
| 339 false, | 372 false, |
| 340 &response, | 373 &response, |
| 341 NULL)); | 374 NULL)); |
| 342 EXPECT_FALSE(response.update_exists); | 375 EXPECT_FALSE(response.update_exists); |
| 343 } | 376 } |
| 344 | 377 |
| 345 TEST(OmahaRequestActionTest, MissingFieldTest) { | 378 TEST(OmahaRequestActionTest, MissingFieldTest) { |
| 346 OmahaRequestParams params("machine_id", | 379 OmahaRequestParams params("machine_id", |
| 347 "user_id", | 380 "user_id", |
| 348 OmahaRequestParams::kOsPlatform, | 381 OmahaRequestParams::kOsPlatform, |
| 349 OmahaRequestParams::kOsVersion, | 382 OmahaRequestParams::kOsVersion, |
| 350 "service_pack", | 383 "service_pack", |
| 351 "x86-generic", | 384 "x86-generic", |
| 352 OmahaRequestParams::kAppId, | 385 OmahaRequestParams::kAppId, |
| 353 "0.1.0.0", | 386 "0.1.0.0", |
| 354 "en-US", | 387 "en-US", |
| 355 "unittest_track", | 388 "unittest_track", |
| 356 "http://url"); | 389 "http://url"); |
| 357 OmahaResponse response; | 390 OmahaResponse response; |
| 358 ASSERT_TRUE(TestOmahaRequestAction(params, | 391 ASSERT_TRUE(TestUpdateCheck(params, |
| 359 string("<?xml version=\"1.0\" " | 392 string("<?xml version=\"1.0\" " |
| 360 "encoding=\"UTF-8\"?><gupdate " | 393 "encoding=\"UTF-8\"?><gupdate " |
| 361 "xmlns=\"http://www.google.com/" | 394 "xmlns=\"http://www.google.com/" |
| 362 "update2/response\" " | 395 "update2/response\" " |
| 363 "protocol=\"2.0\"><app appid=\"") + | 396 "protocol=\"2.0\"><app appid=\"") + |
| 364 OmahaRequestParams::kAppId | 397 OmahaRequestParams::kAppId |
| 365 + "\" status=\"ok\"><ping " | 398 + "\" status=\"ok\"><ping " |
| 366 "status=\"ok\"/><updatecheck " | 399 "status=\"ok\"/><updatecheck " |
| 367 "DisplayVersion=\"1.2.3.4\" " | 400 "DisplayVersion=\"1.2.3.4\" " |
| 368 "Prompt=\"false\" " | 401 "Prompt=\"false\" " |
| 369 "codebase=\"http://code/base\" " | 402 "codebase=\"http://code/base\" " |
| 370 "hash=\"HASH1234=\" needsadmin=\"true\" " | 403 "hash=\"HASH1234=\" needsadmin=\"true\" " |
| 371 "size=\"123\" " | 404 "size=\"123\" " |
| 372 "status=\"ok\"/></app></gupdate>", | 405 "status=\"ok\"/></app></gupdate>", |
| 373 true, | 406 true, |
| 374 &response, | 407 &response, |
| 375 NULL)); | 408 NULL)); |
| 376 EXPECT_TRUE(response.update_exists); | 409 EXPECT_TRUE(response.update_exists); |
| 377 EXPECT_EQ("1.2.3.4", response.display_version); | 410 EXPECT_EQ("1.2.3.4", response.display_version); |
| 378 EXPECT_EQ("http://code/base", response.codebase); | 411 EXPECT_EQ("http://code/base", response.codebase); |
| 379 EXPECT_EQ("", response.more_info_url); | 412 EXPECT_EQ("", response.more_info_url); |
| 380 EXPECT_EQ("HASH1234=", response.hash); | 413 EXPECT_EQ("HASH1234=", response.hash); |
| 381 EXPECT_EQ(123, response.size); | 414 EXPECT_EQ(123, response.size); |
| 382 EXPECT_TRUE(response.needs_admin); | 415 EXPECT_TRUE(response.needs_admin); |
| 383 EXPECT_FALSE(response.prompt); | 416 EXPECT_FALSE(response.prompt); |
| 384 } | 417 } |
| 385 | 418 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 412 OmahaRequestParams::kAppId, | 445 OmahaRequestParams::kAppId, |
| 413 "0.1.0.0", | 446 "0.1.0.0", |
| 414 "en-US", | 447 "en-US", |
| 415 "unittest", | 448 "unittest", |
| 416 "http://url"); | 449 "http://url"); |
| 417 string http_response("doesn't matter"); | 450 string http_response("doesn't matter"); |
| 418 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 451 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 419 | 452 |
| 420 ObjectFeederAction<OmahaRequestParams> feeder_action; | 453 ObjectFeederAction<OmahaRequestParams> feeder_action; |
| 421 feeder_action.set_obj(params); | 454 feeder_action.set_obj(params); |
| 422 OmahaRequestAction action(new MockHttpFetcher(http_response.data(), | 455 OmahaRequestAction action(NULL, |
| 456 new MockHttpFetcher(http_response.data(), |
| 423 http_response.size())); | 457 http_response.size())); |
| 424 TerminateEarlyTestProcessorDelegate delegate; | 458 TerminateEarlyTestProcessorDelegate delegate; |
| 425 delegate.loop_ = loop; | 459 delegate.loop_ = loop; |
| 426 ActionProcessor processor; | 460 ActionProcessor processor; |
| 427 processor.set_delegate(&delegate); | 461 processor.set_delegate(&delegate); |
| 428 processor.EnqueueAction(&feeder_action); | 462 processor.EnqueueAction(&feeder_action); |
| 429 processor.EnqueueAction(&action); | 463 processor.EnqueueAction(&action); |
| 430 BondActions(&feeder_action, &action); | 464 BondActions(&feeder_action, &action); |
| 431 | 465 |
| 432 g_timeout_add(0, &TerminateTransferTestStarter, &processor); | 466 g_timeout_add(0, &TerminateTransferTestStarter, &processor); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 450 OmahaRequestParams::kOsVersion, | 484 OmahaRequestParams::kOsVersion, |
| 451 "testtheservice_pack>", | 485 "testtheservice_pack>", |
| 452 "x86 generic", | 486 "x86 generic", |
| 453 OmahaRequestParams::kAppId, | 487 OmahaRequestParams::kAppId, |
| 454 "0.1.0.0", | 488 "0.1.0.0", |
| 455 "en-US", | 489 "en-US", |
| 456 "unittest_track", | 490 "unittest_track", |
| 457 "http://url"); | 491 "http://url"); |
| 458 OmahaResponse response; | 492 OmahaResponse response; |
| 459 ASSERT_FALSE( | 493 ASSERT_FALSE( |
| 460 TestOmahaRequestAction(params, | 494 TestUpdateCheck(params, |
| 461 "invalid xml>", | 495 "invalid xml>", |
| 462 false, | 496 false, |
| 463 &response, | 497 &response, |
| 464 &post_data)); | 498 &post_data)); |
| 465 // convert post_data to string | 499 // convert post_data to string |
| 466 string post_str(&post_data[0], post_data.size()); | 500 string post_str(&post_data[0], post_data.size()); |
| 467 EXPECT_NE(post_str.find("testthemachine<id"), string::npos); | 501 EXPECT_NE(post_str.find("testthemachine<id"), string::npos); |
| 468 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); | 502 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); |
| 469 EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos); | 503 EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos); |
| 470 EXPECT_EQ(post_str.find("testtheuser_id<"), string::npos); | 504 EXPECT_EQ(post_str.find("testtheuser_id<"), string::npos); |
| 471 EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); | 505 EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); |
| 472 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); | 506 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); |
| 473 EXPECT_NE(post_str.find("x86 generic"), string::npos); | 507 EXPECT_NE(post_str.find("x86 generic"), string::npos); |
| 474 } | 508 } |
| 475 | 509 |
| 476 TEST(OmahaRequestActionTest, XmlDecodeTest) { | 510 TEST(OmahaRequestActionTest, XmlDecodeTest) { |
| 477 OmahaRequestParams params("machine_id", | 511 OmahaRequestParams params("machine_id", |
| 478 "user_id", | 512 "user_id", |
| 479 OmahaRequestParams::kOsPlatform, | 513 OmahaRequestParams::kOsPlatform, |
| 480 OmahaRequestParams::kOsVersion, | 514 OmahaRequestParams::kOsVersion, |
| 481 "service_pack", | 515 "service_pack", |
| 482 "x86-generic", | 516 "x86-generic", |
| 483 OmahaRequestParams::kAppId, | 517 OmahaRequestParams::kAppId, |
| 484 "0.1.0.0", | 518 "0.1.0.0", |
| 485 "en-US", | 519 "en-US", |
| 486 "unittest_track", | 520 "unittest_track", |
| 487 "http://url"); | 521 "http://url"); |
| 488 OmahaResponse response; | 522 OmahaResponse response; |
| 489 ASSERT_TRUE( | 523 ASSERT_TRUE( |
| 490 TestOmahaRequestAction(params, | 524 TestUpdateCheck(params, |
| 491 GetUpdateResponse(OmahaRequestParams::kAppId, | 525 GetUpdateResponse(OmahaRequestParams::kAppId, |
| 492 "1.2.3.4", // version | 526 "1.2.3.4", // version |
| 493 "testthe<url", // more info | 527 "testthe<url", // more info |
| 494 "true", // prompt | 528 "true", // prompt |
| 495 "testthe&code", // dl url | 529 "testthe&codebase", // dl url |
| 496 "HASH1234=", // checksum | 530 "HASH1234=", // checksum |
| 497 "false", // needs admin | 531 "false", // needs admin |
| 498 "123"), // size | 532 "123"), // size |
| 499 true, | 533 true, |
| 500 &response, | 534 &response, |
| 501 NULL)); | 535 NULL)); |
| 502 | 536 |
| 503 EXPECT_EQ(response.more_info_url, "testthe<url"); | 537 EXPECT_EQ(response.more_info_url, "testthe<url"); |
| 504 EXPECT_EQ(response.codebase, "testthe&code"); | 538 EXPECT_EQ(response.codebase, "testthe&codebase"); |
| 505 } | 539 } |
| 506 | 540 |
| 507 TEST(OmahaRequestActionTest, ParseIntTest) { | 541 TEST(OmahaRequestActionTest, ParseIntTest) { |
| 508 OmahaRequestParams params("machine_id", | 542 OmahaRequestParams params("machine_id", |
| 509 "user_id", | 543 "user_id", |
| 510 OmahaRequestParams::kOsPlatform, | 544 OmahaRequestParams::kOsPlatform, |
| 511 OmahaRequestParams::kOsVersion, | 545 OmahaRequestParams::kOsVersion, |
| 512 "service_pack", | 546 "service_pack", |
| 513 "the_board", | 547 "the_board", |
| 514 OmahaRequestParams::kAppId, | 548 OmahaRequestParams::kAppId, |
| 515 "0.1.0.0", | 549 "0.1.0.0", |
| 516 "en-US", | 550 "en-US", |
| 517 "unittest_track", | 551 "unittest_track", |
| 518 "http://url"); | 552 "http://url"); |
| 519 OmahaResponse response; | 553 OmahaResponse response; |
| 520 ASSERT_TRUE( | 554 ASSERT_TRUE( |
| 521 TestOmahaRequestAction(params, | 555 TestUpdateCheck(params, |
| 522 GetUpdateResponse(OmahaRequestParams::kAppId, | 556 GetUpdateResponse(OmahaRequestParams::kAppId, |
| 523 "1.2.3.4", // version | 557 "1.2.3.4", // version |
| 524 "theurl", // more info | 558 "theurl", // more info |
| 525 "true", // prompt | 559 "true", // prompt |
| 526 "thecodebase", // dl url | 560 "thecodebase", // dl url |
| 527 "HASH1234=", // checksum | 561 "HASH1234=", // checksum |
| 528 "false", // needs admin | 562 "false", // needs admin |
| 529 // overflows int32: | 563 // overflows int32: |
| 530 "123123123123123"), // size | 564 "123123123123123"), // size |
| 531 true, | 565 true, |
| 532 &response, | 566 &response, |
| 533 NULL)); | 567 NULL)); |
| 534 | 568 |
| 535 EXPECT_EQ(response.size, 123123123123123ll); | 569 EXPECT_EQ(response.size, 123123123123123ll); |
| 536 } | 570 } |
| 537 | 571 |
| 572 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
| 573 vector<char> post_data; |
| 574 OmahaRequestParams params("machine_id", |
| 575 "user_id", |
| 576 OmahaRequestParams::kOsPlatform, |
| 577 OmahaRequestParams::kOsVersion, |
| 578 "service_pack", |
| 579 "x86-generic", |
| 580 OmahaRequestParams::kAppId, |
| 581 "0.1.0.0", |
| 582 "en-US", |
| 583 "unittest_track", |
| 584 "http://url"); |
| 585 OmahaResponse response; |
| 586 ASSERT_FALSE(TestUpdateCheck(params, |
| 587 "invalid xml>", |
| 588 false, |
| 589 &response, |
| 590 &post_data)); |
| 591 // convert post_data to string |
| 592 string post_str(&post_data[0], post_data.size()); |
| 593 EXPECT_NE(post_str.find(" <o:ping active=\"0\"></o:ping>\n" |
| 594 " <o:updatecheck></o:updatecheck>\n"), |
| 595 string::npos); |
| 596 EXPECT_EQ(post_str.find("o:event"), string::npos); |
| 597 } |
| 598 |
| 599 TEST(OmahaRequestActionTest, FormatEventOutputTest) { |
| 600 vector<char> post_data; |
| 601 OmahaRequestParams params("machine_id", |
| 602 "user_id", |
| 603 OmahaRequestParams::kOsPlatform, |
| 604 OmahaRequestParams::kOsVersion, |
| 605 "service_pack", |
| 606 "x86-generic", |
| 607 OmahaRequestParams::kAppId, |
| 608 "0.1.0.0", |
| 609 "en-US", |
| 610 "unittest_track", |
| 611 "http://url"); |
| 612 TestEvent(params, |
| 613 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
| 614 OmahaEvent::kResultError, |
| 615 5), |
| 616 "invalid xml>", |
| 617 &post_data); |
| 618 // convert post_data to string |
| 619 string post_str(&post_data[0], post_data.size()); |
| 620 string expected_event = StringPrintf( |
| 621 " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 622 "errorcode=\"%d\"></o:event>\n", |
| 623 OmahaEvent::kTypeDownloadComplete, |
| 624 OmahaEvent::kResultError, |
| 625 5); |
| 626 EXPECT_NE(post_str.find(expected_event), string::npos); |
| 627 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 628 } |
| 629 |
| 630 TEST(OmahaRequestActionTest, IsEventTest) { |
| 631 string http_response("doesn't matter"); |
| 632 |
| 633 OmahaRequestAction update_check_action( |
| 634 NULL, |
| 635 new MockHttpFetcher(http_response.data(), |
| 636 http_response.size())); |
| 637 EXPECT_FALSE(update_check_action.IsEvent()); |
| 638 |
| 639 OmahaRequestAction event_action( |
| 640 new OmahaEvent(OmahaEvent::kTypeInstallComplete, |
| 641 OmahaEvent::kResultError, |
| 642 0), |
| 643 new MockHttpFetcher(http_response.data(), |
| 644 http_response.size())); |
| 645 EXPECT_TRUE(event_action.IsEvent()); |
| 646 } |
| 647 |
| 538 } // namespace chromeos_update_engine | 648 } // namespace chromeos_update_engine |
| OLD | NEW |