#![allow(clippy::unwrap_used, clippy::expect_used)]
use super::*;
#[test]
fn no_readiness_is_viewer() {
assert_eq!(Capability::derive(Readiness::none()), Capability::Viewer);
}
#[test]
fn author_readiness_grants_author() {
let r = Readiness {
author: RoleReadiness::Unknown,
maintainer: RoleReadiness::NotReady,
read_only: false,
};
let cap = Capability::derive(r);
assert_eq!(cap, Capability::Author);
assert!(cap.may_author());
assert!(!cap.may_publish());
}
#[test]
fn maintainer_unknown_grants_maintainer_and_implies_author() {
let r = Readiness {
author: RoleReadiness::Unknown,
maintainer: RoleReadiness::Unknown,
read_only: false,
};
let cap = Capability::derive(r);
assert_eq!(cap, Capability::Maintainer);
assert!(cap.may_author());
assert!(cap.may_publish());
}
#[test]
fn maintainer_ready_grants_maintainer() {
let r = Readiness {
author: RoleReadiness::Unknown,
maintainer: RoleReadiness::Known(Binding::Matches),
read_only: false,
};
let cap = Capability::derive(r);
assert_eq!(cap, Capability::Maintainer);
assert!(cap.may_author());
assert!(cap.may_publish());
}
#[test]
fn maintainer_not_ready_without_author_is_viewer() {
let r = Readiness {
author: RoleReadiness::NotReady,
maintainer: RoleReadiness::NotReady,
read_only: false,
};
assert_eq!(Capability::derive(r), Capability::Viewer);
}
#[test]
fn read_only_collapses_everything_to_viewer() {
let r = Readiness {
author: RoleReadiness::Unknown,
maintainer: RoleReadiness::Unknown,
read_only: true,
};
let cap = Capability::derive(r);
assert_eq!(cap, Capability::Viewer);
assert!(!cap.may_author());
assert!(!cap.may_publish());
}
#[test]
fn operator_actions_are_available_regardless_of_signing_readiness() {
let no_keys = Readiness::none();
assert!(no_keys.may_operate());
let fully_ready = Readiness {
author: RoleReadiness::Unknown,
maintainer: RoleReadiness::Unknown,
read_only: false,
};
assert!(fully_ready.may_operate());
}
#[test]
fn read_only_locks_out_recovery_too() {
let read_only_no_keys = Readiness {
author: RoleReadiness::NotReady,
maintainer: RoleReadiness::NotReady,
read_only: true,
};
assert!(!read_only_no_keys.may_operate());
let read_only_fully_keyed = Readiness {
author: RoleReadiness::Unknown,
maintainer: RoleReadiness::Unknown,
read_only: true,
};
assert!(!read_only_fully_keyed.may_operate());
}
#[test]
fn readiness_holds_no_secret_only_flags() {
let r = Readiness::none();
assert_eq!(r.author, RoleReadiness::NotReady);
assert_eq!(r.maintainer, RoleReadiness::NotReady);
assert!(!r.read_only);
}
fn with(author: RoleReadiness, maintainer: RoleReadiness) -> Readiness {
Readiness {
author,
maintainer,
read_only: false,
}
}
#[test]
fn unknown_grants_where_unverifiable_withholds() {
assert!(RoleReadiness::Unknown.arms());
assert!(!RoleReadiness::Unverifiable.arms());
assert_eq!(
Capability::derive(with(RoleReadiness::Unknown, RoleReadiness::Unknown)),
Capability::Maintainer,
"RFC 016 Q1: offer the action and let prikk refuse — hiding seal from someone whose key is \
adopted is its own confident-but-wrong picture"
);
assert_eq!(
Capability::derive(with(
RoleReadiness::Unverifiable,
RoleReadiness::Unverifiable
)),
Capability::Viewer,
"prikk 0.40: stikk cannot see whether there is key material at all, so it offers nothing and \
says unknown — Q1(b)"
);
}
#[test]
fn each_binding_arms_or_withholds_for_its_own_reason() {
for (binding, arms, why) in [
(Binding::Matches, true, "prikk confirmed the key binds"),
(
Binding::Unrecorded,
true,
"prikk accepts a first signature and binds the id then",
),
(
Binding::NotAdopted,
false,
"prikk refuses the seal; offering it would be offering a failure",
),
(
Binding::Mismatch,
false,
"prikk refuses at signing time; the card says which two things disagree",
),
(
Binding::Absent,
false,
"no usable seed to bind, or no repository to ask",
),
] {
assert_eq!(
RoleReadiness::Known(binding).arms(),
arms,
"{binding:?}: {why}"
);
}
}
#[test]
fn a_mismatched_maintainer_key_does_not_reach_maintainer_capability() {
assert_eq!(
Capability::derive(with(
RoleReadiness::Known(Binding::Matches),
RoleReadiness::Known(Binding::Mismatch),
)),
Capability::Author,
"the author half still arms; the maintainer half must not"
);
}
#[test]
fn an_unadopted_maintainer_key_withholds_but_leaves_author_intact() {
assert_eq!(
Capability::derive(with(
RoleReadiness::Known(Binding::Unrecorded),
RoleReadiness::Known(Binding::NotAdopted),
)),
Capability::Author
);
}
#[test]
fn read_only_still_overrides_a_perfectly_bound_pair() {
let readiness = Readiness {
author: RoleReadiness::Known(Binding::Matches),
maintainer: RoleReadiness::Known(Binding::Matches),
read_only: true,
};
assert_eq!(Capability::derive(readiness), Capability::Viewer);
assert!(!readiness.may_operate());
}