[control] API fixes: atomic Idempotency-Key reservation, no echo of odd field names or path parameters, askpass answers only password prompts, file protocol not forced, token test split on the known prefix, serialisation test without second-resolution times

This commit is contained in:
2026-11-07 18:57:54 +01:00
parent 54574702ea
commit f382fe2f76
7 changed files with 158 additions and 51 deletions
+22 -2
View File
@@ -202,7 +202,11 @@ mod unix {
}
everything.push_str(&env.file("edge/edge.json"));
everything.push_str(&env.git(&["log", "-p", "--all"]));
let secret_part = |t: &str| t.rsplit('_').next().unwrap().to_owned();
// `ian_<16 hex>_<secret>`; the secret itself may contain '_'.
let secret_part = |t: &str| {
assert!(t.starts_with("ian_") && t.as_bytes()[20] == b'_');
t[21..].to_owned()
};
for t in [&env.token, &revoked] {
assert!(
!everything.contains(secret_part(t).as_str()),
@@ -265,6 +269,22 @@ mod unix {
.await;
assert_eq!(r.status, 400, "{}", r.text);
assert!(!r.text.contains("secret-ish-value"), "{}", r.text);
// Nor do odd field names, path parameters or credentials in an upstream URL.
let r = env
.call("POST", "/api/v1/tokens", Some(json!({ "pass:hunter2": 1 })))
.await;
assert_eq!(r.status, 422, "{}", r.text);
assert!(!r.text.contains("hunter2"), "{}", r.text);
let r = env.call("GET", "/api/v1/hosts/x%3Chunter2%3E", None).await;
assert_eq!(r.status, 404, "{}", r.text);
assert!(!r.text.contains("hunter2"), "{}", r.text);
let mut leaky = host("a.test", "http://admin:hunter2@10.0.0.2:3000", false);
leaky["upstreams"] = json!(["http://admin:hunter2@10.0.0.2:3000", "ftp://u:hunter2@x"]);
let r = env
.call("POST", "/api/v1/hosts", Some(json!({ "host": leaky })))
.await;
assert_eq!(r.status, 422, "{}", r.text);
assert!(!r.text.contains("hunter2"), "{}", r.text);
// Not JSON, wrong content type, too large.
let raw = format!(
"POST /api/v1/hosts HTTP/1.1\r\nHost: {}\r\nAuthorization: {auth}\r\nContent-Type: application/json\r\nContent-Length: 5\r\nConnection: close\r\n\r\n{{{{{{{{{{",
@@ -518,6 +538,6 @@ mod unix {
.output()
.unwrap();
let text = String::from_utf8_lossy(&out.stdout);
assert!(text.contains("test") && !text.contains(env.token.rsplit('_').next().unwrap()));
assert!(text.contains("test") && !text.contains(&env.token[21..]));
}
}