summaryrefslogtreecommitdiff
path: root/tests/cp/cp-a-selinux.sh
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-01-13 03:30:33 +0000
committerPádraig Brady <P@draigBrady.com>2015-01-14 12:20:32 +0000
commit58cff8a009ed9b8280c5f35074cef97231286023 (patch)
tree771e8b3fa70fab99b548790931803b75dd272603 /tests/cp/cp-a-selinux.sh
parent924b1cadff3f2782475516d7eca9aabe856dbf0f (diff)
downloadcoreutils-58cff8a009ed9b8280c5f35074cef97231286023.tar.xz
tests: add extra protection against unexpected exits
Many tests use `program ... && fail=1` to ensure expected error situations are indicated. However that would mask an unexpected exit (like a crash). Therefore explicitly check the expected exit code. Note where error messages are also verified, the extra protection is not added. * tests/init.sh (returns_): A new helper function to check the return code of a command, and used throughout the tests. * cfg.mk (sc_prohibit_and_fail_1): Add a syntax check to avoid new instances of this issue.
Diffstat (limited to 'tests/cp/cp-a-selinux.sh')
-rwxr-xr-xtests/cp/cp-a-selinux.sh15
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/cp/cp-a-selinux.sh b/tests/cp/cp-a-selinux.sh
index 2ecbd2386..d000ee8f1 100755
--- a/tests/cp/cp-a-selinux.sh
+++ b/tests/cp/cp-a-selinux.sh
@@ -49,14 +49,16 @@ rm -f f
# in the destination, so SELinux contexts should be updated too.
chmod o+rw restore/existing_dir
mkdir -p backup/existing_dir/ || framework_failure_
-ls -Zd backup/existing_dir | grep $ctx && framework_failure_
+ls -Zd backup/existing_dir > ed_ctx || fail=1
+grep $ctx ed_ctx && framework_failure_
touch backup/existing_dir/file || framework_failure_
chcon $ctx backup/existing_dir/file || framework_failure_
# Set the dir context to ensure it is reset
mkdir -p --context="$ctx" restore/existing_dir || framework_failure_
# Copy and ensure existing directories updated
cp -a backup/. restore/
-ls -Zd restore/existing_dir | grep $ctx &&
+ls -Zd restore/existing_dir > ed_ctx || fail=1
+grep $ctx ed_ctx &&
{ ls -lZd restore/existing_dir; fail=1; }
# Check restorecon (-Z) functionality for file and directory
@@ -175,6 +177,7 @@ for no_g_cmd in '' 'rm -f g'; do
# restorecon equivalent. Note even though the context
# returned from matchpathcon() will not match $ctx
# the resulting ENOTSUP warning will be suppressed.
+
# With absolute path
$no_g_cmd
cp -Z ../f $(realpath g) || fail=1
@@ -186,7 +189,7 @@ for no_g_cmd in '' 'rm -f g'; do
cp -Z -a ../f g || fail=1
# -Z doesn't take an arg
$no_g_cmd
- cp -Z "$ctx" ../f g && fail=1
+ returns_ 1 cp -Z "$ctx" ../f g || fail=1
# Explicit context
$no_g_cmd
@@ -198,8 +201,8 @@ for no_g_cmd in '' 'rm -f g'; do
done
# Mutually exclusive options
-cp -Z --preserve=context ../f g && fail=1
-cp --preserve=context -Z ../f g && fail=1
-cp --preserve=context --context="$ctx" ../f g && fail=1
+returns_ 1 cp -Z --preserve=context ../f g || fail=1
+returns_ 1 cp --preserve=context -Z ../f g || fail=1
+returns_ 1 cp --preserve=context --context="$ctx" ../f g || fail=1
Exit $fail