From ba9b61fcf3b2d613be8ce064be4c67817a08dd66 Mon Sep 17 00:00:00 2001 From: Austin Schaefer Date: Wed, 19 Aug 2026 17:34:29 +0200 Subject: [PATCH] fix: skip chmod-0o000 permission tests when running as root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/documents.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/documents.rs b/src/documents.rs index dc51a9e..24c5090 100644 --- a/src/documents.rs +++ b/src/documents.rs @@ -237,11 +237,29 @@ mod tests { 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)] #[test] fn collect_documents_skips_an_unreadable_file_inside_a_directory_but_keeps_the_rest() { 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 readable = dir.path().join("readable.txt"); let unreadable = dir.path().join("unreadable.txt"); @@ -263,6 +281,11 @@ mod tests { fn collect_documents_fails_outright_on_an_unreadable_directory() { 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(); std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o000)).unwrap();