[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:
@@ -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..]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,17 +386,24 @@ mod unix {
|
||||
r["commit"].as_str().unwrap().to_owned(),
|
||||
));
|
||||
}
|
||||
// One after another: each starts after the previous finished, and each commit's
|
||||
// parent is the previous commit (a linear history, nothing lost).
|
||||
spans.sort();
|
||||
for w in spans.windows(2) {
|
||||
assert!(w[1].0 >= w[0].1, "overlap: {w:?}");
|
||||
assert_eq!(
|
||||
env.git(&["rev-parse", &format!("{}^", w[1].2)]),
|
||||
w[0].2,
|
||||
"linear"
|
||||
);
|
||||
// One after another: the five commits form one linear chain at the head (nothing
|
||||
// lost, nothing interleaved). Timestamps have one-second resolution, so they are not
|
||||
// compared.
|
||||
let commits: Vec<String> = spans.iter().map(|s| s.2.clone()).collect();
|
||||
let mut chain = Vec::new();
|
||||
let mut c = env.head();
|
||||
for _ in 0..commits.len() {
|
||||
chain.push(c.clone());
|
||||
c = env.git(&["rev-parse", &format!("{c}^")]);
|
||||
}
|
||||
let mut sorted_chain = chain.clone();
|
||||
sorted_chain.sort();
|
||||
let mut sorted_commits = commits.clone();
|
||||
sorted_commits.sort();
|
||||
assert_eq!(
|
||||
sorted_chain, sorted_commits,
|
||||
"a linear chain of the five commits"
|
||||
);
|
||||
let files = env.head_files();
|
||||
for n in names {
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user