From 74bcd510c4588bb8bcf0440cbcc9108a161f07d1 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Thu, 10 Sep 2020 12:00:50 -0500 Subject: [PATCH] agent/rustjail: add unit tests for ms_move_rootfs and mask_path Increase code coverage of mount.rs Signed-off-by: Julio Montes --- src/agent/rustjail/src/mount.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/agent/rustjail/src/mount.rs b/src/agent/rustjail/src/mount.rs index c8237ad8ed..af45903df9 100644 --- a/src/agent/rustjail/src/mount.rs +++ b/src/agent/rustjail/src/mount.rs @@ -1031,4 +1031,37 @@ mod tests { let ret = pivot_rootfs("/tmp"); assert!(ret.is_ok(), "Should pass. Got: {:?}", ret); } + + #[test] + fn test_ms_move_rootfs() { + let ret = ms_move_root("/abc"); + assert!( + ret.is_err(), + "Should fail. path doesn't exist. Got: {:?}", + ret + ); + + let ret = ms_move_root("/tmp"); + assert!(ret.is_ok(), "Should pass. Got: {:?}", ret); + } + + #[test] + fn test_mask_path() { + let ret = mask_path("abc"); + assert!( + ret.is_err(), + "Should fail: path doesn't start with '/'. Got: {:?}", + ret + ); + + let ret = mask_path("abc/../"); + assert!( + ret.is_err(), + "Should fail: path contains '..'. Got: {:?}", + ret + ); + + let ret = mask_path("/tmp"); + assert!(ret.is_ok(), "Should pass. Got: {:?}", ret); + } }