Hello,
as requested via IRC, adding separate test cases for patches added
previously in that thread. It should check correct diagnostics for
SELinux context/xattrs on filesystem without xattr/SELinux
support(fat32).

Greetings,
         Ondřej
From e6d3f340ad40635425a63a2edceb7c4a833e048e Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <ova...@redhat.com>
Date: Mon, 27 Apr 2009 17:20:23 +0200
Subject: [PATCH] tests: add tests for xattr diagnostics on file system without xattr support

* tests/Makefile.am: add new root-only test
* tests/cp/cp-mv-enotsup-xattr: check if xattr diagnostics are displayed
 correctly on filesystem without xattr support
---
 tests/Makefile.am            |    1 +
 tests/cp/cp-mv-enotsup-xattr |   90 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100755 tests/cp/cp-mv-enotsup-xattr

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3a15a87..5591331 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,7 @@ root_tests =					\
   cp/cp-a-selinux				\
   cp/preserve-gid				\
   cp/special-bits				\
+  cp/cp-mv-enotsup-xattr				\
   dd/skip-seek-past-dev				\
   install/install-C-root			\
   ls/capability					\
diff --git a/tests/cp/cp-mv-enotsup-xattr b/tests/cp/cp-mv-enotsup-xattr
new file mode 100755
index 0000000..d7f15d7
--- /dev/null
+++ b/tests/cp/cp-mv-enotsup-xattr
@@ -0,0 +1,90 @@
+#!/bin/sh
+# Ensure that mv, cp -a and cp --preserve=xattr(all) options do work
+# as expected on filesystem without their support (FAT32) and do show
+# correct diagnostics when required
+
+# Copyright (C) 2009 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+  set -x
+  cp --version
+  mv --version
+fi
+
+. $srcdir/test-lib.sh
+require_root_
+
+cwd=`pwd`
+cleanup_() { cd /; umount "$cwd/mnt"; }
+
+# Create a FAT32 file system, then mount it.
+dd if=/dev/zero of=blob bs=8192 count=200 > /dev/null 2>&1 \
+                                             || framework_failure
+mkdir mnt                                    || framework_failure
+mkdosfs -v -F 32 blob ||
+  skip_test_ "failed to create vfat file system"
+
+mount -oloop blob mnt                        || framework_failure
+echo test > mnt/f                            || framework_failure
+test -s mnt/f                                || framework_failure
+
+# testing xattr name-value pair
+xattr_name="user.foo"
+xattr_value="bar"
+xattr_pair="$xattr_name=\"$xattr_value\""
+
+echo test > a || framework_failure
+getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_a >/dev/null && framework_failure
+setfattr -n "$xattr_name" -v "$xattr_value" a >out_a \
+  || skip_test_ "failed to set xattr of file"
+getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_a >/dev/null \
+  || skip_test_ "failed to set xattr of file"
+
+fail=0                                       || framework_failure
+
+
+#This should pass without diagnostics
+cp -a a mnt/ 2>err  || fail=1
+test -s mnt/a       || fail=1  #destination file must not be empty
+test -s err         && fail=1  #there must be no stderr output
+
+rm -f err mnt/a
+
+#This should pass without diagnostics
+cp --preserve=all a mnt/ 2>err  || fail=1
+test -s mnt/a       || fail=1  #destination file must not be empty
+test -s err         && fail=1  #there must be no stderr output
+
+rm -f err mnt/a
+
+#This should fail with coresponding diagnostics
+cp -a --preserve=xattr a mnt/ 2>err  && fail=1
+cat <<\EOF > exp || fail=1
+cp: setting attributes for `mnt/a': Operation not supported
+EOF
+
+compare err exp     || fail=1
+
+rm -f err mnt/a
+
+#This should pass without diagnostics
+mv a mnt/ 2>err     || fail=1
+test -s mnt/a       || fail=1  #destination file must not be empty
+test -s err         && fail=1  #there must be no stderr output
+
+Exit $fail
-- 
1.5.6.1.156.ge903b

From 0122c2cf362d54da220eb9be9c41586914e5b70d Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <ova...@redhat.com>
Date: Mon, 27 Apr 2009 17:29:53 +0200
Subject: [PATCH] tests: (cp) ensure that -a option doesn't silence --preserve=context

* tests/cp/cp-a-selinux: -a option should not silence error diagnostics
 from --preserve=context (when preserving context is required)
---
 tests/cp/cp-a-selinux |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/tests/cp/cp-a-selinux b/tests/cp/cp-a-selinux
index 8b7cc4d..b1359c0 100755
--- a/tests/cp/cp-a-selinux
+++ b/tests/cp/cp-a-selinux
@@ -78,6 +78,14 @@ cp --preserve=context f g 2> out && fail=1
 # Here, we *do* expect the destination to be empty.
 test -s g && fail=1
 
+rm -f g
+echo > g
+# Check if -a option doesn't silence --preserve=context option diagnostics
+cp -a --preserve=context f g 2> out2 && fail=1
+
+# Here, we *do* expect the destination to be empty.
+test -s g && fail=1
+
 # An alternative to the current approach would be to run in a confined
 # domain (maybe creating/loading it) that lacks the required permissions
 # to the file type.
@@ -87,11 +95,14 @@ test -s g && fail=1
 #   Operation not supported
 sed "s/ .g' to .*//" out > k
 mv k out
+sed "s/ .g' to .*//" out2 > k
+mv k out2
 
 cat <<\EOF > exp || fail=1
 cp: failed to set the security context of
 EOF
 
 compare out exp || fail=1
+compare out2 exp || fail=1
 
 Exit $fail
-- 
1.5.6.1.156.ge903b

Attachment: signature.asc
Description: Toto je digitálně podepsaná část zprávy

_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to