Commit f0a45fa3 authored by James Cook's avatar James Cook Committed by Commit Bot

Use Chrome OS's network file access for lacros.

BUG=1146734
TEST=Ran locally.

Change-Id: Iba08d7f3c205c023b3b93b15e8e49f50ce3d5424
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536577Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarDarin Fisher <darin@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Auto-Submit: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827434}
parent a4d1cee2
......@@ -8,8 +8,9 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
#include "base/system/sys_info.h"
#include "chrome/browser/download/download_prefs.h"
#endif
......@@ -28,12 +29,13 @@ bool IsAccessAllowedInternal(const base::FilePath& path,
if (g_access_to_all_files_enabled)
return true;
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
#if !defined(OS_CHROMEOS) && !BUILDFLAG(IS_CHROMEOS_LACROS) && \
!defined(OS_ANDROID)
return true;
#else
std::vector<base::FilePath> allowlist;
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
// Use an allowlist to only allow access to files residing in the list of
// directories below.
static const base::FilePath::CharType* const kLocalAccessAllowList[] = {
......@@ -109,7 +111,7 @@ bool IsAccessAllowedInternal(const base::FilePath& path,
}
}
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
// Allow access to DriveFS logs. These reside in
// $PROFILE_PATH/GCache/v2/<opaque id>/Logs.
base::FilePath path_within_gcache_v2;
......
......@@ -7,6 +7,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
......@@ -21,7 +22,7 @@
#include "net/base/network_delegate.h"
#include "url/gurl.h"
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
class ChromeNetworkDelegateBrowserTest : public InProcessBrowserTest {
protected:
......@@ -89,4 +90,4 @@ IN_PROC_BROWSER_TEST_F(ChromeNetworkDelegateBrowserTest, AccessToSymlink) {
EXPECT_EQ(net::ERR_ACCESS_DENIED, observer.last_net_error_code());
}
#endif // defined(OS_CHROMEOS)
#endif // defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
......@@ -8,12 +8,12 @@
#include "base/macros.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/scoped_set_running_on_chromeos_for_testing.h"
#include "chrome/browser/download/download_prefs.h"
#endif
......@@ -31,30 +31,40 @@ bool IsAccessAllowed(const std::string& path,
base::FilePath::FromUTF8Unsafe(profile_path));
}
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
const char kLsbRelease[] =
"CHROMEOS_RELEASE_NAME=Chrome OS\n"
"CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
#endif
// TODO(jamescook): Merge with chromeos::ScopedSetRunningOnChromeOSForTesting.
// We can't use that here due to dependency issues.
class ScopedIsRunningOnChromeOS {
public:
ScopedIsRunningOnChromeOS() {
base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
}
~ScopedIsRunningOnChromeOS() {
base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time());
}
};
#endif // defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
} // namespace
TEST(ChromeNetworkDelegateStaticTest, IsAccessAllowed) {
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
// Platforms other than Chrome OS and Android have access to any files.
EXPECT_TRUE(IsAccessAllowed("/", ""));
EXPECT_TRUE(IsAccessAllowed("/foo.txt", ""));
#endif
#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS) || defined(OS_ANDROID)
// Chrome OS and Android don't have access to random files.
EXPECT_FALSE(IsAccessAllowed("/", ""));
EXPECT_FALSE(IsAccessAllowed("/foo.txt", ""));
// Empty path should not be allowed.
EXPECT_FALSE(IsAccessAllowed("", ""));
#else
// Platforms other than Chrome OS and Android have access to any files.
EXPECT_TRUE(IsAccessAllowed("/", ""));
EXPECT_TRUE(IsAccessAllowed("/foo.txt", ""));
#endif
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
base::FilePath temp_dir;
ASSERT_TRUE(base::PathService::Get(base::DIR_TEMP, &temp_dir));
// Chrome OS allows the following directories.
......@@ -98,8 +108,7 @@ TEST(ChromeNetworkDelegateStaticTest, IsAccessAllowed) {
DownloadPrefs::GetDefaultDownloadDirectory().value();
EXPECT_TRUE(IsAccessAllowed(home_downloads, ""));
{
chromeos::ScopedSetRunningOnChromeOSForTesting fake_release(kLsbRelease,
base::Time());
ScopedIsRunningOnChromeOS is_running_on_chromeos;
EXPECT_FALSE(IsAccessAllowed(home_downloads, ""));
}
......
......@@ -23,6 +23,7 @@
#include "base/test/test_switches.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/after_startup_task_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_browser_main.h"
......@@ -316,19 +317,22 @@ void InProcessBrowserTest::SetUp() {
chrome_browser_net::NetErrorTabHelper::set_state_for_testing(
chrome_browser_net::NetErrorTabHelper::TESTING_FORCE_DISABLED);
#if defined(OS_CHROMEOS)
chromeos::device_sync::DeviceSyncImpl::Factory::SetCustomFactory(
GetFakeDeviceSyncImplFactory());
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
// On Chrome OS, access to files via file: scheme is restricted. Enable
// access to all files here since browser_tests and interactive_ui_tests
// rely on the ability to open any files via file: scheme.
ChromeNetworkDelegate::EnableAccessToAllFilesForTesting(true);
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Device sync (for multidevice "Better Together") is ash specific.
chromeos::device_sync::DeviceSyncImpl::Factory::SetCustomFactory(
GetFakeDeviceSyncImplFactory());
// Using a screenshot for clamshell to tablet mode transitions makes the flow
// async which we want to disable for most tests.
ash::ShellTestApi::SetTabletControllerUseScreenshotForTest(false);
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
// Redirect the default download directory to a temporary directory.
ASSERT_TRUE(default_download_dir_.CreateUniqueTempDir());
......
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