Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: base/file_util_unittest.cc

Issue 189333004: Move more file_util functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 std::set<gid_t> ok_gids_; 2120 std::set<gid_t> ok_gids_;
2121 std::set<gid_t> bad_gids_; 2121 std::set<gid_t> bad_gids_;
2122 }; 2122 };
2123 2123
2124 TEST_F(VerifyPathControlledByUserTest, BadPaths) { 2124 TEST_F(VerifyPathControlledByUserTest, BadPaths) {
2125 // File does not exist. 2125 // File does not exist.
2126 FilePath does_not_exist = base_dir_.AppendASCII("does") 2126 FilePath does_not_exist = base_dir_.AppendASCII("does")
2127 .AppendASCII("not") 2127 .AppendASCII("not")
2128 .AppendASCII("exist"); 2128 .AppendASCII("exist");
2129 EXPECT_FALSE( 2129 EXPECT_FALSE(
2130 file_util::VerifyPathControlledByUser( 2130 base::VerifyPathControlledByUser(
2131 base_dir_, does_not_exist, uid_, ok_gids_)); 2131 base_dir_, does_not_exist, uid_, ok_gids_));
2132 2132
2133 // |base| not a subpath of |path|. 2133 // |base| not a subpath of |path|.
2134 EXPECT_FALSE( 2134 EXPECT_FALSE(
2135 file_util::VerifyPathControlledByUser( 2135 base::VerifyPathControlledByUser(
2136 sub_dir_, base_dir_, uid_, ok_gids_)); 2136 sub_dir_, base_dir_, uid_, ok_gids_));
2137 2137
2138 // An empty base path will fail to be a prefix for any path. 2138 // An empty base path will fail to be a prefix for any path.
2139 FilePath empty; 2139 FilePath empty;
2140 EXPECT_FALSE( 2140 EXPECT_FALSE(
2141 file_util::VerifyPathControlledByUser( 2141 base::VerifyPathControlledByUser(
2142 empty, base_dir_, uid_, ok_gids_)); 2142 empty, base_dir_, uid_, ok_gids_));
2143 2143
2144 // Finding that a bad call fails proves nothing unless a good call succeeds. 2144 // Finding that a bad call fails proves nothing unless a good call succeeds.
2145 EXPECT_TRUE( 2145 EXPECT_TRUE(
2146 file_util::VerifyPathControlledByUser( 2146 base::VerifyPathControlledByUser(
2147 base_dir_, sub_dir_, uid_, ok_gids_)); 2147 base_dir_, sub_dir_, uid_, ok_gids_));
2148 } 2148 }
2149 2149
2150 TEST_F(VerifyPathControlledByUserTest, Symlinks) { 2150 TEST_F(VerifyPathControlledByUserTest, Symlinks) {
2151 // Symlinks in the path should cause failure. 2151 // Symlinks in the path should cause failure.
2152 2152
2153 // Symlink to the file at the end of the path. 2153 // Symlink to the file at the end of the path.
2154 FilePath file_link = base_dir_.AppendASCII("file_link"); 2154 FilePath file_link = base_dir_.AppendASCII("file_link");
2155 ASSERT_TRUE(CreateSymbolicLink(text_file_, file_link)) 2155 ASSERT_TRUE(CreateSymbolicLink(text_file_, file_link))
2156 << "Failed to create symlink."; 2156 << "Failed to create symlink.";
2157 2157
2158 EXPECT_FALSE( 2158 EXPECT_FALSE(
2159 file_util::VerifyPathControlledByUser( 2159 base::VerifyPathControlledByUser(
2160 base_dir_, file_link, uid_, ok_gids_)); 2160 base_dir_, file_link, uid_, ok_gids_));
2161 EXPECT_FALSE( 2161 EXPECT_FALSE(
2162 file_util::VerifyPathControlledByUser( 2162 base::VerifyPathControlledByUser(
2163 file_link, file_link, uid_, ok_gids_)); 2163 file_link, file_link, uid_, ok_gids_));
2164 2164
2165 // Symlink from one directory to another within the path. 2165 // Symlink from one directory to another within the path.
2166 FilePath link_to_sub_dir = base_dir_.AppendASCII("link_to_sub_dir"); 2166 FilePath link_to_sub_dir = base_dir_.AppendASCII("link_to_sub_dir");
2167 ASSERT_TRUE(CreateSymbolicLink(sub_dir_, link_to_sub_dir)) 2167 ASSERT_TRUE(CreateSymbolicLink(sub_dir_, link_to_sub_dir))
2168 << "Failed to create symlink."; 2168 << "Failed to create symlink.";
2169 2169
2170 FilePath file_path_with_link = link_to_sub_dir.AppendASCII("file.txt"); 2170 FilePath file_path_with_link = link_to_sub_dir.AppendASCII("file.txt");
2171 ASSERT_TRUE(PathExists(file_path_with_link)); 2171 ASSERT_TRUE(PathExists(file_path_with_link));
2172 2172
2173 EXPECT_FALSE( 2173 EXPECT_FALSE(
2174 file_util::VerifyPathControlledByUser( 2174 base::VerifyPathControlledByUser(
2175 base_dir_, file_path_with_link, uid_, ok_gids_)); 2175 base_dir_, file_path_with_link, uid_, ok_gids_));
2176 2176
2177 EXPECT_FALSE( 2177 EXPECT_FALSE(
2178 file_util::VerifyPathControlledByUser( 2178 base::VerifyPathControlledByUser(
2179 link_to_sub_dir, file_path_with_link, uid_, ok_gids_)); 2179 link_to_sub_dir, file_path_with_link, uid_, ok_gids_));
2180 2180
2181 // Symlinks in parents of base path are allowed. 2181 // Symlinks in parents of base path are allowed.
2182 EXPECT_TRUE( 2182 EXPECT_TRUE(
2183 file_util::VerifyPathControlledByUser( 2183 base::VerifyPathControlledByUser(
2184 file_path_with_link, file_path_with_link, uid_, ok_gids_)); 2184 file_path_with_link, file_path_with_link, uid_, ok_gids_));
2185 } 2185 }
2186 2186
2187 TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) { 2187 TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) {
2188 // Get a uid that is not the uid of files we create. 2188 // Get a uid that is not the uid of files we create.
2189 uid_t bad_uid = uid_ + 1; 2189 uid_t bad_uid = uid_ + 1;
2190 2190
2191 // Make all files and directories non-world-writable. 2191 // Make all files and directories non-world-writable.
2192 ASSERT_NO_FATAL_FAILURE( 2192 ASSERT_NO_FATAL_FAILURE(
2193 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); 2193 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH));
2194 ASSERT_NO_FATAL_FAILURE( 2194 ASSERT_NO_FATAL_FAILURE(
2195 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); 2195 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH));
2196 ASSERT_NO_FATAL_FAILURE( 2196 ASSERT_NO_FATAL_FAILURE(
2197 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); 2197 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH));
2198 2198
2199 // We control these paths. 2199 // We control these paths.
2200 EXPECT_TRUE( 2200 EXPECT_TRUE(
2201 file_util::VerifyPathControlledByUser( 2201 base::VerifyPathControlledByUser(
2202 base_dir_, sub_dir_, uid_, ok_gids_)); 2202 base_dir_, sub_dir_, uid_, ok_gids_));
2203 EXPECT_TRUE( 2203 EXPECT_TRUE(
2204 file_util::VerifyPathControlledByUser( 2204 base::VerifyPathControlledByUser(
2205 base_dir_, text_file_, uid_, ok_gids_)); 2205 base_dir_, text_file_, uid_, ok_gids_));
2206 EXPECT_TRUE( 2206 EXPECT_TRUE(
2207 file_util::VerifyPathControlledByUser( 2207 base::VerifyPathControlledByUser(
2208 sub_dir_, text_file_, uid_, ok_gids_)); 2208 sub_dir_, text_file_, uid_, ok_gids_));
2209 2209
2210 // Another user does not control these paths. 2210 // Another user does not control these paths.
2211 EXPECT_FALSE( 2211 EXPECT_FALSE(
2212 file_util::VerifyPathControlledByUser( 2212 base::VerifyPathControlledByUser(
2213 base_dir_, sub_dir_, bad_uid, ok_gids_)); 2213 base_dir_, sub_dir_, bad_uid, ok_gids_));
2214 EXPECT_FALSE( 2214 EXPECT_FALSE(
2215 file_util::VerifyPathControlledByUser( 2215 base::VerifyPathControlledByUser(
2216 base_dir_, text_file_, bad_uid, ok_gids_)); 2216 base_dir_, text_file_, bad_uid, ok_gids_));
2217 EXPECT_FALSE( 2217 EXPECT_FALSE(
2218 file_util::VerifyPathControlledByUser( 2218 base::VerifyPathControlledByUser(
2219 sub_dir_, text_file_, bad_uid, ok_gids_)); 2219 sub_dir_, text_file_, bad_uid, ok_gids_));
2220 2220
2221 // Another group does not control the paths. 2221 // Another group does not control the paths.
2222 EXPECT_FALSE( 2222 EXPECT_FALSE(
2223 file_util::VerifyPathControlledByUser( 2223 base::VerifyPathControlledByUser(
2224 base_dir_, sub_dir_, uid_, bad_gids_)); 2224 base_dir_, sub_dir_, uid_, bad_gids_));
2225 EXPECT_FALSE( 2225 EXPECT_FALSE(
2226 file_util::VerifyPathControlledByUser( 2226 base::VerifyPathControlledByUser(
2227 base_dir_, text_file_, uid_, bad_gids_)); 2227 base_dir_, text_file_, uid_, bad_gids_));
2228 EXPECT_FALSE( 2228 EXPECT_FALSE(
2229 file_util::VerifyPathControlledByUser( 2229 base::VerifyPathControlledByUser(
2230 sub_dir_, text_file_, uid_, bad_gids_)); 2230 sub_dir_, text_file_, uid_, bad_gids_));
2231 } 2231 }
2232 2232
2233 TEST_F(VerifyPathControlledByUserTest, GroupWriteTest) { 2233 TEST_F(VerifyPathControlledByUserTest, GroupWriteTest) {
2234 // Make all files and directories writable only by their owner. 2234 // Make all files and directories writable only by their owner.
2235 ASSERT_NO_FATAL_FAILURE( 2235 ASSERT_NO_FATAL_FAILURE(
2236 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH|S_IWGRP)); 2236 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH|S_IWGRP));
2237 ASSERT_NO_FATAL_FAILURE( 2237 ASSERT_NO_FATAL_FAILURE(
2238 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH|S_IWGRP)); 2238 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH|S_IWGRP));
2239 ASSERT_NO_FATAL_FAILURE( 2239 ASSERT_NO_FATAL_FAILURE(
2240 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH|S_IWGRP)); 2240 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH|S_IWGRP));
2241 2241
2242 // Any group is okay because the path is not group-writable. 2242 // Any group is okay because the path is not group-writable.
2243 EXPECT_TRUE( 2243 EXPECT_TRUE(
2244 file_util::VerifyPathControlledByUser( 2244 base::VerifyPathControlledByUser(
2245 base_dir_, sub_dir_, uid_, ok_gids_)); 2245 base_dir_, sub_dir_, uid_, ok_gids_));
2246 EXPECT_TRUE( 2246 EXPECT_TRUE(
2247 file_util::VerifyPathControlledByUser( 2247 base::VerifyPathControlledByUser(
2248 base_dir_, text_file_, uid_, ok_gids_)); 2248 base_dir_, text_file_, uid_, ok_gids_));
2249 EXPECT_TRUE( 2249 EXPECT_TRUE(
2250 file_util::VerifyPathControlledByUser( 2250 base::VerifyPathControlledByUser(
2251 sub_dir_, text_file_, uid_, ok_gids_)); 2251 sub_dir_, text_file_, uid_, ok_gids_));
2252 2252
2253 EXPECT_TRUE( 2253 EXPECT_TRUE(
2254 file_util::VerifyPathControlledByUser( 2254 base::VerifyPathControlledByUser(
2255 base_dir_, sub_dir_, uid_, bad_gids_)); 2255 base_dir_, sub_dir_, uid_, bad_gids_));
2256 EXPECT_TRUE( 2256 EXPECT_TRUE(
2257 file_util::VerifyPathControlledByUser( 2257 base::VerifyPathControlledByUser(
2258 base_dir_, text_file_, uid_, bad_gids_)); 2258 base_dir_, text_file_, uid_, bad_gids_));
2259 EXPECT_TRUE( 2259 EXPECT_TRUE(
2260 file_util::VerifyPathControlledByUser( 2260 base::VerifyPathControlledByUser(
2261 sub_dir_, text_file_, uid_, bad_gids_)); 2261 sub_dir_, text_file_, uid_, bad_gids_));
2262 2262
2263 // No group is okay, because we don't check the group 2263 // No group is okay, because we don't check the group
2264 // if no group can write. 2264 // if no group can write.
2265 std::set<gid_t> no_gids; // Empty set of gids. 2265 std::set<gid_t> no_gids; // Empty set of gids.
2266 EXPECT_TRUE( 2266 EXPECT_TRUE(
2267 file_util::VerifyPathControlledByUser( 2267 base::VerifyPathControlledByUser(
2268 base_dir_, sub_dir_, uid_, no_gids)); 2268 base_dir_, sub_dir_, uid_, no_gids));
2269 EXPECT_TRUE( 2269 EXPECT_TRUE(
2270 file_util::VerifyPathControlledByUser( 2270 base::VerifyPathControlledByUser(
2271 base_dir_, text_file_, uid_, no_gids)); 2271 base_dir_, text_file_, uid_, no_gids));
2272 EXPECT_TRUE( 2272 EXPECT_TRUE(
2273 file_util::VerifyPathControlledByUser( 2273 base::VerifyPathControlledByUser(
2274 sub_dir_, text_file_, uid_, no_gids)); 2274 sub_dir_, text_file_, uid_, no_gids));
2275 2275
2276 2276
2277 // Make all files and directories writable by their group. 2277 // Make all files and directories writable by their group.
2278 ASSERT_NO_FATAL_FAILURE( 2278 ASSERT_NO_FATAL_FAILURE(
2279 ChangePosixFilePermissions(base_dir_, S_IWGRP, 0u)); 2279 ChangePosixFilePermissions(base_dir_, S_IWGRP, 0u));
2280 ASSERT_NO_FATAL_FAILURE( 2280 ASSERT_NO_FATAL_FAILURE(
2281 ChangePosixFilePermissions(sub_dir_, S_IWGRP, 0u)); 2281 ChangePosixFilePermissions(sub_dir_, S_IWGRP, 0u));
2282 ASSERT_NO_FATAL_FAILURE( 2282 ASSERT_NO_FATAL_FAILURE(
2283 ChangePosixFilePermissions(text_file_, S_IWGRP, 0u)); 2283 ChangePosixFilePermissions(text_file_, S_IWGRP, 0u));
2284 2284
2285 // Now |ok_gids_| works, but |bad_gids_| fails. 2285 // Now |ok_gids_| works, but |bad_gids_| fails.
2286 EXPECT_TRUE( 2286 EXPECT_TRUE(
2287 file_util::VerifyPathControlledByUser( 2287 base::VerifyPathControlledByUser(
2288 base_dir_, sub_dir_, uid_, ok_gids_)); 2288 base_dir_, sub_dir_, uid_, ok_gids_));
2289 EXPECT_TRUE( 2289 EXPECT_TRUE(
2290 file_util::VerifyPathControlledByUser( 2290 base::VerifyPathControlledByUser(
2291 base_dir_, text_file_, uid_, ok_gids_)); 2291 base_dir_, text_file_, uid_, ok_gids_));
2292 EXPECT_TRUE( 2292 EXPECT_TRUE(
2293 file_util::VerifyPathControlledByUser( 2293 base::VerifyPathControlledByUser(
2294 sub_dir_, text_file_, uid_, ok_gids_)); 2294 sub_dir_, text_file_, uid_, ok_gids_));
2295 2295
2296 EXPECT_FALSE( 2296 EXPECT_FALSE(
2297 file_util::VerifyPathControlledByUser( 2297 base::VerifyPathControlledByUser(
2298 base_dir_, sub_dir_, uid_, bad_gids_)); 2298 base_dir_, sub_dir_, uid_, bad_gids_));
2299 EXPECT_FALSE( 2299 EXPECT_FALSE(
2300 file_util::VerifyPathControlledByUser( 2300 base::VerifyPathControlledByUser(
2301 base_dir_, text_file_, uid_, bad_gids_)); 2301 base_dir_, text_file_, uid_, bad_gids_));
2302 EXPECT_FALSE( 2302 EXPECT_FALSE(
2303 file_util::VerifyPathControlledByUser( 2303 base::VerifyPathControlledByUser(
2304 sub_dir_, text_file_, uid_, bad_gids_)); 2304 sub_dir_, text_file_, uid_, bad_gids_));
2305 2305
2306 // Because any group in the group set is allowed, 2306 // Because any group in the group set is allowed,
2307 // the union of good and bad gids passes. 2307 // the union of good and bad gids passes.
2308 2308
2309 std::set<gid_t> multiple_gids; 2309 std::set<gid_t> multiple_gids;
2310 std::set_union( 2310 std::set_union(
2311 ok_gids_.begin(), ok_gids_.end(), 2311 ok_gids_.begin(), ok_gids_.end(),
2312 bad_gids_.begin(), bad_gids_.end(), 2312 bad_gids_.begin(), bad_gids_.end(),
2313 std::inserter(multiple_gids, multiple_gids.begin())); 2313 std::inserter(multiple_gids, multiple_gids.begin()));
2314 2314
2315 EXPECT_TRUE( 2315 EXPECT_TRUE(
2316 file_util::VerifyPathControlledByUser( 2316 base::VerifyPathControlledByUser(
2317 base_dir_, sub_dir_, uid_, multiple_gids)); 2317 base_dir_, sub_dir_, uid_, multiple_gids));
2318 EXPECT_TRUE( 2318 EXPECT_TRUE(
2319 file_util::VerifyPathControlledByUser( 2319 base::VerifyPathControlledByUser(
2320 base_dir_, text_file_, uid_, multiple_gids)); 2320 base_dir_, text_file_, uid_, multiple_gids));
2321 EXPECT_TRUE( 2321 EXPECT_TRUE(
2322 file_util::VerifyPathControlledByUser( 2322 base::VerifyPathControlledByUser(
2323 sub_dir_, text_file_, uid_, multiple_gids)); 2323 sub_dir_, text_file_, uid_, multiple_gids));
2324 } 2324 }
2325 2325
2326 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) { 2326 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) {
2327 // Make all files and directories non-world-writable. 2327 // Make all files and directories non-world-writable.
2328 ASSERT_NO_FATAL_FAILURE( 2328 ASSERT_NO_FATAL_FAILURE(
2329 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); 2329 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH));
2330 ASSERT_NO_FATAL_FAILURE( 2330 ASSERT_NO_FATAL_FAILURE(
2331 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); 2331 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH));
2332 ASSERT_NO_FATAL_FAILURE( 2332 ASSERT_NO_FATAL_FAILURE(
2333 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); 2333 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH));
2334 2334
2335 // Initialy, we control all parts of the path. 2335 // Initialy, we control all parts of the path.
2336 EXPECT_TRUE( 2336 EXPECT_TRUE(
2337 file_util::VerifyPathControlledByUser( 2337 base::VerifyPathControlledByUser(
2338 base_dir_, sub_dir_, uid_, ok_gids_)); 2338 base_dir_, sub_dir_, uid_, ok_gids_));
2339 EXPECT_TRUE( 2339 EXPECT_TRUE(
2340 file_util::VerifyPathControlledByUser( 2340 base::VerifyPathControlledByUser(
2341 base_dir_, text_file_, uid_, ok_gids_)); 2341 base_dir_, text_file_, uid_, ok_gids_));
2342 EXPECT_TRUE( 2342 EXPECT_TRUE(
2343 file_util::VerifyPathControlledByUser( 2343 base::VerifyPathControlledByUser(
2344 sub_dir_, text_file_, uid_, ok_gids_)); 2344 sub_dir_, text_file_, uid_, ok_gids_));
2345 2345
2346 // Make base_dir_ world-writable. 2346 // Make base_dir_ world-writable.
2347 ASSERT_NO_FATAL_FAILURE( 2347 ASSERT_NO_FATAL_FAILURE(
2348 ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u)); 2348 ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u));
2349 EXPECT_FALSE( 2349 EXPECT_FALSE(
2350 file_util::VerifyPathControlledByUser( 2350 base::VerifyPathControlledByUser(
2351 base_dir_, sub_dir_, uid_, ok_gids_)); 2351 base_dir_, sub_dir_, uid_, ok_gids_));
2352 EXPECT_FALSE( 2352 EXPECT_FALSE(
2353 file_util::VerifyPathControlledByUser( 2353 base::VerifyPathControlledByUser(
2354 base_dir_, text_file_, uid_, ok_gids_)); 2354 base_dir_, text_file_, uid_, ok_gids_));
2355 EXPECT_TRUE( 2355 EXPECT_TRUE(
2356 file_util::VerifyPathControlledByUser( 2356 base::VerifyPathControlledByUser(
2357 sub_dir_, text_file_, uid_, ok_gids_)); 2357 sub_dir_, text_file_, uid_, ok_gids_));
2358 2358
2359 // Make sub_dir_ world writable. 2359 // Make sub_dir_ world writable.
2360 ASSERT_NO_FATAL_FAILURE( 2360 ASSERT_NO_FATAL_FAILURE(
2361 ChangePosixFilePermissions(sub_dir_, S_IWOTH, 0u)); 2361 ChangePosixFilePermissions(sub_dir_, S_IWOTH, 0u));
2362 EXPECT_FALSE( 2362 EXPECT_FALSE(
2363 file_util::VerifyPathControlledByUser( 2363 base::VerifyPathControlledByUser(
2364 base_dir_, sub_dir_, uid_, ok_gids_)); 2364 base_dir_, sub_dir_, uid_, ok_gids_));
2365 EXPECT_FALSE( 2365 EXPECT_FALSE(
2366 file_util::VerifyPathControlledByUser( 2366 base::VerifyPathControlledByUser(
2367 base_dir_, text_file_, uid_, ok_gids_)); 2367 base_dir_, text_file_, uid_, ok_gids_));
2368 EXPECT_FALSE( 2368 EXPECT_FALSE(
2369 file_util::VerifyPathControlledByUser( 2369 base::VerifyPathControlledByUser(
2370 sub_dir_, text_file_, uid_, ok_gids_)); 2370 sub_dir_, text_file_, uid_, ok_gids_));
2371 2371
2372 // Make text_file_ world writable. 2372 // Make text_file_ world writable.
2373 ASSERT_NO_FATAL_FAILURE( 2373 ASSERT_NO_FATAL_FAILURE(
2374 ChangePosixFilePermissions(text_file_, S_IWOTH, 0u)); 2374 ChangePosixFilePermissions(text_file_, S_IWOTH, 0u));
2375 EXPECT_FALSE( 2375 EXPECT_FALSE(
2376 file_util::VerifyPathControlledByUser( 2376 base::VerifyPathControlledByUser(
2377 base_dir_, sub_dir_, uid_, ok_gids_)); 2377 base_dir_, sub_dir_, uid_, ok_gids_));
2378 EXPECT_FALSE( 2378 EXPECT_FALSE(
2379 file_util::VerifyPathControlledByUser( 2379 base::VerifyPathControlledByUser(
2380 base_dir_, text_file_, uid_, ok_gids_)); 2380 base_dir_, text_file_, uid_, ok_gids_));
2381 EXPECT_FALSE( 2381 EXPECT_FALSE(
2382 file_util::VerifyPathControlledByUser( 2382 base::VerifyPathControlledByUser(
2383 sub_dir_, text_file_, uid_, ok_gids_)); 2383 sub_dir_, text_file_, uid_, ok_gids_));
2384 2384
2385 // Make sub_dir_ non-world writable. 2385 // Make sub_dir_ non-world writable.
2386 ASSERT_NO_FATAL_FAILURE( 2386 ASSERT_NO_FATAL_FAILURE(
2387 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); 2387 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH));
2388 EXPECT_FALSE( 2388 EXPECT_FALSE(
2389 file_util::VerifyPathControlledByUser( 2389 base::VerifyPathControlledByUser(
2390 base_dir_, sub_dir_, uid_, ok_gids_)); 2390 base_dir_, sub_dir_, uid_, ok_gids_));
2391 EXPECT_FALSE( 2391 EXPECT_FALSE(
2392 file_util::VerifyPathControlledByUser( 2392 base::VerifyPathControlledByUser(
2393 base_dir_, text_file_, uid_, ok_gids_)); 2393 base_dir_, text_file_, uid_, ok_gids_));
2394 EXPECT_FALSE( 2394 EXPECT_FALSE(
2395 file_util::VerifyPathControlledByUser( 2395 base::VerifyPathControlledByUser(
2396 sub_dir_, text_file_, uid_, ok_gids_)); 2396 sub_dir_, text_file_, uid_, ok_gids_));
2397 2397
2398 // Make base_dir_ non-world-writable. 2398 // Make base_dir_ non-world-writable.
2399 ASSERT_NO_FATAL_FAILURE( 2399 ASSERT_NO_FATAL_FAILURE(
2400 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); 2400 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH));
2401 EXPECT_TRUE( 2401 EXPECT_TRUE(
2402 file_util::VerifyPathControlledByUser( 2402 base::VerifyPathControlledByUser(
2403 base_dir_, sub_dir_, uid_, ok_gids_)); 2403 base_dir_, sub_dir_, uid_, ok_gids_));
2404 EXPECT_FALSE( 2404 EXPECT_FALSE(
2405 file_util::VerifyPathControlledByUser( 2405 base::VerifyPathControlledByUser(
2406 base_dir_, text_file_, uid_, ok_gids_)); 2406 base_dir_, text_file_, uid_, ok_gids_));
2407 EXPECT_FALSE( 2407 EXPECT_FALSE(
2408 file_util::VerifyPathControlledByUser( 2408 base::VerifyPathControlledByUser(
2409 sub_dir_, text_file_, uid_, ok_gids_)); 2409 sub_dir_, text_file_, uid_, ok_gids_));
2410 2410
2411 // Back to the initial state: Nothing is writable, so every path 2411 // Back to the initial state: Nothing is writable, so every path
2412 // should pass. 2412 // should pass.
2413 ASSERT_NO_FATAL_FAILURE( 2413 ASSERT_NO_FATAL_FAILURE(
2414 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); 2414 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH));
2415 EXPECT_TRUE( 2415 EXPECT_TRUE(
2416 file_util::VerifyPathControlledByUser( 2416 base::VerifyPathControlledByUser(
2417 base_dir_, sub_dir_, uid_, ok_gids_)); 2417 base_dir_, sub_dir_, uid_, ok_gids_));
2418 EXPECT_TRUE( 2418 EXPECT_TRUE(
2419 file_util::VerifyPathControlledByUser( 2419 base::VerifyPathControlledByUser(
2420 base_dir_, text_file_, uid_, ok_gids_)); 2420 base_dir_, text_file_, uid_, ok_gids_));
2421 EXPECT_TRUE( 2421 EXPECT_TRUE(
2422 file_util::VerifyPathControlledByUser( 2422 base::VerifyPathControlledByUser(
2423 sub_dir_, text_file_, uid_, ok_gids_)); 2423 sub_dir_, text_file_, uid_, ok_gids_));
2424 } 2424 }
2425 2425
2426 #if defined(OS_ANDROID) 2426 #if defined(OS_ANDROID)
2427 TEST_F(FileUtilTest, ValidContentUriTest) { 2427 TEST_F(FileUtilTest, ValidContentUriTest) {
2428 // Get the test image path. 2428 // Get the test image path.
2429 FilePath data_dir; 2429 FilePath data_dir;
2430 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); 2430 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir));
2431 data_dir = data_dir.AppendASCII("file_util"); 2431 data_dir = data_dir.AppendASCII("file_util");
2432 ASSERT_TRUE(PathExists(data_dir)); 2432 ASSERT_TRUE(PathExists(data_dir));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 // Trying to close it should crash. This is important for security. 2503 // Trying to close it should crash. This is important for security.
2504 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); 2504 EXPECT_DEATH(CloseWithScopedFD(fds[1]), "");
2505 #endif 2505 #endif
2506 } 2506 }
2507 2507
2508 #endif // defined(OS_POSIX) 2508 #endif // defined(OS_POSIX)
2509 2509
2510 } // namespace 2510 } // namespace
2511 2511
2512 } // namespace base 2512 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698