write the remaining test fake executables from a child process
This commit is contained in:
parent
41f832458e
commit
d452da09ae
1 changed files with 80 additions and 23 deletions
|
|
@ -626,23 +626,38 @@ mod tests {
|
|||
let _ = std::fs::remove_dir_all(config.users_file.parent().unwrap());
|
||||
}
|
||||
|
||||
/// 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());
|
||||
}
|
||||
|
||||
/// `handle` waits for the `flock` `swarmctl` takes, not only for the
|
||||
/// in-process lock: it is held here while `handle` runs with a lock of
|
||||
/// its own that nothing contends.
|
||||
#[tokio::test]
|
||||
async fn an_identity_request_waits_for_the_users_file_lock() {
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
use std::time::Duration;
|
||||
|
||||
let mut config = config_with_one_operator();
|
||||
let dir = config.users_file.parent().unwrap().to_owned();
|
||||
let authelia = dir.join("authelia");
|
||||
std::fs::write(
|
||||
write_executable(
|
||||
&authelia,
|
||||
"#!/bin/sh\nprintf 'Random Password: pw\\nDigest: $argon2id$x\\n'\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::set_permissions(&authelia, std::fs::Permissions::from_mode(0o755)).unwrap();
|
||||
);
|
||||
config.authelia_bin = authelia;
|
||||
|
||||
let held = crate::store::lock_users_file(&config.users_file, Duration::from_secs(1))
|
||||
|
|
|
|||
Loading…
Reference in a new issue