|
1 |
| -use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag}; |
| 1 | +use nix::fcntl::{fcntl, FcntlArg, FdFlag, open, OFlag}; |
2 | 2 | use nix::unistd::*;
|
3 | 3 | use nix::unistd::ForkResult::*;
|
4 | 4 | use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction};
|
@@ -301,6 +301,49 @@ fn test_getcwd() {
|
301 | 301 | assert_eq!(getcwd().unwrap(), inner_tmp_dir.as_path());
|
302 | 302 | }
|
303 | 303 |
|
| 304 | +#[test] |
| 305 | +fn test_chown() { |
| 306 | + // Testing for anything other than our own UID/GID is hard. |
| 307 | + let uid = Some(getuid()); |
| 308 | + let gid = Some(getgid()); |
| 309 | + |
| 310 | + let tempdir = tempfile::tempdir().unwrap(); |
| 311 | + let path = tempdir.path().join("file"); |
| 312 | + { |
| 313 | + File::create(&path).unwrap(); |
| 314 | + } |
| 315 | + |
| 316 | + chown(&path, uid, gid).unwrap(); |
| 317 | + chown(&path, uid, None).unwrap(); |
| 318 | + chown(&path, None, gid).unwrap(); |
| 319 | + |
| 320 | + fs::remove_file(&path).unwrap(); |
| 321 | + chown(&path, uid, gid).unwrap_err(); |
| 322 | +} |
| 323 | + |
| 324 | +#[test] |
| 325 | +fn test_fchownat() { |
| 326 | + // Testing for anything other than our own UID/GID is hard. |
| 327 | + let uid = Some(getuid()); |
| 328 | + let gid = Some(getgid()); |
| 329 | + |
| 330 | + let tempdir = tempfile::tempdir().unwrap(); |
| 331 | + let path = tempdir.path().join("file"); |
| 332 | + { |
| 333 | + File::create(&path).unwrap(); |
| 334 | + } |
| 335 | + |
| 336 | + let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); |
| 337 | + |
| 338 | + fchownat(Some(dirfd), "file", uid, gid, FchownatFlags::FollowSymlink).unwrap(); |
| 339 | + |
| 340 | + chdir(tempdir.path()).unwrap(); |
| 341 | + fchownat(None, "file", uid, gid, FchownatFlags::FollowSymlink).unwrap(); |
| 342 | + |
| 343 | + fs::remove_file(&path).unwrap(); |
| 344 | + fchownat(None, "file", uid, gid, FchownatFlags::FollowSymlink).unwrap_err(); |
| 345 | +} |
| 346 | + |
304 | 347 | #[test]
|
305 | 348 | fn test_lseek() {
|
306 | 349 | const CONTENTS: &[u8] = b"abcdef123456";
|
|
0 commit comments