1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-28 11:57:28 +00:00
freebsd/usr.sbin/pw/tests/pw_delete.sh
Baptiste Daroussin 0def1c7441 Ensure pw userdel -u <invalid> do not try to remove root
Check the uid passed is actually a number as early as possible

MFC after:	1 week
2014-10-28 15:46:22 +00:00

48 lines
1.6 KiB
Bash
Executable File

# $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_test_case group_do_not_delete_wheel_if_group_unkown
group_do_not_delete_wheel_if_group_unkown_head() {
atf_set "descr" "Make sure we do not consider as gid 0 an unknown group"
}
group_do_not_delete_wheel_if_group_unkown_body() {
populate_etc_skel
atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x pw -V ${HOME} groupshow wheel
atf_check -e inline:"pw: -g expects a number\n" -s exit:64 -x pw -V ${HOME} groupdel -g I_do_not_exist
atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x pw -V ${HOME} groupshow wheel
}
atf_test_case user_do_not_try_to_delete_root_if_user_unkown
user_do_not_try_to_delete_root_if_user_unkown_head() {
atf_set "descr" "Make sure not to try to remove root if deleteing an unknown user"
}
user_do_not_try_to_delete_root_if_user_unkown_body() {
populate_etc_skel
atf_check -e inline:"pw: -u expects a number\n" -s exit:64 -x pw -V ${HOME} 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_unkown
atf_add_test_case user_do_not_try_to_delete_root_if_user_unkown
}