fn test_INSTALLER_AUDIT_report_metadata_populated() {
let report = audit_toml(
r#"
[installer]
name = "metadata-test"
version = "2.0.0"
[[artifact]]
id = "artifact-a"
url = "https://example.com/a.tar.gz"
sha256 = "deadbeef"
[[artifact]]
id = "artifact-b"
url = "https://example.com/b.tar.gz"
sha256 = "cafebabe"
[[step]]
id = "step-1"
name = "Step 1"
action = "script"
[step.script]
content = "echo a"
[[step]]
id = "step-2"
name = "Step 2"
action = "script"
[step.script]
content = "echo b"
"#,
);
assert_eq!(report.installer_name, "metadata-test");
assert_eq!(report.installer_version, "2.0.0");
assert_eq!(report.metadata.steps_audited, 2);
assert_eq!(report.metadata.artifacts_audited, 2);
assert!(
!report.metadata.audited_at.is_empty(),
"audited_at should be set"
);
}
#[test]
fn test_INSTALLER_AUDIT_report_json_contains_findings() {
let report = audit_toml(
r#"
[installer]
name = "json-test"
version = "1.0.0"
[installer.security]
require_signatures = false
[[step]]
id = "step-1"
name = "Step 1"
action = "script"
[step.script]
content = "eval $CMD"
"#,
);
let json = report.to_json();
assert!(json.contains("\"installer_name\": \"json-test\""));
assert!(json.contains("\"grade\":"));
assert!(json.contains("\"findings\":"));
assert!(json.contains("SEC001") || json.contains("SEC008"));
}
#[test]
fn test_INSTALLER_AUDIT_report_has_errors_vs_warnings() {
let report = audit_toml(
r#"
[installer]
name = "test"
version = "1.0.0"
description = "has desc"
author = "author"
[installer.security]
require_signatures = false
trust_model = "keyring"
[[step]]
id = "step-1"
name = "Step"
action = "script"
[step.script]
content = "echo hello"
[step.postconditions]
command_succeeds = "true"
[step.timing]
timeout = "30s"
[step.checkpoint]
enabled = true
"#,
);
let has_warnings = report
.findings
.iter()
.any(|f| f.severity == AuditSeverity::Warning);
if has_warnings && !report.has_errors() {
assert!(
!report.has_critical_issues(),
"Should not have critical issues with only warnings"
);
}
}
#[test]
fn test_INSTALLER_AUDIT_herm003_step_without_script_no_crash() {
let report = audit_toml(
r#"
[installer]
name = "test"
version = "1.0.0"
[[step]]
id = "no-script"
name = "No Script Step"
action = "copy"
"#,
);
assert!(
!report.findings.iter().any(|f| f.rule_id == "HERM003"),
"Step without script should not trigger HERM003"
);
}