Rename UpdateCheckAction|Params to OmahaRequestAction|Params.
Also, renamed UpdateCheckResponse to OmahaResponse.
BUG=560
TEST=unit tests, gmerge'd on device.
Review URL: http://codereview.chromium.org/2981007
diff --git a/SConstruct b/SConstruct
index 196df2a..df29f86 100644
--- a/SConstruct
+++ b/SConstruct
@@ -209,6 +209,7 @@
libcurl_http_fetcher.cc
marshal.glibmarshal.c
omaha_hash_calculator.cc
+ omaha_request_action.cc
omaha_request_prep_action.cc
omaha_response_handler_action.cc
postinstall_runner_action.cc
@@ -219,7 +220,6 @@
tarjan.cc
topological_sort.cc
update_attempter.cc
- update_check_action.cc
update_metadata.pb.cc
utils.cc""")
main = ['main.cc']
@@ -242,6 +242,7 @@
http_fetcher_unittest.cc
mock_http_fetcher.cc
omaha_hash_calculator_unittest.cc
+ omaha_request_action_unittest.cc
omaha_request_prep_action_unittest.cc
omaha_response_handler_action_unittest.cc
postinstall_runner_action_unittest.cc
@@ -252,7 +253,6 @@
tarjan_unittest.cc
test_utils.cc
topological_sort_unittest.cc
- update_check_action_unittest.cc
utils_unittest.cc
zip_unittest.cc""")
unittest_main = ['testrunner.cc']
diff --git a/integration_unittest.cc b/integration_unittest.cc
index 13102da..7b7a35b 100644
--- a/integration_unittest.cc
+++ b/integration_unittest.cc
@@ -11,12 +11,12 @@
#include "update_engine/install_action.h"
#include "update_engine/libcurl_http_fetcher.h"
#include "update_engine/mock_http_fetcher.h"
+#include "update_engine/omaha_request_action.h"
#include "update_engine/omaha_request_prep_action.h"
#include "update_engine/omaha_response_handler_action.h"
#include "update_engine/postinstall_runner_action.h"
#include "update_engine/set_bootable_flag_action.h"
#include "update_engine/test_utils.h"
-#include "update_engine/update_check_action.h"
#include "update_engine/utils.h"
// The tests here integrate many Action objects together. This test that
@@ -105,7 +105,7 @@
// Actions:
OmahaRequestPrepAction request_prep_action(false);
- UpdateCheckAction update_check_action(new LibcurlHttpFetcher);
+ OmahaRequestAction update_check_action(new LibcurlHttpFetcher);
OmahaResponseHandlerAction response_handler_action;
DownloadAction download_action(new LibcurlHttpFetcher);
InstallAction install_action;
diff --git a/update_check_action.cc b/omaha_request_action.cc
similarity index 83%
rename from update_check_action.cc
rename to omaha_request_action.cc
index fa8d697..3c203e2 100644
--- a/update_check_action.cc
+++ b/omaha_request_action.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "update_engine/update_check_action.h"
+#include "update_engine/omaha_request_action.h"
#include <inttypes.h>
#include <sstream>
@@ -18,11 +18,11 @@
namespace chromeos_update_engine {
-const char* const UpdateCheckParams::kAppId(
+const char* const OmahaRequestParams::kAppId(
"{87efface-864d-49a5-9bb3-4b050a7c227a}");
-const char* const UpdateCheckParams::kOsPlatform("Chrome OS");
-const char* const UpdateCheckParams::kOsVersion("Indy");
-const char* const UpdateCheckParams::kUpdateUrl(
+const char* const OmahaRequestParams::kOsPlatform("Chrome OS");
+const char* const OmahaRequestParams::kOsVersion("Indy");
+const char* const OmahaRequestParams::kUpdateUrl(
"https://tools.google.com/service/update2");
namespace {
@@ -59,14 +59,14 @@
}
};
-// Returns a properly formatted omaha request for an update check
-string FormatRequest(const UpdateCheckParams& params) {
+// Returns a properly formatted omaha request for a request to Omaha.
+string FormatRequest(const OmahaRequestParams& params) {
return string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" "
- "version=\"" + XmlEncode(kGupdateVersion) + "\" "
- "updaterversion=\"" + XmlEncode(kGupdateVersion) + "\" "
- "protocol=\"2.0\" "
- "machineid=\"") + XmlEncode(params.machine_id) + "\" ismachine=\"1\" "
+ "<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" "
+ "version=\"" + XmlEncode(kGupdateVersion) + "\" "
+ "updaterversion=\"" + XmlEncode(kGupdateVersion) + "\" "
+ "protocol=\"2.0\" "
+ "machineid=\"") + XmlEncode(params.machine_id) + "\" ismachine=\"1\" "
"userid=\"" + XmlEncode(params.user_id) + "\">\n"
" <o:os version=\"" + XmlEncode(params.os_version) + "\" platform=\"" +
XmlEncode(params.os_platform) + "\" sp=\"" +
@@ -86,25 +86,25 @@
// Encodes XML entities in a given string with libxml2. input must be
// UTF-8 formatted. Output will be UTF-8 formatted.
string XmlEncode(const string& input) {
-// // TODO(adlr): if allocating a new xmlDoc each time is taking up too much
-// // cpu, considering creating one and caching it.
-// scoped_ptr_malloc<xmlDoc, ScopedPtrXmlDocFree> xml_doc(
-// xmlNewDoc(ConstXMLStr("1.0")));
-// if (!xml_doc.get()) {
-// LOG(ERROR) << "Unable to create xmlDoc";
-// return "";
-// }
+ // // TODO(adlr): if allocating a new xmlDoc each time is taking up too much
+ // // cpu, considering creating one and caching it.
+ // scoped_ptr_malloc<xmlDoc, ScopedPtrXmlDocFree> xml_doc(
+ // xmlNewDoc(ConstXMLStr("1.0")));
+ // if (!xml_doc.get()) {
+ // LOG(ERROR) << "Unable to create xmlDoc";
+ // return "";
+ // }
scoped_ptr_malloc<xmlChar, ScopedPtrXmlFree> str(
xmlEncodeEntitiesReentrant(NULL, ConstXMLStr(input.c_str())));
return string(reinterpret_cast<const char *>(str.get()));
}
-UpdateCheckAction::UpdateCheckAction(HttpFetcher* http_fetcher)
+OmahaRequestAction::OmahaRequestAction(HttpFetcher* http_fetcher)
: http_fetcher_(http_fetcher) {}
-UpdateCheckAction::~UpdateCheckAction() {}
+OmahaRequestAction::~OmahaRequestAction() {}
-void UpdateCheckAction::PerformAction() {
+void OmahaRequestAction::PerformAction() {
CHECK(HasInputObject());
params_ = GetInputObject();
http_fetcher_->set_delegate(this);
@@ -115,15 +115,15 @@
http_fetcher_->BeginTransfer(params_.update_url);
}
-void UpdateCheckAction::TerminateProcessing() {
+void OmahaRequestAction::TerminateProcessing() {
http_fetcher_->TerminateTransfer();
}
// We just store the response in the buffer. Once we've received all bytes,
// we'll look in the buffer and decide what to do.
-void UpdateCheckAction::ReceivedBytes(HttpFetcher *fetcher,
- const char* bytes,
- int length) {
+void OmahaRequestAction::ReceivedBytes(HttpFetcher *fetcher,
+ const char* bytes,
+ int length) {
response_buffer_.reserve(response_buffer_.size() + length);
response_buffer_.insert(response_buffer_.end(), bytes, bytes + length);
}
@@ -192,8 +192,8 @@
// If the transfer was successful, this uses libxml2 to parse the response
// and fill in the appropriate fields of the output object. Also, notifies
// the processor that we're done.
-void UpdateCheckAction::TransferComplete(HttpFetcher *fetcher,
- bool successful) {
+void OmahaRequestAction::TransferComplete(HttpFetcher *fetcher,
+ bool successful) {
ScopedActionCompleter completer(processor_, this);
LOG(INFO) << "Update check response: " << string(response_buffer_.begin(),
response_buffer_.end());
@@ -240,7 +240,7 @@
}
const string status(XmlGetProperty(updatecheck_node, "status"));
- UpdateCheckResponse output_object;
+ OmahaResponse output_object;
if (status == "noupdate") {
LOG(INFO) << "No update.";
output_object.update_exists = false;
diff --git a/update_check_action.h b/omaha_request_action.h
similarity index 62%
rename from update_check_action.h
rename to omaha_request_action.h
index 4e759bd..f8dddc8 100644
--- a/update_check_action.h
+++ b/omaha_request_action.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_CHECK_ACTION_H__
-#define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_CHECK_ACTION_H__
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__
#include <sys/stat.h>
#include <sys/types.h>
@@ -17,8 +17,8 @@
#include "update_engine/action.h"
#include "update_engine/http_fetcher.h"
-// The Update Check action makes an update check request to Omaha and
-// can output the response on the output ActionPipe.
+// The Omaha Request action makes a request to Omaha and can output
+// the response on the output ActionPipe.
namespace chromeos_update_engine {
@@ -26,22 +26,22 @@
// UTF-8 formatted. Output will be UTF-8 formatted.
std::string XmlEncode(const std::string& input);
-// This struct encapsulates the data Omaha gets for the update check.
+// This struct encapsulates the data Omaha gets for the request.
// These strings in this struct should not be XML escaped.
-struct UpdateCheckParams {
- UpdateCheckParams()
+struct OmahaRequestParams {
+ OmahaRequestParams()
: os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {}
- UpdateCheckParams(const std::string& in_machine_id,
- const std::string& in_user_id,
- const std::string& in_os_platform,
- const std::string& in_os_version,
- const std::string& in_os_sp,
- const std::string& in_os_board,
- const std::string& in_app_id,
- const std::string& in_app_version,
- const std::string& in_app_lang,
- const std::string& in_app_track,
- const std::string& in_update_url)
+ OmahaRequestParams(const std::string& in_machine_id,
+ const std::string& in_user_id,
+ const std::string& in_os_platform,
+ const std::string& in_os_version,
+ const std::string& in_os_sp,
+ const std::string& in_os_board,
+ const std::string& in_app_id,
+ const std::string& in_app_version,
+ const std::string& in_app_lang,
+ const std::string& in_app_track,
+ const std::string& in_update_url)
: machine_id(in_machine_id),
user_id(in_user_id),
os_platform(in_os_platform),
@@ -64,7 +64,7 @@
std::string app_version;
std::string app_lang;
std::string app_track;
-
+
std::string update_url;
// Suggested defaults
@@ -74,10 +74,10 @@
static const char* const kUpdateUrl;
};
-// This struct encapsulates the data Omaha returns for the update check.
+// This struct encapsulates the data Omaha's response for the request.
// These strings in this struct are not XML escaped.
-struct UpdateCheckResponse {
- UpdateCheckResponse()
+struct OmahaResponse {
+ OmahaResponse()
: update_exists(false), size(0), needs_admin(false), prompt(false) {}
// True iff there is an update to be downloaded.
bool update_exists;
@@ -93,36 +93,36 @@
};
COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64bit);
-class UpdateCheckAction;
+class OmahaRequestAction;
class NoneType;
template<>
-class ActionTraits<UpdateCheckAction> {
+class ActionTraits<OmahaRequestAction> {
public:
// Takes parameters on the input pipe
- typedef UpdateCheckParams InputObjectType;
+ typedef OmahaRequestParams InputObjectType;
// On success, puts the output path on output
- typedef UpdateCheckResponse OutputObjectType;
+ typedef OmahaResponse OutputObjectType;
};
-class UpdateCheckAction : public Action<UpdateCheckAction>,
- public HttpFetcherDelegate {
+class OmahaRequestAction : public Action<OmahaRequestAction>,
+ public HttpFetcherDelegate {
public:
// The ctor takes in all the parameters that will be used for
// making the request to Omaha. For some of them we have constants
// that should be used.
// Takes ownership of the passed in HttpFetcher. Useful for testing.
// A good calling pattern is:
- // UpdateCheckAction(..., new WhateverHttpFetcher);
- UpdateCheckAction(HttpFetcher* http_fetcher);
- virtual ~UpdateCheckAction();
- typedef ActionTraits<UpdateCheckAction>::InputObjectType InputObjectType;
- typedef ActionTraits<UpdateCheckAction>::OutputObjectType OutputObjectType;
+ // OmahaRequestAction(..., new WhateverHttpFetcher);
+ OmahaRequestAction(HttpFetcher* http_fetcher);
+ virtual ~OmahaRequestAction();
+ typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType;
+ typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType;
void PerformAction();
void TerminateProcessing();
// Debugging/logging
- static std::string StaticType() { return "UpdateCheckAction"; }
+ static std::string StaticType() { return "OmahaRequestAction"; }
std::string Type() const { return StaticType(); }
// Delegate methods (see http_fetcher.h)
@@ -132,7 +132,7 @@
private:
// These are data that are passed in the request to the Omaha server
- UpdateCheckParams params_;
+ OmahaRequestParams params_;
// pointer to the HttpFetcher that does the http work
scoped_ptr<HttpFetcher> http_fetcher_;
@@ -140,9 +140,9 @@
// Stores the response from the omaha server
std::vector<char> response_buffer_;
- DISALLOW_COPY_AND_ASSIGN(UpdateCheckAction);
+ DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction);
};
} // namespace chromeos_update_engine
-#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_CHECK_ACTION_H__
+#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
new file mode 100644
index 0000000..778f408
--- /dev/null
+++ b/omaha_request_action_unittest.cc
@@ -0,0 +1,538 @@
+// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+#include <vector>
+#include <glib.h>
+#include <gtest/gtest.h>
+#include "update_engine/action_pipe.h"
+#include "update_engine/mock_http_fetcher.h"
+#include "update_engine/omaha_hash_calculator.h"
+#include "update_engine/omaha_request_action.h"
+#include "update_engine/test_utils.h"
+
+using std::string;
+using std::vector;
+
+namespace chromeos_update_engine {
+
+class OmahaRequestActionTest : public ::testing::Test { };
+
+namespace {
+string GetNoUpdateResponse(const string& app_id) {
+ return string(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
+ "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
+ "appid=\"") + app_id + "\" status=\"ok\"><ping "
+ "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>";
+}
+
+string GetUpdateResponse(const string& app_id,
+ const string& display_version,
+ const string& more_info_url,
+ const string& prompt,
+ const string& codebase,
+ const string& hash,
+ const string& needsadmin,
+ const string& size) {
+ return string("<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
+ "xmlns=\"http://www.google.com/update2/response\" "
+ "protocol=\"2.0\"><app "
+ "appid=\"") + app_id + "\" status=\"ok\"><ping "
+ "status=\"ok\"/><updatecheck DisplayVersion=\"" + display_version + "\" "
+ "MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" "
+ "codebase=\"" + codebase + "\" "
+ "hash=\"" + hash + "\" needsadmin=\"" + needsadmin + "\" "
+ "size=\"" + size + "\" status=\"ok\"/></app></gupdate>";
+}
+
+class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate {
+ public:
+ OmahaRequestActionTestProcessorDelegate()
+ : loop_(NULL),
+ expected_success_(true) {}
+ virtual ~OmahaRequestActionTestProcessorDelegate() {
+ }
+ virtual void ProcessingDone(const ActionProcessor* processor, bool success) {
+ ASSERT_TRUE(loop_);
+ g_main_loop_quit(loop_);
+ }
+
+ virtual void ActionCompleted(ActionProcessor* processor,
+ AbstractAction* action,
+ bool success) {
+ // make sure actions always succeed
+ if (action->Type() == OmahaRequestAction::StaticType())
+ EXPECT_EQ(expected_success_, success);
+ else
+ EXPECT_TRUE(success);
+ }
+ GMainLoop *loop_;
+ bool expected_success_;
+};
+
+gboolean StartProcessorInRunLoop(gpointer data) {
+ ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data);
+ processor->StartProcessing();
+ return FALSE;
+}
+
+} // namespace {}
+
+class OutputObjectCollectorAction;
+
+template<>
+class ActionTraits<OutputObjectCollectorAction> {
+ public:
+ // Does not take an object for input
+ typedef OmahaResponse InputObjectType;
+ // On success, puts the output path on output
+ typedef NoneType OutputObjectType;
+};
+
+class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> {
+ public:
+ OutputObjectCollectorAction() : has_input_object_(false) {}
+ void PerformAction() {
+ // copy input object
+ has_input_object_ = HasInputObject();
+ if (has_input_object_)
+ omaha_response_ = GetInputObject();
+ processor_->ActionComplete(this, true);
+ }
+ // Should never be called
+ void TerminateProcessing() {
+ CHECK(false);
+ }
+ // Debugging/logging
+ static std::string StaticType() {
+ return "OutputObjectCollectorAction";
+ }
+ std::string Type() const { return StaticType(); }
+ bool has_input_object_;
+ OmahaResponse omaha_response_;
+};
+
+// returns true iff an output response was obtained from the
+// OmahaRequestAction. out_response may be NULL.
+// out_post_data may be null; if non-null, the post-data received by the
+// mock HttpFetcher is returned.
+bool TestOmahaRequestAction(const OmahaRequestParams& params,
+ const string& http_response,
+ bool expected_success,
+ OmahaResponse* out_response,
+ vector<char> *out_post_data) {
+ GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
+ MockHttpFetcher *fetcher = new MockHttpFetcher(http_response.data(),
+ http_response.size());
+ ObjectFeederAction<OmahaRequestParams> feeder_action;
+ OmahaRequestAction action(fetcher); // takes ownership of fetcher
+ OmahaRequestActionTestProcessorDelegate delegate;
+ delegate.loop_ = loop;
+ delegate.expected_success_ = expected_success;
+ ActionProcessor processor;
+ feeder_action.set_obj(params);
+ processor.set_delegate(&delegate);
+ processor.EnqueueAction(&feeder_action);
+ processor.EnqueueAction(&action);
+
+ OutputObjectCollectorAction collector_action;
+
+ BondActions(&feeder_action, &action);
+ BondActions(&action, &collector_action);
+ processor.EnqueueAction(&collector_action);
+
+ g_timeout_add(0, &StartProcessorInRunLoop, &processor);
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+ if (collector_action.has_input_object_ && out_response)
+ *out_response = collector_action.omaha_response_;
+ if (out_post_data)
+ *out_post_data = fetcher->post_data();
+ return collector_action.has_input_object_;
+}
+
+TEST(OmahaRequestActionTest, NoUpdateTest) {
+ OmahaRequestParams params("", // machine_id
+ "", // user_id
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "", // os_sp
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest",
+ ""); // url
+ OmahaResponse response;
+ ASSERT_TRUE(
+ TestOmahaRequestAction(params,
+ GetNoUpdateResponse(OmahaRequestParams::kAppId),
+ true,
+ &response,
+ NULL));
+ EXPECT_FALSE(response.update_exists);
+}
+
+TEST(OmahaRequestActionTest, ValidUpdateTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "arm-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ ""); // url
+ OmahaResponse response;
+ ASSERT_TRUE(
+ TestOmahaRequestAction(params,
+ GetUpdateResponse(OmahaRequestParams::kAppId,
+ "1.2.3.4", // version
+ "http://more/info",
+ "true", // prompt
+ "http://code/base", // dl url
+ "HASH1234=", // checksum
+ "false", // needs admin
+ "123"), // size
+ true,
+ &response,
+ NULL));
+ EXPECT_TRUE(response.update_exists);
+ EXPECT_EQ("1.2.3.4", response.display_version);
+ EXPECT_EQ("http://code/base", response.codebase);
+ EXPECT_EQ("http://more/info", response.more_info_url);
+ EXPECT_EQ("HASH1234=", response.hash);
+ EXPECT_EQ(123, response.size);
+ EXPECT_FALSE(response.needs_admin);
+ EXPECT_TRUE(response.prompt);
+}
+
+TEST(OmahaRequestActionTest, NoOutputPipeTest) {
+ OmahaRequestParams params("", // machine_id
+ "", // usr_id
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "", // os_sp
+ "", // os_board
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest",
+ ""); // url
+ const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId));
+
+ GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
+
+ ObjectFeederAction<OmahaRequestParams> feeder_action;
+ feeder_action.set_obj(params);
+ OmahaRequestAction action(new MockHttpFetcher(http_response.data(),
+ http_response.size()));
+ OmahaRequestActionTestProcessorDelegate delegate;
+ delegate.loop_ = loop;
+ ActionProcessor processor;
+ processor.set_delegate(&delegate);
+ processor.EnqueueAction(&feeder_action);
+ processor.EnqueueAction(&action);
+ BondActions(&feeder_action, &action);
+
+ g_timeout_add(0, &StartProcessorInRunLoop, &processor);
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+ EXPECT_FALSE(processor.IsRunning());
+}
+
+TEST(OmahaRequestActionTest, InvalidXmlTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_FALSE(
+ TestOmahaRequestAction(params,
+ "invalid xml>",
+ false,
+ &response,
+ NULL));
+ EXPECT_FALSE(response.update_exists);
+}
+
+TEST(OmahaRequestActionTest, MissingStatusTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_FALSE(TestOmahaRequestAction(
+ params,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
+ "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
+ "appid=\"foo\" status=\"ok\"><ping "
+ "status=\"ok\"/><updatecheck/></app></gupdate>",
+ false,
+ &response,
+ NULL));
+ EXPECT_FALSE(response.update_exists);
+}
+
+TEST(OmahaRequestActionTest, InvalidStatusTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_FALSE(TestOmahaRequestAction(
+ params,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
+ "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
+ "appid=\"foo\" status=\"ok\"><ping "
+ "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>",
+ false,
+ &response,
+ NULL));
+ EXPECT_FALSE(response.update_exists);
+}
+
+TEST(OmahaRequestActionTest, MissingNodesetTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_FALSE(TestOmahaRequestAction(
+ params,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
+ "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
+ "appid=\"foo\" status=\"ok\"><ping "
+ "status=\"ok\"/></app></gupdate>",
+ false,
+ &response,
+ NULL));
+ EXPECT_FALSE(response.update_exists);
+}
+
+TEST(OmahaRequestActionTest, MissingFieldTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_TRUE(TestOmahaRequestAction(params,
+ string("<?xml version=\"1.0\" "
+ "encoding=\"UTF-8\"?><gupdate "
+ "xmlns=\"http://www.google.com/"
+ "update2/response\" "
+ "protocol=\"2.0\"><app appid=\"") +
+ OmahaRequestParams::kAppId
+ + "\" status=\"ok\"><ping "
+ "status=\"ok\"/><updatecheck "
+ "DisplayVersion=\"1.2.3.4\" "
+ "Prompt=\"false\" "
+ "codebase=\"http://code/base\" "
+ "hash=\"HASH1234=\" needsadmin=\"true\" "
+ "size=\"123\" "
+ "status=\"ok\"/></app></gupdate>",
+ true,
+ &response,
+ NULL));
+ EXPECT_TRUE(response.update_exists);
+ EXPECT_EQ("1.2.3.4", response.display_version);
+ EXPECT_EQ("http://code/base", response.codebase);
+ EXPECT_EQ("", response.more_info_url);
+ EXPECT_EQ("HASH1234=", response.hash);
+ EXPECT_EQ(123, response.size);
+ EXPECT_TRUE(response.needs_admin);
+ EXPECT_FALSE(response.prompt);
+}
+
+namespace {
+class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate {
+ public:
+ void ProcessingStopped(const ActionProcessor* processor) {
+ ASSERT_TRUE(loop_);
+ g_main_loop_quit(loop_);
+ }
+ GMainLoop *loop_;
+};
+
+gboolean TerminateTransferTestStarter(gpointer data) {
+ ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data);
+ processor->StartProcessing();
+ CHECK(processor->IsRunning());
+ processor->StopProcessing();
+ return FALSE;
+}
+} // namespace {}
+
+TEST(OmahaRequestActionTest, TerminateTransferTest) {
+ OmahaRequestParams params("", // machine_id
+ "", // usr_id
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "", // os_sp
+ "", // os_board
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest",
+ "http://url");
+ string http_response("doesn't matter");
+ GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
+
+ ObjectFeederAction<OmahaRequestParams> feeder_action;
+ feeder_action.set_obj(params);
+ OmahaRequestAction action(new MockHttpFetcher(http_response.data(),
+ http_response.size()));
+ TerminateEarlyTestProcessorDelegate delegate;
+ delegate.loop_ = loop;
+ ActionProcessor processor;
+ processor.set_delegate(&delegate);
+ processor.EnqueueAction(&feeder_action);
+ processor.EnqueueAction(&action);
+ BondActions(&feeder_action, &action);
+
+ g_timeout_add(0, &TerminateTransferTestStarter, &processor);
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+}
+
+TEST(OmahaRequestActionTest, XmlEncodeTest) {
+ EXPECT_EQ("ab", XmlEncode("ab"));
+ EXPECT_EQ("a<b", XmlEncode("a<b"));
+ EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9"));
+ EXPECT_EQ("<&>", XmlEncode("<&>"));
+ EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>"));
+
+ vector<char> post_data;
+
+ // Make sure XML Encode is being called on the params
+ OmahaRequestParams params("testthemachine<id",
+ "testtheuser_id<",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "testtheservice_pack>",
+ "x86 generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_FALSE(
+ TestOmahaRequestAction(params,
+ "invalid xml>",
+ false,
+ &response,
+ &post_data));
+ // convert post_data to string
+ string post_str(&post_data[0], post_data.size());
+ EXPECT_NE(post_str.find("testthemachine<id"), string::npos);
+ EXPECT_EQ(post_str.find("testthemachine<id"), string::npos);
+ EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos);
+ EXPECT_EQ(post_str.find("testtheuser_id<"), string::npos);
+ EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos);
+ EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos);
+ EXPECT_NE(post_str.find("x86 generic"), string::npos);
+}
+
+TEST(OmahaRequestActionTest, XmlDecodeTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_TRUE(
+ TestOmahaRequestAction(params,
+ GetUpdateResponse(OmahaRequestParams::kAppId,
+ "1.2.3.4", // version
+ "testthe<url", // more info
+ "true", // prompt
+ "testthe&code", // dl url
+ "HASH1234=", // checksum
+ "false", // needs admin
+ "123"), // size
+ true,
+ &response,
+ NULL));
+
+ EXPECT_EQ(response.more_info_url, "testthe<url");
+ EXPECT_EQ(response.codebase, "testthe&code");
+}
+
+TEST(OmahaRequestActionTest, ParseIntTest) {
+ OmahaRequestParams params("machine_id",
+ "user_id",
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "the_board",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest_track",
+ "http://url");
+ OmahaResponse response;
+ ASSERT_TRUE(
+ TestOmahaRequestAction(params,
+ GetUpdateResponse(OmahaRequestParams::kAppId,
+ "1.2.3.4", // version
+ "theurl", // more info
+ "true", // prompt
+ "thecodebase", // dl url
+ "HASH1234=", // checksum
+ "false", // needs admin
+ // overflows int32:
+ "123123123123123"), // size
+ true,
+ &response,
+ NULL));
+
+ EXPECT_EQ(response.size, 123123123123123ll);
+}
+
+} // namespace chromeos_update_engine
diff --git a/omaha_request_prep_action.cc b/omaha_request_prep_action.cc
index 7163119..365c463 100644
--- a/omaha_request_prep_action.cc
+++ b/omaha_request_prep_action.cc
@@ -35,16 +35,16 @@
const string sp(version + "_" + GetMachineType());
const string track(GetLsbValue("CHROMEOS_RELEASE_TRACK", ""));
const string update_url(GetLsbValue("CHROMEOS_AUSERVER",
- UpdateCheckParams::kUpdateUrl));
+ OmahaRequestParams::kUpdateUrl));
const string board(GetLsbValue("CHROMEOS_RELEASE_BOARD", ""));
- UpdateCheckParams out(machine_id, // machine_id
+ OmahaRequestParams out(machine_id, // machine_id
machine_id, // user_id (use machine_id)
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
sp, // e.g. 0.2.3.3_i686
board, // e.g. x86-generic
- UpdateCheckParams::kAppId,
+ OmahaRequestParams::kAppId,
version, // app version (from lsb-release)
"en-US", // lang
track, // track
@@ -73,12 +73,12 @@
bool OmahaRequestPrepAction::GetMachineId(std::string* out_id) const {
// See if we have an existing Machine ID
const string omaha_id_path = root_ + OmahaIdPath();
-
+
if (utils::ReadFileToString(omaha_id_path, out_id) &&
out_id->size() == kGuidStringLength) {
return true;
}
-
+
// Create a new ID
int rand_fd = open("/dev/urandom", O_RDONLY, 0);
TEST_AND_RETURN_FALSE_ERRNO(rand_fd >= 0);
@@ -107,7 +107,7 @@
string file_data;
if (!utils::ReadFileToString(root_ + files[i], &file_data))
continue;
-
+
map<string, string> data = simple_key_value_store::ParseString(file_data);
if (utils::MapContainsKey(data, key))
return data[key];
diff --git a/omaha_request_prep_action.h b/omaha_request_prep_action.h
index d6030f5..794cfb7 100644
--- a/omaha_request_prep_action.h
+++ b/omaha_request_prep_action.h
@@ -7,7 +7,7 @@
#include <string>
#include "update_engine/action.h"
-#include "update_engine/update_check_action.h"
+#include "update_engine/omaha_request_action.h"
// This gathers local system information and prepares info used by the
// update check action.
@@ -21,7 +21,7 @@
class ActionTraits<OmahaRequestPrepAction> {
public:
typedef NoneType InputObjectType;
- typedef UpdateCheckParams OutputObjectType;
+ typedef OmahaRequestParams OutputObjectType;
};
class OmahaRequestPrepAction : public Action<OmahaRequestPrepAction> {
diff --git a/omaha_request_prep_action_unittest.cc b/omaha_request_prep_action_unittest.cc
index 1397c4d..0813964 100644
--- a/omaha_request_prep_action_unittest.cc
+++ b/omaha_request_prep_action_unittest.cc
@@ -18,7 +18,7 @@
public:
// Return true iff the OmahaResponseHandlerAction succeeded.
// if out is non-NULL, it's set w/ the response from the action.
- bool DoTest(bool force_full_update, UpdateCheckParams* out);
+ bool DoTest(bool force_full_update, OmahaRequestParams* out);
static const string kTestDir;
};
@@ -43,14 +43,14 @@
};
bool OmahaRequestPrepActionTest::DoTest(bool force_full_update,
- UpdateCheckParams* out) {
+ OmahaRequestParams* out) {
ActionProcessor processor;
OmahaRequestPrepActionProcessorDelegate delegate;
processor.set_delegate(&delegate);
OmahaRequestPrepAction request_prep_action(force_full_update);
request_prep_action.set_root(string("./") + kTestDir);
- ObjectCollectorAction<UpdateCheckParams> collector_action;
+ ObjectCollectorAction<OmahaRequestParams> collector_action;
BondActions(&request_prep_action, &collector_action);
processor.EnqueueAction(&request_prep_action);
processor.EnqueueAction(&collector_action);
@@ -69,7 +69,7 @@
((c >= 'a') && (c <= 'f')) ||
((c >= 'A') && (c <= 'F'));
}
-
+
// Returns true iff str is formatted as a GUID. Example GUID:
// "{2251FFAD-DBAB-4E53-8B3A-18F98BB4EB80}"
bool IsValidGuid(const string& str) {
@@ -115,7 +115,7 @@
"CHROMEOS_RELEASE_FOO=bar\n"
"CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
"CHROMEOS_RELEASE_TRACK=footrack"));
- UpdateCheckParams out;
+ OmahaRequestParams out;
EXPECT_TRUE(DoTest(false, &out));
EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id;
// for now we're just using the machine id here
@@ -141,7 +141,7 @@
"CHROMEOS_RELEASE_FOO=bar\n"
"CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
"CHROMEOS_RELEASE_TRXCK=footrack"));
- UpdateCheckParams out;
+ OmahaRequestParams out;
EXPECT_TRUE(DoTest(false, &out));
EXPECT_TRUE(IsValidGuid(out.machine_id));
// for now we're just using the machine id here
@@ -166,7 +166,7 @@
"CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
"CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
"CHROMEOS_RELEASE_TRXCK=footrack"));
- UpdateCheckParams out;
+ OmahaRequestParams out;
EXPECT_TRUE(DoTest(false, &out));
EXPECT_TRUE(IsValidGuid(out.machine_id)) << out.machine_id;
// for now we're just using the machine id here
@@ -190,7 +190,7 @@
"CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
"CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
"CHROMEOS_RELEASE_TRXCK=footrack"));
- UpdateCheckParams out1;
+ OmahaRequestParams out1;
EXPECT_TRUE(DoTest(false, &out1));
string machine_id;
EXPECT_TRUE(utils::ReadFileToString(
@@ -198,7 +198,7 @@
utils::kStatefulPartition + "/etc/omaha_id",
&machine_id));
EXPECT_EQ(machine_id, out1.machine_id);
- UpdateCheckParams out2;
+ OmahaRequestParams out2;
EXPECT_TRUE(DoTest(false, &out2));
EXPECT_EQ(machine_id, out2.machine_id);
EXPECT_EQ(0, System(string("rm -rf ") + kTestDir));
diff --git a/omaha_response_handler_action.cc b/omaha_response_handler_action.cc
index 486f19b..319c825 100644
--- a/omaha_response_handler_action.cc
+++ b/omaha_response_handler_action.cc
@@ -20,7 +20,7 @@
void OmahaResponseHandlerAction::PerformAction() {
CHECK(HasInputObject());
ScopedActionCompleter completer(processor_, this);
- const UpdateCheckResponse& response = GetInputObject();
+ const OmahaResponse& response = GetInputObject();
if (!response.update_exists) {
got_no_update_response_ = true;
LOG(INFO) << "There are no updates. Aborting.";
@@ -42,7 +42,7 @@
SetOutputObject(install_plan_);
LOG(INFO) << "Using this install plan:";
install_plan_.Dump();
-
+
completer.set_success(true);
}
diff --git a/omaha_response_handler_action.h b/omaha_response_handler_action.h
index e79e32b..b5feabd 100644
--- a/omaha_response_handler_action.h
+++ b/omaha_response_handler_action.h
@@ -8,7 +8,7 @@
#include <string>
#include "update_engine/action.h"
#include "update_engine/install_plan.h"
-#include "update_engine/update_check_action.h"
+#include "update_engine/omaha_request_action.h"
// This class reads in an Omaha response and converts what it sees into
// an install plan which is passed out.
@@ -20,7 +20,7 @@
template<>
class ActionTraits<OmahaResponseHandlerAction> {
public:
- typedef UpdateCheckResponse InputObjectType;
+ typedef OmahaResponse InputObjectType;
typedef InstallPlan OutputObjectType;
};
@@ -41,7 +41,7 @@
void set_boot_device(const std::string& boot_device) {
boot_device_ = boot_device;
}
-
+
bool GotNoUpdateResponse() const { return got_no_update_response_; }
const InstallPlan& install_plan() const { return install_plan_; }
@@ -59,10 +59,10 @@
// set to non-empty in unit tests
std::string boot_device_;
-
+
// The install plan, if we have an update.
InstallPlan install_plan_;
-
+
// True only if we got a response and the response said no updates
bool got_no_update_response_;
diff --git a/omaha_response_handler_action_unittest.cc b/omaha_response_handler_action_unittest.cc
index b396a9c..489d5e7 100644
--- a/omaha_response_handler_action_unittest.cc
+++ b/omaha_response_handler_action_unittest.cc
@@ -16,7 +16,7 @@
public:
// Return true iff the OmahaResponseHandlerAction succeeded.
// If out is non-NULL, it's set w/ the response from the action.
- bool DoTest(const UpdateCheckResponse& in,
+ bool DoTest(const OmahaResponse& in,
const string& boot_dev,
InstallPlan* out);
};
@@ -51,14 +51,14 @@
"-the_update_a.b.c.d_DELTA_.tgz";
} // namespace {}
-bool OmahaResponseHandlerActionTest::DoTest(const UpdateCheckResponse& in,
+bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in,
const string& boot_dev,
InstallPlan* out) {
ActionProcessor processor;
OmahaResponseHandlerActionProcessorDelegate delegate;
processor.set_delegate(&delegate);
- ObjectFeederAction<UpdateCheckResponse> feeder_action;
+ ObjectFeederAction<OmahaResponse> feeder_action;
feeder_action.set_obj(in);
OmahaResponseHandlerAction response_handler_action;
response_handler_action.set_boot_device(boot_dev);
@@ -79,7 +79,7 @@
TEST_F(OmahaResponseHandlerActionTest, SimpleTest) {
{
- UpdateCheckResponse in;
+ OmahaResponse in;
in.update_exists = true;
in.display_version = "a.b.c.d";
in.codebase = "http://foo/the_update_a.b.c.d.tgz";
@@ -96,7 +96,7 @@
EXPECT_EQ("/dev/sda5", install_plan.install_path);
}
{
- UpdateCheckResponse in;
+ OmahaResponse in;
in.update_exists = true;
in.display_version = "a.b.c.d";
in.codebase = "http://foo/the_update_a.b.c.d.tgz";
@@ -113,7 +113,7 @@
EXPECT_EQ("/dev/sda3", install_plan.install_path);
}
{
- UpdateCheckResponse in;
+ OmahaResponse in;
in.update_exists = true;
in.display_version = "a.b.c.d";
in.codebase = kLongName;
@@ -132,7 +132,7 @@
}
TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) {
- UpdateCheckResponse in;
+ OmahaResponse in;
in.update_exists = false;
InstallPlan install_plan;
EXPECT_FALSE(DoTest(in, "/dev/sda1", &install_plan));
diff --git a/update_attempter.cc b/update_attempter.cc
index ec0e1f5..a8a3207 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -18,11 +18,11 @@
#include "update_engine/download_action.h"
#include "update_engine/filesystem_copier_action.h"
#include "update_engine/libcurl_http_fetcher.h"
+#include "update_engine/omaha_request_action.h"
#include "update_engine/omaha_request_prep_action.h"
#include "update_engine/omaha_response_handler_action.h"
#include "update_engine/postinstall_runner_action.h"
#include "update_engine/set_bootable_flag_action.h"
-#include "update_engine/update_check_action.h"
using std::tr1::shared_ptr;
using std::string;
@@ -102,8 +102,8 @@
// Actions:
shared_ptr<OmahaRequestPrepAction> request_prep_action(
new OmahaRequestPrepAction(force_full_update));
- shared_ptr<UpdateCheckAction> update_check_action(
- new UpdateCheckAction(new LibcurlHttpFetcher));
+ shared_ptr<OmahaRequestAction> update_check_action(
+ new OmahaRequestAction(new LibcurlHttpFetcher));
shared_ptr<OmahaResponseHandlerAction> response_handler_action(
new OmahaResponseHandlerAction);
shared_ptr<FilesystemCopierAction> filesystem_copier_action(
@@ -118,7 +118,7 @@
new SetBootableFlagAction);
shared_ptr<PostinstallRunnerAction> postinstall_runner_action_postcommit(
new PostinstallRunnerAction(false));
-
+
download_action->set_delegate(this);
response_handler_action_ = response_handler_action;
@@ -134,7 +134,7 @@
actions_.push_back(shared_ptr<AbstractAction>(set_bootable_flag_action));
actions_.push_back(shared_ptr<AbstractAction>(
postinstall_runner_action_postcommit));
-
+
// Enqueue the actions
for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin();
it != actions_.end(); ++it) {
@@ -209,7 +209,7 @@
// Find out which action completed.
if (type == OmahaResponseHandlerAction::StaticType()) {
SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING);
- OmahaResponseHandlerAction* omaha_response_handler_action =
+ OmahaResponseHandlerAction* omaha_response_handler_action =
dynamic_cast<OmahaResponseHandlerAction*>(action);
CHECK(omaha_response_handler_action);
const InstallPlan& plan = omaha_response_handler_action->install_plan();
diff --git a/update_check_action_unittest.cc b/update_check_action_unittest.cc
deleted file mode 100644
index e2e7410..0000000
--- a/update_check_action_unittest.cc
+++ /dev/null
@@ -1,538 +0,0 @@
-// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <string>
-#include <vector>
-#include <glib.h>
-#include <gtest/gtest.h>
-#include "update_engine/action_pipe.h"
-#include "update_engine/update_check_action.h"
-#include "update_engine/mock_http_fetcher.h"
-#include "update_engine/omaha_hash_calculator.h"
-#include "update_engine/test_utils.h"
-
-using std::string;
-using std::vector;
-
-namespace chromeos_update_engine {
-
-class UpdateCheckActionTest : public ::testing::Test { };
-
-namespace {
-string GetNoUpdateResponse(const string& app_id) {
- return string(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
- "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
- "appid=\"") + app_id + "\" status=\"ok\"><ping "
- "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>";
-}
-
-string GetUpdateResponse(const string& app_id,
- const string& display_version,
- const string& more_info_url,
- const string& prompt,
- const string& codebase,
- const string& hash,
- const string& needsadmin,
- const string& size) {
- return string("<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
- "xmlns=\"http://www.google.com/update2/response\" "
- "protocol=\"2.0\"><app "
- "appid=\"") + app_id + "\" status=\"ok\"><ping "
- "status=\"ok\"/><updatecheck DisplayVersion=\"" + display_version + "\" "
- "MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" "
- "codebase=\"" + codebase + "\" "
- "hash=\"" + hash + "\" needsadmin=\"" + needsadmin + "\" "
- "size=\"" + size + "\" status=\"ok\"/></app></gupdate>";
-}
-
-class UpdateCheckActionTestProcessorDelegate : public ActionProcessorDelegate {
- public:
- UpdateCheckActionTestProcessorDelegate()
- : loop_(NULL),
- expected_success_(true) {}
- virtual ~UpdateCheckActionTestProcessorDelegate() {
- }
- virtual void ProcessingDone(const ActionProcessor* processor, bool success) {
- ASSERT_TRUE(loop_);
- g_main_loop_quit(loop_);
- }
-
- virtual void ActionCompleted(ActionProcessor* processor,
- AbstractAction* action,
- bool success) {
- // make sure actions always succeed
- if (action->Type() == UpdateCheckAction::StaticType())
- EXPECT_EQ(expected_success_, success);
- else
- EXPECT_TRUE(success);
- }
- GMainLoop *loop_;
- bool expected_success_;
-};
-
-gboolean StartProcessorInRunLoop(gpointer data) {
- ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data);
- processor->StartProcessing();
- return FALSE;
-}
-
-} // namespace {}
-
-class OutputObjectCollectorAction;
-
-template<>
-class ActionTraits<OutputObjectCollectorAction> {
- public:
- // Does not take an object for input
- typedef UpdateCheckResponse InputObjectType;
- // On success, puts the output path on output
- typedef NoneType OutputObjectType;
-};
-
-class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> {
- public:
- OutputObjectCollectorAction() : has_input_object_(false) {}
- void PerformAction() {
- // copy input object
- has_input_object_ = HasInputObject();
- if (has_input_object_)
- update_check_response_ = GetInputObject();
- processor_->ActionComplete(this, true);
- }
- // Should never be called
- void TerminateProcessing() {
- CHECK(false);
- }
- // Debugging/logging
- static std::string StaticType() {
- return "OutputObjectCollectorAction";
- }
- std::string Type() const { return StaticType(); }
- bool has_input_object_;
- UpdateCheckResponse update_check_response_;
-};
-
-// returns true iff an output response was obtained from the
-// UpdateCheckAction. out_response may be NULL.
-// out_post_data may be null; if non-null, the post-data received by the
-// mock HttpFetcher is returned.
-bool TestUpdateCheckAction(const UpdateCheckParams& params,
- const string& http_response,
- bool expected_success,
- UpdateCheckResponse* out_response,
- vector<char> *out_post_data) {
- GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
- MockHttpFetcher *fetcher = new MockHttpFetcher(http_response.data(),
- http_response.size());
- ObjectFeederAction<UpdateCheckParams> feeder_action;
- UpdateCheckAction action(fetcher); // takes ownership of fetcher
- UpdateCheckActionTestProcessorDelegate delegate;
- delegate.loop_ = loop;
- delegate.expected_success_ = expected_success;
- ActionProcessor processor;
- feeder_action.set_obj(params);
- processor.set_delegate(&delegate);
- processor.EnqueueAction(&feeder_action);
- processor.EnqueueAction(&action);
-
- OutputObjectCollectorAction collector_action;
-
- BondActions(&feeder_action, &action);
- BondActions(&action, &collector_action);
- processor.EnqueueAction(&collector_action);
-
- g_timeout_add(0, &StartProcessorInRunLoop, &processor);
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
- if (collector_action.has_input_object_ && out_response)
- *out_response = collector_action.update_check_response_;
- if (out_post_data)
- *out_post_data = fetcher->post_data();
- return collector_action.has_input_object_;
-}
-
-TEST(UpdateCheckActionTest, NoUpdateTest) {
- UpdateCheckParams params("", // machine_id
- "", // user_id
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "", // os_sp
- "x86-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest",
- ""); // url
- UpdateCheckResponse response;
- ASSERT_TRUE(
- TestUpdateCheckAction(params,
- GetNoUpdateResponse(UpdateCheckParams::kAppId),
- true,
- &response,
- NULL));
- EXPECT_FALSE(response.update_exists);
-}
-
-TEST(UpdateCheckActionTest, ValidUpdateTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "arm-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- ""); // url
- UpdateCheckResponse response;
- ASSERT_TRUE(
- TestUpdateCheckAction(params,
- GetUpdateResponse(UpdateCheckParams::kAppId,
- "1.2.3.4", // version
- "http://more/info",
- "true", // prompt
- "http://code/base", // dl url
- "HASH1234=", // checksum
- "false", // needs admin
- "123"), // size
- true,
- &response,
- NULL));
- EXPECT_TRUE(response.update_exists);
- EXPECT_EQ("1.2.3.4", response.display_version);
- EXPECT_EQ("http://code/base", response.codebase);
- EXPECT_EQ("http://more/info", response.more_info_url);
- EXPECT_EQ("HASH1234=", response.hash);
- EXPECT_EQ(123, response.size);
- EXPECT_FALSE(response.needs_admin);
- EXPECT_TRUE(response.prompt);
-}
-
-TEST(UpdateCheckActionTest, NoOutputPipeTest) {
- UpdateCheckParams params("", // machine_id
- "", // usr_id
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "", // os_sp
- "", // os_board
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest",
- ""); // url
- const string http_response(GetNoUpdateResponse(UpdateCheckParams::kAppId));
-
- GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
-
- ObjectFeederAction<UpdateCheckParams> feeder_action;
- feeder_action.set_obj(params);
- UpdateCheckAction action(new MockHttpFetcher(http_response.data(),
- http_response.size()));
- UpdateCheckActionTestProcessorDelegate delegate;
- delegate.loop_ = loop;
- ActionProcessor processor;
- processor.set_delegate(&delegate);
- processor.EnqueueAction(&feeder_action);
- processor.EnqueueAction(&action);
- BondActions(&feeder_action, &action);
-
- g_timeout_add(0, &StartProcessorInRunLoop, &processor);
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
- EXPECT_FALSE(processor.IsRunning());
-}
-
-TEST(UpdateCheckActionTest, InvalidXmlTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "x86-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_FALSE(
- TestUpdateCheckAction(params,
- "invalid xml>",
- false,
- &response,
- NULL));
- EXPECT_FALSE(response.update_exists);
-}
-
-TEST(UpdateCheckActionTest, MissingStatusTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "x86-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_FALSE(TestUpdateCheckAction(
- params,
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
- "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
- "appid=\"foo\" status=\"ok\"><ping "
- "status=\"ok\"/><updatecheck/></app></gupdate>",
- false,
- &response,
- NULL));
- EXPECT_FALSE(response.update_exists);
-}
-
-TEST(UpdateCheckActionTest, InvalidStatusTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "x86-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_FALSE(TestUpdateCheckAction(
- params,
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
- "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
- "appid=\"foo\" status=\"ok\"><ping "
- "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>",
- false,
- &response,
- NULL));
- EXPECT_FALSE(response.update_exists);
-}
-
-TEST(UpdateCheckActionTest, MissingNodesetTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "x86-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_FALSE(TestUpdateCheckAction(
- params,
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
- "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
- "appid=\"foo\" status=\"ok\"><ping "
- "status=\"ok\"/></app></gupdate>",
- false,
- &response,
- NULL));
- EXPECT_FALSE(response.update_exists);
-}
-
-TEST(UpdateCheckActionTest, MissingFieldTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "x86-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_TRUE(TestUpdateCheckAction(params,
- string("<?xml version=\"1.0\" "
- "encoding=\"UTF-8\"?><gupdate "
- "xmlns=\"http://www.google.com/"
- "update2/response\" "
- "protocol=\"2.0\"><app appid=\"") +
- UpdateCheckParams::kAppId
- + "\" status=\"ok\"><ping "
- "status=\"ok\"/><updatecheck "
- "DisplayVersion=\"1.2.3.4\" "
- "Prompt=\"false\" "
- "codebase=\"http://code/base\" "
- "hash=\"HASH1234=\" needsadmin=\"true\" "
- "size=\"123\" "
- "status=\"ok\"/></app></gupdate>",
- true,
- &response,
- NULL));
- EXPECT_TRUE(response.update_exists);
- EXPECT_EQ("1.2.3.4", response.display_version);
- EXPECT_EQ("http://code/base", response.codebase);
- EXPECT_EQ("", response.more_info_url);
- EXPECT_EQ("HASH1234=", response.hash);
- EXPECT_EQ(123, response.size);
- EXPECT_TRUE(response.needs_admin);
- EXPECT_FALSE(response.prompt);
-}
-
-namespace {
-class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate {
- public:
- void ProcessingStopped(const ActionProcessor* processor) {
- ASSERT_TRUE(loop_);
- g_main_loop_quit(loop_);
- }
- GMainLoop *loop_;
-};
-
-gboolean TerminateTransferTestStarter(gpointer data) {
- ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data);
- processor->StartProcessing();
- CHECK(processor->IsRunning());
- processor->StopProcessing();
- return FALSE;
-}
-} // namespace {}
-
-TEST(UpdateCheckActionTest, TerminateTransferTest) {
- UpdateCheckParams params("", // machine_id
- "", // usr_id
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "", // os_sp
- "", // os_board
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest",
- "http://url");
- string http_response("doesn't matter");
- GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
-
- ObjectFeederAction<UpdateCheckParams> feeder_action;
- feeder_action.set_obj(params);
- UpdateCheckAction action(new MockHttpFetcher(http_response.data(),
- http_response.size()));
- TerminateEarlyTestProcessorDelegate delegate;
- delegate.loop_ = loop;
- ActionProcessor processor;
- processor.set_delegate(&delegate);
- processor.EnqueueAction(&feeder_action);
- processor.EnqueueAction(&action);
- BondActions(&feeder_action, &action);
-
- g_timeout_add(0, &TerminateTransferTestStarter, &processor);
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-}
-
-TEST(UpdateCheckActionTest, XmlEncodeTest) {
- EXPECT_EQ("ab", XmlEncode("ab"));
- EXPECT_EQ("a<b", XmlEncode("a<b"));
- EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9"));
- EXPECT_EQ("<&>", XmlEncode("<&>"));
- EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>"));
-
- vector<char> post_data;
-
- // Make sure XML Encode is being called on the params
- UpdateCheckParams params("testthemachine<id",
- "testtheuser_id<",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "testtheservice_pack>",
- "x86 generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_FALSE(
- TestUpdateCheckAction(params,
- "invalid xml>",
- false,
- &response,
- &post_data));
- // convert post_data to string
- string post_str(&post_data[0], post_data.size());
- EXPECT_NE(post_str.find("testthemachine<id"), string::npos);
- EXPECT_EQ(post_str.find("testthemachine<id"), string::npos);
- EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos);
- EXPECT_EQ(post_str.find("testtheuser_id<"), string::npos);
- EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos);
- EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos);
- EXPECT_NE(post_str.find("x86 generic"), string::npos);
-}
-
-TEST(UpdateCheckActionTest, XmlDecodeTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "x86-generic",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_TRUE(
- TestUpdateCheckAction(params,
- GetUpdateResponse(UpdateCheckParams::kAppId,
- "1.2.3.4", // version
- "testthe<url", // more info
- "true", // prompt
- "testthe&codebase", // dl url
- "HASH1234=", // checksum
- "false", // needs admin
- "123"), // size
- true,
- &response,
- NULL));
-
- EXPECT_EQ(response.more_info_url, "testthe<url");
- EXPECT_EQ(response.codebase, "testthe&codebase");
-}
-
-TEST(UpdateCheckActionTest, ParseIntTest) {
- UpdateCheckParams params("machine_id",
- "user_id",
- UpdateCheckParams::kOsPlatform,
- UpdateCheckParams::kOsVersion,
- "service_pack",
- "the_board",
- UpdateCheckParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest_track",
- "http://url");
- UpdateCheckResponse response;
- ASSERT_TRUE(
- TestUpdateCheckAction(params,
- GetUpdateResponse(UpdateCheckParams::kAppId,
- "1.2.3.4", // version
- "theurl", // more info
- "true", // prompt
- "thecodebase", // dl url
- "HASH1234=", // checksum
- "false", // needs admin
- // overflows int32:
- "123123123123123"), // size
- true,
- &response,
- NULL));
-
- EXPECT_EQ(response.size, 123123123123123ll);
-}
-
-} // namespace chromeos_update_engine