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();