Skip to content

Commit

Permalink
add rrw recursive mount test
Browse files Browse the repository at this point in the history
Signed-off-by: lengrongfu <1275177125@qq.com>
  • Loading branch information
lengrongfu committed Mar 3, 2023
1 parent 60f0a25 commit 1f9e29d
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,47 @@ fn check_recursive_noexec() -> TestResult {
result
}

fn check_recursive_readwrite() -> TestResult {
let rrw_test_base_dir = PathBuf::from_str("/tmp").unwrap();
let rrw_dir_path = rrw_test_base_dir.join("rrw_dir");
let rrw_subdir_path = rrw_dir_path.join("rrw_subdir");
let mount_dest_path = PathBuf::from_str("/rrw").unwrap();

let mount_options = vec!["rbind".to_string(), "rrw".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rrw_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
// check /rrw mount can write
vec!["touch".to_string(), "/rrw/a.txt".to_string()],
);

let result = test_inside_container(spec, &|_| {
setup_mount(&rrw_dir_path, &rrw_subdir_path);
Ok(())
});

clean_mount(&rrw_dir_path, &rrw_subdir_path);

result
}

pub fn get_mounts_recursive_test() -> TestGroup {
let rro_test = Test::new("rro_test", Box::new(check_recursive_readonly));
let rnosuid_test = Test::new("rnosuid_test", Box::new(check_recursive_nosuid));
let rnoexec_test = Test::new("rnoexec_test", Box::new(check_recursive_noexec));
let rrw_test = Test::new("rrw_test", Box::new(check_recursive_readwrite));

let mut tg = TestGroup::new("mounts_recursive");
tg.add(vec![
Box::new(rro_test),
Box::new(rnosuid_test),
Box::new(rnoexec_test),
Box::new(rrw_test),
]);

tg
Expand Down

0 comments on commit 1f9e29d

Please sign in to comment.