Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 635d3802c1 | |||
| 7087b06e24 | |||
| d5917e7aab | |||
| 828962a9e9 | |||
| d02bbff41c |
@@ -4,6 +4,7 @@
|
||||
|
||||
# Fuzzing and proptest artefacts
|
||||
/fuzz/target/
|
||||
/fuzz/target-none/
|
||||
/fuzz/corpus/
|
||||
/fuzz/artifacts/
|
||||
**/proptest-regressions/*.tmp
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
//! 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"
|
||||
);
|
||||
}
|
||||
|
||||
/// 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]
|
||||
#[ignore = "QA F-09 (major): an emptied `until:` or `ports:` silently widens the road to its maximum"]
|
||||
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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
//! QA R-55: renaming every id gives an isomorphic plan.
|
||||
//!
|
||||
//! Road ids are random, so nothing the compiler decides may depend on how ids sort. This test takes the home
|
||||
//! store plus roads that hit the order-sensitive paths (two exits for one device, two kill switches through
|
||||
//! different exits, two roads to one peer with different `via`), renames every road id, person id, group id,
|
||||
//! device key, device name and service hostname consistently, compiles both, maps the renamed output back and
|
||||
//! compares: plans, problems and `explain` must be the same up to the renaming.
|
||||
//!
|
||||
//! Regression-checked by reintroducing the bug, twice, and reverting: (1) the exit conflict resolved as "the
|
||||
//! first exit by key wins" instead of "neither"; (2) two disagreeing kill switches resolved as "the one with
|
||||
//! the smallest road id wins" instead of "no exit". Each made the property fail within a few cases
|
||||
//! ("the plan of mark-pc depends on how ids are spelt").
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{Parts, key, now};
|
||||
use proptest::prelude::*;
|
||||
use roads::{DeviceKey, Place, Store, compile};
|
||||
use serde_json::Value;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
const ALPHA: &[u8] = b"0123456789abcdefghjkmnpqrstvwxyz";
|
||||
|
||||
/// Roads that exercise the paths where an order could leak into the result.
|
||||
fn extra_roads() -> Vec<(String, String)> {
|
||||
let mark_pc = key(1);
|
||||
let home = key(2);
|
||||
let friend = key(6);
|
||||
let road = |id: &str, slug: &str, lines: &[String]| {
|
||||
(
|
||||
format!("{id}-{slug}.md"),
|
||||
format!(
|
||||
"---\nid: {id}\n{}\ncreated: 2026-11-25T10:00:00Z\n---\n",
|
||||
lines.join("\n")
|
||||
),
|
||||
)
|
||||
};
|
||||
vec![
|
||||
// A second exit for mark-pc: with p4n6rb this is an exit conflict, so mark-pc exits through neither.
|
||||
road(
|
||||
"q7r2kd",
|
||||
"mark-pc-exits-friend",
|
||||
&[
|
||||
format!("subject: device:{mark_pc}"),
|
||||
"verb: exits-through".into(),
|
||||
format!("object: exit:{friend}"),
|
||||
],
|
||||
),
|
||||
// A second kill switch through another exit: the kill switch goes through no exit at all.
|
||||
road(
|
||||
"t3w8yn",
|
||||
"mark-pc-kill-friend",
|
||||
&[
|
||||
format!("subject: device:{mark_pc}"),
|
||||
"verb: never-online-without".into(),
|
||||
format!("object: exit:{friend}"),
|
||||
],
|
||||
),
|
||||
// Two roads from jana to the home server with different path hints: the peer gets no hint.
|
||||
road(
|
||||
"v5b1jx",
|
||||
"jana-git-via-friend",
|
||||
&[
|
||||
"subject: person:jana".into(),
|
||||
"verb: can-reach".into(),
|
||||
"object: service:git.home.arpa".into(),
|
||||
format!("via: device:{friend}"),
|
||||
],
|
||||
),
|
||||
road(
|
||||
"y2n4fs",
|
||||
"jana-server-via-home",
|
||||
&[
|
||||
"subject: person:jana".into(),
|
||||
"verb: can-reach".into(),
|
||||
format!("object: device:{home}"),
|
||||
"ports: [tcp/22]".into(),
|
||||
format!("via: device:{home}"),
|
||||
],
|
||||
),
|
||||
// Petr's second exit, the other way round: a conflict whose roads sort the other way.
|
||||
road(
|
||||
"0aa9zz",
|
||||
"petr-exits-home",
|
||||
&[
|
||||
"subject: person:petr".into(),
|
||||
"verb: exits-through".into(),
|
||||
format!("object: exit:{home}"),
|
||||
],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
fn base_parts() -> Parts {
|
||||
let mut p = Parts::home();
|
||||
for (name, text) in extra_roads() {
|
||||
p = p.with_road(&name, &text);
|
||||
}
|
||||
p
|
||||
}
|
||||
|
||||
struct Rng(u64);
|
||||
|
||||
impl Rng {
|
||||
fn next(&mut self) -> u64 {
|
||||
// splitmix64
|
||||
self.0 = self.0.wrapping_add(0x9E37_79B9_7F4A_7C15);
|
||||
let mut z = self.0;
|
||||
z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
|
||||
z = (z ^ (z >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB);
|
||||
z ^ (z >> 31)
|
||||
}
|
||||
fn word(&mut self, alphabet: &[u8], len: usize) -> String {
|
||||
(0..len)
|
||||
.map(|_| alphabet[(self.next() % alphabet.len() as u64) as usize] as char)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// old -> new, for every kind of id at once (the kinds never share a spelling in the home store).
|
||||
struct Renaming {
|
||||
to_new: BTreeMap<String, String>,
|
||||
to_old: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl Renaming {
|
||||
fn new(parts: &Parts, seed: u64) -> Renaming {
|
||||
let mut rng = Rng(seed);
|
||||
let dir: Value = serde_json::from_slice(&parts.directory).unwrap();
|
||||
let devs: Value = serde_json::from_slice(&parts.devices).unwrap();
|
||||
let mut taken: BTreeSet<String> = BTreeSet::new();
|
||||
let mut olds: Vec<(String, u8)> = Vec::new(); // (old, kind)
|
||||
for (name, _) in &parts.roads {
|
||||
olds.push((name.split('-').next().unwrap().to_string(), 0));
|
||||
}
|
||||
for p in dir["people"].as_array().unwrap() {
|
||||
olds.push((p["id"].as_str().unwrap().to_string(), 1));
|
||||
}
|
||||
for g in dir["groups"].as_array().unwrap() {
|
||||
olds.push((g["id"].as_str().unwrap().to_string(), 1));
|
||||
}
|
||||
for d in devs["devices"].as_array().unwrap() {
|
||||
olds.push((d["key"].as_str().unwrap().to_string(), 2));
|
||||
olds.push((d["name"].as_str().unwrap().to_string(), 3));
|
||||
for s in d["services"].as_array().into_iter().flatten() {
|
||||
olds.push((s["host"].as_str().unwrap().to_string(), 4));
|
||||
}
|
||||
}
|
||||
for (o, _) in &olds {
|
||||
taken.insert(o.clone());
|
||||
}
|
||||
let mut to_new = BTreeMap::new();
|
||||
for (old, kind) in olds {
|
||||
let new = loop {
|
||||
let cand = match kind {
|
||||
0 => rng.word(ALPHA, 6),
|
||||
1 => {
|
||||
let len = 1 + (rng.next() % 12) as usize;
|
||||
rng.word(
|
||||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",
|
||||
len,
|
||||
)
|
||||
}
|
||||
2 => {
|
||||
let mut b = [0u8; 32];
|
||||
for x in b.iter_mut() {
|
||||
*x = rng.next() as u8;
|
||||
}
|
||||
DeviceKey::from_bytes(&b).to_string()
|
||||
}
|
||||
3 => format!("n{}", rng.word(b"abcdefghijklmnopqrstuvwxyz0123456789-", 7)),
|
||||
_ => format!("{}.test", rng.word(b"abcdefghijklmnopqrstuvwxyz", 8)),
|
||||
};
|
||||
if taken.insert(cand.clone()) {
|
||||
break cand;
|
||||
}
|
||||
};
|
||||
to_new.insert(old, new);
|
||||
}
|
||||
let to_old = to_new.iter().map(|(a, b)| (b.clone(), a.clone())).collect();
|
||||
Renaming { to_new, to_old }
|
||||
}
|
||||
|
||||
fn new_of(&self, s: &str) -> String {
|
||||
self.to_new.get(s).cloned().unwrap_or_else(|| s.to_string())
|
||||
}
|
||||
|
||||
/// A `kind:value` reference with its value renamed (subnets are left alone).
|
||||
fn reference(&self, r: &str) -> String {
|
||||
match r.split_once(':') {
|
||||
Some((kind, v)) if kind != "subnet" => format!("{kind}:{}", self.new_of(v)),
|
||||
_ => r.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn apply(&self, parts: &Parts) -> Parts {
|
||||
let mut dir: Value = serde_json::from_slice(&parts.directory).unwrap();
|
||||
for p in dir["people"].as_array_mut().unwrap() {
|
||||
p["id"] = Value::String(self.new_of(p["id"].as_str().unwrap()));
|
||||
}
|
||||
for g in dir["groups"].as_array_mut().unwrap() {
|
||||
g["id"] = Value::String(self.new_of(g["id"].as_str().unwrap()));
|
||||
for m in g["members"].as_array_mut().unwrap() {
|
||||
*m = Value::String(self.new_of(m.as_str().unwrap()));
|
||||
}
|
||||
}
|
||||
let mut devs: Value = serde_json::from_slice(&parts.devices).unwrap();
|
||||
for d in devs["devices"].as_array_mut().unwrap() {
|
||||
for k in ["key", "name", "owner"] {
|
||||
if let Some(v) = d.get(k).and_then(|v| v.as_str()).map(|s| self.new_of(s)) {
|
||||
d[k] = Value::String(v);
|
||||
}
|
||||
}
|
||||
for s in d
|
||||
.get_mut("services")
|
||||
.and_then(|s| s.as_array_mut())
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
s["host"] = Value::String(self.new_of(s["host"].as_str().unwrap()));
|
||||
}
|
||||
}
|
||||
let roads = parts
|
||||
.roads
|
||||
.iter()
|
||||
.map(|(name, bytes)| {
|
||||
let (id, rest) = name.split_once('-').unwrap();
|
||||
let text = String::from_utf8(bytes.clone()).unwrap();
|
||||
let mut out = String::new();
|
||||
let mut in_header = 0;
|
||||
for line in text.split_inclusive('\n') {
|
||||
if line.trim_end() == "---" {
|
||||
in_header += 1;
|
||||
out.push_str(line);
|
||||
continue;
|
||||
}
|
||||
if in_header == 1
|
||||
&& let Some((k, v)) = line.trim_end_matches(['\n', '\r']).split_once(": ")
|
||||
{
|
||||
let v2 = match k {
|
||||
"id" => self.new_of(v),
|
||||
"subject" | "object" | "via" => self.reference(v),
|
||||
_ => v.to_string(),
|
||||
};
|
||||
out.push_str(&format!("{k}: {v2}\n"));
|
||||
continue;
|
||||
}
|
||||
out.push_str(line);
|
||||
}
|
||||
(format!("{}-{rest}", self.new_of(id)), out.into_bytes())
|
||||
})
|
||||
.collect();
|
||||
Parts {
|
||||
roads,
|
||||
directory: serde_json::to_vec(&dir).unwrap(),
|
||||
devices: serde_json::to_vec(&devs).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Every string that is exactly a renamed id goes back to its old spelling.
|
||||
fn back(&self, v: &mut Value) {
|
||||
match v {
|
||||
Value::String(s) => {
|
||||
if let Some(o) = self.to_old.get(s.as_str()) {
|
||||
*s = o.clone();
|
||||
}
|
||||
}
|
||||
Value::Array(a) => a.iter_mut().for_each(|x| self.back(x)),
|
||||
Value::Object(m) => m.values_mut().for_each(|x| self.back(x)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn path_back(&self, path: &str) -> String {
|
||||
match path.strip_prefix("roads/").and_then(|n| n.split_once('-')) {
|
||||
Some((id, rest)) => format!(
|
||||
"roads/{}-{rest}",
|
||||
self.to_old.get(id).cloned().unwrap_or(id.to_string())
|
||||
),
|
||||
None => path.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lists are sets in every plan (docs/FORMATS.md, "Every list is sorted"), so sorting each one by its text makes
|
||||
/// two plans that differ only in the spelling of their ids comparable.
|
||||
fn canonical(v: &mut Value) {
|
||||
match v {
|
||||
Value::Array(a) => {
|
||||
a.iter_mut().for_each(canonical);
|
||||
a.sort_by_key(|x| x.to_string());
|
||||
}
|
||||
Value::Object(m) => m.values_mut().for_each(canonical),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn store_of(p: &Parts) -> Store {
|
||||
Store::from_parts(&p.roads, Some(&p.directory), Some(&p.devices))
|
||||
}
|
||||
|
||||
fn check_isomorphic(seed: u64) -> Result<(), TestCaseError> {
|
||||
let parts = base_parts();
|
||||
let ren = Renaming::new(&parts, seed);
|
||||
let renamed = ren.apply(&parts);
|
||||
let (s0, s1) = (store_of(&parts), store_of(&renamed));
|
||||
let (c0, c1) = (compile(&s0, now()), compile(&s1, now()));
|
||||
prop_assert!(c0.has_plans() && c1.has_plans());
|
||||
prop_assert_eq!(c0.plans.len(), c1.plans.len());
|
||||
|
||||
for (k, p0) in &c0.plans {
|
||||
let k1 = DeviceKey::new(&ren.new_of(k.as_str())).unwrap();
|
||||
let mut a = serde_json::to_value(p0).unwrap();
|
||||
let mut b = serde_json::to_value(&c1.plans[&k1]).unwrap();
|
||||
ren.back(&mut b);
|
||||
canonical(&mut a);
|
||||
canonical(&mut b);
|
||||
prop_assert_eq!(a, b, "the plan of {} depends on how ids are spelt", p0.name);
|
||||
}
|
||||
|
||||
let problems =
|
||||
|c: &roads::Compiled, back: bool| -> BTreeSet<(String, Option<String>, String, String)> {
|
||||
c.problems
|
||||
.iter()
|
||||
.map(|p| {
|
||||
(
|
||||
if back {
|
||||
ren.path_back(&p.path)
|
||||
} else {
|
||||
p.path.clone()
|
||||
},
|
||||
p.field.clone(),
|
||||
p.code.to_string(),
|
||||
format!("{:?}", p.severity),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
prop_assert_eq!(problems(&c0, false), problems(&c1, true));
|
||||
|
||||
let (d0, d1) = (s0.devices.as_ref().unwrap(), s1.devices.as_ref().unwrap());
|
||||
for a in d0.devices.keys() {
|
||||
for b in d0.devices.keys() {
|
||||
let a1 = DeviceKey::new(&ren.new_of(a.as_str())).unwrap();
|
||||
let b1 = DeviceKey::new(&ren.new_of(b.as_str())).unwrap();
|
||||
for (p0, p1) in [
|
||||
(Place::Device(b.clone()), Place::Device(b1.clone())),
|
||||
(Place::Exit(b.clone()), Place::Exit(b1)),
|
||||
] {
|
||||
let w0: BTreeSet<String> = roads::explain(&c0, d0, a, &p0)
|
||||
.iter()
|
||||
.map(|r| r.to_string())
|
||||
.collect();
|
||||
let w1: BTreeSet<String> = roads::explain(&c1, d1, &a1, &p1)
|
||||
.iter()
|
||||
.map(|r| ren.to_old[r.as_str()].clone())
|
||||
.collect();
|
||||
prop_assert_eq!(w0, w1, "explain {:?} -> {:?}", a, p0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_extra_roads_reach_the_order_sensitive_paths() {
|
||||
// Guards the fixture: without these the property would pass for a reason that has nothing to do with order.
|
||||
let c = base_parts().compile();
|
||||
let codes: BTreeSet<&str> = c.problems.iter().map(|p| p.code).collect();
|
||||
assert!(codes.contains("exit.conflict"), "{codes:?}");
|
||||
let mark = &c.plans[&key(1)];
|
||||
assert!(mark.exit.is_none(), "two exits: neither");
|
||||
assert_eq!(
|
||||
mark.kill_switch.as_ref().unwrap().through,
|
||||
None,
|
||||
"two kill switches: no exit"
|
||||
);
|
||||
let jana_phone = &c.plans[&key(3)];
|
||||
let server = jana_phone.peers.iter().find(|p| p.key == key(2)).unwrap();
|
||||
assert_eq!(server.via, None, "two different path hints: none");
|
||||
assert!(
|
||||
c.errors().next().is_none(),
|
||||
"{:?}",
|
||||
c.errors().collect::<Vec<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_identity_renaming_changes_nothing() {
|
||||
let parts = base_parts();
|
||||
let before = common::plans_bytes(&parts.compile());
|
||||
let ren = Renaming {
|
||||
to_new: BTreeMap::new(),
|
||||
to_old: BTreeMap::new(),
|
||||
};
|
||||
assert_eq!(
|
||||
common::plans_bytes(&compile(&store_of(&ren.apply(&parts)), now())),
|
||||
before
|
||||
);
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#![proptest_config(ProptestConfig { cases: 300, failure_persistence: None, .. ProptestConfig::default() })]
|
||||
|
||||
#[test]
|
||||
fn r55_renaming_every_id_gives_an_isomorphic_plan(seed in any::<u64>()) {
|
||||
check_isomorphic(seed)?;
|
||||
}
|
||||
}
|
||||
Generated
+424
@@ -0,0 +1,424 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"jobserver",
|
||||
"libc",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"ciborium-ll",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-io"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-ll"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"half",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crunchy",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "175dc66334db3b9ab9985bf8b61cfed50dc16d20964bb47f9e479adcae984a7f"
|
||||
dependencies = [
|
||||
"jiff-core",
|
||||
"jiff-static",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-core"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e599b80292e597019b8b3e392de3f4bea2959ddfb8c7dff60e035e9e311a2c1b"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-static"
|
||||
version = "0.2.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7b1af7547d47354bc438d797e3854601bde8f8d185780c5ba4ab27afa54f1ba"
|
||||
dependencies = [
|
||||
"jiff-core",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.191"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "libfuzzer-sys"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic-util"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proto"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ciborium",
|
||||
"roads",
|
||||
"serde",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "roads"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"ipnet",
|
||||
"jiff",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.154"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "via-core-fuzz"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"jiff",
|
||||
"libfuzzer-sys",
|
||||
"proto",
|
||||
"roads",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32bc8a75f879cd6fe53a6bedf3c28f0e1b914c77424fc2be9e2ec85d7d25aff5"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8bfd2644ea1681f60cf95029ff18aa8ad1cc3f7b8fe37286f8e473bb29f816b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
@@ -0,0 +1,36 @@
|
||||
[package]
|
||||
name = "via-core-fuzz"
|
||||
version = "0.0.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
license = "CPAL-1.0"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1"
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
roads = { path = "../crates/roads" }
|
||||
proto = { path = "../crates/proto" }
|
||||
jiff = { version = "0.2", default-features = false, features = ["std"] }
|
||||
|
||||
# Its own workspace, so the fuzz build never joins the main one (cargo fuzz's layout).
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
||||
[[bin]]
|
||||
name = "road_file"
|
||||
path = "fuzz_targets/road_file.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "envelope"
|
||||
path = "fuzz_targets/envelope.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
@@ -0,0 +1,9 @@
|
||||
// Windows only: give the coverage counters their section bounds (see win_sections.c).
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=win_sections.c");
|
||||
if std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
|
||||
cc::Build::new()
|
||||
.file("win_sections.c")
|
||||
.compile("win_sections");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//! Fuzzes the control-protocol decoder (QA review of PR #1): `Envelope::decode` never panics, and anything it
|
||||
//! accepts encodes to bytes that decode to the same envelope, and encoding is stable.
|
||||
//!
|
||||
//! Run: RUSTC_BOOTSTRAP=1 cargo fuzz run envelope -s none -- -max_total_time=300
|
||||
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use proto::Envelope;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if let Ok(env) = Envelope::decode(data) {
|
||||
let bytes = env.encode();
|
||||
let again = Envelope::decode(&bytes).expect("an encoded envelope decodes");
|
||||
assert_eq!(again, env);
|
||||
assert_eq!(again.encode(), bytes, "encoding is not stable");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,147 @@
|
||||
//! Fuzzes the road-file parser and the compiler behind it (QA review of PR #1).
|
||||
//!
|
||||
//! For any bytes as one road file, added to the home store:
|
||||
//! 1. `Road::parse` never panics;
|
||||
//! 2. a road that parses renders to canonical text that parses back to the same road, and rendering is a fixed
|
||||
//! 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.
|
||||
//!
|
||||
//! Run on Linux with nightly: `cargo fuzz run road_file -- -max_total_time=600`.
|
||||
//!
|
||||
//! Run on Windows with the stable MSVC toolchain and no sanitizer (`cargo fuzz -s none` adds the PC table, which
|
||||
//! does not link on COFF without a sanitizer runtime; `build.rs` + `win_sections.c` supply the counter bounds):
|
||||
//! cd fuzz
|
||||
//! RUSTFLAGS="-Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=4
|
||||
//! -Cllvm-args=-sanitizer-coverage-inline-8bit-counters -Cllvm-args=-sanitizer-coverage-trace-compares
|
||||
//! -Cllvm-args=-simplifycfg-branch-fold-threshold=0 -Ccodegen-units=1 --cfg fuzzing -Cdebug-assertions
|
||||
//! -Clink-arg=/include:main" \
|
||||
//! cargo build --release --target x86_64-pc-windows-msvc --target-dir target-none --bin road_file
|
||||
//! target-none/x86_64-pc-windows-msvc/release/road_file.exe -max_total_time=600 corpus/road_file
|
||||
//! Seed the corpus with `crates/roads/tests/fixtures/home/roads/*` and `fixtures/invalid/roads/*`.
|
||||
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use roads::{Road, RoadId, Store, compile};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
macro_rules! home {
|
||||
($f:literal) => {
|
||||
(
|
||||
$f,
|
||||
include_bytes!(concat!("../../crates/roads/tests/fixtures/home/roads/", $f)).as_slice(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
const DIRECTORY: &[u8] = include_bytes!("../../crates/roads/tests/fixtures/home/directory.json");
|
||||
const DEVICES: &[u8] = include_bytes!("../../crates/roads/tests/fixtures/home/devices.json");
|
||||
const HOME: [(&str, &[u8]); 10] = [
|
||||
home!("7tq0mz-jana-photos-until-sunday.md"),
|
||||
home!("c0z5wn-petr-exits-friend.md"),
|
||||
home!("e5yj1s-steam-goes-direct.md"),
|
||||
home!("h2x8vd-mark-home-lan.md"),
|
||||
home!("k3f9q2-household-home-server.md"),
|
||||
home!("m6v0hp-petr-git-expired.md"),
|
||||
home!("p4n6rb-mark-pc-exits-home.md"),
|
||||
home!("r8m2tg-router-home-server.md"),
|
||||
home!("w9c3ke-mark-pc-kill-switch.md"),
|
||||
home!("x1d7qa-router-imported.md"),
|
||||
];
|
||||
|
||||
fn now() -> jiff::Timestamp {
|
||||
"2026-11-25T12:00:00+01:00".parse().unwrap()
|
||||
}
|
||||
|
||||
fn files(extra: Option<(&str, &[u8])>) -> Vec<(String, Vec<u8>)> {
|
||||
HOME.iter()
|
||||
.copied()
|
||||
.chain(extra)
|
||||
.map(|(n, b)| (n.to_string(), b.to_vec()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn plans_json(store: &Store) -> (Vec<String>, roads::Compiled) {
|
||||
let c = compile(store, now());
|
||||
(c.plans.values().map(|p| p.to_json()).collect(), c)
|
||||
}
|
||||
|
||||
fn baseline() -> &'static Vec<String> {
|
||||
static B: OnceLock<Vec<String>> = OnceLock::new();
|
||||
B.get_or_init(|| {
|
||||
plans_json(&Store::from_parts(
|
||||
&files(None),
|
||||
Some(DIRECTORY),
|
||||
Some(DEVICES),
|
||||
))
|
||||
.0
|
||||
})
|
||||
}
|
||||
|
||||
/// 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)
|
||||
.ok()
|
||||
.and_then(|t| {
|
||||
t.lines()
|
||||
.find_map(|l| l.strip_prefix("id: ").map(|v| v.trim_end_matches('\r')))
|
||||
})
|
||||
.filter(|v| RoadId::new(v).is_some())
|
||||
.unwrap_or("zz9zz9")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let id = claimed_id(data);
|
||||
let name = format!("{id}-fuzz.md");
|
||||
let path = format!("roads/{name}");
|
||||
|
||||
// 1 and 2: the parser, and the canonical round trip.
|
||||
let parsed = Road::parse(&path, data);
|
||||
if let Ok(road) = &parsed {
|
||||
let text = road.render();
|
||||
let again = match Road::parse(&path, text.as_bytes()) {
|
||||
Ok(r) => r,
|
||||
Err(p) => panic!("a rendered road does not parse: {p:?}\n--- rendered ---\n{text}"),
|
||||
};
|
||||
assert_eq!(again.render(), text, "render is not a fixed point");
|
||||
assert_eq!(
|
||||
(
|
||||
&again.id,
|
||||
&again.subject,
|
||||
again.verb,
|
||||
&again.object,
|
||||
&again.until,
|
||||
&again.ports,
|
||||
&again.via,
|
||||
again.classic,
|
||||
&again.created,
|
||||
&again.body
|
||||
),
|
||||
(
|
||||
&road.id,
|
||||
&road.subject,
|
||||
road.verb,
|
||||
&road.object,
|
||||
&road.until,
|
||||
&road.ports,
|
||||
&road.via,
|
||||
road.classic,
|
||||
&road.created,
|
||||
&road.body
|
||||
),
|
||||
"the canonical text means something else:\n{text}"
|
||||
);
|
||||
}
|
||||
|
||||
// 3 and 4: the compiler behind it, with the home store.
|
||||
let store = Store::from_parts(&files(Some((&name, data))), Some(DIRECTORY), Some(DEVICES));
|
||||
let (plans, c) = plans_json(&store);
|
||||
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");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
/* Section bounds for SanitizerCoverage's inline 8-bit counters on Windows (COFF), so the fuzz targets link
|
||||
* without a sanitizer runtime. LLVM puts the counters in ".SCOV$CM"; the linker sorts ".SCOV$CA" before it and
|
||||
* ".SCOV$CZ" after it, and libFuzzer reads everything in between. compiler-rt does the same in
|
||||
* sanitizer_coverage_win_sections.cpp, which only ships inside a sanitizer runtime. Built only for MSVC targets
|
||||
* and only for the fuzz crate, which is never part of a release. */
|
||||
#pragma section(".SCOV$CA", read, write)
|
||||
__declspec(allocate(".SCOV$CA")) unsigned char __start___sancov_cntrs[1] = {0};
|
||||
#pragma section(".SCOV$CZ", read, write)
|
||||
__declspec(allocate(".SCOV$CZ")) unsigned char __stop___sancov_cntrs[1] = {0};
|
||||
Reference in New Issue
Block a user