test: move the last inline test modules to tests/, document new signals
- All remaining #[cfg(test)] modules left src/ (manager auth/heartbeat, protocol registry and HTTP parser, traffic hook/prefix/profile, TUI Prometheus); 41 tests moved into 10 integration suites with the same names and assertions, so `grep -rn '#[cfg(test)]' src/` is now empty. - runbook.md: degradation signals (overloaded connections, ClickHouse drops, XDP drops, generic mode, EMFILE backoff) and how to verify XDP was detached. - troubleshooting.md: accept backoff, orphaned XDP, password/JWT startup requirements, ClickHouse event loss. - TODO: review round recorded as fixed/deferred.
This commit is contained in:
parent
e456cb583f
commit
da87d2a11f
21 changed files with 600 additions and 521 deletions
58
tests/traffic_profile_alert.rs
Normal file
58
tests/traffic_profile_alert.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
//! Alert formatting and the deduplicating dispatcher: alerts fire only on the
|
||||
//! detector's attack-boundary transitions, never on every tick.
|
||||
|
||||
use rampart::traffic::alert::{Alert, AlertDispatcher, AlertLevel};
|
||||
use rampart::traffic::detector::AttackStatus;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[test]
|
||||
fn test_alert_display_with_ip() {
|
||||
let alert = Alert::new(
|
||||
AlertLevel::Critical,
|
||||
"possible attack".into(),
|
||||
Some(Ipv4Addr::new(192, 168, 1, 1)),
|
||||
100500.0,
|
||||
);
|
||||
let s = alert.to_string();
|
||||
assert!(s.contains("CRITICAL"));
|
||||
assert!(s.contains("192.168.1.1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alert_display_without_ip() {
|
||||
let alert = Alert::new(AlertLevel::Info, "traffic spike".into(), None, 5000.0);
|
||||
let s = alert.to_string();
|
||||
assert!(s.contains("INFO"));
|
||||
assert!(s.contains("traffic spike"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dispatcher_two_transitions_two_alerts() {
|
||||
let dispatcher = AlertDispatcher::new();
|
||||
assert_eq!(dispatcher.on_status(AttackStatus::Normal), None);
|
||||
assert_eq!(dispatcher.on_status(AttackStatus::Suspicious), None);
|
||||
let started = dispatcher.on_status(AttackStatus::UnderAttack);
|
||||
assert_eq!(dispatcher.on_status(AttackStatus::UnderAttack), None);
|
||||
assert_eq!(dispatcher.on_status(AttackStatus::UnderAttack), None);
|
||||
let ended = dispatcher.on_status(AttackStatus::Normal);
|
||||
assert_eq!(dispatcher.on_status(AttackStatus::Normal), None);
|
||||
assert!(started.is_some());
|
||||
assert!(ended.is_some());
|
||||
assert!(
|
||||
started.expect("started alert").message.contains("attack started")
|
||||
&& ended.expect("ended alert").message.contains("attack ended")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dispatcher_suspicious_does_not_flap_alerts() {
|
||||
let dispatcher = AlertDispatcher::new();
|
||||
for status in [
|
||||
AttackStatus::Normal,
|
||||
AttackStatus::Suspicious,
|
||||
AttackStatus::Normal,
|
||||
AttackStatus::Suspicious,
|
||||
] {
|
||||
assert_eq!(dispatcher.on_status(status), None);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue