mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fix(tests): refine feature checks for SELinux
This commit is contained in:
committed by
Daniel Hofstetter
parent
fb8e4b1612
commit
7449705a98
@@ -4,7 +4,10 @@
|
||||
// file that was distributed with this source code.
|
||||
// spell-checker:ignore (jargon) xattributes
|
||||
#![allow(clippy::missing_errors_doc, clippy::similar_names)]
|
||||
#![cfg(feature = "feat_selinux")]
|
||||
#![cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::path::Path;
|
||||
|
||||
+40
-10
@@ -8,7 +8,10 @@
|
||||
#[cfg(unix)]
|
||||
use rstest::rstest;
|
||||
use uucore::display::Quotable;
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
use uucore::selinux::get_getfattr_output;
|
||||
use uutests::util::TestScenario;
|
||||
use uutests::{at_and_ucmd, new_ucmd, path_concat, util_name};
|
||||
@@ -6771,7 +6774,10 @@ fn test_cp_from_stream_permission() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_selinux() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
@@ -6820,7 +6826,10 @@ fn test_cp_selinux_invalid() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_preserve_selinux() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
@@ -6858,7 +6867,10 @@ fn test_cp_preserve_selinux() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_preserve_selinux_admin_context() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
@@ -6917,7 +6929,10 @@ fn test_cp_preserve_selinux_admin_context() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_selinux_context_priority() {
|
||||
// This test verifies that -Z takes priority over --context
|
||||
|
||||
@@ -6997,7 +7012,10 @@ fn test_cp_selinux_context_priority() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_selinux_empty_context() {
|
||||
// This test verifies that --context without a value works like -Z
|
||||
|
||||
@@ -7043,7 +7061,10 @@ fn test_cp_selinux_empty_context() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_selinux_recursive() {
|
||||
// Test SELinux context preservation in recursive directory copies
|
||||
|
||||
@@ -7097,7 +7118,10 @@ fn test_cp_selinux_recursive() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_preserve_context_root() {
|
||||
use uutests::util::run_ucmd_as_root;
|
||||
let scene = TestScenario::new(util_name!());
|
||||
@@ -7800,7 +7824,10 @@ fn test_cp_gnu_preserve_mode() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_a_z_overrides_context() {
|
||||
// Verifies -aZ succeeds (-Z overrides implicit --preserve=context from -a)
|
||||
use std::path::Path;
|
||||
@@ -7818,7 +7845,10 @@ fn test_cp_a_z_overrides_context() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_cp_a_preserves_context() {
|
||||
use std::path::Path;
|
||||
use uucore::selinux::{get_selinux_security_context, set_selinux_security_context};
|
||||
|
||||
@@ -383,7 +383,10 @@ fn test_id_zero() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_id_context() {
|
||||
if !uucore::selinux::is_selinux_enabled() {
|
||||
println!("test skipped: Kernel has no support for SElinux context");
|
||||
|
||||
@@ -15,7 +15,10 @@ use std::process;
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use std::thread::sleep;
|
||||
use uucore::process::{getegid, geteuid};
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
use uucore::selinux::get_getfattr_output;
|
||||
use uutests::at_and_ucmd;
|
||||
use uutests::new_ucmd;
|
||||
@@ -2334,7 +2337,10 @@ fn test_install_no_target_basic() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_selinux() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
@@ -2383,7 +2389,10 @@ fn test_selinux() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_selinux_invalid_args() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
@@ -2416,7 +2425,10 @@ fn test_selinux_invalid_args() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_selinux_default_context() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
@@ -4654,7 +4654,10 @@ fn test_ls_dangling_symlinks() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_ls_context1() {
|
||||
if !uucore::selinux::is_selinux_enabled() {
|
||||
println!("test skipped: Kernel has no support for SElinux context");
|
||||
@@ -4669,7 +4672,10 @@ fn test_ls_context1() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_ls_context2() {
|
||||
if !uucore::selinux::is_selinux_enabled() {
|
||||
println!("test skipped: Kernel has no support for SElinux context");
|
||||
@@ -4685,7 +4691,10 @@ fn test_ls_context2() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_ls_context_long() {
|
||||
if !uucore::selinux::is_selinux_enabled() {
|
||||
return;
|
||||
@@ -4704,7 +4713,10 @@ fn test_ls_context_long() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_ls_context_format() {
|
||||
if !uucore::selinux::is_selinux_enabled() {
|
||||
println!("test skipped: Kernel has no support for SElinux context");
|
||||
@@ -4734,7 +4746,10 @@ fn test_ls_context_format() {
|
||||
}
|
||||
|
||||
/// Helper function to validate `SELinux` context format
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn validate_selinux_context(context: &str) {
|
||||
assert!(
|
||||
context.contains(':'),
|
||||
@@ -4749,7 +4764,10 @@ fn validate_selinux_context(context: &str) {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_ls_selinux_context_format() {
|
||||
if !uucore::selinux::is_selinux_enabled() {
|
||||
println!("test skipped: Kernel has no support for SElinux context");
|
||||
@@ -4782,7 +4800,10 @@ fn test_ls_selinux_context_format() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_ls_selinux_context_indicator() {
|
||||
if !uucore::selinux::is_selinux_enabled() {
|
||||
println!("test skipped: Kernel has no support for SElinux context");
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
use libc::mode_t;
|
||||
#[cfg(not(windows))]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
use uucore::selinux::get_getfattr_output;
|
||||
#[cfg(not(windows))]
|
||||
use uutests::at_and_ucmd;
|
||||
@@ -449,7 +452,10 @@ fn test_empty_argument() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_selinux() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
@@ -473,7 +479,10 @@ fn test_selinux() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_selinux_invalid() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
|
||||
// spell-checker:ignore nconfined
|
||||
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
use uucore::selinux::get_getfattr_output;
|
||||
use uutests::new_ucmd;
|
||||
use uutests::util::TestScenario;
|
||||
@@ -167,7 +170,10 @@ fn test_create_fifo_permission_denied() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_mkfifo_selinux() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
@@ -191,7 +197,10 @@ fn test_mkfifo_selinux() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_mkfifo_selinux_invalid() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
use uucore::selinux::get_getfattr_output;
|
||||
use uutests::new_ucmd;
|
||||
use uutests::util::TestScenario;
|
||||
@@ -184,7 +187,10 @@ fn test_mknod_mode_comma_separated() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_mknod_selinux() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
@@ -215,7 +221,10 @@ fn test_mknod_selinux() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_mknod_selinux_invalid() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
@@ -242,7 +251,10 @@ fn test_mknod_selinux_invalid() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_mknod_selinux_invalid_cleanup() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
@@ -10,7 +10,10 @@ use rstest::rstest;
|
||||
use std::io::Write;
|
||||
#[cfg(not(windows))]
|
||||
use std::path::Path;
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
use uucore::selinux::get_getfattr_output;
|
||||
use uutests::new_ucmd;
|
||||
#[cfg(unix)]
|
||||
@@ -2617,7 +2620,10 @@ fn test_mv_cross_device_permission_denied() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_mv_selinux_context() {
|
||||
let test_cases = [
|
||||
("-Z", None),
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
// file that was distributed with this source code.
|
||||
// spell-checker:ignore (jargon) xattributes
|
||||
|
||||
#![cfg(feature = "feat_selinux")]
|
||||
#![cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
|
||||
use uutests::new_ucmd;
|
||||
|
||||
@@ -84,7 +87,10 @@ fn invalid() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn plain_context() {
|
||||
let ctx = "unconfined_u:unconfined_r:unconfined_t:s0-s0";
|
||||
new_ucmd!().args(&[ctx, "/bin/true"]).succeeds();
|
||||
@@ -103,7 +109,10 @@ fn plain_context() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn custom_context() {
|
||||
let t_ud = "unconfined_t";
|
||||
let u_ud = "unconfined_u";
|
||||
|
||||
@@ -550,7 +550,10 @@ fn test_printf_invalid_directive() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
#[cfg(all(
|
||||
feature = "feat_selinux",
|
||||
any(target_os = "linux", target_os = "android")
|
||||
))]
|
||||
fn test_stat_selinux() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
Reference in New Issue
Block a user