Skip to content

Commit 8fff5f4

Browse files
ilanhIlan Harel
andauthored
test: add real OpenShell v0.1.7 OCSF 1.8.0 log fixtures (#73)
Closes #70 Rebased onto main after #71 and #72 merged. The golden note now says OpenShell 0.1.7. Adds a log fixture captured from a real OpenShell v0.1.7 sandbox: the playground image and policy, with `ocsf_json_enabled=true`. - `tests/fixtures/logs/ocsf-1.8.0.jsonl`: 17 native OCSF 1.8.0 records (`metadata.version` is `1.8.0` on every line): - 4001 Open, allowed and denied - two 4001 Refuse records with `policy_dns_ineligible` - 4002 L7 allow and deny - one record each of 0 (relay open/close), 4007 (SSH) and 5019 (policy DNS mapped/staged), which `diff-logs` ignores - Scrubbed: - Device hostname → `sandbox`. - Container → `fixture` with an all-zero UUID. - `metadata.uid`, SSH channel ids and DNS mapping ids → fixed fake UUIDs. - Real resolved IPs → 203.0.113.x (TEST-NET-3). - The 198.18.x synthetic IPs, the proxy loopback address and the public test hostnames are unchanged. - Timestamps rebased. - No usernames or tokens. - `tests/fixtures/ocsf-1.8.0-app/`: a minimal annotated app that matches the captured run. - `tests/cli.rs` `diff_logs_reads_openshell_0_1_7_ocsf_1_8_0_records`: - Checks `10 events: 3 denied, 7 allowed`. - Expects `missing_egress` for example.com (curl) and pypi.org (python3.12), and `l7_allow` for httpbin.org POST /post. - Expects no `manual` items. - Adds the plain human golden `tests/golden/diff_logs_ocsf_1_8_0_plain.txt`. Filesystem denials (two in the run) were not logged at all, which matches NVIDIA/OpenShell#4270 (still open). Ran locally: fmt, clippy `-D warnings`, `cargo test --locked`, `--test gateway_policies` and `gen-docs.sh --check` all pass. Signed-off-by: Ilan Harel <[email protected]> Co-authored-by: Ilan Harel <[email protected]>
1 parent 5a1ec7c commit 8fff5f4

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)