fix: skip chmod-0o000 permission tests when running as root
All checks were successful
CI / test (pull_request) Successful in 1m22s

CI runs the test suite as root inside an unmodified Docker base image
(data.forgejo.org/oci/node:20-bookworm), where chmod 0o000 doesn't
actually block reads — root bypasses Unix permission bits entirely.
The two new permission-based tests from the previous commit passed
locally (non-root) but failed in CI for exactly that reason. Skip them
under root via a raw geteuid() FFI check instead of asserting behavior
the OS isn't enforcing.

Verified with cargo build/test (34 passed)/clippy -D warnings/fmt --check.
This commit is contained in:
Austin Schaefer 2026-08-19 17:34:29 +02:00
parent f916787962
commit ba9b61fcf3

View file

@ -237,11 +237,29 @@ mod tests {
assert_eq!(documents[1].text, "scanned"); assert_eq!(documents[1].text, "scanned");
} }
/// Unix permission bits are meaningless to a root process — it can read
/// anything regardless of mode — so the two `chmod 0o000` tests below
/// would fail under a root-run CI container (e.g. an unmodified Docker
/// base image) despite the code being correct. Skip rather than assert
/// behavior the OS isn't actually enforcing.
#[cfg(unix)]
fn running_as_root() -> bool {
unsafe extern "C" {
fn geteuid() -> u32;
}
unsafe { geteuid() == 0 }
}
#[cfg(unix)] #[cfg(unix)]
#[test] #[test]
fn collect_documents_skips_an_unreadable_file_inside_a_directory_but_keeps_the_rest() { fn collect_documents_skips_an_unreadable_file_inside_a_directory_but_keeps_the_rest() {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
if running_as_root() {
eprintln!("skipping: running as root, chmod 0o000 has no effect");
return;
}
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();
let readable = dir.path().join("readable.txt"); let readable = dir.path().join("readable.txt");
let unreadable = dir.path().join("unreadable.txt"); let unreadable = dir.path().join("unreadable.txt");
@ -263,6 +281,11 @@ mod tests {
fn collect_documents_fails_outright_on_an_unreadable_directory() { fn collect_documents_fails_outright_on_an_unreadable_directory() {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
if running_as_root() {
eprintln!("skipping: running as root, chmod 0o000 has no effect");
return;
}
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();
std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o000)).unwrap(); std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o000)).unwrap();