summaryrefslogtreecommitdiff
path: root/test/test_mount.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_mount.rs')
-rw-r--r--test/test_mount.rs167
1 files changed, 101 insertions, 66 deletions
diff --git a/test/test_mount.rs b/test/test_mount.rs
index 1ddfcfe9..febcadfb 100644
--- a/test/test_mount.rs
+++ b/test/test_mount.rs
@@ -27,16 +27,18 @@ exit 23";
const EXPECTED_STATUS: i32 = 23;
const NONE: Option<&'static [u8]> = None;
- #[allow(clippy::bind_instead_of_map)] // False positive
+ #[allow(clippy::bind_instead_of_map)] // False positive
pub fn test_mount_tmpfs_without_flags_allows_rwx() {
let tempdir = tempfile::tempdir().unwrap();
- mount(NONE,
- tempdir.path(),
- Some(b"tmpfs".as_ref()),
- MsFlags::empty(),
- NONE)
- .unwrap_or_else(|e| panic!("mount failed: {}", e));
+ mount(
+ NONE,
+ tempdir.path(),
+ Some(b"tmpfs".as_ref()),
+ MsFlags::empty(),
+ NONE,
+ )
+ .unwrap_or_else(|e| panic!("mount failed: {}", e));
let test_path = tempdir.path().join("test");
@@ -46,8 +48,10 @@ exit 23";
.write(true)
.mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits())
.open(&test_path)
- .or_else(|e|
- if Errno::from_i32(e.raw_os_error().unwrap()) == Errno::EOVERFLOW {
+ .or_else(|e| {
+ if Errno::from_i32(e.raw_os_error().unwrap())
+ == Errno::EOVERFLOW
+ {
// Skip tests on certain Linux kernels which have a bug
// regarding tmpfs in namespaces.
// Ubuntu 14.04 and 16.04 are known to be affected; 16.10 is
@@ -56,13 +60,16 @@ exit 23";
// https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1659087
let stderr = io::stderr();
let mut handle = stderr.lock();
- writeln!(handle, "Buggy Linux kernel detected. Skipping test.")
+ writeln!(
+ handle,
+ "Buggy Linux kernel detected. Skipping test."
+ )
.unwrap();
process::exit(0);
- } else {
- panic!("open failed: {}", e);
- }
- )
+ } else {
+ panic!("open failed: {}", e);
+ }
+ })
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
.unwrap_or_else(|e| panic!("write failed: {}", e));
@@ -74,42 +81,55 @@ exit 23";
assert_eq!(buf, SCRIPT_CONTENTS);
// Verify execute.
- assert_eq!(EXPECTED_STATUS,
- Command::new(&test_path)
- .status()
- .unwrap_or_else(|e| panic!("exec failed: {}", e))
- .code()
- .unwrap_or_else(|| panic!("child killed by signal")));
-
- umount(tempdir.path()).unwrap_or_else(|e| panic!("umount failed: {}", e));
+ assert_eq!(
+ EXPECTED_STATUS,
+ Command::new(&test_path)
+ .status()
+ .unwrap_or_else(|e| panic!("exec failed: {}", e))
+ .code()
+ .unwrap_or_else(|| panic!("child killed by signal"))
+ );
+
+ umount(tempdir.path())
+ .unwrap_or_else(|e| panic!("umount failed: {}", e));
}
pub fn test_mount_rdonly_disallows_write() {
let tempdir = tempfile::tempdir().unwrap();
- mount(NONE,
- tempdir.path(),
- Some(b"tmpfs".as_ref()),
- MsFlags::MS_RDONLY,
- NONE)
- .unwrap_or_else(|e| panic!("mount failed: {}", e));
+ mount(
+ NONE,
+ tempdir.path(),
+ Some(b"tmpfs".as_ref()),
+ MsFlags::MS_RDONLY,
+ NONE,
+ )
+ .unwrap_or_else(|e| panic!("mount failed: {}", e));
// EROFS: Read-only file system
- assert_eq!(EROFS as i32,
- File::create(tempdir.path().join("test")).unwrap_err().raw_os_error().unwrap());
-
- umount(tempdir.path()).unwrap_or_else(|e| panic!("umount failed: {}", e));
+ assert_eq!(
+ EROFS as i32,
+ File::create(tempdir.path().join("test"))
+ .unwrap_err()
+ .raw_os_error()
+ .unwrap()
+ );
+
+ umount(tempdir.path())
+ .unwrap_or_else(|e| panic!("umount failed: {}", e));
}
pub fn test_mount_noexec_disallows_exec() {
let tempdir = tempfile::tempdir().unwrap();
- mount(NONE,
- tempdir.path(),
- Some(b"tmpfs".as_ref()),
- MsFlags::MS_NOEXEC,
- NONE)
- .unwrap_or_else(|e| panic!("mount failed: {}", e));
+ mount(
+ NONE,
+ tempdir.path(),
+ Some(b"tmpfs".as_ref()),
+ MsFlags::MS_NOEXEC,
+ NONE,
+ )
+ .unwrap_or_else(|e| panic!("mount failed: {}", e));
let test_path = tempdir.path().join("test");
@@ -122,21 +142,30 @@ exit 23";
.unwrap_or_else(|e| panic!("write failed: {}", e));
// Verify that we cannot execute despite a+x permissions being set.
- let mode = stat::Mode::from_bits_truncate(fs::metadata(&test_path)
- .map(|md| md.permissions().mode())
- .unwrap_or_else(|e| {
- panic!("metadata failed: {}", e)
- }));
-
- assert!(mode.contains(Mode::S_IXUSR | Mode::S_IXGRP | Mode::S_IXOTH),
- "{:?} did not have execute permissions",
- &test_path);
+ let mode = stat::Mode::from_bits_truncate(
+ fs::metadata(&test_path)
+ .map(|md| md.permissions().mode())
+ .unwrap_or_else(|e| panic!("metadata failed: {}", e)),
+ );
+
+ assert!(
+ mode.contains(Mode::S_IXUSR | Mode::S_IXGRP | Mode::S_IXOTH),
+ "{:?} did not have execute permissions",
+ &test_path
+ );
// EACCES: Permission denied
- assert_eq!(EACCES as i32,
- Command::new(&test_path).status().unwrap_err().raw_os_error().unwrap());
-
- umount(tempdir.path()).unwrap_or_else(|e| panic!("umount failed: {}", e));
+ assert_eq!(
+ EACCES as i32,
+ Command::new(&test_path)
+ .status()
+ .unwrap_err()
+ .raw_os_error()
+ .unwrap()
+ );
+
+ umount(tempdir.path())
+ .unwrap_or_else(|e| panic!("umount failed: {}", e));
}
pub fn test_mount_bind() {
@@ -146,12 +175,14 @@ exit 23";
{
let mount_point = tempfile::tempdir().unwrap();
- mount(Some(tempdir.path()),
- mount_point.path(),
- NONE,
- MsFlags::MS_BIND,
- NONE)
- .unwrap_or_else(|e| panic!("mount failed: {}", e));
+ mount(
+ Some(tempdir.path()),
+ mount_point.path(),
+ NONE,
+ MsFlags::MS_BIND,
+ NONE,
+ )
+ .unwrap_or_else(|e| panic!("mount failed: {}", e));
fs::OpenOptions::new()
.create(true)
@@ -161,7 +192,8 @@ exit 23";
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
.unwrap_or_else(|e| panic!("write failed: {}", e));
- umount(mount_point.path()).unwrap_or_else(|e| panic!("umount failed: {}", e));
+ umount(mount_point.path())
+ .unwrap_or_else(|e| panic!("umount failed: {}", e));
}
// Verify the file written in the mount shows up in source directory, even
@@ -199,7 +231,6 @@ exit 23";
}
}
-
// Test runner
/// Mimic normal test output (hackishly).
@@ -220,16 +251,20 @@ macro_rules! run_tests {
#[cfg(target_os = "linux")]
fn main() {
- use test_mount::{setup_namespaces, test_mount_tmpfs_without_flags_allows_rwx,
- test_mount_rdonly_disallows_write, test_mount_noexec_disallows_exec,
- test_mount_bind};
+ use test_mount::{
+ setup_namespaces, test_mount_bind, test_mount_noexec_disallows_exec,
+ test_mount_rdonly_disallows_write,
+ test_mount_tmpfs_without_flags_allows_rwx,
+ };
skip_if_cirrus!("Fails for an unknown reason Cirrus CI. Bug #1351");
setup_namespaces();
- run_tests!(test_mount_tmpfs_without_flags_allows_rwx,
- test_mount_rdonly_disallows_write,
- test_mount_noexec_disallows_exec,
- test_mount_bind);
+ run_tests!(
+ test_mount_tmpfs_without_flags_allows_rwx,
+ test_mount_rdonly_disallows_write,
+ test_mount_noexec_disallows_exec,
+ test_mount_bind
+ );
}
#[cfg(not(target_os = "linux"))]