| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/base_paths.h" |
| 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/macros.h" |
| 8 #include "base/path_service.h" |
| 9 #include "chrome/browser/net/chrome_network_delegate.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/test/browser_test_utils.h" |
| 17 #include "content/public/test/test_navigation_observer.h" |
| 18 #include "net/base/filename_util.h" |
| 19 #include "net/base/network_delegate.h" |
| 20 #include "url/gurl.h" |
| 21 |
| 22 #if defined(OS_CHROMEOS) |
| 23 |
| 24 class ChromeNetworkDelegateBrowserTest : public InProcessBrowserTest { |
| 25 protected: |
| 26 ChromeNetworkDelegateBrowserTest() {} |
| 27 |
| 28 void SetUpInProcessBrowserTestFixture() override { |
| 29 // Access to all files via file: scheme is allowed on browser |
| 30 // tests. Bring back the production behaviors. |
| 31 ChromeNetworkDelegate::EnableAccessToAllFilesForTesting(false); |
| 32 } |
| 33 |
| 34 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegateBrowserTest); |
| 36 }; |
| 37 |
| 38 // Ensure that access to a test file, that is not in an accessible location, |
| 39 // via file: scheme is rejected with ERR_ACCESS_DENIED. |
| 40 IN_PROC_BROWSER_TEST_F(ChromeNetworkDelegateBrowserTest, AccessToFile) { |
| 41 base::FilePath test_dir; |
| 42 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); |
| 43 base::FilePath test_file = test_dir.AppendASCII("empty.html"); |
| 44 ASSERT_FALSE( |
| 45 ChromeNetworkDelegate::IsAccessAllowed(test_file, base::FilePath())); |
| 46 |
| 47 GURL url = net::FilePathToFileURL(test_file); |
| 48 |
| 49 content::WebContents* web_contents = |
| 50 browser()->tab_strip_model()->GetActiveWebContents(); |
| 51 content::TestNavigationObserver observer(web_contents); |
| 52 ui_test_utils::NavigateToURL(browser(), url); |
| 53 EXPECT_EQ(net::ERR_ACCESS_DENIED, observer.last_net_error_code()); |
| 54 } |
| 55 |
| 56 // Ensure that access to a symbolic link, that is in an accessible location, |
| 57 // to a test file, that isn't, via file: scheme is rejected with |
| 58 // ERR_ACCESS_DENIED. |
| 59 IN_PROC_BROWSER_TEST_F(ChromeNetworkDelegateBrowserTest, AccessToSymlink) { |
| 60 base::FilePath test_dir; |
| 61 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); |
| 62 base::FilePath test_file = test_dir.AppendASCII("empty.html"); |
| 63 ASSERT_FALSE( |
| 64 ChromeNetworkDelegate::IsAccessAllowed(test_file, base::FilePath())); |
| 65 |
| 66 base::FilePath temp_dir; |
| 67 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &temp_dir)); |
| 68 base::ScopedTempDir scoped_temp_dir; |
| 69 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(temp_dir)); |
| 70 base::FilePath symlink = scoped_temp_dir.GetPath().AppendASCII("symlink"); |
| 71 ASSERT_TRUE(base::CreateSymbolicLink(test_file, symlink)); |
| 72 ASSERT_TRUE( |
| 73 ChromeNetworkDelegate::IsAccessAllowed(symlink, base::FilePath())); |
| 74 |
| 75 GURL url = net::FilePathToFileURL(symlink); |
| 76 |
| 77 content::WebContents* web_contents = |
| 78 browser()->tab_strip_model()->GetActiveWebContents(); |
| 79 content::TestNavigationObserver observer(web_contents); |
| 80 ui_test_utils::NavigateToURL(browser(), url); |
| 81 EXPECT_EQ(net::ERR_ACCESS_DENIED, observer.last_net_error_code()); |
| 82 } |
| 83 |
| 84 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |