From c419445ea337c5e9f082e6a48f4e28e8e0c1d60d Mon Sep 17 00:00:00 2001 From: Patrik Koncity Date: Mon, 22 May 2023 12:52:07 +0200 Subject: [PATCH] IGNORE: Improving upstream rust code coverage --- keylime-agent/src/secure_mount.rs | 91 +++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/keylime-agent/src/secure_mount.rs b/keylime-agent/src/secure_mount.rs index d4668a899..48f33fa9b 100644 --- a/keylime-agent/src/secure_mount.rs +++ b/keylime-agent/src/secure_mount.rs @@ -161,13 +161,104 @@ pub(crate) fn mount(work_dir: &Path, secure_size: &str) -> Result { 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(); + } + } + +