1458cbf0aSEnji Cooper 2458cbf0aSEnji Cooper# Import helper functions 3458cbf0aSEnji Cooper. $(atf_get_srcdir)/helper_functions.shin 4458cbf0aSEnji Cooper 5458cbf0aSEnji Cooper# Test modifying a user 6458cbf0aSEnji Cooperatf_test_case user_mod 7458cbf0aSEnji Cooperuser_mod_body() { 8458cbf0aSEnji Cooper populate_etc_skel 9458cbf0aSEnji Cooper 10458cbf0aSEnji Cooper atf_check -s exit:67 -e match:"no such user" ${PW} usermod test 11458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test 12458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod test 13458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*" \ 14458cbf0aSEnji Cooper grep "^test:.*" $HOME/master.passwd 15458cbf0aSEnji Cooper} 16458cbf0aSEnji Cooper 17458cbf0aSEnji Cooper# Test modifying a user with option -N 18458cbf0aSEnji Cooperatf_test_case user_mod_noupdate 19458cbf0aSEnji Cooperuser_mod_noupdate_body() { 20458cbf0aSEnji Cooper populate_etc_skel 21458cbf0aSEnji Cooper 22458cbf0aSEnji Cooper atf_check -s exit:67 -e match:"no such user" ${PW} usermod test -N 23458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test 24458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*" ${PW} usermod test -N 25458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*" \ 26458cbf0aSEnji Cooper grep "^test:.*" $HOME/master.passwd 27458cbf0aSEnji Cooper} 28458cbf0aSEnji Cooper 29458cbf0aSEnji Cooper# Test modifying a user with comments 30458cbf0aSEnji Cooperatf_test_case user_mod_comments 31458cbf0aSEnji Cooperuser_mod_comments_body() { 32458cbf0aSEnji Cooper populate_etc_skel 33458cbf0aSEnji Cooper 34458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -c "Test User,home,123,456" 35458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod test -c "Test User,work,123,456" 36458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \ 37458cbf0aSEnji Cooper grep "^test:.*:Test User,work,123,456:" $HOME/master.passwd 38458cbf0aSEnji Cooper} 39458cbf0aSEnji Cooper 40458cbf0aSEnji Cooper# Test modifying a user with comments with option -N 41458cbf0aSEnji Cooperatf_test_case user_mod_comments_noupdate 42458cbf0aSEnji Cooperuser_mod_comments_noupdate_body() { 43458cbf0aSEnji Cooper populate_etc_skel 44458cbf0aSEnji Cooper 45458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -c "Test User,home,123,456" 46458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \ 47458cbf0aSEnji Cooper ${PW} usermod test -c "Test User,work,123,456" -N 48458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*:Test User,home,123,456:" \ 49458cbf0aSEnji Cooper grep "^test:.*:Test User,home,123,456:" $HOME/master.passwd 50458cbf0aSEnji Cooper} 51458cbf0aSEnji Cooper 52458cbf0aSEnji Cooper# Test modifying a user with invalid comments 53458cbf0aSEnji Cooperatf_test_case user_mod_comments_invalid 54458cbf0aSEnji Cooperuser_mod_comments_invalid_body() { 55458cbf0aSEnji Cooper populate_etc_skel 56458cbf0aSEnji Cooper 57458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test 58458cbf0aSEnji Cooper atf_check -s exit:65 -e match:"invalid character" \ 59458cbf0aSEnji Cooper ${PW} usermod test -c "Test User,work,123:456,456" 60458cbf0aSEnji Cooper atf_check -s exit:1 -o empty \ 61458cbf0aSEnji Cooper grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd 62458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*" \ 63458cbf0aSEnji Cooper grep "^test:\*" $HOME/master.passwd 64458cbf0aSEnji Cooper} 65458cbf0aSEnji Cooper 66458cbf0aSEnji Cooper# Test modifying a user with invalid comments with option -N 67458cbf0aSEnji Cooperatf_test_case user_mod_comments_invalid_noupdate 68458cbf0aSEnji Cooperuser_mod_comments_invalid_noupdate_body() { 69458cbf0aSEnji Cooper populate_etc_skel 70458cbf0aSEnji Cooper 71458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test 72458cbf0aSEnji Cooper atf_check -s exit:65 -e match:"invalid character" \ 73458cbf0aSEnji Cooper ${PW} usermod test -c "Test User,work,123:456,456" -N 74458cbf0aSEnji Cooper atf_check -s exit:1 -o empty \ 75458cbf0aSEnji Cooper grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd 76458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*" \ 77458cbf0aSEnji Cooper grep "^test:\*" $HOME/master.passwd 78458cbf0aSEnji Cooper} 79458cbf0aSEnji Cooper 80458cbf0aSEnji Cooper# Test modifying a user name with -l 81458cbf0aSEnji Cooperatf_test_case user_mod_name 82458cbf0aSEnji Cooperuser_mod_name_body() { 83458cbf0aSEnji Cooper populate_etc_skel 84458cbf0aSEnji Cooper 85458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 86458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -l "bar" 87458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^bar:.*" \ 88458cbf0aSEnji Cooper grep "^bar:.*" $HOME/master.passwd 89458cbf0aSEnji Cooper} 90458cbf0aSEnji Cooper 91458cbf0aSEnji Cooper# Test modifying a user name with -l with option -N 92458cbf0aSEnji Cooperatf_test_case user_mod_name_noupdate 93458cbf0aSEnji Cooperuser_mod_name_noupdate_body() { 94458cbf0aSEnji Cooper populate_etc_skel 95458cbf0aSEnji Cooper 96458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 97458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^bar:.*" ${PW} usermod foo -l "bar" -N 98458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^foo:.*" \ 99458cbf0aSEnji Cooper grep "^foo:.*" $HOME/master.passwd 100458cbf0aSEnji Cooper} 101458cbf0aSEnji Cooper 102458cbf0aSEnji Cooperatf_test_case user_mod_rename_multigroups 103458cbf0aSEnji Cooperuser_mod_rename_multigroups_body() { 104458cbf0aSEnji Cooper populate_etc_skel 105458cbf0aSEnji Cooper 106458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} groupadd test1 107458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} groupadd test2 108458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -G test1,test2 109458cbf0aSEnji Cooper atf_check -o match:"foo" -s exit:0 ${PW} groupshow test1 110458cbf0aSEnji Cooper atf_check -o match:"foo" -s exit:0 ${PW} groupshow test2 111458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -l bar 112458cbf0aSEnji Cooper atf_check -o match:"bar" -s exit:0 ${PW} groupshow test1 113458cbf0aSEnji Cooper atf_check -o match:"bar" -s exit:0 ${PW} groupshow test2 114458cbf0aSEnji Cooper} 115458cbf0aSEnji Cooper 116458cbf0aSEnji Cooperatf_test_case user_mod_nogroups 117458cbf0aSEnji Cooperuser_mod_nogroups_body() { 118458cbf0aSEnji Cooper populate_etc_skel 119458cbf0aSEnji Cooper 120458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} groupadd test1 121458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} groupadd test2 122458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} groupadd test3 123458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} groupadd test4 124458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -G test1,test2 125458cbf0aSEnji Cooper atf_check -o match:"foo" -s exit:0 ${PW} groupshow test1 126458cbf0aSEnji Cooper atf_check -o match:"foo" -s exit:0 ${PW} groupshow test2 127458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -G test3,test4 128458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:"test3\ntest4\n" \ 129458cbf0aSEnji Cooper awk -F\: '$4 == "foo" { print $1 }' ${HOME}/group 130*3dc869c2SEd Maste atf_check -s exit:0 ${PW} usermod foo -G "" 131*3dc869c2SEd Maste atf_check -s exit:0 -o empty \ 132*3dc869c2SEd Maste awk -F\: '$4 == "foo" { print $1 }' ${HOME}/group 133458cbf0aSEnji Cooper} 134458cbf0aSEnji Cooper 135458cbf0aSEnji Cooperatf_test_case user_mod_rename 136458cbf0aSEnji Cooperuser_mod_rename_body() { 137458cbf0aSEnji Cooper populate_etc_skel 138458cbf0aSEnji Cooper 139458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 140458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -l bar 141458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^bar:.*" \ 142458cbf0aSEnji Cooper grep "^bar:.*" ${HOME}/master.passwd 143458cbf0aSEnji Cooper} 144458cbf0aSEnji Cooper 145458cbf0aSEnji Cooperatf_test_case user_mod_rename_too_long 146458cbf0aSEnji Cooperuser_mod_rename_too_long_body() { 147458cbf0aSEnji Cooper populate_etc_skel 148458cbf0aSEnji Cooper 149458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 150458cbf0aSEnji Cooper atf_check -s exit:64 -e match:"too long" ${PW} usermod foo \ 151458cbf0aSEnji Cooper -l name_very_very_very_very_very_long 152458cbf0aSEnji Cooper} 153458cbf0aSEnji Cooper 154458cbf0aSEnji Cooperatf_test_case user_mod_h 155458cbf0aSEnji Cooperuser_mod_h_body() { 156458cbf0aSEnji Cooper populate_etc_skel 157458cbf0aSEnji Cooper 158458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 159458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -h 0 <<- EOF 160458cbf0aSEnji Cooper $(echo a) 161458cbf0aSEnji Cooper EOF 162458cbf0aSEnji Cooper passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd` 163458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:$passhash \ 164458cbf0aSEnji Cooper $(atf_get_srcdir)/crypt $passhash "a" 165458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -h - <<- EOF 166458cbf0aSEnji Cooper $(echo b) 167458cbf0aSEnji Cooper EOF 168458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^foo:\*:.*" \ 169458cbf0aSEnji Cooper grep "^foo" ${HOME}/master.passwd 170458cbf0aSEnji Cooper atf_check -e inline:"pw: Bad file descriptor 'a': invalid\n" \ 171458cbf0aSEnji Cooper -s exit:64 ${PW} usermod foo -h a <<- EOF 172458cbf0aSEnji Cooper $(echo a) 173458cbf0aSEnji Cooper EOF 174458cbf0aSEnji Cooper} 175458cbf0aSEnji Cooper 176458cbf0aSEnji Cooperatf_test_case user_mod_H 177458cbf0aSEnji Cooperuser_mod_H_body() { 178458cbf0aSEnji Cooper populate_etc_skel 179458cbf0aSEnji Cooper 180458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 181458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -H 0 <<- EOF 182458cbf0aSEnji Cooper $(echo a) 183458cbf0aSEnji Cooper EOF 184458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^foo:a:.*" \ 185458cbf0aSEnji Cooper grep "^foo" ${HOME}/master.passwd 186458cbf0aSEnji Cooper atf_check -s exit:64 -e inline:"pw: -H expects a file descriptor\n" \ 187458cbf0aSEnji Cooper ${PW} usermod foo -H - 188458cbf0aSEnji Cooper} 189458cbf0aSEnji Cooper 190458cbf0aSEnji Cooperatf_test_case user_mod_renamehome 191458cbf0aSEnji Cooperuser_mod_renamehome_body() { 192458cbf0aSEnji Cooper populate_root_etc_skel 193458cbf0aSEnji Cooper 194458cbf0aSEnji Cooper mkdir -p ${HOME}/home 195458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} useradd foo -m 196458cbf0aSEnji Cooper test -d ${HOME}/home/foo || atf_fail "Directory not created" 197458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} usermod foo -l bar -d /home/bar -m 198458cbf0aSEnji Cooper test -d ${HOME}/home/bar || atf_fail "Directory not created" 199458cbf0aSEnji Cooper} 200458cbf0aSEnji Cooper 201458cbf0aSEnji Cooperatf_test_case user_mod_uid 202458cbf0aSEnji Cooperuser_mod_uid_body() { 203458cbf0aSEnji Cooper populate_etc_skel 204458cbf0aSEnji Cooper 205458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 206458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -u 5000 207458cbf0aSEnji Cooper} 208458cbf0aSEnji Cooper 209458cbf0aSEnji Cooperatf_test_case user_mod_w_error 210458cbf0aSEnji Cooperuser_mod_w_error_body() { 211458cbf0aSEnji Cooper populate_etc_skel 212458cbf0aSEnji Cooper 213458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 214458cbf0aSEnji Cooper atf_check -s exit:1 -e match:"pw: Invalid value for default password" \ 215458cbf0aSEnji Cooper ${PW} usermod foo -w invalid_value 216458cbf0aSEnji Cooper} 217458cbf0aSEnji Cooper 218458cbf0aSEnji Cooperatf_test_case user_mod_w_no 219458cbf0aSEnji Cooperuser_mod_w_no_body() { 220458cbf0aSEnji Cooper populate_etc_skel 221458cbf0aSEnji Cooper 222458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 223458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -w no 224458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^foo:\*" grep "^foo:" $HOME/master.passwd 225458cbf0aSEnji Cooper} 226458cbf0aSEnji Cooper 227458cbf0aSEnji Cooperatf_test_case user_mod_w_none 228458cbf0aSEnji Cooperuser_mod_w_none_body() { 229458cbf0aSEnji Cooper populate_etc_skel 230458cbf0aSEnji Cooper 231458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 232458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -w none 233458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^foo::" grep "^foo:" $HOME/master.passwd 234458cbf0aSEnji Cooper} 235458cbf0aSEnji Cooper 236458cbf0aSEnji Cooperatf_test_case user_mod_w_random 237458cbf0aSEnji Cooperuser_mod_w_random_body() { 238458cbf0aSEnji Cooper populate_etc_skel 239458cbf0aSEnji Cooper 240458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 241458cbf0aSEnji Cooper password=`${PW} usermod foo -w random | cat` 242458cbf0aSEnji Cooper passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd` 243458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:$passhash \ 244458cbf0aSEnji Cooper $(atf_get_srcdir)/crypt $passhash "$password" 245458cbf0aSEnji Cooper} 246458cbf0aSEnji Cooper 247458cbf0aSEnji Cooperatf_test_case user_mod_w_yes 248458cbf0aSEnji Cooperuser_mod_w_yes_body() { 249458cbf0aSEnji Cooper populate_etc_skel 250458cbf0aSEnji Cooper 251458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 252458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} usermod foo -w yes 253458cbf0aSEnji Cooper passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd` 254458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:$passhash \ 255458cbf0aSEnji Cooper $(atf_get_srcdir)/crypt $passhash "foo" 256458cbf0aSEnji Cooper} 257458cbf0aSEnji Cooper 258458cbf0aSEnji Cooperatf_test_case user_mod_m 259458cbf0aSEnji Cooperuser_mod_m_body() { 260458cbf0aSEnji Cooper populate_root_etc_skel 261458cbf0aSEnji Cooper 262458cbf0aSEnji Cooper mkdir -p ${HOME}/home 263458cbf0aSEnji Cooper mkdir -p ${HOME}/skel 264458cbf0aSEnji Cooper echo "entry" > ${HOME}/skel/.file 265458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} useradd foo 266458cbf0aSEnji Cooper ! test -d ${HOME}/home/foo || atf_fail "Directory should not have been created" 267458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} usermod foo -m -k /skel 268458cbf0aSEnji Cooper test -d ${HOME}/home/foo || atf_fail "Directory should have been created" 269458cbf0aSEnji Cooper test -f ${HOME}/home/foo/.file || atf_fail "Skell files not added" 270458cbf0aSEnji Cooper echo "entry" > ${HOME}/skel/.file2 271458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} usermod foo -m -k /skel 272458cbf0aSEnji Cooper test -f ${HOME}/home/foo/.file2 || atf_fail "Skell files not added" 273458cbf0aSEnji Cooper echo > ${HOME}/home/foo/.file2 274458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} usermod foo -m -k /skel 275458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:"\n" cat ${HOME}/home/foo/.file2 276458cbf0aSEnji Cooper} 277458cbf0aSEnji Cooper 278458cbf0aSEnji Cooper 279458cbf0aSEnji Cooperatf_init_test_cases() { 280458cbf0aSEnji Cooper atf_add_test_case user_mod 281458cbf0aSEnji Cooper atf_add_test_case user_mod_noupdate 282458cbf0aSEnji Cooper atf_add_test_case user_mod_comments 283458cbf0aSEnji Cooper atf_add_test_case user_mod_comments_noupdate 284458cbf0aSEnji Cooper atf_add_test_case user_mod_comments_invalid 285458cbf0aSEnji Cooper atf_add_test_case user_mod_comments_invalid_noupdate 286458cbf0aSEnji Cooper atf_add_test_case user_mod_nogroups 287458cbf0aSEnji Cooper atf_add_test_case user_mod_rename 288458cbf0aSEnji Cooper atf_add_test_case user_mod_name_noupdate 289458cbf0aSEnji Cooper atf_add_test_case user_mod_rename_too_long 290458cbf0aSEnji Cooper atf_add_test_case user_mod_rename_multigroups 291458cbf0aSEnji Cooper atf_add_test_case user_mod_h 292458cbf0aSEnji Cooper atf_add_test_case user_mod_H 293458cbf0aSEnji Cooper atf_add_test_case user_mod_renamehome 294458cbf0aSEnji Cooper atf_add_test_case user_mod_uid 295458cbf0aSEnji Cooper atf_add_test_case user_mod_w_error 296458cbf0aSEnji Cooper atf_add_test_case user_mod_w_no 297458cbf0aSEnji Cooper atf_add_test_case user_mod_w_none 298458cbf0aSEnji Cooper atf_add_test_case user_mod_w_random 299458cbf0aSEnji Cooper atf_add_test_case user_mod_w_yes 300458cbf0aSEnji Cooper atf_add_test_case user_mod_m 301458cbf0aSEnji Cooper} 302