Skip to content

Commit

Permalink
IGNORE: Improving upstream rust code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Koncpa committed May 25, 2023
1 parent 4c8d575 commit c419445
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions keylime-agent/src/secure_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,104 @@ pub(crate) fn mount(work_dir: &Path, secure_size: &str) -> Result<PathBuf> {
mod tests {
use super::*;

#[test]
fn test_dir_not_mounted(){
let path = "/var/lib/keylime";
let work_dir= Path::new(&path);
let secure_dir_path = Path::new(work_dir).join("secure");
let secure_size = "1m";
assert!(check_mount(&secure_dir_path).is_ok());
}

#[test]
fn test_secure_mount() {
let path = "/var/lib/keylime";
let work_dir = Path::new(&path);
let secure_dir_path = Path::new(work_dir).join("secure");
//Command::new("/usr/bin/umount")
//.arg(secure_dir_path.to_str().unwrap())
//.output();
let secure_size = "1m";
let test_mount = mount(&secure_dir_path, secure_size);
assert!(check_mount(&secure_dir_path).is_ok());
/*
//debug
let cat_cmd = Command::new("cat")
.arg("/proc/mounts")
.output();
//println!("{:?}", cat_cmd);
//assert
//debug
*/
match check_mount(&secure_dir_path) {
Err(_) => println!("Got error"),
Ok(true) => println!("Got value TRUE"),
Ok(false) => println!("Got value FALSE"),
}
}

#[test]
fn test_mount_wrong_fs(){
Command::new("systemctl")
.arg("stop")
.arg("var-lib-keylime-secure.mount")
.output();
Command::new("systemctl")
.arg("stop")
.arg("keylime_agent")
.output();
Command::new("sed")
.arg("-i")
.arg("'5,6d'")
.arg("/usr/lib/systemd/system/keylime_agent.service")
.output();
Command::new("systemctl")
.arg("daemon-reload")
.output();
Command::new("systemctl")
.arg("restart")
.arg("keylime_agent")
.output();
let path = "/var/lib/keylime";
let work_dir= Path::new(&path);
let secure_dir_path = Path::new(work_dir).join("secure");
Command::new("/usr/bin/umount")
.arg(secure_dir_path.to_str().unwrap())
.output();
let secure_size = "1m";
//mount with wrong fs
let mount_cmd=Command::new("/usr/bin/mount")
.args([
"-t",
"ramfs",
"-o",
format!("size={secure_size},mode=0700").as_str(),
"ramfs",
secure_dir_path.to_str().unwrap(),
])
.output();
/*
//debugging
println!("{:?}", mount_cmd);
let cat_cmd = Command::new("cat")
.arg("/proc/mounts")
.output();
//println!("{:?}", cat_cmd);
//debug
*/
let test_mount = mount(&secure_dir_path, secure_size);
assert!(check_mount(&secure_dir_path).is_err());
match check_mount(&secure_dir_path) {
Err(_) => println!("Got error"),
Ok(true) => println!("Got value TRUE"),
Ok(false) => println!("Got value FALSE"),
}
Command::new("/usr/bin/umount")
.arg(secure_dir_path.to_str().unwrap())
.output();
}

}


0 comments on commit c419445

Please sign in to comment.