[control] QC minors: device install links open a page and download on POST (never listed), approve and install failures show on the request and the CLI waits, PBKDF2 floor, private pki dirs or an error, trusted_proxies for a proxy in front, a placeholder keeps the device allow list from being empty (Caddy refuses that)
This commit is contained in:
@@ -115,6 +115,7 @@ impl Env {
|
||||
caddy_credentials_dir: dir.str("creds"),
|
||||
caddy_admin: None,
|
||||
caddy_admin_socket: None,
|
||||
trusted_proxies: Vec::new(),
|
||||
};
|
||||
// Edge starts from an empty config; control brings it in line on its first start.
|
||||
let empty = load(
|
||||
|
||||
@@ -35,6 +35,15 @@ mod unix {
|
||||
|
||||
const PASSWORD: &str = "intermediate-test-password-123";
|
||||
|
||||
/// Whether an allow list names any device (the placeholder that keeps it from being
|
||||
/// empty is not one).
|
||||
fn lists_a_device(allow: &str) -> bool {
|
||||
pki::chain_der(allow)
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.any(|d| pki::inspect_der(d).is_ok_and(|i| i.subject_cn != pki::NO_DEVICE_CN))
|
||||
}
|
||||
|
||||
fn now() -> i64 {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
@@ -341,7 +350,7 @@ mod unix {
|
||||
|
||||
// The allow list both engines read has it.
|
||||
let allow = std::fs::read_to_string(env.dir.join("certs/domi-devices.pem")).unwrap();
|
||||
assert!(allow.contains("BEGIN CERTIFICATE"));
|
||||
assert!(lists_a_device(&allow));
|
||||
|
||||
// One-time install file.
|
||||
let b = env
|
||||
@@ -359,8 +368,16 @@ mod unix {
|
||||
.split_once("/api/v1/")
|
||||
.map(|(_, p)| format!("/api/v1/{p}"))
|
||||
.unwrap();
|
||||
// Opening the link (GET, as a link preview or prefetcher would) shows a page and
|
||||
// uses nothing up; its button posts.
|
||||
for _ in 0..2 {
|
||||
let g = env.call_with("GET", &path, &[], None).await;
|
||||
assert_eq!(g.status, 200, "{}", g.text);
|
||||
assert!(g.text.contains("<form method=\"post\">"), "{}", g.text);
|
||||
assert!(g.text.contains("Mark's phone"), "{}", g.text);
|
||||
}
|
||||
// No token needed for the download itself (the link is the secret) ...
|
||||
let d = env.call_with("GET", &path, &[], None).await;
|
||||
let d = env.call_with("POST", &path, &[], None).await;
|
||||
assert_eq!(d.status, 200, "{}", d.text);
|
||||
assert_eq!(d.header("content-type"), Some("application/x-pkcs12"));
|
||||
let ks = p12_keystore::KeyStore::from_pkcs12(
|
||||
@@ -372,9 +389,11 @@ mod unix {
|
||||
let (_, chain) = ks.private_key_chain().unwrap();
|
||||
assert_eq!(chain.certs().len(), 3, "leaf, intermediate, root");
|
||||
// ... and it works only once.
|
||||
let d = env.call_with("GET", &path, &[], None).await;
|
||||
let d = env.call_with("POST", &path, &[], None).await;
|
||||
assert_eq!(d.status, 410, "{}", d.text);
|
||||
assert_eq!(d.json["error"]["code"], "pki.bundle_used");
|
||||
let g = env.call_with("GET", &path, &[], None).await;
|
||||
assert_eq!(g.status, 410, "{}", g.text);
|
||||
|
||||
// Revoke: off the allow list, no new install file.
|
||||
let r = env
|
||||
@@ -382,7 +401,11 @@ mod unix {
|
||||
.await;
|
||||
assert_eq!(r.status, 204, "{}", r.text);
|
||||
let allow = std::fs::read_to_string(env.dir.join("certs/domi-devices.pem")).unwrap();
|
||||
assert!(!allow.contains("BEGIN CERTIFICATE"), "{allow}");
|
||||
assert!(!lists_a_device(&allow), "{allow}");
|
||||
assert!(
|
||||
allow.contains("BEGIN CERTIFICATE"),
|
||||
"never empty (Caddy refuses that)"
|
||||
);
|
||||
let b = env
|
||||
.call(
|
||||
"POST",
|
||||
@@ -698,11 +721,7 @@ mod unix {
|
||||
let done = wait_request(&env, &rid, "approved").await;
|
||||
let did = done["device_id"].as_str().unwrap().to_owned();
|
||||
let allow_file = env.dir.join("certs/domi-devices.pem");
|
||||
let on_list = || {
|
||||
std::fs::read_to_string(&allow_file)
|
||||
.unwrap_or_default()
|
||||
.contains("BEGIN CERTIFICATE")
|
||||
};
|
||||
let on_list = || lists_a_device(&std::fs::read_to_string(&allow_file).unwrap_or_default());
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
while !on_list() {
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user