summaryrefslogtreecommitdiffstats
path: root/pw
diff options
context:
space:
mode:
authorBrad Davis <brd@FreeBSD.org>2014-10-02 19:53:37 +0000
committerBrad Davis <brd@FreeBSD.org>2014-10-02 19:53:37 +0000
commit42e7794740f3037d831043846a20a5fce4125631 (patch)
tree5be7ed624629d3eb852b0df630e8e2f6d3fd7a5b /pw
parent541ffe0f9d8c657b529483a6725a6f2b4b45058e (diff)
downloadpw-darwin-42e7794740f3037d831043846a20a5fce4125631.tar.gz
pw-darwin-42e7794740f3037d831043846a20a5fce4125631.tar.zst
pw-darwin-42e7794740f3037d831043846a20a5fce4125631.zip
- Add a test for bug 191427 where pw(8) will go into an infinite loop
Reviewed by: will MFC after: 1 month
Diffstat (limited to 'pw')
-rw-r--r--pw/Makefile6
-rw-r--r--pw/tests/Makefile10
-rw-r--r--pw/tests/group3
-rwxr-xr-xpw/tests/helper_functions.shin15
-rw-r--r--pw/tests/master.passwd4
-rwxr-xr-xpw/tests/pw_delete.sh24
6 files changed, 62 insertions, 0 deletions
diff --git a/pw/Makefile b/pw/Makefile
index eae0b87..8c5acf9 100644
--- a/pw/Makefile
+++ b/pw/Makefile
@@ -11,4 +11,10 @@ WARNS?= 2
DPADD= ${LIBCRYPT} ${LIBUTIL}
LDADD= -lcrypt -lutil
+.include <src.opts.mk>
+
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
diff --git a/pw/tests/Makefile b/pw/tests/Makefile
new file mode 100644
index 0000000..577ea93
--- /dev/null
+++ b/pw/tests/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/usr.sbin/pw
+
+ATF_TESTS_SH= pw_delete
+
+FILES= group helper_functions.shin master.passwd
+FILESDIR= ${TESTSDIR}
+
+.include <bsd.test.mk>
diff --git a/pw/tests/group b/pw/tests/group
new file mode 100644
index 0000000..620c588
--- /dev/null
+++ b/pw/tests/group
@@ -0,0 +1,3 @@
+# $FreeBSD$
+#
+wheel:*:0:root
diff --git a/pw/tests/helper_functions.shin b/pw/tests/helper_functions.shin
new file mode 100755
index 0000000..f87b1e7
--- /dev/null
+++ b/pw/tests/helper_functions.shin
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+# Workdir to run tests in
+TESTDIR=$(atf_get_srcdir)
+
+# Populate the files pw needs to use into $HOME/etc
+populate_etc_skel() {
+ cp ${TESTDIR}/master.passwd ${HOME} || \
+ atf_fail "Populating master.passwd in ${HOME}"
+ cp ${TESTDIR}/group ${HOME} || atf_fail "Populating group in ${HOME}"
+
+ # Generate the passwd file
+ pwd_mkdb -p -d ${HOME} ${HOME}/master.passwd || \
+ atf_fail "generate passwd from master.passwd"
+}
diff --git a/pw/tests/master.passwd b/pw/tests/master.passwd
new file mode 100644
index 0000000..f7dc837
--- /dev/null
+++ b/pw/tests/master.passwd
@@ -0,0 +1,4 @@
+# $FreeBSD$
+#
+root:*:0:0::0:0:Charlie &:/root:/bin/csh
+toor:*:0:0::0:0:Bourne-again Superuser:/root:
diff --git a/pw/tests/pw_delete.sh b/pw/tests/pw_delete.sh
new file mode 100755
index 0000000..0636629
--- /dev/null
+++ b/pw/tests/pw_delete.sh
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+# Test that a user can be deleted when another user is part of this
+# user's default group and does not go into an infinate loop.
+# PR: 191427
+atf_test_case rmuser_seperate_group cleanup
+rmuser_seperate_group_head() {
+ atf_set "timeout" "30"
+}
+rmuser_seperate_group_body() {
+ populate_etc_skel
+ pw -V ${HOME} useradd test || atf_fail "Creating test user"
+ pw -V ${HOME} groupmod test -M 'test,root' || \
+ atf_fail "Modifying the group"
+ pw -V ${HOME} userdel test || atf_fail "delete the user"
+}
+
+
+atf_init_test_cases() {
+ atf_add_test_case rmuser_seperate_group
+}