diff options
-rw-r--r-- | ObsoleteFiles.inc | 2 | ||||
-rw-r--r-- | bin/chmod/Makefile | 4 | ||||
-rw-r--r-- | bin/chmod/tests/Makefile | 5 | ||||
-rwxr-xr-x | bin/chmod/tests/chmod_test.sh | 160 | ||||
-rw-r--r-- | etc/mtree/BSD.tests.dist | 4 | ||||
-rw-r--r-- | tools/build/mk/OptionalObsoleteFiles.inc | 3 | ||||
-rw-r--r-- | usr.sbin/chown/tests/Makefile | 6 | ||||
-rwxr-xr-x | usr.sbin/chown/tests/chown-f_test.sh | 21 | ||||
-rwxr-xr-x | usr.sbin/chown/tests/chown_test.sh | 206 |
9 files changed, 384 insertions, 27 deletions
diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 31aac76..2cfb8a8 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -40,6 +40,8 @@ # 20170620: remove stale manpage OLD_FILES+=usr/share/man/man2/cap_rights_get.2.gz +# 20170610: chown-f_test replaced by chown_test +OLD_FILES+=usr/tests/usr.sbin/chown/chown-f_test # 20170531: remove pcap-int.h OLD_FILES+=usr/include/pcap-int.h # 20170402: new libc++ import which bumps version from 3.9.1 to 4.0.0. diff --git a/bin/chmod/Makefile b/bin/chmod/Makefile index 58b1afc..3b2c2d1 100644 --- a/bin/chmod/Makefile +++ b/bin/chmod/Makefile @@ -1,7 +1,11 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD$ +.include <src.opts.mk> + PACKAGE=runtime PROG= chmod +SUBDIR.${MK_TESTS}+= tests + .include <bsd.prog.mk> diff --git a/bin/chmod/tests/Makefile b/bin/chmod/tests/Makefile new file mode 100644 index 0000000..1cf107f --- /dev/null +++ b/bin/chmod/tests/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +ATF_TESTS_SH+= chmod_test + +.include <bsd.test.mk> diff --git a/bin/chmod/tests/chmod_test.sh b/bin/chmod/tests/chmod_test.sh new file mode 100755 index 0000000..4a6a6a3 --- /dev/null +++ b/bin/chmod/tests/chmod_test.sh @@ -0,0 +1,160 @@ +# +# Copyright (c) 2017 Dell EMC +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +atf_test_case RH_flag +RH_flag_head() +{ + atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -H " \ + "is specified" +} +RH_flag_body() +{ + atf_check mkdir -m 0777 -p A/B + atf_check ln -s B A/C + atf_check chmod -h 0777 A/C + atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RH 0700 A + atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C + atf_check chmod -RH 0600 A/C + atf_check -o inline:'40700\n40600\n120700\n' stat -f '%p' A A/B A/C +} + +atf_test_case RL_flag +RL_flag_head() +{ + atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -L " \ + "is specified" +} +RL_flag_body() +{ + atf_check mkdir -m 0777 -p A/B + atf_check ln -s B A/C + atf_check chmod -h 0777 A/C + atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RL 0700 A + atf_check -o inline:'40700\n40700\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RL 0600 A/C + atf_check -o inline:'40700\n40600\n120777\n' stat -f '%p' A A/B A/C +} + +atf_test_case RP_flag +RP_flag_head() +{ + atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -P " \ + "is specified" +} +RP_flag_body() +{ + atf_check mkdir -m 0777 -p A/B + atf_check ln -s B A/C + atf_check chmod -h 0777 A/C + atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RP 0700 A + atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C + atf_check chmod -RP 0600 A/C + atf_check -o inline:'40700\n40700\n120600\n' stat -f '%p' A A/B A/C +} + +atf_test_case f_flag cleanup +f_flag_head() +{ + atf_set "descr" "Verify that setting a mode for a file with -f " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" +} + +f_flag_body() +{ + atf_check truncate -s 0 foo bar + atf_check chmod 0750 foo bar + atf_check chflags uchg foo + atf_check -e not-empty -s not-exit:0 chmod 0700 foo bar + atf_check -o inline:'100750\n100700\n' stat -f '%p' foo bar + atf_check -s exit:0 chmod -f 0600 foo bar + atf_check -o inline:'100750\n100600\n' stat -f '%p' foo bar +} + +f_flag_cleanup() +{ + atf_check chflags 0 foo +} + +atf_test_case h_flag +h_flag_head() +{ + atf_set "descr" "Verify that setting a mode for a file with -f " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" +} + +h_flag_body() +{ + atf_check truncate -s 0 foo + atf_check chmod 0600 foo + atf_check -o inline:'100600\n' stat -f '%p' foo + umask 0077 + atf_check ln -s foo bar + atf_check -o inline:'100600\n120700\n' stat -f '%p' foo bar + atf_check chmod -h 0500 bar + atf_check -o inline:'100600\n120500\n' stat -f '%p' foo bar + atf_check chmod 0660 bar + atf_check -o inline:'100660\n120500\n' stat -f '%p' foo bar +} + +atf_test_case v_flag +v_flag_head() +{ + atf_set "descr" "Verify that setting a mode with -v emits the file when " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" +} +v_flag_body() +{ + atf_check truncate -s 0 foo bar + atf_check chmod 0600 foo + atf_check chmod 0750 bar + atf_check -o 'inline:bar\n' chmod -v 0600 foo bar + atf_check chmod -v 0600 foo bar + for f in foo bar; do + echo "$f: 0100600 [-rw------- ] -> 0100700 [-rwx------ ]"; + done > output.txt + atf_check -o file:output.txt chmod -vv 0700 foo bar + atf_check chmod -vv 0700 foo bar +} + +atf_init_test_cases() +{ + atf_add_test_case RH_flag + atf_add_test_case RL_flag + atf_add_test_case RP_flag + atf_add_test_case f_flag + atf_add_test_case h_flag + atf_add_test_case v_flag +} diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index edd8a2f..d6883da 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -8,7 +8,7 @@ bin cat .. - chown + chmod .. date .. @@ -684,6 +684,8 @@ .. .. usr.sbin + chown + .. etcupdate .. extattr diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc index a9d9a78..a1e4887 100644 --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -7767,6 +7767,9 @@ OLD_FILES+=usr/share/aclocal/atf-c.m4 OLD_FILES+=usr/share/aclocal/atf-common.m4 OLD_FILES+=usr/share/aclocal/atf-sh.m4 OLD_DIRS+=usr/share/aclocal +OLD_DIRS+=usr/tests/bin/chown +OLD_FILES+=usr/tests/bin/chown/Kyuafile +OLD_FILES+=usr/tests/bin/chown/chown-f_test OLD_FILES+=usr/tests/bin/chown/units_basics OLD_FILES+=usr/tests/bin/date/legacy_test OLD_FILES+=usr/tests/bin/sh/legacy_test diff --git a/usr.sbin/chown/tests/Makefile b/usr.sbin/chown/tests/Makefile index fb13f3f..506d81c 100644 --- a/usr.sbin/chown/tests/Makefile +++ b/usr.sbin/chown/tests/Makefile @@ -1,9 +1,5 @@ # $FreeBSD$ -.include <bsd.own.mk> - -TESTSDIR= ${TESTSBASE}/bin/chown - -TAP_TESTS_SH= chown-f_test +ATF_TESTS_SH+= chown_test .include <bsd.test.mk> diff --git a/usr.sbin/chown/tests/chown-f_test.sh b/usr.sbin/chown/tests/chown-f_test.sh deleted file mode 100755 index c66b008..0000000 --- a/usr.sbin/chown/tests/chown-f_test.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -base=`basename $0` - -echo "1..1" - -name="chown -f root:wheel file" -if [ `id -u` -eq 0 ]; then - echo "ok 1 - $name # skip Test must not be uid 0." -else - touch file - output=$(chown -f root:wheel file 2>&1) - if [ $? -eq 0 -a -z "$output" ] - then - echo "ok 1 - $name" - else - echo "not ok 1 - $name" - fi - rm file -fi diff --git a/usr.sbin/chown/tests/chown_test.sh b/usr.sbin/chown/tests/chown_test.sh new file mode 100755 index 0000000..a5e55f9 --- /dev/null +++ b/usr.sbin/chown/tests/chown_test.sh @@ -0,0 +1,206 @@ +# +# Copyright (c) 2017 Dell EMC +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +atf_test_case RH_flag +RH_flag_head() +{ + atf_set "descr" "Verify that setting ownership recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -H " \ + "is specified" + atf_set "require.user" "root" +} +RH_flag_body() +{ + atf_check mkdir -p A/B + atf_check ln -s B A/C + atf_check chown -h 42:42 A/C + atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C + atf_check chown -RH 84:84 A + atf_check -o inline:'84:84\n84:84\n84:84\n' stat -f '%u:%g' A A/B A/C + atf_check chown -RH 126:126 A/C + atf_check -o inline:'84:84\n126:126\n84:84\n' stat -f '%u:%g' A A/B A/C +} + +atf_test_case RL_flag +RL_flag_head() +{ + atf_set "descr" "Verify that setting ownership recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -L " \ + "is specified" + atf_set "require.user" "root" +} +RL_flag_body() +{ + atf_check mkdir -p A/B + atf_check ln -s B A/C + atf_check chown -h 42:42 A/C + atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C + atf_check chown -RL 84:84 A + atf_check -o inline:'84:84\n84:84\n42:42\n' stat -f '%u:%g' A A/B A/C + atf_check chown -RL 126:126 A/C + atf_check -o inline:'84:84\n126:126\n42:42\n' stat -f '%u:%g' A A/B A/C +} + +atf_test_case RP_flag +RP_flag_head() +{ + atf_set "descr" "Verify that setting ownership recursively via -R " \ + "doesn't affect symlinks specified via the arguments " \ + "when -P is specified" + atf_set "require.user" "root" +} +RP_flag_body() +{ + atf_check mkdir -p A/B + atf_check ln -s B A/C + atf_check chown -h 42:42 A/C + atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C + atf_check chown -RP 84:84 A + atf_check -o inline:'84:84\n84:84\n84:84\n' stat -f '%u:%g' A A/B A/C + atf_check chown -RP 126:126 A/C + atf_check -o inline:'84:84\n84:84\n126:126\n' stat -f '%u:%g' A A/B A/C +} + +atf_test_case f_flag cleanup +f_flag_head() +{ + atf_set "descr" "Verify that setting a mode for a file with -f " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" + atf_set "require.user" "root" +} + +f_flag_body() +{ + atf_check truncate -s 0 foo bar + atf_check chown 0:0 foo bar + atf_check chflags uchg foo + atf_check -e not-empty -s not-exit:0 chown 42:42 foo bar + atf_check -o inline:'0:0\n42:42\n' stat -f '%u:%g' foo bar + atf_check -s exit:0 chown -f 84:84 foo bar + atf_check -o inline:'0:0\n84:84\n' stat -f '%u:%g' foo bar +} + +f_flag_cleanup() +{ + atf_check chflags 0 foo +} + +atf_test_case h_flag +h_flag_head() +{ + atf_set "descr" "Verify that setting a mode for a file with -f " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" + atf_set "require.user" "root" +} + +h_flag_body() +{ + atf_check truncate -s 0 foo + atf_check -o inline:'0:0\n' stat -f '%u:%g' foo + atf_check ln -s foo bar + atf_check -o inline:'0:0\n0:0\n' stat -f '%u:%g' foo bar + atf_check chown -h 42:42 bar + atf_check -o inline:'0:0\n42:42\n' stat -f '%u:%g' foo bar + atf_check chown 84:84 bar + atf_check -o inline:'84:84\n42:42\n' stat -f '%u:%g' foo bar +} + +atf_test_case v_flag +v_flag_head() +{ + atf_set "descr" "Verify that setting ownership with -v emits the " \ + "file doesn't emit an error message/exit with a " \ + "non-zero code" + atf_set "require.user" "root" +} +v_flag_body() +{ + atf_check truncate -s 0 foo bar + atf_check chown 0:0 foo + atf_check chown 42:42 bar + atf_check -o 'inline:bar\n' chown -v 0:0 foo bar + atf_check chown -v 0:0 foo bar + for f in foo bar; do + echo "$f: 0:0 -> 84:84"; + done > output.txt + atf_check -o file:output.txt chown -vv 84:84 foo bar + atf_check chown -vv 84:84 foo bar +} + +md_file="md.out" +atf_test_case x_flag cleanup +x_flag_head() +{ + atf_set "descr" "Verify that setting a mode with -x doesn't set " \ + "ownership across mountpoints" + atf_set "require.user" "root" +} +x_flag_body() +{ + atf_check -o save:$md_file mdconfig -a -t malloc -s 20m + if ! md_device=$(cat $md_file); then + atf_fail "cat $md_file failed" + fi + atf_check -o not-empty newfs /dev/$md_device + atf_check mkdir mnt + atf_check mount /dev/$md_device mnt + atf_check truncate -s 0 foo bar mnt/bazbaz + atf_check ln -s bar mnt/barbaz + atf_check ln -s ../foo mnt/foobaz + cd mnt + test_files="../foo ../bar barbaz bazbaz foobaz" + atf_check -o inline:'0:0\n0:0\n0:0\n0:0\n0:0\n' \ + stat -f '%u:%g' $test_files + atf_check chown -Rx 42:42 . + atf_check -o inline:'0:0\n0:0\n42:42\n42:42\n42:42\n' \ + stat -f '%u:%g' $test_files + atf_check chown -R 84:84 . + atf_check -o inline:'0:0\n0:0\n84:84\n84:84\n84:84\n' \ + stat -f '%u:%g' $test_files +} +x_flag_cleanup() +{ + if ! md_device=$(cat $md_file) || [ -z "$md_device" ]; then + echo "Couldn't get device from $md_file" + exit 0 + fi + umount mnt + mdconfig -d -u $md_device +} + +atf_init_test_cases() +{ + atf_add_test_case RH_flag + atf_add_test_case RL_flag + atf_add_test_case RP_flag + atf_add_test_case f_flag + atf_add_test_case h_flag + atf_add_test_case v_flag + atf_add_test_case x_flag +} |