Files
mnovak 3b39ce137d [roads] Mark's decision: person and group grants leave classic devices out
Mark, 2026-11-25, "Leave classic out": a grant to a person or a group covers
only their post-quantum devices. A classic router is reached only through a
device: road of its own, which says classic: true. Before, a person grant
covered their classic devices and so needed classic: true itself, and one
classic device blocked every road of its owner (builder's self-review #5).
New test a_person_grant_never_covers_their_classic_device, which fails with
the old compiler. Docs and HANDOVER updated: 91 tests, debug and release.
2026-11-25 10:58:57 +01:00

244 lines
8.2 KiB
Rust

//! Mandatory test 2: deleting a road, expiring it, or removing a device from a person removes the access
//! from the compiled plan — on the receiving side (the firewall of the device that serves the place) and on
//! the sending side (the peer and its allowed IPs).
mod common;
use common::{Parts, at, fw_accepts, key};
use roads::{Hostname, Place, compile, explain};
use std::net::IpAddr;
/// photos.home.arpa's own address on the home server (QA F-01: a service road reaches only its service).
const PHOTOS_HOST: &str = "100.96.1.2";
fn home_server() -> IpAddr {
PHOTOS_HOST.parse().unwrap()
}
fn photos() -> Place {
Place::Service(Hostname::new("photos.home.arpa").unwrap())
}
/// jana-phone → home-server on tcp/443, judged on the receiving side.
fn jana_reaches_photos(c: &roads::Compiled) -> bool {
fw_accepts(c, &key(3), home_server(), Some(("tcp", 443)))
}
fn has_peer(c: &roads::Compiled, on: u8, peer: u8) -> bool {
c.plans[&key(on)].peers.iter().any(|p| p.key == key(peer))
}
#[test]
fn the_baseline_grants_it() {
let c = Parts::home().compile();
assert!(jana_reaches_photos(&c));
assert!(has_peer(&c, 3, 2) && has_peer(&c, 2, 3));
}
#[test]
fn deleting_the_roads_removes_the_access() {
let c = Parts::home()
.without_road("7tq0mz")
.without_road("k3f9q2")
.compile();
assert!(!jana_reaches_photos(&c));
assert!(
!has_peer(&c, 3, 2),
"jana-phone kept a peer for the home server"
);
assert!(
!has_peer(&c, 2, 3),
"the home server kept a peer for jana-phone"
);
assert!(
c.plans[&key(2)]
.firewall
.rules
.iter()
.all(|r| r.src.to_string() != "100.96.0.3/32")
);
assert!(c.plans[&key(3)].dns.is_empty());
}
#[test]
fn deleting_one_of_two_roads_leaves_the_other_visible() {
// QA R-46: revoking the person-level road leaves the group road, and explain says so.
let parts = Parts::home().without_road("7tq0mz");
let c = parts.compile();
assert!(jana_reaches_photos(&c));
let devs = parts.store().devices.unwrap();
let why: Vec<String> = explain(&c, &devs, &key(3), &photos())
.iter()
.map(|r| r.to_string())
.collect();
assert_eq!(why, ["k3f9q2"]);
}
#[test]
fn an_expired_road_grants_nothing_from_the_instant_of_until() {
// until is 2026-11-29T23:59:59+01:00 and exclusive (QA R-22). Without the household road only it grants.
let parts = Parts::home().without_road("k3f9q2");
let store = parts.store();
assert!(jana_reaches_photos(&compile(
&store,
at("2026-11-29T23:59:58+01:00")
)));
for now in [
"2026-11-29T23:59:59+01:00",
"2026-11-29T22:59:59Z",
"2026-11-30T00:00:00+01:00",
"2027-11-25T12:00:00Z",
] {
let c = compile(&store, at(now));
assert!(!jana_reaches_photos(&c), "still granted at {now}");
assert!(
!has_peer(&c, 2, 3),
"the home server kept jana-phone at {now}"
);
assert!(
c.problems
.iter()
.any(|p| p.code == roads::rules::ROAD_EXPIRED && p.path.contains("7tq0mz")),
"{now}"
);
}
}
#[test]
fn each_plan_carries_its_own_expiry_on_both_sides() {
// QA R-26: a road with an until stops on time even before the next compile, if the engine honours
// `expires`. Both the subject's and the serving device's plans carry it.
let c = Parts::home().compile();
for dev in [2, 3, 4] {
assert_eq!(
c.plans[&key(dev)].expires.as_deref(),
Some("2026-11-29T22:59:59Z"),
"device {dev}"
);
}
assert_eq!(c.plans[&key(1)].expires, None, "mark-pc has no timed road");
assert_eq!(
c.plans[&key(7)].expires,
None,
"the expired road no longer counts"
);
}
#[test]
fn moving_a_device_to_another_person_moves_its_access() {
// QA R-18: the receiving side's rules follow the device's owner in this snapshot, nothing cached.
let moved = Parts::home().edit_devices(|d| {
d.replace(
r#""name": "jana-phone", "owner": "jana""#,
r#""name": "jana-phone", "owner": "petr""#,
)
});
let c = moved.compile();
assert!(!jana_reaches_photos(&c), "the phone kept Jana's access");
assert!(!has_peer(&c, 2, 3));
// It gains Petr's road: exits through the friend node.
assert_eq!(
c.plans[&key(3)].exit.as_ref().map(|e| e.through.clone()),
Some(key(6))
);
// Jana's other device keeps hers.
assert!(fw_accepts(&c, &key(4), home_server(), Some(("tcp", 443))));
}
#[test]
fn removing_a_device_removes_it_from_every_plan() {
// QA P-6: no plan but its own (which no longer exists) names its key or its address.
let removed = Parts::home().edit_devices(|d| {
d.lines()
.filter(|l| !l.contains("\"jana-phone\""))
.collect::<Vec<_>>()
.join("\n")
});
let c = removed.compile();
assert!(c.errors().next().is_none(), "{:?}", c.problems);
assert!(!c.plans.contains_key(&key(3)));
for p in c.plans.values() {
let json = p.to_json();
assert!(
!json.contains(key(3).as_str()) && !json.contains("100.96.0.3"),
"{} still names jana-phone",
p.name
);
}
}
#[test]
fn removing_a_person_from_a_group_removes_the_group_road_only() {
let parts = Parts::home()
.edit_directory(|d| d.replace(r#""members": ["mark", "jana"]"#, r#""members": ["mark"]"#));
let c = parts.compile();
// The group road no longer covers Jana: no rule from her address for all traffic.
assert!(
!fw_accepts(&c, &key(3), home_server(), Some(("tcp", 22))),
"group access remained"
);
// Her own road to the photos still holds.
assert!(jana_reaches_photos(&c));
}
#[test]
fn a_person_deleted_from_the_directory_leaves_their_roads_reported_and_void() {
// QA R-20: the road naming petr is an error. The device petr owned is edited to have no owner here; QA
// F-04 (`qa_findings.rs`) covers the upstream-only edit, where the dangling owner leaves it ownerless.
let parts = Parts::home()
.edit_directory(|d| d.replace(r#" { "id": "petr", "name": "Petr" },"#, ""))
.edit_devices(|d| d.replace(r#""owner": "petr", "#, ""));
let c = parts.compile();
assert!(
c.problems
.iter()
.any(|p| p.code == roads::rules::SUBJECT_UNKNOWN && p.path.contains("c0z5wn"))
);
assert!(c.plans[&key(7)].exit.is_none(), "petr-phone kept its exit");
assert!(
c.plans[&key(6)].peers.is_empty(),
"the friend node kept petr-phone as a peer"
);
}
/// Mark, 2026-11-25, "Leave classic out": a grant to a person or a group covers only their post-quantum
/// devices. A classic router that Mark owns is reached by none of Mark's or the household's roads, only by
/// its own `device:` road with `classic: true`, and that road keeps working.
#[test]
fn a_person_grant_never_covers_their_classic_device() {
let parts = Parts::home().edit_devices(|d| {
d.replace(
r#""name": "router", "address""#,
r#""name": "router", "owner": "mark", "address""#,
)
});
let c = parts.compile();
assert_eq!(c.errors().count(), 0, "{:?}", c.problems);
let router = &c.plans[&key(5)];
// h2x8vd (person:mark -> the home LAN) and k3f9q2 (group:household -> home-server) leave it out.
for p in &router.peers {
assert!(
p.roads.iter().all(|r| r.as_str() == "r8m2tg"),
"the router got a peer from a person or group road: {:?}",
p.roads
);
}
assert!(
!router
.peers
.iter()
.flat_map(|p| p.allowed_ips.iter())
.any(|n| n.to_string() == "192.168.100.0/24"),
"mark's LAN road reached his classic router"
);
// Its own classic road still gives it the home server on udp/53 and tcp/22.
assert!(fw_accepts(
&c,
&key(5),
"100.96.0.2".parse().unwrap(),
Some(("tcp", 22))
));
// And mark's post-quantum devices keep their access.
assert!(c.plans[&key(1)].peers.iter().any(|p| p.key == key(2)));
}