use super::*;
#[test]
fn every_door_in_the_roster_has_an_answer_with_three_parts() {
for door in DOORS {
let answered = conformance::sample(door)
.unwrap_or_else(|door| panic!("{}: the sample allowed", door.as_str()));
let error = match &answered {
GateOutcome::Allow => panic!("{}: the sample allowed", door.as_str()),
GateOutcome::Deny { refusal } | GateOutcome::Ask { question: refusal } => refusal,
};
let parts = error
.gate()
.unwrap_or_else(|| panic!("{}: answer without the three parts", door.as_str()));
assert!(!parts.rule().is_empty(), "{}: empty rule", door.as_str());
assert!(
!parts.violation().is_empty(),
"{}: empty violation",
door.as_str()
);
assert!(
parts.alternative().len() > 12,
"{}: the alternative must direct the next action",
door.as_str()
);
}
}
#[test]
fn the_roster_holds_every_door_exactly_once() {
let mut names: Vec<&str> = DOORS.iter().map(|door| door.as_str()).collect();
let before = names.len();
names.sort_unstable();
names.dedup();
assert_eq!(names.len(), before, "a door is listed twice");
let mut all: Vec<DoorId> = DOORS.to_vec();
all.sort_unstable();
all.dedup();
assert_eq!(all.len(), before);
}
#[test]
fn the_doors_that_see_taint_refuse_on_it() {
for (door, denies) in conformance::taint_readers() {
assert!(
denies,
"{}: taint changed no verdict, so C15 is a false branch there",
door.as_str()
);
}
}
#[test]
fn the_attach_door_asks_then_allows_loopback_then_refuses_a_network() {
assert!(matches!(super::attach(None), GateOutcome::Ask { .. }));
assert!(matches!(
super::attach(Some(&super::EgressTarget::Loopback)),
GateOutcome::Allow
));
assert!(matches!(
super::attach(Some(&super::EgressTarget::Public {
host: "example.com".to_owned()
})),
GateOutcome::Deny { .. }
));
}