]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: ls: also test security context output for symlinks
authorPádraig Brady <P@draigBrady.com>
Tue, 12 Nov 2024 11:34:07 +0000 (11:34 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 12 Nov 2024 11:43:45 +0000 (11:43 +0000)
* tests/ls/selinux.sh: Test symlinks as well as files.

tests/ls/selinux.sh

index 7b3ad6af32ce31831ed315363add0a9cdd9bf774..364e32d9b9fb3ef28b4f5a9dc71707ccc3c47a5e 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Test selinux output
+# Test ls SELinux file context output
 
 # Copyright (C) 2024 Free Software Foundation, Inc.
 
 print_ver_ ls
 require_selinux_
 
-touch f || framework_failure_
-case $(stat --printf='%C' f) in
+touch file || framework_failure_
+ln -s file link || framework_failure_
+
+case $(stat --printf='%C' file) in
   *:*:*:*) ;;
   *) skip_ 'unable to match default security context';;
 esac
 
-# ensure that ls -l output includes the "."
-test "$(ls -l f|cut -c11)" = . || fail=1
+for f in file link; do
 
-# ensure that ls -lZ output includes context
-ls_output=$(LC_ALL=C ls -lnZ f) || fail=1
-set x $ls_output
-case $6 in
-  *:*:*:*) ;;
-  *) fail=1 ;;
-esac
+  # ensure that ls -l output includes the "."
+  test "$(ls -l $f | cut -c11)" = . || fail=1
+
+  # ensure that ls -lZ output includes context
+  ls_output=$(LC_ALL=C ls -lnZ "$f") || fail=1
+  set x $ls_output
+  case $6 in
+    *:*:*:*) ;;
+    *) fail=1 ;;
+  esac
+done
 
 Exit $fail