feat: incoming rate limit, identity backup, v0.2.0
All checks were successful
ci / test (push) Successful in 4m11s
All checks were successful
ci / test (push) Successful in 4m11s
App-level token bucket on rend accepts (30/60s, burst 10), panic-safe TUI restore, sqlite WAL + integrity_check fail-closed. Encrypted owbak1 identity backup/restore. README and threat model cover profile, XMR sidecar, backup, mixed-version frames.
This commit is contained in:
parent
1a9b54d138
commit
e63203ff56
14 changed files with 809 additions and 26 deletions
28
tests/ratelimit.rs
Normal file
28
tests/ratelimit.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
//! Incoming rend accepts: 30 / 60s, burst 10.
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use onionwire::ratelimit::TokenBucket;
|
||||
|
||||
#[test]
|
||||
fn burst_allows_then_denies() {
|
||||
let t0 = Instant::now();
|
||||
let mut b = TokenBucket::new(30, Duration::from_secs(60), 10);
|
||||
for _ in 0..10 {
|
||||
assert!(b.try_acquire_at(t0), "burst of 10 must pass");
|
||||
}
|
||||
assert!(!b.try_acquire_at(t0), "11th in the burst must drop");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refill_one_token_after_two_seconds() {
|
||||
let t0 = Instant::now();
|
||||
let mut b = TokenBucket::new(30, Duration::from_secs(60), 10);
|
||||
for _ in 0..10 {
|
||||
assert!(b.try_acquire_at(t0));
|
||||
}
|
||||
// 30 tokens / 60s = 0.5/s → 2s yields one token.
|
||||
let t1 = t0 + Duration::from_secs(2);
|
||||
assert!(b.try_acquire_at(t1));
|
||||
assert!(!b.try_acquire_at(t1));
|
||||
}
|
||||
Loading…
Reference in a new issue