3 # Import helper functions
4 . $(atf_get_srcdir)/helper_functions.shin
6 # Test modifying a user
11 atf_check -s exit:67 -e match:"no such user" ${PW} usermod test
12 atf_check -s exit:0 ${PW} useradd test
13 atf_check -s exit:0 ${PW} usermod test
14 atf_check -s exit:0 -o match:"^test:.*" \
15 grep "^test:.*" $HOME/master.passwd
18 # Test modifying a user with option -N
19 atf_test_case user_mod_noupdate
20 user_mod_noupdate_body() {
23 atf_check -s exit:67 -e match:"no such user" ${PW} usermod test -N
24 atf_check -s exit:0 ${PW} useradd test
25 atf_check -s exit:0 -o match:"^test:.*" ${PW} usermod test -N
26 atf_check -s exit:0 -o match:"^test:.*" \
27 grep "^test:.*" $HOME/master.passwd
30 # Test modifying a user with comments
31 atf_test_case user_mod_comments
32 user_mod_comments_body() {
35 atf_check -s exit:0 ${PW} useradd test -c "Test User,home,123,456"
36 atf_check -s exit:0 ${PW} usermod test -c "Test User,work,123,456"
37 atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
38 grep "^test:.*:Test User,work,123,456:" $HOME/master.passwd
41 # Test modifying a user with comments with option -N
42 atf_test_case user_mod_comments_noupdate
43 user_mod_comments_noupdate_body() {
46 atf_check -s exit:0 ${PW} useradd test -c "Test User,home,123,456"
47 atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
48 ${PW} usermod test -c "Test User,work,123,456" -N
49 atf_check -s exit:0 -o match:"^test:.*:Test User,home,123,456:" \
50 grep "^test:.*:Test User,home,123,456:" $HOME/master.passwd
53 # Test modifying a user with invalid comments
54 atf_test_case user_mod_comments_invalid
55 user_mod_comments_invalid_body() {
58 atf_check -s exit:0 ${PW} useradd test
59 atf_check -s exit:65 -e match:"invalid character" \
60 ${PW} usermod test -c "Test User,work,123:456,456"
61 atf_check -s exit:1 -o empty \
62 grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
63 atf_check -s exit:0 -o match:"^test:\*" \
64 grep "^test:\*" $HOME/master.passwd
67 # Test modifying a user with invalid comments with option -N
68 atf_test_case user_mod_comments_invalid_noupdate
69 user_mod_comments_invalid_noupdate_body() {
72 atf_check -s exit:0 ${PW} useradd test
73 atf_check -s exit:65 -e match:"invalid character" \
74 ${PW} usermod test -c "Test User,work,123:456,456" -N
75 atf_check -s exit:1 -o empty \
76 grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
77 atf_check -s exit:0 -o match:"^test:\*" \
78 grep "^test:\*" $HOME/master.passwd
81 # Test modifying a user name with -l
82 atf_test_case user_mod_name
83 user_mod_name_body() {
86 atf_check -s exit:0 ${PW} useradd foo
87 atf_check -s exit:0 ${PW} usermod foo -l "bar"
88 atf_check -s exit:0 -o match:"^bar:.*" \
89 grep "^bar:.*" $HOME/master.passwd
92 # Test modifying a user name with -l with option -N
93 atf_test_case user_mod_name_noupdate
94 user_mod_name_noupdate_body() {
97 atf_check -s exit:0 ${PW} useradd foo
98 atf_check -s exit:0 -o match:"^bar:.*" ${PW} usermod foo -l "bar" -N
99 atf_check -s exit:0 -o match:"^foo:.*" \
100 grep "^foo:.*" $HOME/master.passwd
103 atf_test_case user_mod_rename_multigroups
104 user_mod_rename_multigroups_body() {
107 atf_check -s exit:0 ${PW} groupadd test1
108 atf_check -s exit:0 ${PW} groupadd test2
109 atf_check -s exit:0 ${PW} useradd foo -G test1,test2
110 atf_check -o match:"foo" -s exit:0 ${PW} groupshow test1
111 atf_check -o match:"foo" -s exit:0 ${PW} groupshow test2
112 atf_check -s exit:0 ${PW} usermod foo -l bar
113 atf_check -o match:"bar" -s exit:0 ${PW} groupshow test1
114 atf_check -o match:"bar" -s exit:0 ${PW} groupshow test2
117 atf_test_case user_mod_nogroups
118 user_mod_nogroups_body() {
121 atf_check -s exit:0 ${PW} groupadd test1
122 atf_check -s exit:0 ${PW} groupadd test2
123 atf_check -s exit:0 ${PW} groupadd test3
124 atf_check -s exit:0 ${PW} groupadd test4
125 atf_check -s exit:0 ${PW} useradd foo -G test1,test2
126 atf_check -o match:"foo" -s exit:0 ${PW} groupshow test1
127 atf_check -o match:"foo" -s exit:0 ${PW} groupshow test2
128 atf_check -s exit:0 ${PW} usermod foo -G test3,test4
129 atf_check -s exit:0 -o inline:"test3\ntest4\n" \
130 awk -F\: '$4 == "foo" { print $1 }' ${HOME}/group
133 atf_test_case user_mod_rename
134 user_mod_rename_body() {
137 atf_check -s exit:0 ${PW} useradd foo
138 atf_check -s exit:0 ${PW} usermod foo -l bar
139 atf_check -s exit:0 -o match:"^bar:.*" \
140 grep "^bar:.*" ${HOME}/master.passwd
143 atf_test_case user_mod_rename_too_long
144 user_mod_rename_too_long_body() {
147 atf_check -s exit:0 ${PW} useradd foo
148 atf_check -s exit:64 -e match:"too long" ${PW} usermod foo \
149 -l name_very_very_very_very_very_long
152 atf_test_case user_mod_h
156 atf_check -s exit:0 ${PW} useradd foo
157 atf_check -s exit:0 ${PW} usermod foo -h 0 <<- EOF
160 atf_check -s exit:0 -o not-match:"^foo:\*:.*" \
161 grep "^foo" ${HOME}/master.passwd
162 atf_check -s exit:0 ${PW} usermod foo -h - <<- EOF
165 atf_check -s exit:0 -o match:"^foo:\*:.*" \
166 grep "^foo" ${HOME}/master.passwd
167 atf_check -e inline:"pw: Bad file descriptor 'a': invalid\n" \
168 -s exit:64 ${PW} usermod foo -h a <<- EOF
173 atf_test_case user_mod_H
177 atf_check -s exit:0 ${PW} useradd foo
178 atf_check -s exit:0 ${PW} usermod foo -H 0 <<- EOF
181 atf_check -s exit:0 -o match:"^foo:a:.*" \
182 grep "^foo" ${HOME}/master.passwd
183 atf_check -s exit:64 -e inline:"pw: -H expects a file descriptor\n" \
184 ${PW} usermod foo -H -
187 atf_test_case user_mod_renamehome
188 user_mod_renamehome_body() {
189 populate_root_etc_skel
191 mkdir -p ${HOME}/home
192 atf_check -s exit:0 ${RPW} useradd foo -m
193 test -d ${HOME}/home/foo || atf_fail "Directory not created"
194 atf_check -s exit:0 ${RPW} usermod foo -l bar -d /home/bar -m
195 test -d ${HOME}/home/bar || atf_fail "Directory not created"
198 atf_test_case user_mod_uid
199 user_mod_uid_body() {
202 atf_check -s exit:0 ${PW} useradd foo
203 atf_check -s exit:0 ${PW} usermod foo -u 5000
206 atf_init_test_cases() {
207 atf_add_test_case user_mod
208 atf_add_test_case user_mod_noupdate
209 atf_add_test_case user_mod_comments
210 atf_add_test_case user_mod_comments_noupdate
211 atf_add_test_case user_mod_comments_invalid
212 atf_add_test_case user_mod_comments_invalid_noupdate
213 atf_add_test_case user_mod_nogroups
214 atf_add_test_case user_mod_rename
215 atf_add_test_case user_mod_name_noupdate
216 atf_add_test_case user_mod_rename_too_long
217 atf_add_test_case user_mod_rename_multigroups
218 atf_add_test_case user_mod_h
219 atf_add_test_case user_mod_H
220 atf_add_test_case user_mod_renamehome
221 atf_add_test_case user_mod_uid