Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rsymfollow recursive mount test #1967

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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/`)
Expand All @@ -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![
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/rust-integration-tests/runtimetest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
22 changes: 22 additions & 0 deletions tests/rust-integration-tests/runtimetest/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down