Skip to content

Commit

Permalink
Added new utils functions unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okynos committed Feb 16, 2024
1 parent 94b8d03 commit fc71f27
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub fn run_auditctl(args: &[&str]) {
#[cfg(test)]
mod tests {
use super::*;
use crate::config::Config;

#[test]
fn test_pop() {
Expand Down Expand Up @@ -425,4 +426,35 @@ mod tests {
}
}

// ------------------------------------------------------------------------

#[cfg(target_os = "linux")]
#[test]
fn test_get_audit_rule_permissions() {
let config = Config::new(&get_os(), Some("test/unit/config/linux/audit_rule.yml"));
assert_eq!(get_audit_rule_permissions(config.audit[0]["rule"].as_str()), "rwax");
}

// ------------------------------------------------------------------------

#[cfg(target_os = "linux")]
#[test]
fn test_run_auditctl() {
let config = Config::new(&get_os(), Some("test/unit/config/linux/audit_rule.yml"));
let path = config.audit[0]["path"].as_str().unwrap();
let rule = config.audit[0]["rule"].as_str().unwrap();
run_auditctl(&["-w", path, "-k", "fim", "-p", rule]);

match Command::new("/usr/sbin/auditctl")
.args(["-l", "-k", "fim"])
.output()
{
Ok(data) => assert_eq!(String::from_utf8(data.stdout).unwrap(), "-w /tmp -p rwxa -k fim\n"),
Err(e) => {
println!("{:?}", e);
assert!(true)
}
};
}

}
28 changes: 28 additions & 0 deletions test/unit/config/linux/audit_rule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
node: "FIM"

# Events configuration, where to store produced events
events:
destination: file
file: /var/lib/fim/events.json

# Audit extended files and folders information
audit:
- path: /tmp
labels: ["tmp", "linux"]
ignore: [".swp"]
allowed: [".txt", ".rs"]
rule: "rwax"

# Simple files and folders information
monitor:
- path: /bin/
- path: /usr/bin/
labels: ["usr/bin", "linux"]
- path: /etc
labels: ["etc", "linux"]

# App procedure and errors logging
log:
file: /var/log/fim/fim.log
# Available levels [debug, info, error, warning]
level: info

0 comments on commit fc71f27

Please sign in to comment.