Skip to content

Commit

Permalink
Only store Omaha XML response for update check
Browse files Browse the repository at this point in the history
The full Omaha XML response is stored to a file for the postinst action,
but we only want the response for the initial update check passed this
way and not overwrite the file with responses for state reports.
Only store the Omaha XML response for the update check and not all of
the interaction with the Omaha server.
  • Loading branch information
pothos committed Dec 11, 2023
1 parent a9b9bee commit 2670b28
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
12 changes: 8 additions & 4 deletions src/update_engine/omaha_request_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ string XmlEncode(const string& input) {
OmahaRequestAction::OmahaRequestAction(SystemState* system_state,
OmahaEvent* event,
HttpFetcher* http_fetcher,
bool ping_only)
bool ping_only,
bool store_response)
: system_state_(system_state),
event_(event),
http_fetcher_(http_fetcher),
ping_only_(ping_only),
ping_active_days_(0),
ping_roll_call_days_(0) {
ping_roll_call_days_(0),
store_response_(store_response) {
params_ = system_state->request_params();
}

Expand Down Expand Up @@ -614,8 +616,10 @@ void OmahaRequestAction::TransferComplete(HttpFetcher *fetcher,
string current_response(response_buffer_.begin(), response_buffer_.end());
LOG(INFO) << "Omaha request response: " << current_response;

LOG_IF(WARNING, !system_state_->prefs()->SetString(kPrefsFullResponse, current_response))
<< "Unable to write full response.";
if (store_response_) {
LOG_IF(WARNING, !system_state_->prefs()->SetString(kPrefsFullResponse, current_response))
<< "Unable to write full response.";
}

// Events are best effort transactions -- assume they always succeed.
if (IsEvent()) {
Expand Down
6 changes: 5 additions & 1 deletion src/update_engine/omaha_request_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class OmahaRequestAction : public Action<OmahaRequestAction>,
OmahaRequestAction(SystemState* system_state,
OmahaEvent* event,
HttpFetcher* http_fetcher,
bool ping_only);
bool ping_only,
bool store_response);
virtual ~OmahaRequestAction();
typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType;
typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType;
Expand Down Expand Up @@ -204,6 +205,9 @@ class OmahaRequestAction : public Action<OmahaRequestAction>,
int ping_active_days_;
int ping_roll_call_days_;

// If true, store full response to XML dump file for the postinst action.
bool store_response_;

DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction);
};

Expand Down
9 changes: 7 additions & 2 deletions src/update_engine/omaha_request_action_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ bool TestUpdateCheck(PrefsInterface* prefs,
OmahaRequestAction action(&mock_system_state,
NULL,
fetcher,
ping_only);
ping_only,
false);
processor.EnqueueAction(&action);

ObjectCollectorAction<OmahaResponse> collector_action;
Expand Down Expand Up @@ -169,7 +170,7 @@ void TestEvent(OmahaRequestParams params,
ActionProcessor processor;
ActionTestDelegate<OmahaRequestAction> delegate;

OmahaRequestAction action(&mock_system_state, event, fetcher, false);
OmahaRequestAction action(&mock_system_state, event, fetcher, false, false);
processor.EnqueueAction(&action);

delegate.RunProcessorInMainLoop(&processor);
Expand Down Expand Up @@ -230,6 +231,7 @@ TEST(OmahaRequestActionTest, NoOutputPipeTest) {
OmahaRequestAction action(&mock_system_state, NULL,
new MockHttpFetcher(http_response.data(),
http_response.size()),
false,
false);
processor.EnqueueAction(&action);

Expand Down Expand Up @@ -412,6 +414,7 @@ TEST(OmahaRequestActionTest, TerminateTransferTest) {
OmahaRequestAction action(&mock_system_state, NULL,
new MockHttpFetcher(http_response.data(),
http_response.size()),
false,
false);
TerminateEarlyTestProcessorDelegate delegate;
delegate.loop_ = loop;
Expand Down Expand Up @@ -586,6 +589,7 @@ TEST(OmahaRequestActionTest, IsEventTest) {
NULL,
new MockHttpFetcher(http_response.data(),
http_response.size()),
false,
false);
EXPECT_FALSE(update_check_action.IsEvent());

Expand All @@ -596,6 +600,7 @@ TEST(OmahaRequestActionTest, IsEventTest) {
new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
new MockHttpFetcher(http_response.data(),
http_response.size()),
false,
false);
EXPECT_TRUE(event_action.IsEvent());
}
Expand Down
10 changes: 8 additions & 2 deletions src/update_engine/update_attempter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ void UpdateAttempter::BuildUpdateActions(bool interactive) {
new OmahaRequestAction(system_state_,
NULL,
update_check_fetcher, // passes ownership
false));
false,
true)); // Store full response for the update check
shared_ptr<OmahaResponseHandlerAction> response_handler_action(
new OmahaResponseHandlerAction(system_state_));
shared_ptr<FilesystemCopierAction> filesystem_copier_action(
Expand All @@ -199,6 +200,7 @@ void UpdateAttempter::BuildUpdateActions(bool interactive) {
new OmahaEvent(
OmahaEvent::kTypeUpdateDownloadStarted),
new LibcurlHttpFetcher(),
false,
false));
LibcurlHttpFetcher* download_fetcher = new LibcurlHttpFetcher();
download_fetcher->set_check_certificate(CertificateChecker::kDownload);
Expand All @@ -214,6 +216,7 @@ void UpdateAttempter::BuildUpdateActions(bool interactive) {
new OmahaEvent(
OmahaEvent::kTypeUpdateDownloadFinished),
new LibcurlHttpFetcher(),
false,
false));
shared_ptr<FilesystemCopierAction> filesystem_verifier_action(
new FilesystemCopierAction(true));
Expand All @@ -227,6 +230,7 @@ void UpdateAttempter::BuildUpdateActions(bool interactive) {
new OmahaRequestAction(system_state_,
new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
new LibcurlHttpFetcher(),
false,
false));

download_action->set_delegate(this);
Expand Down Expand Up @@ -620,6 +624,7 @@ bool UpdateAttempter::ScheduleErrorEventAction() {
new OmahaRequestAction(system_state_,
error_event_.release(), // Pass ownership.
new LibcurlHttpFetcher(),
false,
false));
actions_.push_back(shared_ptr<AbstractAction>(error_event_action));
processor_->EnqueueAction(error_event_action.get());
Expand Down Expand Up @@ -690,7 +695,8 @@ void UpdateAttempter::PingOmaha() {
new OmahaRequestAction(system_state_,
NULL,
new LibcurlHttpFetcher(),
true));
true,
false));
actions_.push_back(shared_ptr<OmahaRequestAction>(ping_action));
processor_->set_delegate(NULL);
processor_->EnqueueAction(ping_action.get());
Expand Down
4 changes: 2 additions & 2 deletions src/update_engine/update_attempter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TEST_F(UpdateAttempterTest, ActionCompletedOmahaRequestTest) {
std::unique_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0));
fetcher->FailTransfer(500); // Sets the HTTP response code.
OmahaRequestAction action(&mock_system_state_, NULL,
fetcher.release(), false);
fetcher.release(), false, false);
ObjectCollectorAction<OmahaResponse> collector_action;
BondActions(&action, &collector_action);
OmahaResponse response;
Expand Down Expand Up @@ -168,7 +168,7 @@ TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) {

MockSystemState mock_system_state;
OmahaRequestAction omaha_request_action(&mock_system_state, NULL,
NULL, false);
NULL, false, false);
EXPECT_EQ(kActionCodeOmahaRequestError,
GetErrorCodeForAction(&omaha_request_action, kActionCodeError));
OmahaResponseHandlerAction omaha_response_handler_action(&mock_system_state_);
Expand Down

0 comments on commit 2670b28

Please sign in to comment.