1
0
mirror of https://github.com/containers/youki synced 2024-11-23 09:21:57 +01:00

add rsymfollow recursive mount test (#1967)

Signed-off-by: Adrian Pop <pop.adrian61@gmail.com>
This commit is contained in:
adrianalin 2023-06-07 08:43:35 +03:00 committed by GitHub
parent 93a0afdeb0
commit 67311c81f9
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 0 deletions

@ -565,6 +565,44 @@ fn check_recursive_rnosymfollow() -> TestResult {
result
}
fn check_recursive_rsymfollow() -> TestResult {
let rsymfollow_dir_path = PathBuf::from_str("/tmp/rsymfollow").unwrap();
let mount_dest_path = PathBuf::from_str("/mnt/rsymfollow").unwrap();
fs::create_dir_all(rsymfollow_dir_path.clone()).unwrap();
let mount_options = vec![
"rbind".to_string(),
"rsymfollow".to_string(),
"rsuid".to_string(),
];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rsymfollow_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
vec!["runtimetest".to_string(), "mounts_recursive".to_string()],
);
let result = test_inside_container(spec, &|_| {
let original_file_path = format!("{}/{}", rsymfollow_dir_path.to_str().unwrap(), "file");
let file = File::create(&original_file_path)?;
let link_file_path = format!("{}/{}", rsymfollow_dir_path.to_str().unwrap(), "link");
let mut permission = file.metadata()?.permissions();
permission.set_mode(permission.mode() | libc::S_ISUID | libc::S_ISGID);
file.set_permissions(permission)
.with_context(|| "failed to set permission")?;
symlink(original_file_path, link_file_path)?;
println!("symlink success");
Ok(())
});
fs::remove_dir_all(rsymfollow_dir_path).unwrap();
result
}
/// this mount test how to work?
/// 1. Create mount_options based on the mount properties of the test
/// 2. Create OCI.Spec content, container one process is runtimetest,(runtimetest is cargo model, file path `tests/rust-integration-tests/runtimetest/`)
@ -586,6 +624,7 @@ pub fn get_mounts_recursive_test() -> TestGroup {
let rnoatime_test = Test::new("rnoatime_test", Box::new(check_recursive_rnoatime));
let rstrictatime_test = Test::new("rstrictatime_test", Box::new(check_recursive_rstrictatime));
let rnosymfollow_test = Test::new("rnosymfollow_test", Box::new(check_recursive_rnosymfollow));
let rsymfollow_test = Test::new("rsymfollow_test", Box::new(check_recursive_rsymfollow));
let mut tg = TestGroup::new("mounts_recursive");
tg.add(vec![
@ -604,6 +643,7 @@ pub fn get_mounts_recursive_test() -> TestGroup {
Box::new(rnoatime_test),
Box::new(rstrictatime_test),
Box::new(rnosymfollow_test),
Box::new(rsymfollow_test),
]);
tg

@ -240,6 +240,13 @@ pub fn validate_mounts_recursive(spec: &Spec) {
eprintln!("path expected to be rnosymfollow, found not rnosymfollow, error: {e}");
}
}
"rsymfollow" => {
if let Err(e) = utils::test_mount_rsymfollow_option(
mount.destination().to_str().unwrap(),
) {
eprintln!("path expected to be rsymfollow, found not rsymfollow, error: {e}");
}
}
"rsuid" => {
if let Err(e) = utils::test_mount_rsuid_option(
mount.destination().to_str().unwrap(),

@ -426,6 +426,28 @@ pub fn test_mount_rnosymfollow_option(path: &str) -> Result<(), std::io::Error>
}
}
pub fn test_mount_rsymfollow_option(path: &str) -> Result<(), std::io::Error> {
let path = format!("{}/{}", path, "link");
let metadata = match symlink_metadata(path.clone()) {
Ok(metadata) => metadata,
Err(e) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("get file symlink_metadata err {path:?}, {e}"),
));
}
};
// check symbolic is followed
if metadata.file_type().is_symlink() && metadata.mode() & 0o777 == 0o777 {
Ok(())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("get file symlink_metadata err {path:?}"),
))
}
}
pub fn test_mount_rsuid_option(path: &str) -> Result<(), std::io::Error> {
let path = PathBuf::from(path).join("file");