Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Dec 2014 21:43:03 +0000 (UTC)
From:      Brad Davis <brd@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r275656 - head/usr.sbin/pw/tests
Message-ID:  <201412092143.sB9Lh3rI017679@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: brd (doc committer)
Date: Tue Dec  9 21:43:03 2014
New Revision: 275656
URL: https://svnweb.freebsd.org/changeset/base/275656

Log:
  Break out the tests into a file per command and clean up some long lines
  
  Approved by:	will

Added:
  head/usr.sbin/pw/tests/pw_groupdel.sh   (contents, props changed)
  head/usr.sbin/pw/tests/pw_groupmod.sh
     - copied unchanged from r275652, head/usr.sbin/pw/tests/pw_modify.sh
  head/usr.sbin/pw/tests/pw_useradd.sh
     - copied unchanged from r275655, head/usr.sbin/pw/tests/pw_add.sh
  head/usr.sbin/pw/tests/pw_userdel.sh
     - copied, changed from r275652, head/usr.sbin/pw/tests/pw_delete.sh
Deleted:
  head/usr.sbin/pw/tests/pw_add.sh
  head/usr.sbin/pw/tests/pw_delete.sh
  head/usr.sbin/pw/tests/pw_modify.sh
Modified:
  head/usr.sbin/pw/tests/Makefile

Modified: head/usr.sbin/pw/tests/Makefile
==============================================================================
--- head/usr.sbin/pw/tests/Makefile	Tue Dec  9 20:46:17 2014	(r275655)
+++ head/usr.sbin/pw/tests/Makefile	Tue Dec  9 21:43:03 2014	(r275656)
@@ -5,11 +5,11 @@ TESTSRC=	${.CURDIR}/../../../contrib/net
 
 TESTSDIR=	${TESTSBASE}/usr.sbin/pw
 
-ATF_TESTS_SH=	pw_add pw_delete pw_etcdir pw_lock pw_modify
+ATF_TESTS_SH=	pw_etcdir pw_lock pw_groupmod pw_useradd pw_userdel
 
-TEST_METADATA.pw_add+=		required_user="root"
-TEST_METADATA.pw_delete+=	required_user="root"
-TEST_METADATA.pw_modify+=	required_user="root"
+TEST_METADATA.pw_groupmod+=	required_user="root"
+TEST_METADATA.pw_useradd+=	required_user="root"
+TEST_METADATA.pw_userdel+=	required_user="root"
 
 FILES=		group helper_functions.shin master.passwd
 FILESDIR=       ${TESTSDIR}

Added: head/usr.sbin/pw/tests/pw_groupdel.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/usr.sbin/pw/tests/pw_groupdel.sh	Tue Dec  9 21:43:03 2014	(r275656)
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+
+# Test to make sure we do not accidentially delete wheel when trying to delete
+# an unknown group
+atf_test_case group_do_not_delete_wheel_if_group_unknown
+group_do_not_delete_wheel_if_group_unknown_head() {
+        atf_set "descr" "Make sure we do not consider gid 0 an unknown group"
+}
+group_do_not_delete_wheel_if_group_unknown_body() {
+        populate_etc_skel
+        atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x ${PW} groupshow wheel
+        atf_check -e inline:"pw: -g expects a number\n" -s exit:64 -x \
+		${PW} groupdel -g I_do_not_exist
+        atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x ${PW} groupshow wheel
+}
+
+
+atf_init_test_cases() {
+        atf_add_test_case group_do_not_delete_wheel_if_group_unknown
+}

Copied: head/usr.sbin/pw/tests/pw_groupmod.sh (from r275652, head/usr.sbin/pw/tests/pw_modify.sh)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/usr.sbin/pw/tests/pw_groupmod.sh	Tue Dec  9 21:43:03 2014	(r275656, copy of r275652, head/usr.sbin/pw/tests/pw_modify.sh)
@@ -0,0 +1,80 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+
+# Test adding & removing a user from a group
+atf_test_case groupmod_user
+groupmod_user_body() {
+	populate_etc_skel
+	atf_check -s exit:0 ${PW} addgroup test
+	atf_check -s exit:0 ${PW} groupmod test -m root
+	atf_check -s exit:0 -o match:"^test:\*:1001:root$" \
+		grep "^test:\*:.*:root$" $HOME/group
+	atf_check -s exit:0 ${PW} groupmod test -d root
+	atf_check -s exit:0 -o match:"^test:\*:1001:$" \
+		grep "^test:\*:.*:$" $HOME/group
+}
+
+
+# Test adding and removing a user that does not exist
+atf_test_case groupmod_invalid_user
+groupmod_invalid_user_body() {
+	populate_etc_skel
+	atf_check -s exit:0 ${PW} addgroup test
+	atf_check -s exit:67 -e match:"does not exist" ${PW} groupmod test -m foo
+	atf_check -s exit:0  ${PW} groupmod test -d foo
+}
+
+atf_test_case groupmod_bug_193704
+groupmod_bug_193704_head() {
+	atf_set "descr" "Regression test for the #193704 bug"
+}
+groupmod_bug_193704_body() {
+	populate_etc_skel
+	atf_check -s exit:0 -x ${PW} groupadd test
+	atf_check -s exit:0 -x ${PW} groupmod test -l newgroupname
+	atf_check -s exit:65 -e match:"^pw: unknown group" -x ${PW} groupshow test
+}
+
+atf_test_case usermod_bug_185666
+usermod_bug_185666_head() {
+	atf_set "descr" "Regression test for the #185666 bug"
+}
+
+usermod_bug_185666_body() {
+	populate_etc_skel
+	atf_check -s exit:0 -x ${PW} useradd testuser
+	atf_check -s exit:0 -x ${PW} groupadd testgroup
+	atf_check -s exit:0 -x ${PW} groupadd testgroup2
+	atf_check -s exit:0 -x ${PW} usermod testuser -G testgroup
+	atf_check -o inline:"testuser:*:1001:\n" -x ${PW} groupshow testuser
+	atf_check -o inline:"testgroup:*:1002:testuser\n" -x ${PW} groupshow testgroup
+	atf_check -o inline:"testgroup2:*:1003:\n" -x ${PW} groupshow testgroup2
+	atf_check -s exit:0 -x ${PW} usermod testuser -G testgroup2
+	atf_check -o inline:"testuser:*:1001:\n" -x ${PW} groupshow testuser
+	atf_check -o inline:"testgroup:*:1002:\n" -x ${PW} groupshow testgroup
+	atf_check -o inline:"testgroup2:*:1003:testuser\n" -x ${PW} groupshow testgroup2
+}
+
+atf_test_case do_not_duplicate_group_on_gid_change
+do_not_duplicate_group_on_gid_change_head() {
+	atf_set "descr" "Do not duplicate group on gid change"
+}
+
+do_not_duplicate_group_on_gid_change_body() {
+	populate_etc_skel
+	atf_check -s exit:0 -x ${PW} groupadd testgroup
+	atf_check -s exit:0 -x ${PW} groupmod testgroup -g 12345
+	# use grep to see if the entry has not be duplicated
+	atf_check -o inline:"testgroup:*:12345:\n" -s exit:0 -x grep "^testgroup" ${HOME}/group
+}
+
+atf_init_test_cases() {
+	atf_add_test_case groupmod_user
+	atf_add_test_case groupmod_invalid_user
+	atf_add_test_case groupmod_bug_193704
+	atf_add_test_case usermod_bug_185666
+	atf_add_test_case do_not_duplicate_group_on_gid_change
+}

Copied: head/usr.sbin/pw/tests/pw_useradd.sh (from r275655, head/usr.sbin/pw/tests/pw_add.sh)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/usr.sbin/pw/tests/pw_useradd.sh	Tue Dec  9 21:43:03 2014	(r275656, copy of r275655, head/usr.sbin/pw/tests/pw_add.sh)
@@ -0,0 +1,40 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+# Test add user
+atf_test_case user_add
+user_add_body() {
+	populate_etc_skel
+
+	atf_check -s exit:0 ${PW} useradd test
+	atf_check -s exit:0 -o match:"^test:.*" \
+		grep "^test:.*" $HOME/master.passwd
+}
+
+
+atf_test_case user_add_comments
+user_add_comments_body() {
+	populate_etc_skel
+
+	atf_check -s exit:0 ${PW} useradd test -c "Test User,work,123,456"
+	atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
+		grep "^test:.*:Test User,work,123,456:" $HOME/master.passwd
+}
+
+atf_test_case user_add_comments_invalid
+user_add_comments_invalid_body() {
+	populate_etc_skel
+
+	atf_check -s exit:65 -e match:"invalid character" \
+		${PW} useradd test -c "Test User,work,123:456,456"
+	atf_check -s exit:1 -o empty \
+		grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
+}
+
+atf_init_test_cases() {
+	atf_add_test_case user_add
+	atf_add_test_case user_add_comments
+	atf_add_test_case user_add_comments_invalid 
+}

Copied and modified: head/usr.sbin/pw/tests/pw_userdel.sh (from r275652, head/usr.sbin/pw/tests/pw_delete.sh)
==============================================================================
--- head/usr.sbin/pw/tests/pw_delete.sh	Tue Dec  9 20:05:05 2014	(r275652, copy source)
+++ head/usr.sbin/pw/tests/pw_userdel.sh	Tue Dec  9 21:43:03 2014	(r275656)
@@ -3,6 +3,7 @@
 # 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
@@ -18,30 +19,19 @@ rmuser_seperate_group_body() {
 	${PW} userdel test || atf_fail "Delete the test user"
 }
 
-atf_test_case group_do_not_delete_wheel_if_group_unknown
-group_do_not_delete_wheel_if_group_unknown_head() {
-	atf_set "descr" "Make sure we do not consider gid 0 an unknown group"
-}
-
-group_do_not_delete_wheel_if_group_unknown_body() {
-	populate_etc_skel
-	atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x ${PW} groupshow wheel
-	atf_check -e inline:"pw: -g expects a number\n" -s exit:64 -x ${PW} groupdel -g I_do_not_exist
-	atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x ${PW} groupshow wheel
-}
 
 atf_test_case user_do_not_try_to_delete_root_if_user_unknown
 user_do_not_try_to_delete_root_if_user_unknown_head() {
-	atf_set "descr" "Make sure not to try to remove root if deleting an unknown user"
+	atf_set "descr" \
+		"Make sure not to try to remove root if deleting an unknown user"
 }
-
 user_do_not_try_to_delete_root_if_user_unknown_body() {
 	populate_etc_skel
-	atf_check -e inline:"pw: -u expects a number\n" -s exit:64 -x ${PW} userdel -u plop
+	atf_check -e inline:"pw: -u expects a number\n" -s exit:64 -x \
+		${PW} userdel -u plop
 }
 
 atf_init_test_cases() {
 	atf_add_test_case rmuser_seperate_group
-	atf_add_test_case group_do_not_delete_wheel_if_group_unknown
 	atf_add_test_case user_do_not_try_to_delete_root_if_user_unknown
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201412092143.sB9Lh3rI017679>