OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 sub_dir_, enabled_permissions, disabled_permissions)); | 1885 sub_dir_, enabled_permissions, disabled_permissions)); |
1886 } | 1886 } |
1887 | 1887 |
1888 FilePath base_dir_; | 1888 FilePath base_dir_; |
1889 FilePath sub_dir_; | 1889 FilePath sub_dir_; |
1890 FilePath text_file_; | 1890 FilePath text_file_; |
1891 uid_t uid_; | 1891 uid_t uid_; |
1892 gid_t gid_; | 1892 gid_t gid_; |
1893 }; | 1893 }; |
1894 | 1894 |
1895 TEST_F(VerifyPathControlledByUserTest, BadPaths) { | 1895 #if defined(OS_MACOSX) |
| 1896 // http://crbug.com/97876 |
| 1897 #define MAYBE_BadPaths FAILS_BadPaths |
| 1898 #else |
| 1899 #define MAYBE_BadPaths BadPaths |
| 1900 #endif |
| 1901 |
| 1902 TEST_F(VerifyPathControlledByUserTest, MAYBE_BadPaths) { |
1896 // File does not exist. | 1903 // File does not exist. |
1897 FilePath does_not_exist = base_dir_.AppendASCII("does") | 1904 FilePath does_not_exist = base_dir_.AppendASCII("does") |
1898 .AppendASCII("not") | 1905 .AppendASCII("not") |
1899 .AppendASCII("exist"); | 1906 .AppendASCII("exist"); |
1900 | 1907 |
1901 EXPECT_FALSE( | 1908 EXPECT_FALSE( |
1902 file_util::VerifyPathControlledByUser( | 1909 file_util::VerifyPathControlledByUser( |
1903 base_dir_, does_not_exist, uid_, gid_)); | 1910 base_dir_, does_not_exist, uid_, gid_)); |
1904 | 1911 |
1905 // |base| not a subpath of |path|. | 1912 // |base| not a subpath of |path|. |
1906 EXPECT_FALSE( | 1913 EXPECT_FALSE( |
1907 file_util::VerifyPathControlledByUser(sub_dir_, base_dir_, uid_, gid_)); | 1914 file_util::VerifyPathControlledByUser(sub_dir_, base_dir_, uid_, gid_)); |
1908 | 1915 |
1909 // An empty base path will fail to be a prefix for any path. | 1916 // An empty base path will fail to be a prefix for any path. |
1910 FilePath empty; | 1917 FilePath empty; |
1911 EXPECT_FALSE( | 1918 EXPECT_FALSE( |
1912 file_util::VerifyPathControlledByUser(empty, base_dir_, uid_, gid_)); | 1919 file_util::VerifyPathControlledByUser(empty, base_dir_, uid_, gid_)); |
1913 | 1920 |
1914 // Finding that a bad call fails proves nothing unless a good call succeeds. | 1921 // Finding that a bad call fails proves nothing unless a good call succeeds. |
1915 EXPECT_TRUE( | 1922 EXPECT_TRUE( |
1916 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 1923 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); |
1917 } | 1924 } |
1918 | 1925 |
| 1926 #if defined(OS_MACOSX) |
| 1927 // http://crbug.com/97876 |
| 1928 #define MAYBE_Symlinks FAILS_Symlinks |
| 1929 #else |
| 1930 #define MAYBE_Symlinks Symlinks |
| 1931 #endif |
| 1932 |
1919 TEST_F(VerifyPathControlledByUserTest, Symlinks) { | 1933 TEST_F(VerifyPathControlledByUserTest, Symlinks) { |
1920 // Symlinks in the path should cause failure. | 1934 // Symlinks in the path should cause failure. |
1921 | 1935 |
1922 // Symlink to the file at the end of the path. | 1936 // Symlink to the file at the end of the path. |
1923 FilePath file_link = base_dir_.AppendASCII("file_link"); | 1937 FilePath file_link = base_dir_.AppendASCII("file_link"); |
1924 ASSERT_TRUE(file_util::CreateSymbolicLink(text_file_, file_link)) | 1938 ASSERT_TRUE(file_util::CreateSymbolicLink(text_file_, file_link)) |
1925 << "Failed to create symlink."; | 1939 << "Failed to create symlink."; |
1926 | 1940 |
1927 EXPECT_FALSE( | 1941 EXPECT_FALSE( |
1928 file_util::VerifyPathControlledByUser(base_dir_, file_link, uid_, gid_)); | 1942 file_util::VerifyPathControlledByUser(base_dir_, file_link, uid_, gid_)); |
(...skipping 15 matching lines...) Expand all Loading... |
1944 EXPECT_FALSE( | 1958 EXPECT_FALSE( |
1945 file_util::VerifyPathControlledByUser( | 1959 file_util::VerifyPathControlledByUser( |
1946 link_to_sub_dir, file_path_with_link, uid_, gid_)); | 1960 link_to_sub_dir, file_path_with_link, uid_, gid_)); |
1947 | 1961 |
1948 // Symlinks in parents of base path are allowed. | 1962 // Symlinks in parents of base path are allowed. |
1949 EXPECT_TRUE( | 1963 EXPECT_TRUE( |
1950 file_util::VerifyPathControlledByUser( | 1964 file_util::VerifyPathControlledByUser( |
1951 file_path_with_link, file_path_with_link, uid_, gid_)); | 1965 file_path_with_link, file_path_with_link, uid_, gid_)); |
1952 } | 1966 } |
1953 | 1967 |
1954 TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) { | 1968 #if defined(OS_MACOSX) |
| 1969 // http://crbug.com/97876 |
| 1970 #define MAYBE_OwnershipChecks FAILS_OwnershipChecks |
| 1971 #else |
| 1972 #define MAYBE_OwnershipChecks OwnershipChecks |
| 1973 #endif |
| 1974 |
| 1975 TEST_F(VerifyPathControlledByUserTest, MAYBE_OwnershipChecks) { |
1955 // Get a uid that is not the uid of files we create. | 1976 // Get a uid that is not the uid of files we create. |
1956 uid_t bad_uid = uid_ + 1; | 1977 uid_t bad_uid = uid_ + 1; |
1957 | 1978 |
1958 // Get a gid that is not ours. | 1979 // Get a gid that is not ours. |
1959 gid_t bad_gid = gid_ + 1; | 1980 gid_t bad_gid = gid_ + 1; |
1960 | 1981 |
1961 // Make all files and directories non-world-writable. | 1982 // Make all files and directories non-world-writable. |
1962 ASSERT_NO_FATAL_FAILURE( | 1983 ASSERT_NO_FATAL_FAILURE( |
1963 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 1984 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
1964 ASSERT_NO_FATAL_FAILURE( | 1985 ASSERT_NO_FATAL_FAILURE( |
(...skipping 25 matching lines...) Expand all Loading... |
1990 file_util::VerifyPathControlledByUser( | 2011 file_util::VerifyPathControlledByUser( |
1991 base_dir_, sub_dir_, uid_, bad_gid)); | 2012 base_dir_, sub_dir_, uid_, bad_gid)); |
1992 EXPECT_FALSE( | 2013 EXPECT_FALSE( |
1993 file_util::VerifyPathControlledByUser( | 2014 file_util::VerifyPathControlledByUser( |
1994 base_dir_, text_file_, uid_, bad_gid)); | 2015 base_dir_, text_file_, uid_, bad_gid)); |
1995 EXPECT_FALSE( | 2016 EXPECT_FALSE( |
1996 file_util::VerifyPathControlledByUser( | 2017 file_util::VerifyPathControlledByUser( |
1997 sub_dir_, text_file_, uid_, bad_gid)); | 2018 sub_dir_, text_file_, uid_, bad_gid)); |
1998 } | 2019 } |
1999 | 2020 |
2000 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) { | 2021 #if defined(OS_MACOSX) |
| 2022 // http://crbug.com/97876 |
| 2023 #define MAYBE_WriteBitChecks FAILS_WriteBitChecks |
| 2024 #else |
| 2025 #define MAYBE_WriteBitChecks WriteBitChecks |
| 2026 #endif |
| 2027 |
| 2028 TEST_F(VerifyPathControlledByUserTest, MAYBE_WriteBitChecks) { |
2001 // Make all files and directories non-world-writable. | 2029 // Make all files and directories non-world-writable. |
2002 ASSERT_NO_FATAL_FAILURE( | 2030 ASSERT_NO_FATAL_FAILURE( |
2003 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 2031 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
2004 ASSERT_NO_FATAL_FAILURE( | 2032 ASSERT_NO_FATAL_FAILURE( |
2005 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); | 2033 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); |
2006 ASSERT_NO_FATAL_FAILURE( | 2034 ASSERT_NO_FATAL_FAILURE( |
2007 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); | 2035 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); |
2008 | 2036 |
2009 // Initialy, we control all parts of the path. | 2037 // Initialy, we control all parts of the path. |
2010 EXPECT_TRUE( | 2038 EXPECT_TRUE( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2072 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2100 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); |
2073 EXPECT_TRUE( | 2101 EXPECT_TRUE( |
2074 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2102 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); |
2075 EXPECT_TRUE( | 2103 EXPECT_TRUE( |
2076 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2104 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); |
2077 } | 2105 } |
2078 | 2106 |
2079 #endif // defined(OS_POSIX) | 2107 #endif // defined(OS_POSIX) |
2080 | 2108 |
2081 } // namespace | 2109 } // namespace |
OLD | NEW |