summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Merino <jmmv@google.com>2018-10-17 12:03:08 -0400
committerJulio Merino <julio@meroh.net>2018-10-19 22:09:13 -0400
commit9bf4ab32764be9b05fd74d67b21c6433bed7e488 (patch)
tree299f195c6407c34bd3b41aaab693842bb5df1f28
parentf3dab48a9221ede9f5409662eacca4b53de34171 (diff)
downloadnix-9bf4ab32764be9b05fd74d67b21c6433bed7e488.zip
Add trivial tests for chown and fchownat
These are mostly to ensure that all the platforms we care about in our CI can reference these primitives.
-rw-r--r--test/test_unistd.rs45
1 files changed, 44 insertions, 1 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 981ab53d..e5f9d448 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -1,4 +1,4 @@
-use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag};
+use nix::fcntl::{fcntl, FcntlArg, FdFlag, open, OFlag};
use nix::unistd::*;
use nix::unistd::ForkResult::*;
use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction};
@@ -302,6 +302,49 @@ fn test_getcwd() {
}
#[test]
+fn test_chown() {
+ // Testing for anything other than our own UID/GID is hard.
+ let uid = Some(getuid());
+ let gid = Some(getgid());
+
+ let tempdir = tempfile::tempdir().unwrap();
+ let path = tempdir.path().join("file");
+ {
+ File::create(&path).unwrap();
+ }
+
+ chown(&path, uid, gid).unwrap();
+ chown(&path, uid, None).unwrap();
+ chown(&path, None, gid).unwrap();
+
+ fs::remove_file(&path).unwrap();
+ chown(&path, uid, gid).unwrap_err();
+}
+
+#[test]
+fn test_fchownat() {
+ // Testing for anything other than our own UID/GID is hard.
+ let uid = Some(getuid());
+ let gid = Some(getgid());
+
+ let tempdir = tempfile::tempdir().unwrap();
+ let path = tempdir.path().join("file");
+ {
+ File::create(&path).unwrap();
+ }
+
+ let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap();
+
+ fchownat(Some(dirfd), "file", uid, gid, FchownatFlags::FollowSymlink).unwrap();
+
+ chdir(tempdir.path()).unwrap();
+ fchownat(None, "file", uid, gid, FchownatFlags::FollowSymlink).unwrap();
+
+ fs::remove_file(&path).unwrap();
+ fchownat(None, "file", uid, gid, FchownatFlags::FollowSymlink).unwrap_err();
+}
+
+#[test]
fn test_lseek() {
const CONTENTS: &[u8] = b"abcdef123456";
let mut tmp = tempfile().unwrap();