1 2# Import helper functions 3. $(atf_get_srcdir)/helper_functions.shin 4 5 6# Test that a user can be deleted when another user is part of this 7# user's default group and does not go into an infinate loop. 8# PR: 191427 9atf_test_case rmuser_seperate_group cleanup 10rmuser_seperate_group_head() { 11 atf_set "timeout" "30" 12} 13rmuser_seperate_group_body() { 14 populate_etc_skel 15 ${PW} useradd test || atf_fail "Creating test user" 16 ${PW} groupmod test -M 'test,root' || \ 17 atf_fail "Modifying the group" 18 ${PW} userdel test || atf_fail "Delete the test user" 19} 20 21 22atf_test_case user_do_not_try_to_delete_root_if_user_unknown 23user_do_not_try_to_delete_root_if_user_unknown_head() { 24 atf_set "descr" \ 25 "Make sure not to try to remove root if deleting an unknown user" 26} 27user_do_not_try_to_delete_root_if_user_unknown_body() { 28 populate_etc_skel 29 atf_check -e inline:"pw: Bad id 'plop': invalid\n" -s exit:64 -x \ 30 ${PW} userdel -u plop 31} 32 33atf_test_case delete_files 34delete_files_body() { 35 populate_root_etc_skel 36 37 mkdir -p ${HOME}/skel 38 touch ${HOME}/skel/a 39 mkdir -p ${HOME}/home 40 mkdir -p ${HOME}/var/mail 41 atf_check -s exit:0 ${RPW} useradd foo -k /skel -m 42 test -d ${HOME}/home || atf_fail "Fail to create home directory" 43 test -f ${HOME}/var/mail/foo || atf_fail "Mail file not created" 44 atf_check -s exit:0 ${RPW} userdel foo -r 45 if test -f ${HOME}/var/mail/foo; then 46 atf_fail "Mail file not removed" 47 fi 48} 49 50atf_test_case delete_numeric_name 51delete_numeric_name_body() { 52 populate_etc_skel 53 54 atf_check ${PW} useradd -n foo -u 4001 55 atf_check -e inline:"pw: no such user \`4001'\n" -s exit:67 \ 56 ${PW} userdel -n 4001 57} 58 59atf_test_case home_not_a_dir 60home_not_a_dir_body() { 61 populate_root_etc_skel 62 touch ${HOME}/foo 63 atf_check ${RPW} useradd foo -d /foo 64 atf_check ${RPW} userdel foo -r 65} 66 67atf_test_case home_shared 68home_shared_body() { 69 populate_root_etc_skel 70 mkdir ${HOME}/shared 71 atf_check ${RPW} useradd -n testuser1 -d /shared 72 atf_check ${RPW} useradd -n testuser2 -d /shared 73 atf_check ${RPW} userdel -n testuser1 -r 74 test -d ${HOME}/shared || atf_fail "Shared home has been removed" 75} 76 77atf_test_case home_regular_dir 78home_regular_dir_body() { 79 populate_root_etc_skel 80 atf_check ${RPW} useradd -n foo -d /foo 81 atf_check ${RPW} userdel -n foo -r 82 [ ! -d ${HOME}/foo ] || atf_fail "Home has not been removed" 83} 84 85atf_init_test_cases() { 86 atf_add_test_case rmuser_seperate_group 87 atf_add_test_case user_do_not_try_to_delete_root_if_user_unknown 88 atf_add_test_case delete_files 89 atf_add_test_case delete_numeric_name 90 atf_add_test_case home_not_a_dir 91 atf_add_test_case home_shared 92 atf_add_test_case home_regular_dir 93} 94