| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 data.ReparseTag = 0xa0000003; | 104 data.ReparseTag = 0xa0000003; |
| 105 if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, | 105 if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, |
| 106 &returned, NULL)) { | 106 &returned, NULL)) { |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 #endif | 111 #endif |
| 112 | 112 |
| 113 #if defined(OS_POSIX) | 113 #if defined(OS_POSIX) |
| 114 // Provide a simple way to change the permissions bits on |path| in tests. | |
| 115 // ASSERT failures will return, but not stop the test. Caller should wrap | |
| 116 // calls to this function in ASSERT_NO_FATAL_FAILURE(). | |
| 117 void ChangePosixFilePermissions(const FilePath& path, | |
| 118 mode_t mode_bits_to_set, | |
| 119 mode_t mode_bits_to_clear) { | |
| 120 ASSERT_FALSE(mode_bits_to_set & mode_bits_to_clear) | |
| 121 << "Can't set and clear the same bits."; | |
| 122 | |
| 123 struct stat stat_buf; | |
| 124 ASSERT_EQ(0, stat(path.value().c_str(), &stat_buf)); | |
| 125 | |
| 126 mode_t updated_mode_bits = stat_buf.st_mode; | |
| 127 updated_mode_bits |= mode_bits_to_set; | |
| 128 updated_mode_bits &= ~mode_bits_to_clear; | |
| 129 | |
| 130 ASSERT_EQ(0, chmod(path.value().c_str(), updated_mode_bits)); | |
| 131 } | |
| 132 #endif // defined(OS_POSIX) | 114 #endif // defined(OS_POSIX) |
| 133 | 115 |
| 134 const wchar_t bogus_content[] = L"I'm cannon fodder."; | 116 const wchar_t bogus_content[] = L"I'm cannon fodder."; |
| 135 | 117 |
| 136 const file_util::FileEnumerator::FileType FILES_AND_DIRECTORIES = | 118 const file_util::FileEnumerator::FileType FILES_AND_DIRECTORIES = |
| 137 static_cast<file_util::FileEnumerator::FileType>( | 119 static_cast<file_util::FileEnumerator::FileType>( |
| 138 file_util::FileEnumerator::FILES | | 120 file_util::FileEnumerator::FILES | |
| 139 file_util::FileEnumerator::DIRECTORIES); | 121 file_util::FileEnumerator::DIRECTORIES); |
| 140 | 122 |
| 141 // file_util winds up using autoreleased objects on the Mac, so this needs | 123 // file_util winds up using autoreleased objects on the Mac, so this needs |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from)) | 642 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from)) |
| 661 << "Failed to create directory symlink."; | 643 << "Failed to create directory symlink."; |
| 662 | 644 |
| 663 // Test failures. | 645 // Test failures. |
| 664 ASSERT_FALSE(file_util::CreateSymbolicLink(link_to, link_to)); | 646 ASSERT_FALSE(file_util::CreateSymbolicLink(link_to, link_to)); |
| 665 ASSERT_FALSE(file_util::ReadSymbolicLink(link_to, &result)); | 647 ASSERT_FALSE(file_util::ReadSymbolicLink(link_to, &result)); |
| 666 FilePath missing = temp_dir_.path().Append(FPL("missing")); | 648 FilePath missing = temp_dir_.path().Append(FPL("missing")); |
| 667 ASSERT_FALSE(file_util::ReadSymbolicLink(missing, &result)); | 649 ASSERT_FALSE(file_util::ReadSymbolicLink(missing, &result)); |
| 668 } | 650 } |
| 669 | 651 |
| 670 | |
| 671 // The following test of NormalizeFilePath() require that we create a symlink. | 652 // The following test of NormalizeFilePath() require that we create a symlink. |
| 672 // This can not be done on Windows before Vista. On Vista, creating a symlink | 653 // This can not be done on Windows before Vista. On Vista, creating a symlink |
| 673 // requires privilege "SeCreateSymbolicLinkPrivilege". | 654 // requires privilege "SeCreateSymbolicLinkPrivilege". |
| 674 // TODO(skerner): Investigate the possibility of giving base_unittests the | 655 // TODO(skerner): Investigate the possibility of giving base_unittests the |
| 675 // privileges required to create a symlink. | 656 // privileges required to create a symlink. |
| 676 TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { | 657 TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { |
| 677 FilePath normalized_path; | 658 FilePath normalized_path; |
| 678 | 659 |
| 679 // Link one file to another. | 660 // Link one file to another. |
| 680 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); | 661 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 // Make sure the symbolic link is exist | 758 // Make sure the symbolic link is exist |
| 778 EXPECT_TRUE(file_util::IsLink(file_link)); | 759 EXPECT_TRUE(file_util::IsLink(file_link)); |
| 779 EXPECT_FALSE(file_util::PathExists(file_link)); | 760 EXPECT_FALSE(file_util::PathExists(file_link)); |
| 780 | 761 |
| 781 // Delete the symbolic link | 762 // Delete the symbolic link |
| 782 EXPECT_TRUE(file_util::Delete(file_link, false)); | 763 EXPECT_TRUE(file_util::Delete(file_link, false)); |
| 783 | 764 |
| 784 // Make sure the symbolic link is deleted | 765 // Make sure the symbolic link is deleted |
| 785 EXPECT_FALSE(file_util::IsLink(file_link)); | 766 EXPECT_FALSE(file_util::IsLink(file_link)); |
| 786 } | 767 } |
| 768 |
| 769 TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { |
| 770 // Create a file path |
| 771 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); |
| 772 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 773 |
| 774 char buffer[32] = "hello"; |
| 775 std::string data(buffer); |
| 776 |
| 777 // Write file |
| 778 EXPECT_EQ(static_cast<int>(data.length()), |
| 779 file_util::WriteFile(file_name, data.c_str(), data.length())); |
| 780 EXPECT_TRUE(file_util::PathExists(file_name)); |
| 781 |
| 782 // Meke sure the file is readable |
| 783 mode_t mode; |
| 784 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
| 785 EXPECT_EQ(S_IRUSR, static_cast<int>(mode) & S_IRUSR); |
| 786 |
| 787 // Get rid of the read permission |
| 788 EXPECT_TRUE(file_util::ChangePosixFilePermissions(file_name, 0u, S_IRUSR)); |
| 789 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
| 790 EXPECT_EQ(0, static_cast<int>(mode) & S_IRUSR); |
| 791 // Make sure the file can't be read |
| 792 EXPECT_EQ(-1, file_util::ReadFile(file_name, buffer, sizeof(buffer))); |
| 793 |
| 794 // Give the read permission |
| 795 EXPECT_TRUE(file_util::ChangePosixFilePermissions(file_name, S_IRUSR, 0u)); |
| 796 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
| 797 EXPECT_EQ(S_IRUSR, static_cast<int>(mode) & S_IRUSR); |
| 798 // Make sure the file can be read |
| 799 EXPECT_EQ(static_cast<int>(data.length()), |
| 800 file_util::ReadFile(file_name, buffer, sizeof(buffer))); |
| 801 |
| 802 // Delete the file |
| 803 EXPECT_TRUE(file_util::Delete(file_name, false)); |
| 804 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 805 } |
| 806 |
| 807 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { |
| 808 // Create a file path |
| 809 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); |
| 810 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 811 |
| 812 char buffer[32] = "hello"; |
| 813 std::string data(buffer); |
| 814 |
| 815 // Write file |
| 816 EXPECT_EQ(static_cast<int>(data.length()), |
| 817 file_util::WriteFile(file_name, data.c_str(), data.length())); |
| 818 EXPECT_TRUE(file_util::PathExists(file_name)); |
| 819 |
| 820 // Meke sure the file is writable |
| 821 mode_t mode; |
| 822 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
| 823 EXPECT_EQ(S_IWUSR, static_cast<int>(mode) & S_IWUSR); |
| 824 EXPECT_TRUE(file_util::PathIsWritable(file_name)); |
| 825 |
| 826 // Get rid of the write permission |
| 827 EXPECT_TRUE(file_util::ChangePosixFilePermissions(file_name, 0u, S_IWUSR)); |
| 828 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
| 829 EXPECT_EQ(0, static_cast<int>(mode) & S_IWUSR); |
| 830 // Make sure the file can't be write |
| 831 EXPECT_EQ(-1, |
| 832 file_util::WriteFile(file_name, data.c_str(), data.length())); |
| 833 EXPECT_FALSE(file_util::PathIsWritable(file_name)); |
| 834 |
| 835 // Give read permission |
| 836 EXPECT_TRUE(file_util::ChangePosixFilePermissions(file_name, S_IWUSR, 0u)); |
| 837 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
| 838 EXPECT_EQ(S_IWUSR, static_cast<int>(mode) & S_IWUSR); |
| 839 // Make sure the file can be write |
| 840 EXPECT_EQ(static_cast<int>(data.length()), |
| 841 file_util::WriteFile(file_name, data.c_str(), data.length())); |
| 842 EXPECT_TRUE(file_util::PathIsWritable(file_name)); |
| 843 |
| 844 // Delete the file |
| 845 EXPECT_TRUE(file_util::Delete(file_name, false)); |
| 846 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 847 } |
| 848 |
| 849 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { |
| 850 // Create a directory path |
| 851 FilePath subdir_path = |
| 852 temp_dir_.path().Append(FPL("PermissionTest1")); |
| 853 file_util::CreateDirectory(subdir_path); |
| 854 ASSERT_TRUE(file_util::PathExists(subdir_path)); |
| 855 |
| 856 // Create a dummy file to enumerate |
| 857 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); |
| 858 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 859 char buffer[32] = "hello"; |
| 860 std::string data(buffer); |
| 861 EXPECT_EQ(static_cast<int>(data.length()), |
| 862 file_util::WriteFile(file_name, data.c_str(), data.length())); |
| 863 EXPECT_TRUE(file_util::PathExists(file_name)); |
| 864 |
| 865 // Meke sure the file is the all permissions |
| 866 mode_t mode; |
| 867 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); |
| 868 EXPECT_EQ(S_IRWXU, static_cast<int>(mode) & S_IRWXU); |
| 869 |
| 870 // Get rid of the permissions from the directory |
| 871 EXPECT_TRUE(file_util::ChangePosixFilePermissions(subdir_path, 0u, S_IRWXU)); |
| 872 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); |
| 873 EXPECT_EQ(0, static_cast<int>(mode) & S_IRWXU); |
| 874 |
| 875 // Make sure the file in the directory can't be enumerated. |
| 876 file_util::FileEnumerator f1(subdir_path, true, |
| 877 file_util::FileEnumerator::FILES); |
| 878 EXPECT_TRUE(file_util::PathExists(subdir_path)); |
| 879 FindResultCollector c1(f1); |
| 880 EXPECT_EQ(c1.size(), 0); |
| 881 EXPECT_FALSE(file_util::GetPosixFilePermissions(file_name, &mode)); |
| 882 |
| 883 // Give the permissions to the directory |
| 884 EXPECT_TRUE(file_util::ChangePosixFilePermissions(subdir_path, S_IRWXU, 0u)); |
| 885 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); |
| 886 EXPECT_EQ(S_IRWXU, static_cast<int>(mode) & S_IRWXU); |
| 887 |
| 888 // Make sure the file in the directory can be enumerated. |
| 889 file_util::FileEnumerator f2(subdir_path, true, |
| 890 file_util::FileEnumerator::FILES); |
| 891 FindResultCollector c2(f2); |
| 892 EXPECT_TRUE(c2.HasFile(file_name)); |
| 893 EXPECT_EQ(c2.size(), 1); |
| 894 |
| 895 // Delete the file |
| 896 EXPECT_TRUE(file_util::Delete(subdir_path, true)); |
| 897 EXPECT_FALSE(file_util::PathExists(subdir_path)); |
| 898 } |
| 899 |
| 787 #endif // defined(OS_POSIX) | 900 #endif // defined(OS_POSIX) |
| 788 | 901 |
| 789 #if defined(OS_WIN) | 902 #if defined(OS_WIN) |
| 790 // Tests that the Delete function works for wild cards, especially | 903 // Tests that the Delete function works for wild cards, especially |
| 791 // with the recursion flag. Also coincidentally tests PathExists. | 904 // with the recursion flag. Also coincidentally tests PathExists. |
| 792 // TODO(erikkay): see if anyone's actually using this feature of the API | 905 // TODO(erikkay): see if anyone's actually using this feature of the API |
| 793 TEST_F(FileUtilTest, DeleteWildCard) { | 906 TEST_F(FileUtilTest, DeleteWildCard) { |
| 794 // Create a file and a directory | 907 // Create a file and a directory |
| 795 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | 908 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); |
| 796 CreateTextFile(file_name, bogus_content); | 909 CreateTextFile(file_name, bogus_content); |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 // To ensure that umask settings do not cause the initial state | 2109 // To ensure that umask settings do not cause the initial state |
| 1997 // of permissions to be different from what we expect, explicitly | 2110 // of permissions to be different from what we expect, explicitly |
| 1998 // set permissions on the directories we create. | 2111 // set permissions on the directories we create. |
| 1999 // Make all files and directories non-world-writable. | 2112 // Make all files and directories non-world-writable. |
| 2000 mode_t enabled_permissions = | 2113 mode_t enabled_permissions = |
| 2001 S_IRWXU | // User can read, write, traverse | 2114 S_IRWXU | // User can read, write, traverse |
| 2002 S_IRWXG; // Group can read, write, traverse | 2115 S_IRWXG; // Group can read, write, traverse |
| 2003 mode_t disabled_permissions = | 2116 mode_t disabled_permissions = |
| 2004 S_IRWXO; // Other users can't read, write, traverse. | 2117 S_IRWXO; // Other users can't read, write, traverse. |
| 2005 | 2118 |
| 2006 ASSERT_NO_FATAL_FAILURE( | 2119 ASSERT_TRUE( |
| 2007 ChangePosixFilePermissions( | 2120 file_util::ChangePosixFilePermissions( |
| 2008 base_dir_, enabled_permissions, disabled_permissions)); | 2121 base_dir_, enabled_permissions, disabled_permissions)); |
| 2009 ASSERT_NO_FATAL_FAILURE( | 2122 ASSERT_TRUE( |
| 2010 ChangePosixFilePermissions( | 2123 file_util::ChangePosixFilePermissions( |
| 2011 sub_dir_, enabled_permissions, disabled_permissions)); | 2124 sub_dir_, enabled_permissions, disabled_permissions)); |
| 2012 } | 2125 } |
| 2013 | 2126 |
| 2014 FilePath base_dir_; | 2127 FilePath base_dir_; |
| 2015 FilePath sub_dir_; | 2128 FilePath sub_dir_; |
| 2016 FilePath text_file_; | 2129 FilePath text_file_; |
| 2017 uid_t uid_; | 2130 uid_t uid_; |
| 2018 | 2131 |
| 2019 std::set<gid_t> ok_gids_; | 2132 std::set<gid_t> ok_gids_; |
| 2020 std::set<gid_t> bad_gids_; | 2133 std::set<gid_t> bad_gids_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2081 EXPECT_TRUE( | 2194 EXPECT_TRUE( |
| 2082 file_util::VerifyPathControlledByUser( | 2195 file_util::VerifyPathControlledByUser( |
| 2083 file_path_with_link, file_path_with_link, uid_, ok_gids_)); | 2196 file_path_with_link, file_path_with_link, uid_, ok_gids_)); |
| 2084 } | 2197 } |
| 2085 | 2198 |
| 2086 TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) { | 2199 TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) { |
| 2087 // Get a uid that is not the uid of files we create. | 2200 // Get a uid that is not the uid of files we create. |
| 2088 uid_t bad_uid = uid_ + 1; | 2201 uid_t bad_uid = uid_ + 1; |
| 2089 | 2202 |
| 2090 // Make all files and directories non-world-writable. | 2203 // Make all files and directories non-world-writable. |
| 2091 ASSERT_NO_FATAL_FAILURE( | 2204 ASSERT_TRUE( |
| 2092 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 2205 file_util:: ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
| 2093 ASSERT_NO_FATAL_FAILURE( | 2206 ASSERT_TRUE( |
| 2094 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); | 2207 file_util::ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); |
| 2095 ASSERT_NO_FATAL_FAILURE( | 2208 ASSERT_TRUE( |
| 2096 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); | 2209 file_util::ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); |
| 2097 | 2210 |
| 2098 // We control these paths. | 2211 // We control these paths. |
| 2099 EXPECT_TRUE( | 2212 EXPECT_TRUE( |
| 2100 file_util::VerifyPathControlledByUser( | 2213 file_util::VerifyPathControlledByUser( |
| 2101 base_dir_, sub_dir_, uid_, ok_gids_)); | 2214 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2102 EXPECT_TRUE( | 2215 EXPECT_TRUE( |
| 2103 file_util::VerifyPathControlledByUser( | 2216 file_util::VerifyPathControlledByUser( |
| 2104 base_dir_, text_file_, uid_, ok_gids_)); | 2217 base_dir_, text_file_, uid_, ok_gids_)); |
| 2105 EXPECT_TRUE( | 2218 EXPECT_TRUE( |
| 2106 file_util::VerifyPathControlledByUser( | 2219 file_util::VerifyPathControlledByUser( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2124 EXPECT_FALSE( | 2237 EXPECT_FALSE( |
| 2125 file_util::VerifyPathControlledByUser( | 2238 file_util::VerifyPathControlledByUser( |
| 2126 base_dir_, text_file_, uid_, bad_gids_)); | 2239 base_dir_, text_file_, uid_, bad_gids_)); |
| 2127 EXPECT_FALSE( | 2240 EXPECT_FALSE( |
| 2128 file_util::VerifyPathControlledByUser( | 2241 file_util::VerifyPathControlledByUser( |
| 2129 sub_dir_, text_file_, uid_, bad_gids_)); | 2242 sub_dir_, text_file_, uid_, bad_gids_)); |
| 2130 } | 2243 } |
| 2131 | 2244 |
| 2132 TEST_F(VerifyPathControlledByUserTest, GroupWriteTest) { | 2245 TEST_F(VerifyPathControlledByUserTest, GroupWriteTest) { |
| 2133 // Make all files and directories writable only by their owner. | 2246 // Make all files and directories writable only by their owner. |
| 2134 ASSERT_NO_FATAL_FAILURE( | 2247 ASSERT_TRUE( |
| 2135 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH|S_IWGRP)); | 2248 file_util::ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH|S_IWGRP)); |
| 2136 ASSERT_NO_FATAL_FAILURE( | 2249 ASSERT_TRUE( |
| 2137 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH|S_IWGRP)); | 2250 file_util::ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH|S_IWGRP)); |
| 2138 ASSERT_NO_FATAL_FAILURE( | 2251 ASSERT_TRUE( |
| 2139 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH|S_IWGRP)); | 2252 file_util::ChangePosixFilePermissions(text_file_, 0u, S_IWOTH|S_IWGRP)); |
| 2140 | 2253 |
| 2141 // Any group is okay because the path is not group-writable. | 2254 // Any group is okay because the path is not group-writable. |
| 2142 EXPECT_TRUE( | 2255 EXPECT_TRUE( |
| 2143 file_util::VerifyPathControlledByUser( | 2256 file_util::VerifyPathControlledByUser( |
| 2144 base_dir_, sub_dir_, uid_, ok_gids_)); | 2257 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2145 EXPECT_TRUE( | 2258 EXPECT_TRUE( |
| 2146 file_util::VerifyPathControlledByUser( | 2259 file_util::VerifyPathControlledByUser( |
| 2147 base_dir_, text_file_, uid_, ok_gids_)); | 2260 base_dir_, text_file_, uid_, ok_gids_)); |
| 2148 EXPECT_TRUE( | 2261 EXPECT_TRUE( |
| 2149 file_util::VerifyPathControlledByUser( | 2262 file_util::VerifyPathControlledByUser( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2167 base_dir_, sub_dir_, uid_, no_gids)); | 2280 base_dir_, sub_dir_, uid_, no_gids)); |
| 2168 EXPECT_TRUE( | 2281 EXPECT_TRUE( |
| 2169 file_util::VerifyPathControlledByUser( | 2282 file_util::VerifyPathControlledByUser( |
| 2170 base_dir_, text_file_, uid_, no_gids)); | 2283 base_dir_, text_file_, uid_, no_gids)); |
| 2171 EXPECT_TRUE( | 2284 EXPECT_TRUE( |
| 2172 file_util::VerifyPathControlledByUser( | 2285 file_util::VerifyPathControlledByUser( |
| 2173 sub_dir_, text_file_, uid_, no_gids)); | 2286 sub_dir_, text_file_, uid_, no_gids)); |
| 2174 | 2287 |
| 2175 | 2288 |
| 2176 // Make all files and directories writable by their group. | 2289 // Make all files and directories writable by their group. |
| 2177 ASSERT_NO_FATAL_FAILURE( | 2290 ASSERT_TRUE( |
| 2178 ChangePosixFilePermissions(base_dir_, S_IWGRP, 0u)); | 2291 file_util::ChangePosixFilePermissions(base_dir_, S_IWGRP, 0u)); |
| 2179 ASSERT_NO_FATAL_FAILURE( | 2292 ASSERT_TRUE( |
| 2180 ChangePosixFilePermissions(sub_dir_, S_IWGRP, 0u)); | 2293 file_util::ChangePosixFilePermissions(sub_dir_, S_IWGRP, 0u)); |
| 2181 ASSERT_NO_FATAL_FAILURE( | 2294 ASSERT_TRUE( |
| 2182 ChangePosixFilePermissions(text_file_, S_IWGRP, 0u)); | 2295 file_util::ChangePosixFilePermissions(text_file_, S_IWGRP, 0u)); |
| 2183 | 2296 |
| 2184 // Now |ok_gids_| works, but |bad_gids_| fails. | 2297 // Now |ok_gids_| works, but |bad_gids_| fails. |
| 2185 EXPECT_TRUE( | 2298 EXPECT_TRUE( |
| 2186 file_util::VerifyPathControlledByUser( | 2299 file_util::VerifyPathControlledByUser( |
| 2187 base_dir_, sub_dir_, uid_, ok_gids_)); | 2300 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2188 EXPECT_TRUE( | 2301 EXPECT_TRUE( |
| 2189 file_util::VerifyPathControlledByUser( | 2302 file_util::VerifyPathControlledByUser( |
| 2190 base_dir_, text_file_, uid_, ok_gids_)); | 2303 base_dir_, text_file_, uid_, ok_gids_)); |
| 2191 EXPECT_TRUE( | 2304 EXPECT_TRUE( |
| 2192 file_util::VerifyPathControlledByUser( | 2305 file_util::VerifyPathControlledByUser( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2217 EXPECT_TRUE( | 2330 EXPECT_TRUE( |
| 2218 file_util::VerifyPathControlledByUser( | 2331 file_util::VerifyPathControlledByUser( |
| 2219 base_dir_, text_file_, uid_, multiple_gids)); | 2332 base_dir_, text_file_, uid_, multiple_gids)); |
| 2220 EXPECT_TRUE( | 2333 EXPECT_TRUE( |
| 2221 file_util::VerifyPathControlledByUser( | 2334 file_util::VerifyPathControlledByUser( |
| 2222 sub_dir_, text_file_, uid_, multiple_gids)); | 2335 sub_dir_, text_file_, uid_, multiple_gids)); |
| 2223 } | 2336 } |
| 2224 | 2337 |
| 2225 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) { | 2338 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) { |
| 2226 // Make all files and directories non-world-writable. | 2339 // Make all files and directories non-world-writable. |
| 2227 ASSERT_NO_FATAL_FAILURE( | 2340 ASSERT_TRUE( |
| 2228 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 2341 file_util::ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
| 2229 ASSERT_NO_FATAL_FAILURE( | 2342 ASSERT_TRUE( |
| 2230 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); | 2343 file_util::ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); |
| 2231 ASSERT_NO_FATAL_FAILURE( | 2344 ASSERT_TRUE( |
| 2232 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); | 2345 file_util::ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); |
| 2233 | 2346 |
| 2234 // Initialy, we control all parts of the path. | 2347 // Initialy, we control all parts of the path. |
| 2235 EXPECT_TRUE( | 2348 EXPECT_TRUE( |
| 2236 file_util::VerifyPathControlledByUser( | 2349 file_util::VerifyPathControlledByUser( |
| 2237 base_dir_, sub_dir_, uid_, ok_gids_)); | 2350 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2238 EXPECT_TRUE( | 2351 EXPECT_TRUE( |
| 2239 file_util::VerifyPathControlledByUser( | 2352 file_util::VerifyPathControlledByUser( |
| 2240 base_dir_, text_file_, uid_, ok_gids_)); | 2353 base_dir_, text_file_, uid_, ok_gids_)); |
| 2241 EXPECT_TRUE( | 2354 EXPECT_TRUE( |
| 2242 file_util::VerifyPathControlledByUser( | 2355 file_util::VerifyPathControlledByUser( |
| 2243 sub_dir_, text_file_, uid_, ok_gids_)); | 2356 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2244 | 2357 |
| 2245 // Make base_dir_ world-writable. | 2358 // Make base_dir_ world-writable. |
| 2246 ASSERT_NO_FATAL_FAILURE( | 2359 ASSERT_TRUE( |
| 2247 ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u)); | 2360 file_util::ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u)); |
| 2248 EXPECT_FALSE( | 2361 EXPECT_FALSE( |
| 2249 file_util::VerifyPathControlledByUser( | 2362 file_util::VerifyPathControlledByUser( |
| 2250 base_dir_, sub_dir_, uid_, ok_gids_)); | 2363 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2251 EXPECT_FALSE( | 2364 EXPECT_FALSE( |
| 2252 file_util::VerifyPathControlledByUser( | 2365 file_util::VerifyPathControlledByUser( |
| 2253 base_dir_, text_file_, uid_, ok_gids_)); | 2366 base_dir_, text_file_, uid_, ok_gids_)); |
| 2254 EXPECT_TRUE( | 2367 EXPECT_TRUE( |
| 2255 file_util::VerifyPathControlledByUser( | 2368 file_util::VerifyPathControlledByUser( |
| 2256 sub_dir_, text_file_, uid_, ok_gids_)); | 2369 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2257 | 2370 |
| 2258 // Make sub_dir_ world writable. | 2371 // Make sub_dir_ world writable. |
| 2259 ASSERT_NO_FATAL_FAILURE( | 2372 ASSERT_TRUE( |
| 2260 ChangePosixFilePermissions(sub_dir_, S_IWOTH, 0u)); | 2373 file_util::ChangePosixFilePermissions(sub_dir_, S_IWOTH, 0u)); |
| 2261 EXPECT_FALSE( | 2374 EXPECT_FALSE( |
| 2262 file_util::VerifyPathControlledByUser( | 2375 file_util::VerifyPathControlledByUser( |
| 2263 base_dir_, sub_dir_, uid_, ok_gids_)); | 2376 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2264 EXPECT_FALSE( | 2377 EXPECT_FALSE( |
| 2265 file_util::VerifyPathControlledByUser( | 2378 file_util::VerifyPathControlledByUser( |
| 2266 base_dir_, text_file_, uid_, ok_gids_)); | 2379 base_dir_, text_file_, uid_, ok_gids_)); |
| 2267 EXPECT_FALSE( | 2380 EXPECT_FALSE( |
| 2268 file_util::VerifyPathControlledByUser( | 2381 file_util::VerifyPathControlledByUser( |
| 2269 sub_dir_, text_file_, uid_, ok_gids_)); | 2382 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2270 | 2383 |
| 2271 // Make text_file_ world writable. | 2384 // Make text_file_ world writable. |
| 2272 ASSERT_NO_FATAL_FAILURE( | 2385 ASSERT_TRUE( |
| 2273 ChangePosixFilePermissions(text_file_, S_IWOTH, 0u)); | 2386 file_util::ChangePosixFilePermissions(text_file_, S_IWOTH, 0u)); |
| 2274 EXPECT_FALSE( | 2387 EXPECT_FALSE( |
| 2275 file_util::VerifyPathControlledByUser( | 2388 file_util::VerifyPathControlledByUser( |
| 2276 base_dir_, sub_dir_, uid_, ok_gids_)); | 2389 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2277 EXPECT_FALSE( | 2390 EXPECT_FALSE( |
| 2278 file_util::VerifyPathControlledByUser( | 2391 file_util::VerifyPathControlledByUser( |
| 2279 base_dir_, text_file_, uid_, ok_gids_)); | 2392 base_dir_, text_file_, uid_, ok_gids_)); |
| 2280 EXPECT_FALSE( | 2393 EXPECT_FALSE( |
| 2281 file_util::VerifyPathControlledByUser( | 2394 file_util::VerifyPathControlledByUser( |
| 2282 sub_dir_, text_file_, uid_, ok_gids_)); | 2395 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2283 | 2396 |
| 2284 // Make sub_dir_ non-world writable. | 2397 // Make sub_dir_ non-world writable. |
| 2285 ASSERT_NO_FATAL_FAILURE( | 2398 ASSERT_TRUE( |
| 2286 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); | 2399 file_util::ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); |
| 2287 EXPECT_FALSE( | 2400 EXPECT_FALSE( |
| 2288 file_util::VerifyPathControlledByUser( | 2401 file_util::VerifyPathControlledByUser( |
| 2289 base_dir_, sub_dir_, uid_, ok_gids_)); | 2402 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2290 EXPECT_FALSE( | 2403 EXPECT_FALSE( |
| 2291 file_util::VerifyPathControlledByUser( | 2404 file_util::VerifyPathControlledByUser( |
| 2292 base_dir_, text_file_, uid_, ok_gids_)); | 2405 base_dir_, text_file_, uid_, ok_gids_)); |
| 2293 EXPECT_FALSE( | 2406 EXPECT_FALSE( |
| 2294 file_util::VerifyPathControlledByUser( | 2407 file_util::VerifyPathControlledByUser( |
| 2295 sub_dir_, text_file_, uid_, ok_gids_)); | 2408 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2296 | 2409 |
| 2297 // Make base_dir_ non-world-writable. | 2410 // Make base_dir_ non-world-writable. |
| 2298 ASSERT_NO_FATAL_FAILURE( | 2411 ASSERT_TRUE( |
| 2299 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 2412 file_util::ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
| 2300 EXPECT_TRUE( | 2413 EXPECT_TRUE( |
| 2301 file_util::VerifyPathControlledByUser( | 2414 file_util::VerifyPathControlledByUser( |
| 2302 base_dir_, sub_dir_, uid_, ok_gids_)); | 2415 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2303 EXPECT_FALSE( | 2416 EXPECT_FALSE( |
| 2304 file_util::VerifyPathControlledByUser( | 2417 file_util::VerifyPathControlledByUser( |
| 2305 base_dir_, text_file_, uid_, ok_gids_)); | 2418 base_dir_, text_file_, uid_, ok_gids_)); |
| 2306 EXPECT_FALSE( | 2419 EXPECT_FALSE( |
| 2307 file_util::VerifyPathControlledByUser( | 2420 file_util::VerifyPathControlledByUser( |
| 2308 sub_dir_, text_file_, uid_, ok_gids_)); | 2421 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2309 | 2422 |
| 2310 // Back to the initial state: Nothing is writable, so every path | 2423 // Back to the initial state: Nothing is writable, so every path |
| 2311 // should pass. | 2424 // should pass. |
| 2312 ASSERT_NO_FATAL_FAILURE( | 2425 ASSERT_TRUE( |
| 2313 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); | 2426 file_util::ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); |
| 2314 EXPECT_TRUE( | 2427 EXPECT_TRUE( |
| 2315 file_util::VerifyPathControlledByUser( | 2428 file_util::VerifyPathControlledByUser( |
| 2316 base_dir_, sub_dir_, uid_, ok_gids_)); | 2429 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2317 EXPECT_TRUE( | 2430 EXPECT_TRUE( |
| 2318 file_util::VerifyPathControlledByUser( | 2431 file_util::VerifyPathControlledByUser( |
| 2319 base_dir_, text_file_, uid_, ok_gids_)); | 2432 base_dir_, text_file_, uid_, ok_gids_)); |
| 2320 EXPECT_TRUE( | 2433 EXPECT_TRUE( |
| 2321 file_util::VerifyPathControlledByUser( | 2434 file_util::VerifyPathControlledByUser( |
| 2322 sub_dir_, text_file_, uid_, ok_gids_)); | 2435 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2323 } | 2436 } |
| 2324 | 2437 |
| 2325 #endif // defined(OS_POSIX) | 2438 #endif // defined(OS_POSIX) |
| 2326 | 2439 |
| 2327 } // namespace | 2440 } // namespace |
| OLD | NEW |