828962a9e9
Eight tests, each #[ignore]d with its finding id (F-01 to F-08 in Via/qa/review-via-core-pr1.md), each verified to FAIL on this code for the reason it names (cargo test -p roads --test qa_findings -- --ignored: 0 passed, 8 failed): F-01 a service road opens every service on the same host and port (explain admits it) F-02 goes-direct may name mesh addresses or tunnelled subnets, kill switch or not F-03 a kill switch whose exit stops being one fails open F-04 deleting a person from directory.json leaves no plan for anybody F-05 a custom block on a classic device is labelled classic: false F-06 a road across address families compiles into a rule that never matches F-07 a missing roads/ folder is not reported F-08 a public address is accepted as a mesh address
207 lines
8.9 KiB
Rust
207 lines
8.9 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]
|
|
#[ignore = "QA F-04 (major): one dangling owner means no plans for anybody"]
|
|
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]
|
|
#[ignore = "QA F-07 (minor): a missing roads/ folder is not reported"]
|
|
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"
|
|
);
|
|
}
|