From 838a935d34e11bce146cfe8e2054a2998a9168f3 Mon Sep 17 00:00:00 2001 From: kazuminn Date: Thu, 2 Dec 2021 00:33:19 +0900 Subject: [PATCH] pass test --- src/detections/detection.rs | 5 ++++- src/main.rs | 2 +- src/yaml.rs | 34 ++++++++++++++++++---------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/detections/detection.rs b/src/detections/detection.rs index 7e610c42..97ab8a9b 100644 --- a/src/detections/detection.rs +++ b/src/detections/detection.rs @@ -266,6 +266,9 @@ impl Detection { fn test_parse_rule_files() { let level = "INFO"; let opt_rule_path = Some("./test_files/rules/level_yaml"); - let cole = Detection::parse_rule_files(level.to_owned(), opt_rule_path); + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), + }; + let cole = Detection::parse_rule_files(level.to_owned(), opt_rule_path, fill_ids); assert_eq!(5, cole.len()); } diff --git a/src/main.rs b/src/main.rs index 12d4c8a8..075d116e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -134,7 +134,7 @@ fn analysis_files(evtx_files: Vec) { } let mut fill_ids = fillter::RuleFill { - no_use_rule: HashMap::new(), + no_use_rule: HashMap::from([("".to_string(), true)]), }; for v in ids.split_whitespace().next() { diff --git a/src/yaml.rs b/src/yaml.rs index e67ac40b..9d5ece71 100644 --- a/src/yaml.rs +++ b/src/yaml.rs @@ -140,7 +140,7 @@ impl ParseYaml { //除外されたルールは無視する match fill_ids .no_use_rule - .get(&yaml_doc["id"].as_str().unwrap().to_string()) + .get(&yaml_doc["id"].as_str().unwrap_or("").to_string()) { Some(_) => (), None => { @@ -161,16 +161,18 @@ impl ParseYaml { mod tests { use crate::yaml; + use crate::yaml::RuleFill; + use std::collections::HashMap; use std::path::Path; use yaml_rust::YamlLoader; #[test] fn test_read_dir_yaml() { let mut yaml = yaml::ParseYaml::new(); - let mut fill_ids = fillter::RuleFill { - no_use_rule: HashMap::new(), + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), }; - &yaml.read_dir( + let _ = &yaml.read_dir( "test_files/rules/yaml/".to_string(), &"".to_owned(), fill_ids, @@ -209,8 +211,8 @@ mod tests { fn test_default_level_read_yaml() { let mut yaml = yaml::ParseYaml::new(); let path = Path::new("test_files/rules/level_yaml"); - let mut fill_ids = RuleFill { - no_use_rule: HashMap::new(), + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), }; yaml.read_dir(path.to_path_buf(), &"", fill_ids).unwrap(); assert_eq!(yaml.files.len(), 4); @@ -220,8 +222,8 @@ mod tests { fn test_info_level_read_yaml() { let mut yaml = yaml::ParseYaml::new(); let path = Path::new("test_files/rules/level_yaml"); - let mut fill_ids = RuleFill { - no_use_rule: HashMap::new(), + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), }; yaml.read_dir(path.to_path_buf(), &"INFO", fill_ids) .unwrap(); @@ -231,8 +233,8 @@ mod tests { fn test_low_level_read_yaml() { let mut yaml = yaml::ParseYaml::new(); let path = Path::new("test_files/rules/level_yaml"); - let mut fill_ids = RuleFill { - no_use_rule: HashMap::new(), + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), }; yaml.read_dir(path.to_path_buf(), &"LOW", fill_ids).unwrap(); assert_eq!(yaml.files.len(), 4); @@ -241,8 +243,8 @@ mod tests { fn test_medium_level_read_yaml() { let mut yaml = yaml::ParseYaml::new(); let path = Path::new("test_files/rules/level_yaml"); - let mut fill_ids = RuleFill { - no_use_rule: HashMap::new(), + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), }; yaml.read_dir(path.to_path_buf(), &"MEDIUM", fill_ids) .unwrap(); @@ -252,8 +254,8 @@ mod tests { fn test_high_level_read_yaml() { let mut yaml = yaml::ParseYaml::new(); let path = Path::new("test_files/rules/level_yaml"); - let mut fill_ids = RuleFill { - no_use_rule: HashMap::new(), + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), }; yaml.read_dir(path.to_path_buf(), &"HIGH", fill_ids) .unwrap(); @@ -263,8 +265,8 @@ mod tests { fn test_critical_level_read_yaml() { let mut yaml = yaml::ParseYaml::new(); let path = Path::new("test_files/rules/level_yaml"); - let mut fill_ids = RuleFill { - no_use_rule: HashMap::new(), + let fill_ids = RuleFill { + no_use_rule: HashMap::from([("".to_string(), true)]), }; yaml.read_dir(path.to_path_buf(), &"CRITICAL", fill_ids) .unwrap();