use crate::report::Severity;
pub fn privileged_group_severity(group_name: &str) -> Severity {
if group_name.contains("Domain Admins") || group_name.contains("Enterprise Admins") {
Severity::Info } else {
Severity::High }
}
pub fn password_policy_severity(min_len: u32, lockout_threshold: u32) -> Severity {
if min_len < 8 || lockout_threshold == 0 {
Severity::Medium } else {
Severity::Info }
}
pub fn password_age_severity(age_days: i64) -> Severity {
if age_days > 365 {
Severity::Medium } else if age_days > 180 {
Severity::Low } else {
Severity::Info }
}
pub fn encryption_type_severity(has_aes: bool, rc4_only: bool) -> Severity {
if rc4_only {
Severity::Medium } else if has_aes {
Severity::Low } else {
Severity::High }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_privileged_group_domain_admins() {
let severity = privileged_group_severity("CN=Domain Admins,OU=Groups,DC=corp,DC=local");
assert_eq!(severity, Severity::Info, "Domain Admins should be Info (expected)");
}
#[test]
fn test_privileged_group_enterprise_admins() {
let severity = privileged_group_severity("Enterprise Admins");
assert_eq!(severity, Severity::Info, "Enterprise Admins should be Info (expected)");
}
#[test]
fn test_privileged_group_backup_operators() {
let severity = privileged_group_severity("Backup Operators");
assert_eq!(severity, Severity::High, "Backup Operators should be High (unexpected)");
}
#[test]
fn test_privileged_group_account_operators() {
let severity = privileged_group_severity("Account Operators");
assert_eq!(severity, Severity::High, "Account Operators should be High");
}
#[test]
fn test_privileged_group_print_operators() {
let severity = privileged_group_severity("Print Operators");
assert_eq!(severity, Severity::High, "Print Operators should be High");
}
#[test]
fn test_password_policy_weak_length() {
let severity = password_policy_severity(7, 5);
assert_eq!(severity, Severity::Medium, "Short password should be Medium");
}
#[test]
fn test_password_policy_weak_no_lockout() {
let severity = password_policy_severity(14, 0);
assert_eq!(severity, Severity::Medium, "No lockout should be Medium");
}
#[test]
fn test_password_policy_adequate() {
let severity = password_policy_severity(8, 5);
assert_eq!(severity, Severity::Info, "Adequate policy should be Info");
}
#[test]
fn test_password_policy_strong() {
let severity = password_policy_severity(14, 10);
assert_eq!(severity, Severity::Info, "Strong policy should be Info");
}
#[test]
fn test_password_age_very_stale() {
let severity = password_age_severity(400);
assert_eq!(severity, Severity::Medium, "Very stale password should be Medium");
}
#[test]
fn test_password_age_somewhat_stale() {
let severity = password_age_severity(270);
assert_eq!(severity, Severity::Low, "Somewhat aged password should be Low");
}
#[test]
fn test_password_age_recent() {
let severity = password_age_severity(90);
assert_eq!(severity, Severity::Info, "Recent password should be Info");
}
#[test]
fn test_password_age_boundaries() {
let age_180 = password_age_severity(180);
let age_181 = password_age_severity(181);
let age_365 = password_age_severity(365);
let age_366 = password_age_severity(366);
assert_eq!(age_180, Severity::Info, "180 days should be Info (not > 180)");
assert_eq!(age_181, Severity::Low, "181 days should be Low (> 180)");
assert_eq!(age_365, Severity::Low, "365 days should be Low (not > 365)");
assert_eq!(age_366, Severity::Medium, "366 days should be Medium (> 365)");
}
#[test]
fn test_encryption_type_rc4_only() {
let severity = encryption_type_severity(false, true);
assert_eq!(severity, Severity::Medium, "RC4-only should be Medium");
}
#[test]
fn test_encryption_type_with_aes() {
let severity = encryption_type_severity(true, false);
assert_eq!(severity, Severity::Low, "With AES should be Low");
}
#[test]
fn test_encryption_type_no_supported() {
let severity = encryption_type_severity(false, false);
assert_eq!(severity, Severity::High, "No supported encryption should be High");
}
#[test]
fn test_encryption_type_aes_and_rc4() {
let severity = encryption_type_severity(true, false);
assert_eq!(severity, Severity::Low, "With AES should be Low");
}
#[test]
fn test_severity_comparison_order() {
assert!(Severity::Critical < Severity::High);
assert!(Severity::High < Severity::Medium);
assert!(Severity::Medium < Severity::Low);
assert!(Severity::Low < Severity::Info);
}
}