svn commit: r319830 - in head: . usr.sbin/chown/tests
Ngie Cooper
ngie at FreeBSD.org
Sun Jun 11 19:31:43 UTC 2017
Author: ngie
Date: Sun Jun 11 19:31:42 2017
New Revision: 319830
URL: https://svnweb.freebsd.org/changeset/base/319830
Log:
Add more simple positive tests for chown(1)
The tests are largely symmetric with the tests for chmod(1)--added in r319642.
Remove chown-f_test (added in r268030) since the test coverage is now being
provided by `chown_test`.
MFC after: 1 month
Sponsored by: Dell EMC Isilon
Added:
head/usr.sbin/chown/tests/chown_test.sh
- copied, changed from r319642, head/bin/chmod/tests/chmod_test.sh
Deleted:
head/usr.sbin/chown/tests/chown-f_test.sh
Modified:
head/ObsoleteFiles.inc
head/usr.sbin/chown/tests/Makefile
Modified: head/ObsoleteFiles.inc
==============================================================================
--- head/ObsoleteFiles.inc Sun Jun 11 19:09:10 2017 (r319829)
+++ head/ObsoleteFiles.inc Sun Jun 11 19:31:42 2017 (r319830)
@@ -38,6 +38,8 @@
# xargs -n1 | sort | uniq -d;
# done
+# 20170610: chown-f_test replaced by chown_test
+OLD_FILES+=usr/tests/usr.sbin/chown/chown-f_test
# 20170609: drop obsolete manpage link (if_rtwn.ko -> rtwn.ko)
OLD_FILES+=usr/share/man/man4/if_rtwn.4.gz
# 20170531: removal of groff
Modified: head/usr.sbin/chown/tests/Makefile
==============================================================================
--- head/usr.sbin/chown/tests/Makefile Sun Jun 11 19:09:10 2017 (r319829)
+++ head/usr.sbin/chown/tests/Makefile Sun Jun 11 19:31:42 2017 (r319830)
@@ -1,9 +1,5 @@
# $FreeBSD$
-.include <bsd.own.mk>
-
-TESTSDIR= ${TESTSBASE}/usr.sbin/chown
-
-TAP_TESTS_SH= chown-f_test
+ATF_TESTS_SH+= chown_test
.include <bsd.test.mk>
Copied and modified: head/usr.sbin/chown/tests/chown_test.sh (from r319642, head/bin/chmod/tests/chmod_test.sh)
==============================================================================
--- head/bin/chmod/tests/chmod_test.sh Wed Jun 7 05:33:56 2017 (r319642, copy source)
+++ head/usr.sbin/chown/tests/chown_test.sh Sun Jun 11 19:31:42 2017 (r319830)
@@ -28,58 +28,61 @@
atf_test_case RH_flag
RH_flag_head()
{
- atf_set "descr" "Verify that setting modes recursively via -R doesn't " \
+ 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 -m 0777 -p A/B
+ atf_check mkdir -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_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 modes recursively via -R doesn't " \
+ 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 -m 0777 -p A/B
+ atf_check mkdir -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_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 modes recursively via -R doesn't " \
- "affect symlinks specified via the arguments when -P " \
- "is specified"
+ 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 -m 0777 -p A/B
+ atf_check mkdir -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_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
@@ -88,17 +91,18 @@ 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 chmod 0750 foo bar
+ atf_check chown 0:0 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
+ 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()
@@ -112,43 +116,84 @@ 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 chmod 0600 foo
- atf_check -o inline:'100600\n' stat -f '%p' foo
- umask 0077
+ atf_check -o inline:'0:0\n' stat -f '%u:%g' foo
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_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 a mode with -v emits the file when " \
- "doesn't emit an error message/exit with a non-zero " \
- "code"
+ 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 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
+ 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: 0100600 [-rw------- ] -> 0100700 [-rwx------ ]";
+ echo "$f: 0:0 -> 84:84";
done > output.txt
- atf_check -o file:output.txt chmod -vv 0700 foo bar
- atf_check chmod -vv 0700 foo bar
+ 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
@@ -157,4 +202,5 @@ atf_init_test_cases()
atf_add_test_case f_flag
atf_add_test_case h_flag
atf_add_test_case v_flag
+ atf_add_test_case x_flag
}
More information about the svn-src-all
mailing list