Files
via-core/crates/roads/tests/qa_findings.rs
T
mnovak 3bd87ebccf [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.
2026-11-25 08:46:30 +01:00

298 lines
11 KiB
Rust

//! QA review of PR #1 (`feature/roads`): one test per finding that the code does not yet answer.
//!
//! Every test here **fails on the current code** and is `#[ignore]`d so the suite stays green; each `ignore`
//! names its finding in `Via/qa/review-via-core-pr1.md`. Run them with `cargo test -p roads --test qa_findings
//! -- --ignored`: a fix is done when its test passes and the `#[ignore]` is removed in the same commit. If a
//! finding is answered by a design decision instead, change the test to that decision, do not delete it.
mod common;
use common::{Parts, key};
use roads::plan::Dst;
use roads::{Hostname, Place, Store, compile, explain};
fn road(id: &str, slug: &str, lines: &[String]) -> (String, String) {
(
format!("{id}-{slug}.md"),
format!(
"---\nid: {id}\n{}\ncreated: 2026-11-25T10:00:00Z\n---\n",
lines.join("\n")
),
)
}
fn with(parts: Parts, r: (String, String)) -> Parts {
parts.with_road(&r.0, &r.1)
}
/// F-01. A road to one Ianitor service opens every service on that host that shares a port. The firewall can
/// only say "Jana's address may reach 100.96.0.2 on tcp/443", and photos and git both live there on tcp/443,
/// so "Jana can reach Photos" is also "Jana can reach Git"; `explain` admits it.
#[test]
#[ignore = "QA F-01 (blocker): a service road grants every service on the same host and port"]
fn f01_a_service_road_grants_only_that_service() {
// Without the household road, Jana's only road to the home server is 7tq0mz: photos, tcp/443.
let parts = Parts::home().without_road("k3f9q2");
let c = parts.compile();
let store = parts.store();
let devs = store.devices.as_ref().unwrap();
let git = Place::Service(Hostname::new("git.home.arpa").unwrap());
let why = explain(&c, devs, &key(3), &git);
let refused = c
.problems
.iter()
.any(|p| p.path.contains("7tq0mz") && p.is_error());
assert!(
why.is_empty() || refused,
"jana-phone reaches git.home.arpa through {why:?}, a road that names only photos.home.arpa"
);
}
/// F-02. `goes-direct` may name the mesh's own addresses or a subnet the mesh routes. Then traffic that the
/// plan also routes into the tunnel is told to bypass it, on whatever network the device is on, and the
/// kill switch does not stop it because the subnet is "private".
#[test]
#[ignore = "QA F-02 (major): goes-direct can take mesh addresses and tunnelled subnets out of the tunnel"]
fn f02_going_direct_never_overlaps_what_the_tunnel_carries() {
let mark_pc = key(1);
for subnet in ["100.96.0.0/16", "192.168.100.0/24", "192.168.0.0/16"] {
let parts = with(
Parts::home(),
road(
"f02aaa",
"mark-pc-direct",
&[
format!("subject: device:{mark_pc}"),
"verb: goes-direct".into(),
format!("object: subnet:{subnet}"),
],
),
);
let c = parts.compile();
let plan = &c.plans[&mark_pc];
assert!(plan.kill_switch.is_some(), "mark-pc has a kill switch");
let tunnelled: Vec<_> = plan
.peers
.iter()
.flat_map(|p| p.allowed_ips.iter())
.filter(|n| n.prefix_len() > 0)
.collect();
for d in &plan.direct {
for n in &tunnelled {
assert!(
!d.subnet.overlaps(n),
"goes-direct {} overlaps {n}, which the plan sends through the tunnel",
d.subnet
);
}
}
}
}
/// F-03. A kill switch whose road stops validating turns the protection off. The realistic trigger is not a
/// typo: the exit device stops offering itself as an exit (or leaves devices.json), and every kill switch
/// through it silently disappears while the rest of the plan compiles.
#[test]
fn f03_a_kill_switch_whose_exit_goes_away_fails_closed() {
let parts = Parts::home().edit_devices(|d| {
d.replace(
r#""address": "100.96.0.2", "exit": true,"#,
r#""address": "100.96.0.2","#,
)
});
let c = parts.compile();
assert!(c.has_plans());
assert!(
c.problems
.iter()
.any(|p| p.path.contains("w9c3ke") && p.is_error()),
"the kill-switch road is reported"
);
let ks = c.plans[&key(1)].kill_switch.as_ref();
assert!(
ks.is_some(),
"mark-pc lost its kill switch because its exit stopped being one: it now fails open"
);
assert_eq!(
ks.unwrap().through,
None,
"closed means through no exit: only the mesh"
);
// Mutation guard: the same road made valid again keeps its exit.
assert_eq!(
Parts::home().compile().plans[&key(1)]
.kill_switch
.as_ref()
.unwrap()
.through,
Some(key(2))
);
}
/// F-03, the other references: an unknown exit, and an exit road that has expired, which ends as written.
#[test]
fn f03_an_unknown_exit_fails_closed_and_an_expired_kill_switch_ends() {
let text = Parts::home().road_text("w9c3ke");
let unknown = text.replace(
"exit:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
"exit:CQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQk",
);
let c = Parts::home().replace_road("w9c3ke", &unknown).compile();
assert!(
c.problems
.iter()
.any(|p| p.path.contains("w9c3ke") && p.is_error())
);
assert_eq!(c.plans[&key(1)].kill_switch.as_ref().unwrap().through, None);
let expired = unknown.replace("created:", "until: 2026-11-01T00:00:00+01:00\ncreated:");
let c = Parts::home().replace_road("w9c3ke", &expired).compile();
assert!(
c.plans[&key(1)].kill_switch.is_none(),
"an expired kill switch ends as written"
);
}
/// F-04. Deleting a person from the directory (the upstream event, without also editing devices.json) leaves
/// a dangling `owner`, which is a snapshot error, which means no plan for anybody. Day 3 then has to choose
/// between the household offline and the deleted person keeping their access.
#[test]
fn f04_deleting_a_person_revokes_them_and_nobody_else() {
let parts =
Parts::home().edit_directory(|d| d.replace(r#" { "id": "petr", "name": "Petr" },"#, ""));
let c = parts.compile();
assert!(
c.has_plans(),
"removing petr from directory.json produced no plans at all: {:?}",
c.errors().map(|p| p.to_string()).collect::<Vec<_>>()
);
assert!(c.plans[&key(7)].exit.is_none(), "petr-phone kept its exit");
assert!(
c.plans[&key(3)].peers.iter().any(|p| p.key == key(2)),
"jana kept hers"
);
}
/// F-05. A custom road on a classic device is carried as `classic: false` unless the road says otherwise, so the
/// plan labels a classic peer's raw block as post-quantum (CLAUDE.md: classic peers are labelled everywhere).
#[test]
#[ignore = "QA F-05 (minor): plan.custom takes `classic` from the road, not from the device"]
fn f05_a_custom_block_on_a_classic_device_is_labelled_classic() {
let router = key(5);
let text = Parts::home()
.road_text("x1d7qa")
.replace("classic: true\n", "");
let parts = Parts::home().replace_road("x1d7qa", &text);
let c = parts.compile();
let refused = c
.problems
.iter()
.any(|p| p.path.contains("x1d7qa") && p.is_error());
let custom = &c.plans[&router].custom;
assert!(
refused || custom.iter().all(|x| x.classic),
"the router is classic, its custom block says classic: false"
);
}
/// F-06. Roads whose subject devices have an IPv4 mesh address and whose object is an IPv6 subnet (or the
/// other way round) compile cleanly into rules that can never match: a road that grants nothing, reported as
/// nothing.
#[test]
#[ignore = "QA F-06 (minor): a road across address families compiles into a rule that never matches"]
fn f06_a_road_across_address_families_is_reported() {
let parts = with(
Parts::home().edit_devices(|d| {
d.replace(
r#""routes": ["192.168.100.0/24"]"#,
r#""routes": ["192.168.100.0/24", "fd00:1::/64"]"#,
)
}),
road(
"f06aaa",
"mark-v6",
&[
"subject: person:mark".into(),
"verb: can-reach".into(),
"object: subnet:fd00:1::/64".into(),
],
),
);
let c = parts.compile();
let mixed = c
.plans
.values()
.flat_map(|p| p.firewall.rules.iter())
.any(|r| match r.dst {
Dst::Net(n) => n.inner().addr().is_ipv4() != r.src.inner().addr().is_ipv4(),
Dst::Internet => false,
});
let reported = c.problems.iter().any(|p| p.path.contains("f06aaa"));
assert!(
reported || !mixed,
"an IPv4 source to an IPv6 destination, silently"
);
}
/// F-07. A store folder without `roads/` compiles to plans with no access and no problem at all, so pointing
/// `--store` one folder too high revokes everything, kill switches included, without a word.
#[test]
fn f07_a_missing_roads_folder_is_reported() {
let dir = tempfile::tempdir().unwrap();
std::fs::copy(
common::home_dir().join("directory.json"),
dir.path().join("directory.json"),
)
.unwrap();
std::fs::copy(
common::home_dir().join("devices.json"),
dir.path().join("devices.json"),
)
.unwrap();
let store = Store::load_dir(dir.path()).unwrap();
let c = compile(&store, common::now());
assert!(
!c.problems.is_empty(),
"no roads/ folder, every plan empty, and nothing said"
);
}
/// F-08. A device's mesh address may be a public address. The exit's forward rule to `internet` then covers
/// another device's mesh address, so "exit through the friend node" also reaches that device through the exit.
#[test]
#[ignore = "QA F-08 (minor): mesh addresses are not confined to private ranges"]
fn f08_mesh_addresses_are_never_internet_addresses() {
let parts = Parts::home()
.edit_devices(|d| d.replace(r#""address": "100.96.0.4""#, r#""address": "198.51.100.4""#));
let store = parts.store();
assert!(
store.devices.is_none(),
"198.51.100.4 was accepted as a mesh address; an exit's `internet` rule covers it"
);
}
/// F-09. An empty value means "absent" (docs/FORMATS.md), and for the two conditions that narrow a road absent
/// is the widest value: `until:` left empty is a permanent grant and `ports:` left empty is all traffic, with no
/// problem reported. The same failure as QA R-35 (a misspelt `until`), reached by deleting the value instead.
#[test]
fn f09_an_emptied_narrowing_condition_is_an_error() {
for (from, to) in [
("until: 2026-11-29T23:59:59+01:00\n", "until:\n"),
("ports: [tcp/443]\n", "ports:\n"),
("until: 2026-11-29T23:59:59+01:00\n", "until: # Sunday\n"),
] {
let text = Parts::home().road_text("7tq0mz").replace(from, to);
assert!(text.contains(to), "fixture edit {to:?}");
let c = Parts::home().replace_road("7tq0mz", &text).compile();
assert!(
c.problems.iter().any(|p| p.path.contains("7tq0mz")),
"`{}` compiled as {} with no problem reported",
to.trim_end(),
if to.starts_with("until") {
"a permanent grant"
} else {
"all traffic"
}
);
}
}