[roads] QA F-03: a kill-switch road with an error fails closed, through no exit
Any check() error used to make a road grant nothing, and for never-online-without nothing meant no kill switch: an exit that stopped being one (or left devices.json) silently turned off every kill switch through it. The road is still reported as an error, but its subject's kill switch stays on through no exit (only the mesh), and going direct to the internet is still dropped. An expired kill switch ends as written. The road_file fuzz target's deny-by-default check now allows exactly that narrowing and nothing else.
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
//! point (`render(parse(render(r))) == render(r)`);
|
||||
//! 3. `compile` never panics (its `expect`/`unreachable!` paths assume the parser's checks);
|
||||
//! 4. deny by default: a file that does not parse, or a road the compiler reports an error for, leaves every
|
||||
//! plan byte-identical to the home store without it.
|
||||
//! plan byte-identical to the home store without it. The one exception fails closed (QA F-03): a kill-switch
|
||||
//! road with an error may turn a kill switch on through no exit, and so drop going direct to the internet,
|
||||
//! and nothing else.
|
||||
//!
|
||||
//! Run on Linux with nightly: `cargo fuzz run road_file -- -max_total_time=600`.
|
||||
//!
|
||||
@@ -80,6 +82,17 @@ fn baseline() -> &'static Vec<String> {
|
||||
})
|
||||
}
|
||||
|
||||
fn baseline_plans() -> &'static std::collections::BTreeMap<roads::DeviceKey, roads::plan::Plan> {
|
||||
static B: OnceLock<std::collections::BTreeMap<roads::DeviceKey, roads::plan::Plan>> = OnceLock::new();
|
||||
B.get_or_init(|| {
|
||||
compile(
|
||||
&Store::from_parts(&files(None), Some(DIRECTORY), Some(DEVICES)),
|
||||
now(),
|
||||
)
|
||||
.plans
|
||||
})
|
||||
}
|
||||
|
||||
/// The id the file claims, so the file name can match it and the fuzzer reaches past `id.file-name`.
|
||||
fn claimed_id(data: &[u8]) -> String {
|
||||
std::str::from_utf8(data)
|
||||
@@ -142,6 +155,30 @@ fuzz_target!(|data: &[u8]| {
|
||||
let collides = HOME.iter().any(|(n, _)| n.starts_with(&format!("{id}-")));
|
||||
let refused = parsed.is_err() || c.errors().any(|p| p.path == path);
|
||||
if refused && !collides {
|
||||
assert_eq!(&plans, baseline(), "a refused road changed a plan");
|
||||
let kill = parsed
|
||||
.as_ref()
|
||||
.is_ok_and(|r| r.verb == roads::Verb::NeverOnlineWithout);
|
||||
if kill {
|
||||
let base = baseline_plans();
|
||||
for (k, p) in &c.plans {
|
||||
let b = &base[k];
|
||||
let mut p = p.clone();
|
||||
let ks = p.kill_switch.take();
|
||||
assert!(
|
||||
ks.as_ref().is_none_or(|ks| ks.through.is_none()) || ks == b.kill_switch,
|
||||
"a refused kill switch named an exit"
|
||||
);
|
||||
assert!(
|
||||
p.direct.iter().all(|d| b.direct.contains(d)),
|
||||
"a refused kill switch added a direct subnet"
|
||||
);
|
||||
p.direct = b.direct.clone();
|
||||
p.kill_switch = b.kill_switch.clone();
|
||||
p.expires = b.expires.clone();
|
||||
assert_eq!(&p, b, "a refused kill-switch road changed more than the kill switch");
|
||||
}
|
||||
} else {
|
||||
assert_eq!(&plans, baseline(), "a refused road changed a plan");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user