diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2024-03-02 01:10:47 +0100 |
---|---|---|
committer | Sylvestre Ledru <sylvestre@debian.org> | 2024-03-09 22:52:55 +0100 |
commit | dbfd4d80eeb2828406ce8bf7bad6285f2776968b (patch) | |
tree | 7589627110ee96aa7f3b23673470184da04c7746 | |
parent | 6c29ed037bb727b43eed66d963c8f64b93641780 (diff) |
chcon: allow overriding between --dereference and --no-dereference
-rw-r--r-- | src/uu/chcon/src/chcon.rs | 2 | ||||
-rw-r--r-- | tests/by-util/test_chcon.rs | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index ec111c853..ddbaec98b 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -163,7 +163,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::dereference::DEREFERENCE) .long(options::dereference::DEREFERENCE) - .conflicts_with(options::dereference::NO_DEREFERENCE) + .overrides_with(options::dereference::NO_DEREFERENCE) .help( "Affect the referent of each symbolic link (this is the default), \ rather than the symbolic link itself.", diff --git a/tests/by-util/test_chcon.rs b/tests/by-util/test_chcon.rs index 71405e451..b28996b2b 100644 --- a/tests/by-util/test_chcon.rs +++ b/tests/by-util/test_chcon.rs @@ -89,6 +89,33 @@ fn valid_context_on_valid_symlink() { } #[test] +fn valid_context_on_valid_symlink_override_dereference() { + let (dir, mut cmd) = at_and_ucmd!(); + dir.touch("a.tmp"); + dir.symlink_file("a.tmp", "la.tmp"); + + let a_context = get_file_context(dir.plus("a.tmp")).unwrap(); + let la_context = get_file_context(dir.plus("la.tmp")).unwrap(); + let new_a_context = "guest_u:object_r:etc_t:s0:c42"; + assert_ne!(a_context.as_deref(), Some(new_a_context)); + assert_ne!(la_context.as_deref(), Some(new_a_context)); + + cmd.args(&[ + "--verbose", + "--no-dereference", + "--dereference", + new_a_context, + ]) + .arg(dir.plus("la.tmp")) + .succeeds(); + assert_eq!( + get_file_context(dir.plus("a.tmp")).unwrap().as_deref(), + Some(new_a_context) + ); + assert_eq!(get_file_context(dir.plus("la.tmp")).unwrap(), la_context); +} + +#[test] fn valid_context_on_broken_symlink() { let (dir, mut cmd) = at_and_ucmd!(); dir.symlink_file("a.tmp", "la.tmp"); @@ -105,6 +132,29 @@ fn valid_context_on_broken_symlink() { } #[test] +fn valid_context_on_broken_symlink_after_deref() { + let (dir, mut cmd) = at_and_ucmd!(); + dir.symlink_file("a.tmp", "la.tmp"); + + let la_context = get_file_context(dir.plus("la.tmp")).unwrap(); + let new_la_context = "guest_u:object_r:etc_t:s0:c42"; + assert_ne!(la_context.as_deref(), Some(new_la_context)); + + cmd.args(&[ + "--verbose", + "--dereference", + "--no-dereference", + new_la_context, + ]) + .arg(dir.plus("la.tmp")) + .succeeds(); + assert_eq!( + get_file_context(dir.plus("la.tmp")).unwrap().as_deref(), + Some(new_la_context) + ); +} + +#[test] fn valid_context_with_prior_xattributes() { let (dir, mut cmd) = at_and_ucmd!(); dir.touch("a.tmp"); |