From 9d8de52aff164af21c5f4f2870451007c3ac03ed Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 15 Jun 2024 10:15:31 +0900 Subject: [PATCH] test: to embed rule information in the binary, the way test arguments are given has been changed. --- src/afterfact.rs | 28 ++++++------- src/detections/configs.rs | 4 +- src/detections/detection.rs | 12 +++--- src/detections/rule/condition_parser.rs | 2 +- src/detections/rule/count.rs | 2 +- src/detections/rule/matchers.rs | 2 +- src/detections/rule/mod.rs | 2 +- src/detections/rule/selectionnodes.rs | 2 +- src/detections/utils.rs | 2 +- src/main.rs | 10 ++--- src/options/htmlreport.rs | 8 ++-- src/options/profile.rs | 6 +-- src/yaml.rs | 52 ++++++++++++------------- 13 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/afterfact.rs b/src/afterfact.rs index 37e6613bd..a1ae98fb3 100644 --- a/src/afterfact.rs +++ b/src/afterfact.rs @@ -2285,7 +2285,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -2378,7 +2378,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -2625,7 +2625,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -2728,7 +2728,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -2959,7 +2959,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -3052,7 +3052,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -3294,7 +3294,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -3387,7 +3387,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -3702,7 +3702,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -3796,7 +3796,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -4056,7 +4056,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -4150,7 +4150,7 @@ mod tests { us_time: false, utc: true, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -4335,7 +4335,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -4429,7 +4429,7 @@ mod tests { us_time: false, utc: true, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/detections/configs.rs b/src/detections/configs.rs index 7fe4a8c20..3eadac370 100644 --- a/src/detections/configs.rs +++ b/src/detections/configs.rs @@ -2796,7 +2796,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -2874,7 +2874,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/detections/detection.rs b/src/detections/detection.rs index 26702aadc..852ba7a7d 100644 --- a/src/detections/detection.rs +++ b/src/detections/detection.rs @@ -1249,7 +1249,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -1302,7 +1302,7 @@ mod tests { let cole = Detection::parse_rule_files( level, "", - opt_rule_path, + Some(opt_rule_path), &filter::exclude_ids(&dummy_stored_static), &dummy_stored_static, ); @@ -1511,7 +1511,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -1650,7 +1650,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -1784,7 +1784,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -1934,7 +1934,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { diff --git a/src/detections/rule/condition_parser.rs b/src/detections/rule/condition_parser.rs index b9ba3d9c7..067393cc0 100644 --- a/src/detections/rule/condition_parser.rs +++ b/src/detections/rule/condition_parser.rs @@ -475,7 +475,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/detections/rule/count.rs b/src/detections/rule/count.rs index 397002514..2e8bbfc1c 100644 --- a/src/detections/rule/count.rs +++ b/src/detections/rule/count.rs @@ -624,7 +624,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/detections/rule/matchers.rs b/src/detections/rule/matchers.rs index ceb3e0ce6..9b932a986 100644 --- a/src/detections/rule/matchers.rs +++ b/src/detections/rule/matchers.rs @@ -887,7 +887,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/detections/rule/mod.rs b/src/detections/rule/mod.rs index d2951febf..d1bb138ab 100644 --- a/src/detections/rule/mod.rs +++ b/src/detections/rule/mod.rs @@ -448,7 +448,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/detections/rule/selectionnodes.rs b/src/detections/rule/selectionnodes.rs index 2e10e2496..41f4b62e6 100644 --- a/src/detections/rule/selectionnodes.rs +++ b/src/detections/rule/selectionnodes.rs @@ -543,7 +543,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/detections/utils.rs b/src/detections/utils.rs index 1f86ca563..442a38681 100644 --- a/src/detections/utils.rs +++ b/src/detections/utils.rs @@ -1078,7 +1078,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: Some(Path::new("dummy.html").to_path_buf()), no_summary: false, common_options: CommonOptions { diff --git a/src/main.rs b/src/main.rs index 48f61f429..329a505ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2385,7 +2385,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -2559,7 +2559,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./test_files/rules/yaml/test_json_detect.yml").to_path_buf(), + rules: Some(Path::new("./test_files/rules/yaml/test_json_detect.yml").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -2647,7 +2647,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("test_files/rules/yaml/test_json_detect.yml").to_path_buf(), + rules: Some(Path::new("test_files/rules/yaml/test_json_detect.yml").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -2734,7 +2734,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./test_files/rules/yaml/test_json_detect.yml").to_path_buf(), + rules: Some(Path::new("./test_files/rules/yaml/test_json_detect.yml").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { @@ -2822,7 +2822,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("test_files/rules/yaml/test_json_detect.yml").to_path_buf(), + rules: Some(Path::new("test_files/rules/yaml/test_json_detect.yml").to_path_buf()), html_report: None, no_summary: true, common_options: CommonOptions { diff --git a/src/options/htmlreport.rs b/src/options/htmlreport.rs index dec5fbc62..eae12251b 100644 --- a/src/options/htmlreport.rs +++ b/src/options/htmlreport.rs @@ -276,7 +276,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: Some(Path::new("./dummy").to_path_buf()), no_summary: false, common_options: CommonOptions { @@ -346,7 +346,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -419,7 +419,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: Some(Path::new("./dummy").to_path_buf()), no_summary: false, common_options: CommonOptions { @@ -489,7 +489,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/options/profile.rs b/src/options/profile.rs index 2375d8b8b..b7645f187 100644 --- a/src/options/profile.rs +++ b/src/options/profile.rs @@ -504,7 +504,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -585,7 +585,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -696,7 +696,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { diff --git a/src/yaml.rs b/src/yaml.rs index 5fb410858..93a6ba01f 100644 --- a/src/yaml.rs +++ b/src/yaml.rs @@ -812,7 +812,7 @@ mod tests { us_time: false, utc: false, visualize_timeline: false, - rules: Path::new("./rules").to_path_buf(), + rules: Some(Path::new("./rules").to_path_buf()), html_report: None, no_summary: false, common_options: CommonOptions { @@ -863,7 +863,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); let _ = &yaml.read_dir( - "test_files/rules/yaml/1.yml", + &Some("test_files/rules/yaml/1.yml"), &String::default(), "", &exclude_ids, @@ -880,7 +880,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); let _ = &yaml.read_dir( - "test_files/rules/yaml/", + &Some("test_files/rules/yaml/"), &String::default(), "", &exclude_ids, @@ -920,7 +920,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -936,7 +936,7 @@ mod tests { let path = Path::new("test_files/rules/level_yaml"); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "INFORMATIONAL", "", &filter::exclude_ids(&dummy_stored_static), @@ -951,7 +951,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "LOW", "", &filter::exclude_ids(&dummy_stored_static), @@ -966,7 +966,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "MEDIUM", "", &filter::exclude_ids(&dummy_stored_static), @@ -981,7 +981,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "HIGH", "", &filter::exclude_ids(&dummy_stored_static), @@ -996,7 +996,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "CRITICAL", "", &filter::exclude_ids(&dummy_stored_static), @@ -1011,7 +1011,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1026,7 +1026,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1042,7 +1042,7 @@ mod tests { dummy_stored_static.include_status = HashSet::from_iter(vec![CompactString::from("*")]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); let exclude_ids = RuleExclude::new(); - yaml.read_dir(path, "", "", &exclude_ids, &dummy_stored_static) + yaml.read_dir(&Some(path), "", "", &exclude_ids, &dummy_stored_static) .unwrap(); assert_eq!(yaml.rule_load_cnt.get("excluded").unwrap().to_owned(), 0); } @@ -1053,7 +1053,7 @@ mod tests { dummy_stored_static.include_status = HashSet::from_iter(vec![CompactString::from("*")]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); let exclude_ids = RuleExclude::new(); - yaml.read_dir(path, "", "", &exclude_ids, &dummy_stored_static) + yaml.read_dir(&Some(path), "", "", &exclude_ids, &dummy_stored_static) .unwrap(); assert_eq!( yaml.rule_status_cnt.get("deprecated").unwrap().to_owned(), @@ -1068,7 +1068,7 @@ mod tests { dummy_stored_static.include_status = HashSet::from_iter(vec![CompactString::from("*")]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); let exclude_ids = RuleExclude::new(); - yaml.read_dir(path, "", "", &exclude_ids, &dummy_stored_static) + yaml.read_dir(&Some(path), "", "", &exclude_ids, &dummy_stored_static) .unwrap(); assert_eq!( yaml.rule_status_cnt.get("unsupported").unwrap().to_owned(), @@ -1082,7 +1082,7 @@ mod tests { let path = Path::new("test_files/rules/level_yaml"); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "INFORMATIONAL", &filter::exclude_ids(&dummy_stored_static), @@ -1098,7 +1098,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "LOW", &filter::exclude_ids(&dummy_stored_static), @@ -1114,7 +1114,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "MEDIUM", &filter::exclude_ids(&dummy_stored_static), @@ -1130,7 +1130,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "HIGH", &filter::exclude_ids(&dummy_stored_static), @@ -1146,7 +1146,7 @@ mod tests { let dummy_stored_static = create_dummy_stored_static(); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "CRITICAL", &filter::exclude_ids(&dummy_stored_static), @@ -1167,7 +1167,7 @@ mod tests { .include_tag = Some(vec!["tag1".to_string(), "tag2".to_string()]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1188,7 +1188,7 @@ mod tests { .include_category = Some(vec!["test_category1".to_string()]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1212,7 +1212,7 @@ mod tests { ]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1233,7 +1233,7 @@ mod tests { .include_category = Some(vec!["not found".to_string()]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1254,7 +1254,7 @@ mod tests { .exclude_category = Some(vec!["test_category1".to_string()]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1278,7 +1278,7 @@ mod tests { ]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static), @@ -1299,7 +1299,7 @@ mod tests { .exclude_category = Some(vec!["not found".to_string()]); let mut yaml = yaml::ParseYaml::new(&dummy_stored_static); yaml.read_dir( - path, + &Some(path), "", "", &filter::exclude_ids(&dummy_stored_static),