Commit 3be3631a authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Check if crostini export import is allowed by policy

Check policy before starting an export or import.

Bug: 1003944
Change-Id: I2f87ab7f1995fbb47ed4e4da13e0cff7c5852041
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809123
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Auto-Submit: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697837}
parent 08524b00
......@@ -160,6 +160,9 @@ void CrostiniExportImport::Start(
ContainerId container_id,
base::FilePath path,
CrostiniManager::CrostiniResultCallback callback) {
if (!IsCrostiniExportImportUIAllowedForProfile(profile_)) {
return std::move(callback).Run(CrostiniResult::NOT_ALLOWED);
}
auto* notification = CrostiniExportImportNotification::Create(
profile_, type, GetUniqueNotificationId(), path, container_id);
......
......@@ -7,6 +7,8 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_test_helper.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/file_manager/path_util.h"
#include "chrome/browser/chromeos/guest_os/guest_os_share_path.h"
......@@ -15,6 +17,7 @@
#include "chromeos/dbus/fake_cicerone_client.h"
#include "chromeos/dbus/fake_seneschal_client.h"
#include "chromeos/dbus/seneschal/seneschal_service.pb.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_task_environment.h"
#include "storage/browser/fileapi/external_mount_points.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -86,8 +89,12 @@ class CrostiniExportImportTest : public testing::Test {
void SetUp() override {
profile_ = std::make_unique<TestingProfile>();
crostini_export_import_ = std::make_unique<CrostiniExportImport>(profile());
test_helper_ = std::make_unique<CrostiniTestHelper>(profile_.get());
CrostiniManager::GetForProfile(profile())->AddRunningVmForTesting(
kCrostiniDefaultVmName);
CrostiniManager::GetForProfile(profile())->set_skip_restart_for_testing();
profile()->GetPrefs()->SetBoolean(
crostini::prefs::kUserCrostiniExportImportUIAllowedByPolicy, true);
container_id_ =
ContainerId(kCrostiniDefaultVmName, kCrostiniDefaultContainerName);
......@@ -109,6 +116,7 @@ class CrostiniExportImportTest : public testing::Test {
guest_os::GuestOsSharePath::GetForProfile(profile())->Shutdown();
task_environment_.RunUntilIdle();
base::DeleteFile(tarball_, false);
test_helper_.reset();
profile_.reset();
}
......@@ -121,6 +129,8 @@ class CrostiniExportImportTest : public testing::Test {
std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<CrostiniExportImport> crostini_export_import_;
std::unique_ptr<CrostiniTestHelper> test_helper_;
ContainerId container_id_;
base::FilePath tarball_;
......@@ -130,6 +140,19 @@ class CrostiniExportImportTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(CrostiniExportImportTest);
};
TEST_F(CrostiniExportImportTest, TestNotAllowed) {
profile()->GetPrefs()->SetBoolean(
crostini::prefs::kUserCrostiniExportImportUIAllowedByPolicy, false);
crostini_export_import_->ExportContainer(
container_id_, tarball_, base::BindOnce([](CrostiniResult result) {
EXPECT_EQ(result, CrostiniResult::NOT_ALLOWED);
}));
crostini_export_import_->ImportContainer(
container_id_, tarball_, base::BindOnce([](CrostiniResult result) {
EXPECT_EQ(result, CrostiniResult::NOT_ALLOWED);
}));
}
// TODO(juwa): remove this once tremplin has been shipped.
TEST_F(CrostiniExportImportTest, TestDeprecatedExportSuccess) {
crostini_export_import_->FileSelected(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment