Skip to content

Commit 9507f43

Browse files
committed
lib/config/base.rs: Add more unit tests
Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent 0b0c096 commit 9507f43

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

keylime/src/config/base.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,79 @@ mod tests {
865865
assert!(result.is_ok());
866866
}
867867

868+
#[test]
869+
fn test_invalid_revocation_actions_dir() {
870+
let test_config = KeylimeConfig {
871+
agent: AgentConfig {
872+
enable_revocation_notifications: true,
873+
revocation_actions_dir: "/invalid".to_string(),
874+
..Default::default()
875+
},
876+
};
877+
let result = config_translate_keywords(&test_config);
878+
// Expect error due to the inexistent directory
879+
assert!(result.is_err());
880+
let test_config = KeylimeConfig {
881+
agent: AgentConfig {
882+
enable_revocation_notifications: false,
883+
revocation_actions_dir: "/invalid".to_string(),
884+
..Default::default()
885+
},
886+
};
887+
888+
// Now unset enable_revocation_notifications and check that is allowed
889+
let result = config_translate_keywords(&test_config);
890+
assert!(result.is_ok());
891+
}
892+
893+
#[test]
894+
fn test_keylime_dir_option() {
895+
let dir = tempfile::tempdir()
896+
.expect("Failed to create temporary directory");
897+
let test_config = KeylimeConfig {
898+
agent: AgentConfig {
899+
keylime_dir: dir.path().display().to_string(),
900+
..Default::default()
901+
},
902+
};
903+
904+
let result = config_translate_keywords(&test_config);
905+
assert!(result.is_ok());
906+
}
907+
908+
#[test]
909+
fn test_invalid_api_versions() {
910+
// Check that invalid API versions are ignored
911+
let test_config = KeylimeConfig {
912+
agent: AgentConfig {
913+
api_versions: "invalid.api".to_string(),
914+
..Default::default()
915+
},
916+
};
917+
let result = config_translate_keywords(&test_config);
918+
assert!(result.is_ok());
919+
920+
// Check that unsupported API versions are ignored
921+
let test_config = KeylimeConfig {
922+
agent: AgentConfig {
923+
api_versions: "['0.0']".to_string(),
924+
..Default::default()
925+
},
926+
};
927+
let result = config_translate_keywords(&test_config);
928+
assert!(result.is_ok());
929+
930+
// Check that 'latest' keyword is supported
931+
let test_config = KeylimeConfig {
932+
agent: AgentConfig {
933+
api_versions: "\"latest\"".to_string(),
934+
..Default::default()
935+
},
936+
};
937+
let result = config_translate_keywords(&test_config);
938+
assert!(result.is_ok());
939+
}
940+
868941
#[test]
869942
fn test_translate_api_versions_latest_keyword() {
870943
let test_config = KeylimeConfig {

0 commit comments

Comments
 (0)