acb98a6a1c
Deleting a person from directory.json without editing devices.json left a dangling owner, a snapshot error, and so no plans for anybody. A well-formed owner or member id that is not a person is now reported on its own codes (devices.owner-unknown, directory.member-unknown) and removed: the device is ownerless, the member leaves the group. Malformed ids, duplicates and bad JSON still stop every plan. Two new structural fixtures keep devices.owner and directory.member covered.
261 lines
10 KiB
Rust
261 lines
10 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]
|
|
#[ignore = "QA F-03 (major): an invalid kill-switch road fails open"]
|
|
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"
|
|
);
|
|
assert!(
|
|
c.plans[&key(1)].kill_switch.is_some(),
|
|
"mark-pc lost its kill switch because its exit stopped being one: it now fails open"
|
|
);
|
|
}
|
|
|
|
/// 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"
|
|
}
|
|
);
|
|
}
|
|
}
|