Skip to content

Commit

Permalink
Add test to verify that install respects enterprise policies.
Browse files Browse the repository at this point in the history
Bug: 1464354

Change-Id: Idaefce266efb405c5142c6db8b5704ba89726959
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4811810
Commit-Queue: Xiaoling Bao <xiaolingbao@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: S Ganesh <ganesh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1188589}
  • Loading branch information
gxbao authored and Chromium LUCI CQ committed Aug 25, 2023
1 parent af62122 commit 632c86a
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 2 deletions.
1 change: 1 addition & 0 deletions chrome/updater/test/integration_test_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class IntegrationTestCommands
virtual void ExpectLegacyPolicyStatusSucceeds() const = 0;
virtual void RunUninstallCmdLine() const = 0;
virtual void RunHandoff(const std::string& app_id) const = 0;
virtual void InstallAppViaService(const std::string& app_id) const = 0;
#endif // BUILDFLAG(IS_WIN)
virtual void StressUpdateService() const = 0;
virtual void CallServiceUpdate(const std::string& app_id,
Expand Down
4 changes: 4 additions & 0 deletions chrome/updater/test/integration_test_commands_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ class IntegrationTestCommandsSystem : public IntegrationTestCommands {
void RunHandoff(const std::string& app_id) const override {
RunCommand("run_handoff", {Param("app_id", app_id)});
}

void InstallAppViaService(const std::string& app_id) const override {
RunCommand("install_app_via_service", {Param("app_id", app_id)});
}
#endif // BUILDFLAG(IS_WIN)

base::FilePath GetDifferentUserPath() const override {
Expand Down
4 changes: 4 additions & 0 deletions chrome/updater/test/integration_test_commands_user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ class IntegrationTestCommandsUser : public IntegrationTestCommands {
void RunHandoff(const std::string& app_id) const override {
updater::test::RunHandoff(updater_scope_, app_id);
}

void InstallAppViaService(const std::string& app_id) const override {
updater::test::InstallAppViaService(updater_scope_, app_id);
}
#endif // BUILDFLAG(IS_WIN)

base::FilePath GetDifferentUserPath() const override {
Expand Down
52 changes: 52 additions & 0 deletions chrome/updater/test/integration_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "chrome/updater/device_management/dm_storage.h"
#include "chrome/updater/ipc/ipc_support.h"
#include "chrome/updater/protos/omaha_settings.pb.h"
#include "chrome/updater/registration_data.h"
#include "chrome/updater/service_proxy_factory.h"
#include "chrome/updater/test/integration_test_commands.h"
#include "chrome/updater/test/integration_tests_impl.h"
Expand Down Expand Up @@ -263,6 +264,11 @@ class IntegrationTest : public ::testing::Test {
void RunHandoff(const std::string& app_id) {
test_commands_->RunHandoff(app_id);
}

void InstallAppViaService(const std::string& app_id) {
test_commands_->InstallAppViaService(app_id);
}

#endif // BUILDFLAG(IS_WIN)

void SetupFakeUpdaterHigherVersion() {
Expand Down Expand Up @@ -1680,6 +1686,44 @@ TEST_F(IntegrationTestDeviceManagement, PolicyFetchBeforeInstall) {
}

#if !defined(COMPONENT_BUILD)

TEST_F(IntegrationTestDeviceManagement, AppInstall) {
const base::Version kApp1Version = base::Version("1.2.3.4");
OmahaSettingsClientProto omaha_settings;
omaha_settings.set_install_default(
enterprise_management::INSTALL_DEFAULT_DISABLED);
ApplicationSettings app;
app.set_app_guid(kAppId1);
app.set_install(enterprise_management::INSTALL_ENABLED);
omaha_settings.mutable_application_settings()->Add(std::move(app));

PushEnrollmentToken(kEnrollmentToken);
ExpectDeviceManagementRegistrationRequest(test_server_.get(),
kEnrollmentToken, kDMToken);
ExpectDeviceManagementPolicyFetchRequest(test_server_.get(), kDMToken,
omaha_settings);
ASSERT_NO_FATAL_FAILURE(Install());
ASSERT_NO_FATAL_FAILURE(ExpectInstalled());

const base::FilePath crx_path = GetInstallerPath(kAppCRX);
ExpectAppsUpdateSequence(
UpdaterScope::kSystem, test_server_.get(),
{
AppUpdateExpectation({kAppId1, base::Version({0, 0, 0, 0}),
kApp1Version,
/*is_install=*/true,
/*should_update=*/true, false, "", crx_path}),
});

ASSERT_NO_FATAL_FAILURE(InstallAppViaService(kAppId1));
ASSERT_NO_FATAL_FAILURE(InstallAppViaService(kAppId2));
ExpectAppInstalled(kAppId1, kApp1Version);
ASSERT_NO_FATAL_FAILURE(ExpectNotRegistered(kAppId2));

ASSERT_NO_FATAL_FAILURE(ExpectUninstallPing(test_server_.get()));
ASSERT_NO_FATAL_FAILURE(Uninstall());
}

TEST_F(IntegrationTestDeviceManagement, AppUpdateConflictPolicies) {
const base::Version kApp1InitialVersion = base::Version("1.2.3.4");
const base::Version kApp1UpdatedVersion = base::Version("2.3.4.5");
Expand Down Expand Up @@ -1719,12 +1763,15 @@ TEST_F(IntegrationTestDeviceManagement, AppUpdateConflictPolicies) {
{
AppUpdateExpectation({kAppId1, kApp1InitialVersion,
kApp1UpdatedVersion,
/*is_install=*/false,
/*should_update=*/true, false, "", crx_path}),
AppUpdateExpectation({kAppId2, kApp2InitialVersion,
kApp2UpdatedVersion,
/*is_install=*/false,
/*should_update=*/true, false, "", crx_path}),
AppUpdateExpectation({kAppId3, kApp3InitialVersion,
kApp3UpdatedVersion,
/*is_install=*/false,
/*should_update=*/false, false, "", crx_path}),
});
ASSERT_NO_FATAL_FAILURE(RunWake(0));
Expand Down Expand Up @@ -1779,12 +1826,15 @@ TEST_F(IntegrationTestDeviceManagement, CloudPolicyOverridesPlatformPolicy) {
{
AppUpdateExpectation({kAppId1, kApp1InitialVersion,
kApp1UpdatedVersion,
/*is_install=*/false,
/*should_update=*/true, false, "", crx_path}),
AppUpdateExpectation({kAppId2, kApp2InitialVersion,
kApp2InitialVersion,
/*is_install=*/false,
/*should_update=*/false, false, "", crx_path}),
AppUpdateExpectation({kAppId3, kApp3InitialVersion,
kApp3UpdatedVersion,
/*is_install=*/false,
/*should_update=*/true, false, "", crx_path}),
});
ASSERT_NO_FATAL_FAILURE(RunWake(0));
Expand Down Expand Up @@ -1823,6 +1873,7 @@ TEST_F(IntegrationTestDeviceManagement, RollbackToTargetVersion) {
ExpectAppsUpdateSequence(
UpdaterScope::kSystem, test_server_.get(),
{AppUpdateExpectation(kAppId1, kAppInitialVersion, kAppRollbackVersion,
/*is_install=*/false,
/*should_update=*/true, /*allow_rollback=*/true,
kTargetVersionPrefix, GetInstallerPath(kAppCRX))});
ASSERT_NO_FATAL_FAILURE(RunWake(0));
Expand Down Expand Up @@ -1884,6 +1935,7 @@ TEST_F(IntegrationTestDeviceManagement, MsiInstallUpgrade) {
{
AppUpdateExpectation({kMsiAppId, kMsiInitialVersion,
kMsiUpdatedVersion,
/*is_install=*/false,
/*should_update=*/true, false, "", crx_path}),
});
ASSERT_NO_FATAL_FAILURE(RunWake(0));
Expand Down
2 changes: 2 additions & 0 deletions chrome/updater/test/integration_tests_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ void AppTestHelper::FirstTaskRun() {
{"install_app",
WithSwitch("version",
WithSwitch("app_id", WithSystemScope(Wrap(&InstallApp))))},
{"install_app_via_service",
WithSwitch("app_id", WithSystemScope(Wrap(&InstallAppViaService)))},
{"uninstall_app",
WithSwitch("app_id", WithSystemScope(Wrap(&UninstallApp)))},
{"set_existence_checker_path",
Expand Down
21 changes: 19 additions & 2 deletions chrome/updater/test/integration_tests_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,15 @@ AppUpdateExpectation::AppUpdateExpectation(
const std::string& app_id,
const base::Version& from_version,
const base::Version& to_version,
bool is_install,
bool should_update,
bool allow_rollback,
const std::string& target_version_prefix,
const base::FilePath& crx_relative_path)
: app_id(app_id),
from_version(from_version),
to_version(to_version),
is_install(is_install),
should_update(should_update),
allow_rollback(allow_rollback),
target_version_prefix(target_version_prefix),
Expand Down Expand Up @@ -539,10 +541,11 @@ void ExpectAppsUpdateSequence(UpdaterScope scope,
{request::GetPathMatcher(test_server->update_path()),
request::GetContentMatcher({base::StringPrintf(
R"(.*"appid":"%s",.*)"
R"("eventresult":1,"eventtype":3,)"
R"("eventresult":1,"eventtype":%d,)"
R"("nextversion":"%s","previousversion":"%s".*)"
R"("version":"%s".*)",
app.app_id.c_str(), app.to_version.GetString().c_str(),
app.app_id.c_str(), app.is_install ? 2 : 3,
app.to_version.GetString().c_str(),
app.from_version.GetString().c_str(),
app.to_version.GetString().c_str())})},
")]}'\n");
Expand Down Expand Up @@ -643,6 +646,20 @@ void UpdateAll(UpdaterScope scope) {
loop.Run();
}

void InstallAppViaService(UpdaterScope scope, const std::string& app_id) {
RegistrationRequest registration;
registration.app_id = app_id;
registration.version = base::Version({0, 0, 0, 0});
scoped_refptr<UpdateService> update_service = CreateUpdateServiceProxy(scope);
base::RunLoop loop;
update_service->Install(
registration, /*client_install_data=*/"", /*install_data_index=*/"",
UpdateService::Priority::kForeground, base::DoNothing(),
base::BindLambdaForTesting(
[&loop](UpdateService::Result result_unused) { loop.Quit(); }));
loop.Run();
}

void GetAppStates(UpdaterScope updater_scope,
const base::Value::Dict& expected_app_states) {
scoped_refptr<UpdateService> update_service =
Expand Down
6 changes: 6 additions & 0 deletions chrome/updater/test/integration_tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct AppUpdateExpectation {
AppUpdateExpectation(const std::string& app_id,
const base::Version& from_version,
const base::Version& to_version,
bool is_install,
bool should_update,
bool allow_rollback,
const std::string& target_version_prefix,
Expand All @@ -55,6 +56,7 @@ struct AppUpdateExpectation {
const std::string app_id;
const base::Version from_version;
const base::Version to_version;
const bool is_install;
const bool should_update;
const bool allow_rollback;
const std::string target_version_prefix;
Expand Down Expand Up @@ -162,6 +164,10 @@ void CheckForUpdate(UpdaterScope scope, const std::string& app_id);
// Invokes the active instance's UpdateService::UpdateAll (via RPC).
void UpdateAll(UpdaterScope scope);

// Invokes the active instance's UpdateService::Install (via RPC) for an
// app.
void InstallAppViaService(UpdaterScope scope, const std::string& app_id);

void GetAppStates(UpdaterScope updater_scope,
const base::Value::Dict& expected_app_states);

Expand Down

0 comments on commit 632c86a

Please sign in to comment.