[roads] rustfmt the QA tests and the fuzz targets (no change in behaviour)
This commit is contained in:
@@ -96,7 +96,10 @@ fn f02_going_direct_never_overlaps_what_the_tunnel_carries() {
|
|||||||
#[ignore = "QA F-03 (major): an invalid kill-switch road fails open"]
|
#[ignore = "QA F-03 (major): an invalid kill-switch road fails open"]
|
||||||
fn f03_a_kill_switch_whose_exit_goes_away_fails_closed() {
|
fn f03_a_kill_switch_whose_exit_goes_away_fails_closed() {
|
||||||
let parts = Parts::home().edit_devices(|d| {
|
let parts = Parts::home().edit_devices(|d| {
|
||||||
d.replace(r#""address": "100.96.0.2", "exit": true,"#, r#""address": "100.96.0.2","#)
|
d.replace(
|
||||||
|
r#""address": "100.96.0.2", "exit": true,"#,
|
||||||
|
r#""address": "100.96.0.2","#,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
let c = parts.compile();
|
let c = parts.compile();
|
||||||
assert!(c.has_plans());
|
assert!(c.has_plans());
|
||||||
@@ -118,7 +121,8 @@ fn f03_a_kill_switch_whose_exit_goes_away_fails_closed() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore = "QA F-04 (major): one dangling owner means no plans for anybody"]
|
#[ignore = "QA F-04 (major): one dangling owner means no plans for anybody"]
|
||||||
fn f04_deleting_a_person_revokes_them_and_nobody_else() {
|
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 parts =
|
||||||
|
Parts::home().edit_directory(|d| d.replace(r#" { "id": "petr", "name": "Petr" },"#, ""));
|
||||||
let c = parts.compile();
|
let c = parts.compile();
|
||||||
assert!(
|
assert!(
|
||||||
c.has_plans(),
|
c.has_plans(),
|
||||||
@@ -126,7 +130,10 @@ fn f04_deleting_a_person_revokes_them_and_nobody_else() {
|
|||||||
c.errors().map(|p| p.to_string()).collect::<Vec<_>>()
|
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(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");
|
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
|
/// F-05. A custom road on a classic device is carried as `classic: false` unless the road says otherwise, so the
|
||||||
@@ -135,10 +142,15 @@ fn f04_deleting_a_person_revokes_them_and_nobody_else() {
|
|||||||
#[ignore = "QA F-05 (minor): plan.custom takes `classic` from the road, not from the device"]
|
#[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() {
|
fn f05_a_custom_block_on_a_classic_device_is_labelled_classic() {
|
||||||
let router = key(5);
|
let router = key(5);
|
||||||
let text = Parts::home().road_text("x1d7qa").replace("classic: true\n", "");
|
let text = Parts::home()
|
||||||
|
.road_text("x1d7qa")
|
||||||
|
.replace("classic: true\n", "");
|
||||||
let parts = Parts::home().replace_road("x1d7qa", &text);
|
let parts = Parts::home().replace_road("x1d7qa", &text);
|
||||||
let c = parts.compile();
|
let c = parts.compile();
|
||||||
let refused = c.problems.iter().any(|p| p.path.contains("x1d7qa") && p.is_error());
|
let refused = c
|
||||||
|
.problems
|
||||||
|
.iter()
|
||||||
|
.any(|p| p.path.contains("x1d7qa") && p.is_error());
|
||||||
let custom = &c.plans[&router].custom;
|
let custom = &c.plans[&router].custom;
|
||||||
assert!(
|
assert!(
|
||||||
refused || custom.iter().all(|x| x.classic),
|
refused || custom.iter().all(|x| x.classic),
|
||||||
@@ -154,7 +166,10 @@ fn f05_a_custom_block_on_a_classic_device_is_labelled_classic() {
|
|||||||
fn f06_a_road_across_address_families_is_reported() {
|
fn f06_a_road_across_address_families_is_reported() {
|
||||||
let parts = with(
|
let parts = with(
|
||||||
Parts::home().edit_devices(|d| {
|
Parts::home().edit_devices(|d| {
|
||||||
d.replace(r#""routes": ["192.168.100.0/24"]"#, r#""routes": ["192.168.100.0/24", "fd00:1::/64"]"#)
|
d.replace(
|
||||||
|
r#""routes": ["192.168.100.0/24"]"#,
|
||||||
|
r#""routes": ["192.168.100.0/24", "fd00:1::/64"]"#,
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
road(
|
road(
|
||||||
"f06aaa",
|
"f06aaa",
|
||||||
@@ -167,12 +182,19 @@ fn f06_a_road_across_address_families_is_reported() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
let c = parts.compile();
|
let c = parts.compile();
|
||||||
let mixed = c.plans.values().flat_map(|p| p.firewall.rules.iter()).any(|r| match r.dst {
|
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::Net(n) => n.inner().addr().is_ipv4() != r.src.inner().addr().is_ipv4(),
|
||||||
Dst::Internet => false,
|
Dst::Internet => false,
|
||||||
});
|
});
|
||||||
let reported = c.problems.iter().any(|p| p.path.contains("f06aaa"));
|
let reported = c.problems.iter().any(|p| p.path.contains("f06aaa"));
|
||||||
assert!(reported || !mixed, "an IPv4 source to an IPv6 destination, silently");
|
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
|
/// F-07. A store folder without `roads/` compiles to plans with no access and no problem at all, so pointing
|
||||||
@@ -181,8 +203,16 @@ fn f06_a_road_across_address_families_is_reported() {
|
|||||||
#[ignore = "QA F-07 (minor): a missing roads/ folder is not reported"]
|
#[ignore = "QA F-07 (minor): a missing roads/ folder is not reported"]
|
||||||
fn f07_a_missing_roads_folder_is_reported() {
|
fn f07_a_missing_roads_folder_is_reported() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
std::fs::copy(common::home_dir().join("directory.json"), dir.path().join("directory.json")).unwrap();
|
std::fs::copy(
|
||||||
std::fs::copy(common::home_dir().join("devices.json"), dir.path().join("devices.json")).unwrap();
|
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 store = Store::load_dir(dir.path()).unwrap();
|
||||||
let c = compile(&store, common::now());
|
let c = compile(&store, common::now());
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -318,12 +318,17 @@ fn check_isomorphic(seed: u64) -> Result<(), TestCaseError> {
|
|||||||
prop_assert_eq!(a, b, "the plan of {} depends on how ids are spelt", p0.name);
|
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)> {
|
let problems =
|
||||||
|
|c: &roads::Compiled, back: bool| -> BTreeSet<(String, Option<String>, String, String)> {
|
||||||
c.problems
|
c.problems
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
(
|
(
|
||||||
if back { ren.path_back(&p.path) } else { p.path.clone() },
|
if back {
|
||||||
|
ren.path_back(&p.path)
|
||||||
|
} else {
|
||||||
|
p.path.clone()
|
||||||
|
},
|
||||||
p.field.clone(),
|
p.field.clone(),
|
||||||
p.code.to_string(),
|
p.code.to_string(),
|
||||||
format!("{:?}", p.severity),
|
format!("{:?}", p.severity),
|
||||||
@@ -342,8 +347,10 @@ fn check_isomorphic(seed: u64) -> Result<(), TestCaseError> {
|
|||||||
(Place::Device(b.clone()), Place::Device(b1.clone())),
|
(Place::Device(b.clone()), Place::Device(b1.clone())),
|
||||||
(Place::Exit(b.clone()), Place::Exit(b1)),
|
(Place::Exit(b.clone()), Place::Exit(b1)),
|
||||||
] {
|
] {
|
||||||
let w0: BTreeSet<String> =
|
let w0: BTreeSet<String> = roads::explain(&c0, d0, a, &p0)
|
||||||
roads::explain(&c0, d0, a, &p0).iter().map(|r| r.to_string()).collect();
|
.iter()
|
||||||
|
.map(|r| r.to_string())
|
||||||
|
.collect();
|
||||||
let w1: BTreeSet<String> = roads::explain(&c1, d1, &a1, &p1)
|
let w1: BTreeSet<String> = roads::explain(&c1, d1, &a1, &p1)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|r| ren.to_old[r.as_str()].clone())
|
.map(|r| ren.to_old[r.as_str()].clone())
|
||||||
@@ -363,11 +370,19 @@ fn the_extra_roads_reach_the_order_sensitive_paths() {
|
|||||||
assert!(codes.contains("exit.conflict"), "{codes:?}");
|
assert!(codes.contains("exit.conflict"), "{codes:?}");
|
||||||
let mark = &c.plans[&key(1)];
|
let mark = &c.plans[&key(1)];
|
||||||
assert!(mark.exit.is_none(), "two exits: neither");
|
assert!(mark.exit.is_none(), "two exits: neither");
|
||||||
assert_eq!(mark.kill_switch.as_ref().unwrap().through, None, "two kill switches: no exit");
|
assert_eq!(
|
||||||
|
mark.kill_switch.as_ref().unwrap().through,
|
||||||
|
None,
|
||||||
|
"two kill switches: no exit"
|
||||||
|
);
|
||||||
let jana_phone = &c.plans[&key(3)];
|
let jana_phone = &c.plans[&key(3)];
|
||||||
let server = jana_phone.peers.iter().find(|p| p.key == key(2)).unwrap();
|
let server = jana_phone.peers.iter().find(|p| p.key == key(2)).unwrap();
|
||||||
assert_eq!(server.via, None, "two different path hints: none");
|
assert_eq!(server.via, None, "two different path hints: none");
|
||||||
assert!(c.errors().next().is_none(), "{:?}", c.errors().collect::<Vec<_>>());
|
assert!(
|
||||||
|
c.errors().next().is_none(),
|
||||||
|
"{:?}",
|
||||||
|
c.errors().collect::<Vec<_>>()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -378,7 +393,10 @@ fn the_identity_renaming_changes_nothing() {
|
|||||||
to_new: BTreeMap::new(),
|
to_new: BTreeMap::new(),
|
||||||
to_old: BTreeMap::new(),
|
to_old: BTreeMap::new(),
|
||||||
};
|
};
|
||||||
assert_eq!(common::plans_bytes(&compile(&store_of(&ren.apply(&parts)), now())), before);
|
assert_eq!(
|
||||||
|
common::plans_bytes(&compile(&store_of(&ren.apply(&parts)), now())),
|
||||||
|
before
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
|
|||||||
+3
-1
@@ -2,6 +2,8 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-changed=win_sections.c");
|
println!("cargo:rerun-if-changed=win_sections.c");
|
||||||
if std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
|
if std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
|
||||||
cc::Build::new().file("win_sections.c").compile("win_sections");
|
cc::Build::new()
|
||||||
|
.file("win_sections.c")
|
||||||
|
.compile("win_sections");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,14 @@ fn plans_json(store: &Store) -> (Vec<String>, roads::Compiled) {
|
|||||||
|
|
||||||
fn baseline() -> &'static Vec<String> {
|
fn baseline() -> &'static Vec<String> {
|
||||||
static B: OnceLock<Vec<String>> = OnceLock::new();
|
static B: OnceLock<Vec<String>> = OnceLock::new();
|
||||||
B.get_or_init(|| plans_json(&Store::from_parts(&files(None), Some(DIRECTORY), Some(DEVICES))).0)
|
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`.
|
/// The id the file claims, so the file name can match it and the fuzzer reaches past `id.file-name`.
|
||||||
@@ -101,8 +108,30 @@ fuzz_target!(|data: &[u8]| {
|
|||||||
};
|
};
|
||||||
assert_eq!(again.render(), text, "render is not a fixed point");
|
assert_eq!(again.render(), text, "render is not a fixed point");
|
||||||
assert_eq!(
|
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),
|
&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}"
|
"the canonical text means something else:\n{text}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user