@@ -3,7 +3,6 @@ extern crate csv;
|
||||
extern crate regex;
|
||||
|
||||
use crate::detections::configs;
|
||||
use crate::filter::DataFilterRule;
|
||||
|
||||
use tokio::runtime::Builder;
|
||||
use tokio::runtime::Runtime;
|
||||
@@ -40,26 +39,6 @@ pub fn check_regex(string: &str, regex_list: &[Regex]) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// replace string from all defined regex in input to replace_str
|
||||
pub fn replace_target_character<'a>(
|
||||
input_str: Option<&'a String>,
|
||||
replace_rule: Option<&'a DataFilterRule>,
|
||||
) -> Option<String> {
|
||||
input_str?;
|
||||
if replace_rule.is_none() {
|
||||
return Some(input_str.unwrap().to_string());
|
||||
}
|
||||
|
||||
let replace_regex_rule = &replace_rule.unwrap().regex_rule;
|
||||
let replace_str = &replace_rule.unwrap().replace_str;
|
||||
|
||||
Some(
|
||||
replace_regex_rule
|
||||
.replace_all(input_str.unwrap(), replace_str)
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn check_allowlist(target: &str, regexes: &[Regex]) -> bool {
|
||||
for regex in regexes {
|
||||
if regex.is_match(target) {
|
||||
@@ -247,7 +226,7 @@ pub fn create_rec_info(data: Value, path: String, keys: &[String]) -> EvtxRecord
|
||||
continue;
|
||||
}
|
||||
|
||||
rec.key_2_value.insert(key.to_string(), val.unwrap());
|
||||
rec.key_2_value.insert(key.trim().to_string(), val.unwrap());
|
||||
}
|
||||
|
||||
rec
|
||||
@@ -256,7 +235,6 @@ pub fn create_rec_info(data: Value, path: String, keys: &[String]) -> EvtxRecord
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::detections::utils;
|
||||
use crate::filter::DataFilterRule;
|
||||
use regex::Regex;
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -347,25 +325,4 @@ mod tests {
|
||||
|
||||
assert!(utils::get_serde_number_to_string(&event_record["Event"]["EventData"]).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// 指定された文字から指定されたregexぉ実行する関数が動作するかのテスト
|
||||
fn test_remove_space_control() {
|
||||
let test_filter_rule = DataFilterRule {
|
||||
regex_rule: Regex::new(r"[\r\n\t]+").unwrap(),
|
||||
replace_str: "".to_string(),
|
||||
};
|
||||
let none_test_str: Option<&String> = None;
|
||||
|
||||
assert!(utils::replace_target_character(none_test_str, None).is_none());
|
||||
|
||||
assert!(utils::replace_target_character(none_test_str, Some(&test_filter_rule)).is_none());
|
||||
|
||||
let tmp = "h\ra\ny\ta\tb\nu\r\nsa".to_string();
|
||||
let test_str: Option<&String> = Some(&tmp);
|
||||
assert_eq!(
|
||||
utils::replace_target_character(test_str, Some(&test_filter_rule)).unwrap(),
|
||||
"hayabusa"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user