Skip to content

Commit 2bcc30e

Browse files
committed
test(proxy): verify L4 deny enqueues a DenialEvent
Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
1 parent f128aab commit 2bcc30e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

crates/openshell-sandbox/src/proxy.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6443,4 +6443,28 @@ network_policies:
64436443
}
64446444
}
64456445
}
6446+
6447+
#[test]
6448+
fn test_emit_denial_enqueues_denial_event() {
6449+
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<crate::denial_aggregator::DenialEvent>();
6450+
let decision = ConnectDecision {
6451+
action: NetworkAction::Deny { reason: "no matching policy".into() },
6452+
generation: 0,
6453+
binary: Some(std::path::PathBuf::from("/usr/bin/curl")),
6454+
binary_pid: Some(1234),
6455+
ancestors: vec![],
6456+
cmdline_paths: vec![],
6457+
};
6458+
6459+
emit_denial(&Some(tx), "blocked.invalid", 443, "/usr/bin/curl", &decision, "no matching policy", "connect");
6460+
6461+
let event = rx.try_recv().expect("DenialEvent should be enqueued after L4 deny");
6462+
assert_eq!(event.host, "blocked.invalid");
6463+
assert_eq!(event.port, 443);
6464+
assert_eq!(event.binary, "/usr/bin/curl");
6465+
assert_eq!(event.denial_stage, "connect");
6466+
assert_eq!(event.deny_reason, "no matching policy");
6467+
assert!(event.l7_method.is_none());
6468+
assert!(event.l7_path.is_none());
6469+
}
64466470
}

0 commit comments

Comments
 (0)