Some checks failed
rust-ci / checks (push) Has been cancelled
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI) - Sim: fix false Delivered after a route cut, derive traffic class from payload size, per-link airtime slots (link capacity, queueing) - Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers, drop unimplemented seed claims, uncheck store-and-forward - License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
use icenet_core::{NodeId, ServiceId};
|
|
use icenet_guard::{Context, Guard, Limits, Verdict};
|
|
|
|
fn limits(window: u64) -> Limits {
|
|
Limits {
|
|
replay_window: window,
|
|
rate_per_second: 0,
|
|
..Limits::default()
|
|
}
|
|
}
|
|
|
|
fn context(peer: u64, sequence: u64) -> Context {
|
|
Context {
|
|
authenticated: true,
|
|
peer: NodeId(peer),
|
|
service: ServiceId(7),
|
|
payload_bytes: 1,
|
|
sequence,
|
|
now_ms: 0,
|
|
queue_depth: 0,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn duplicate_sequence_is_denied() {
|
|
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
|
assert_eq!(guard.check(context(1, 1)), Verdict::Permit);
|
|
assert_eq!(guard.check(context(1, 1)), Verdict::Deny("replay"));
|
|
}
|
|
|
|
#[test]
|
|
fn sequence_below_the_window_is_denied() {
|
|
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
|
assert_eq!(guard.check(context(1, 10)), Verdict::Permit);
|
|
assert_eq!(guard.check(context(1, 6)), Verdict::Deny("replay"));
|
|
assert_eq!(guard.check(context(1, 7)), Verdict::Permit);
|
|
}
|
|
|
|
#[test]
|
|
fn higher_sequence_advances_and_prunes_the_window() {
|
|
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
|
assert_eq!(guard.check(context(1, 4)), Verdict::Permit);
|
|
assert_eq!(guard.check(context(1, 5)), Verdict::Permit);
|
|
assert_eq!(guard.check(context(1, 1)), Verdict::Deny("replay"));
|
|
assert_eq!(guard.check(context(1, 2)), Verdict::Permit);
|
|
}
|
|
|
|
#[test]
|
|
fn replay_state_is_per_peer() {
|
|
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
|
assert_eq!(guard.check(context(1, 5)), Verdict::Permit);
|
|
assert_eq!(guard.check(context(2, 5)), Verdict::Permit);
|
|
assert_eq!(guard.check(context(2, 5)), Verdict::Deny("replay"));
|
|
}
|