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
|
|
@ -66,38 +66,3 @@ pub async fn auth_middleware(
|
|||
|
||||
Ok(next.run(request).await)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn valid_secret() -> String {
|
||||
"this-is-a-test-secret-32-bytes-long!".to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_verify_roundtrip_passes() {
|
||||
let secret = valid_secret();
|
||||
let token = create_token(&secret, 3600, "rampart").expect("token creation should succeed");
|
||||
let claims = verify_token(&token, &secret, "rampart").expect("verification should succeed");
|
||||
assert_eq!(claims.sub, "rampart-admin");
|
||||
assert_eq!(claims.aud, "rampart");
|
||||
assert_eq!(claims.role, "admin");
|
||||
assert!(claims.exp > claims.iat);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_rejects_wrong_audience() {
|
||||
let secret = valid_secret();
|
||||
let token = create_token(&secret, 3600, "rampart").expect("token creation should succeed");
|
||||
assert!(verify_token(&token, &secret, "other").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_rejects_wrong_secret() {
|
||||
let secret = valid_secret();
|
||||
let other_secret = "another-test-secret-also-32-bytes-long!".to_string();
|
||||
let token = create_token(&secret, 3600, "rampart").expect("token creation should succeed");
|
||||
assert!(verify_token(&token, &other_secret, "rampart").is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ use tokio::time::{Duration, interval};
|
|||
|
||||
/// SCAN pattern for node records (blocking KEYS is forbidden under load).
|
||||
#[cfg(feature = "store-redis")]
|
||||
const NODES_KEY_PATTERN: &str = "rampart:nodes:*";
|
||||
pub const NODES_KEY_PATTERN: &str = "rampart:nodes:*";
|
||||
/// SCAN COUNT hint per round.
|
||||
#[cfg(feature = "store-redis")]
|
||||
const SCAN_BATCH: usize = 100;
|
||||
/// Node is offline when the last heartbeat is older than this.
|
||||
#[cfg(any(feature = "store-redis", test))]
|
||||
#[cfg(feature = "store-redis")]
|
||||
const NODE_TTL_SECS: i64 = 60;
|
||||
|
||||
#[cfg(feature = "store-redis")]
|
||||
|
|
@ -68,8 +68,8 @@ async fn collect_node_keys(conn: &mut redis::aio::MultiplexedConnection) -> anyh
|
|||
/// the RFC3339 `last_heartbeat` is older than `NODE_TTL_SECS` (a missing or
|
||||
/// unparseable timestamp counts as expired, matching the previous behavior);
|
||||
/// `None` when the node is fresh, unparsable, or not a JSON object.
|
||||
#[cfg(any(feature = "store-redis", test))]
|
||||
fn offline_update(raw: &str, now: i64) -> Option<String> {
|
||||
#[cfg(feature = "store-redis")]
|
||||
pub fn offline_update(raw: &str, now: i64) -> Option<String> {
|
||||
let mut node = serde_json::from_str::<serde_json::Value>(raw).ok()?;
|
||||
let hb = node["last_heartbeat"]
|
||||
.as_str()
|
||||
|
|
@ -83,54 +83,3 @@ fn offline_update(raw: &str, now: i64) -> Option<String> {
|
|||
.insert("status".to_string(), serde_json::Value::String("offline".to_string()));
|
||||
serde_json::to_string(&node).ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn rfc3339(ts: i64) -> String {
|
||||
chrono::DateTime::from_timestamp(ts, 0)
|
||||
.expect("in-range timestamp")
|
||||
.to_rfc3339()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expired_heartbeat_is_marked_offline() {
|
||||
let now = 2_000_000_i64;
|
||||
let raw = format!(
|
||||
r#"{{"name":"edge1","last_heartbeat":"{}","status":"online"}}"#,
|
||||
rfc3339(now - 120)
|
||||
);
|
||||
let updated = offline_update(&raw, now).expect("expired node should be marked offline");
|
||||
assert!(updated.contains("offline"));
|
||||
assert!(updated.contains("edge1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fresh_heartbeat_is_left_untouched() {
|
||||
let now = 2_000_000_i64;
|
||||
let raw = format!(r#"{{"last_heartbeat":"{}","status":"online"}}"#, rfc3339(now - 5));
|
||||
assert!(offline_update(&raw, now).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_or_broken_timestamp_counts_as_expired() {
|
||||
let now = 2_000_000_i64;
|
||||
let updated = offline_update(r#"{"status":"online"}"#, now).expect("missing heartbeat counts as expired");
|
||||
assert!(updated.contains("offline"));
|
||||
let updated = offline_update(r#"{"last_heartbeat":"garbage","status":"online"}"#, now)
|
||||
.expect("unparseable heartbeat counts as expired");
|
||||
assert!(updated.contains("offline"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_json_is_ignored() {
|
||||
assert!(offline_update("not json", 2_000_000).is_none());
|
||||
}
|
||||
|
||||
#[cfg(feature = "store-redis")]
|
||||
#[test]
|
||||
fn node_key_pattern_targets_rampart_nodes() {
|
||||
assert_eq!(NODES_KEY_PATTERN, "rampart:nodes:*");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue