Skip to content

Commit ec1597d

Browse files
Ilan HarelIlan Harel
authored andcommitted
test: add real OpenShell v0.1.7 OCSF 1.8.0 log fixtures
tests/fixtures/logs/ocsf-1.8.0.jsonl holds 17 supervisor records captured from an OpenShell v0.1.7 sandbox: classes 0, 4001 (Open allowed/denied and two policy-DNS Refuse records), 4002 (L7 allow/deny), 4007 and 5019. Device, container and record identifiers are scrubbed, and real resolved IPs are replaced with 203.0.113.x. tests/fixtures/ocsf-1.8.0-app mirrors the annotated app the records came from. The new CLI test checks the JSON counts and suggestions and adds a plain human golden. Closes #70 Signed-off-by: Ilan Harel <[email protected]>
1 parent 5a1ec7c commit ec1597d

5 files changed

Lines changed: 148 additions & 0 deletions

File tree

‎tests/cli.rs‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,3 +2152,57 @@ fn committed_policy(example: &Path) -> String {
21522152
.unwrap()
21532153
.replace("@VERSION@", env!("CARGO_PKG_VERSION"))
21542154
}
2155+
2156+
/// Real OpenShell v0.1.7 supervisor records (native OCSF 1.8.0, scrubbed), checked against the app they came from.
2157+
/// The two policy-DNS "Refuse" records (activity 5) are skipped (#69), so JSON gives the same result as shorthand.
2158+
#[test]
2159+
fn diff_logs_reads_openshell_0_1_7_ocsf_1_8_0_records() {
2160+
let t = tempfile::tempdir().unwrap();
2161+
copy_dir(
2162+
&Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/ocsf-1.8.0-app"),
2163+
t.path(),
2164+
);
2165+
std::fs::copy(
2166+
logs_fixture("ocsf-1.8.0.jsonl"),
2167+
t.path().join("ocsf.jsonl"),
2168+
)
2169+
.unwrap();
2170+
let text = std::fs::read_to_string(logs_fixture("ocsf-1.8.0.jsonl")).unwrap();
2171+
assert!(text
2172+
.lines()
2173+
.all(|l| l.contains("\"metadata\":{\"version\":\"1.8.0\"")));
2174+
2175+
let o = run(t.path(), &["diff-logs", "ocsf.jsonl", "--json"]);
2176+
assert_eq!(o.status.code(), Some(1), "{}", err(&o));
2177+
let v: serde_json::Value = serde_json::from_str(&out(&o)).unwrap();
2178+
assert_eq!(
2179+
(
2180+
v["events"].as_u64(),
2181+
v["denied"].as_u64(),
2182+
v["allowed"].as_u64()
2183+
),
2184+
(Some(10), Some(3), Some(7))
2185+
);
2186+
let k = kinds(&v);
2187+
for want in [
2188+
("missing_egress", "example.com", "/usr/bin/curl"),
2189+
("missing_egress", "pypi.org", "/usr/local/bin/python3.12"),
2190+
("l7_allow", "httpbin.org", ""),
2191+
] {
2192+
assert!(
2193+
k.iter()
2194+
.any(|(a, b, c)| (a.as_str(), b.as_str()) == (want.0, want.1)
2195+
&& (want.2.is_empty() || c == want.2)),
2196+
"{want:?} not in {k:?}"
2197+
);
2198+
}
2199+
assert!(!k.iter().any(|(a, _, _)| a == "manual"), "{k:?}");
2200+
2201+
let o = run_env(
2202+
t.path(),
2203+
&["diff-logs", "ocsf.jsonl", "--color", "never", "--no-icons"],
2204+
&[],
2205+
);
2206+
assert_eq!(o.status.code(), Some(1), "{}", err(&o));
2207+
golden("diff_logs_ocsf_1_8_0_plain.txt", &out(&o));
2208+
}

0 commit comments

Comments
 (0)