Watch
0
0
Fork
You've already forked hyperhive
0

write the remaining test fake executables from a child process

This commit is contained in:
atlas 2026-10-28 12:49:30 +01:00
commit d452da09ae

View file

@ -1573,6 +1573,24 @@ mod tests {
fs::remove_dir_all(&dir).ok();
}
/// Write the script `body` to `path` as an executable, from a child process
/// rather than from this one: a write fd on it held here could be inherited
/// by a child another test thread forks, and exec'ing a file some process
/// still holds open for writing fails with `ETXTBSY`.
fn write_executable(path: &std::path::Path, body: &str) {
let status = std::process::Command::new("/bin/sh")
.args([
"-c",
r#"printf '%s' "$1" > "$2" && chmod 755 "$2""#,
"sh",
body,
])
.arg(path)
.status()
.expect("run /bin/sh");
assert!(status.success(), "writing {} failed", path.display());
}
/// A scratch directory holding a `users.yml` with one user, `carol`, and
/// a stand-in `authelia` that takes `delay` seconds to mint a password.
fn locked_users_fixture(tag: &str, delay: &str) -> Paths {
@ -1580,14 +1598,12 @@ mod tests {
let _ = fs::remove_dir_all(&dir);
fs::create_dir_all(&dir).expect("temp dir");
let authelia_bin = dir.join("authelia");
fs::write(
write_executable(
&authelia_bin,
format!(
&format!(
"#!/bin/sh\nsleep {delay}\nprintf 'Random Password: pw\\nDigest: $argon2id$x\\n'\n"
),
)
.expect("fake authelia");
fs::set_permissions(&authelia_bin, Permissions::from_mode(0o755)).expect("chmod");
);
let users_file = dir.join("users.yml");
fs::write(
&users_file,