xref: /freebsd/usr.sbin/pw/tests/pw_useradd_test.sh (revision d1005f6a13933c0928de73c1660fdf751362c5e5)
1458cbf0aSEnji Cooper# $FreeBSD$
2458cbf0aSEnji Cooper
3458cbf0aSEnji Cooper# Import helper functions
4458cbf0aSEnji Cooper. $(atf_get_srcdir)/helper_functions.shin
5458cbf0aSEnji Cooper
6458cbf0aSEnji Cooper# Test add user
7458cbf0aSEnji Cooperatf_test_case user_add
8458cbf0aSEnji Cooperuser_add_body() {
9458cbf0aSEnji Cooper	populate_etc_skel
10458cbf0aSEnji Cooper
11458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test
12458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:.*" \
13458cbf0aSEnji Cooper		grep "^test:.*" $HOME/master.passwd
14458cbf0aSEnji Cooper}
15458cbf0aSEnji Cooper
16458cbf0aSEnji Cooper# Test add user with option -N
17458cbf0aSEnji Cooperatf_test_case user_add_noupdate
18458cbf0aSEnji Cooperuser_add_noupdate_body() {
19458cbf0aSEnji Cooper	populate_etc_skel
20458cbf0aSEnji Cooper
21458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:.*" ${PW} useradd test -N
22458cbf0aSEnji Cooper	atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
23458cbf0aSEnji Cooper}
24458cbf0aSEnji Cooper
25458cbf0aSEnji Cooper# Test add user with comments
26458cbf0aSEnji Cooperatf_test_case user_add_comments
27458cbf0aSEnji Cooperuser_add_comments_body() {
28458cbf0aSEnji Cooper	populate_etc_skel
29458cbf0aSEnji Cooper
30458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -c "Test User,work,123,456"
31458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
32458cbf0aSEnji Cooper		grep "^test:.*:Test User,work,123,456:" $HOME/master.passwd
33458cbf0aSEnji Cooper}
34458cbf0aSEnji Cooper
35458cbf0aSEnji Cooper# Test add user with comments and option -N
36458cbf0aSEnji Cooperatf_test_case user_add_comments_noupdate
37458cbf0aSEnji Cooperuser_add_comments_noupdate_body() {
38458cbf0aSEnji Cooper	populate_etc_skel
39458cbf0aSEnji Cooper
40458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
41458cbf0aSEnji Cooper		${PW} useradd test -c "Test User,work,123,456" -N
42458cbf0aSEnji Cooper	atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
43458cbf0aSEnji Cooper}
44458cbf0aSEnji Cooper
45458cbf0aSEnji Cooper# Test add user with invalid comments
46458cbf0aSEnji Cooperatf_test_case user_add_comments_invalid
47458cbf0aSEnji Cooperuser_add_comments_invalid_body() {
48458cbf0aSEnji Cooper	populate_etc_skel
49458cbf0aSEnji Cooper
50458cbf0aSEnji Cooper	atf_check -s exit:65 -e match:"invalid character" \
51458cbf0aSEnji Cooper		${PW} useradd test -c "Test User,work,123:456,456"
52458cbf0aSEnji Cooper	atf_check -s exit:1 -o empty \
53458cbf0aSEnji Cooper		grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
54458cbf0aSEnji Cooper}
55458cbf0aSEnji Cooper
56458cbf0aSEnji Cooper# Test add user with invalid comments and option -N
57458cbf0aSEnji Cooperatf_test_case user_add_comments_invalid_noupdate
58458cbf0aSEnji Cooperuser_add_comments_invalid_noupdate_body() {
59458cbf0aSEnji Cooper	populate_etc_skel
60458cbf0aSEnji Cooper
61458cbf0aSEnji Cooper	atf_check -s exit:65 -e match:"invalid character" \
62458cbf0aSEnji Cooper		${PW} useradd test -c "Test User,work,123:456,456" -N
63458cbf0aSEnji Cooper	atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
64458cbf0aSEnji Cooper}
65458cbf0aSEnji Cooper
66458cbf0aSEnji Cooper# Test add user with alternate homedir
67458cbf0aSEnji Cooperatf_test_case user_add_homedir
68458cbf0aSEnji Cooperuser_add_homedir_body() {
69458cbf0aSEnji Cooper	populate_etc_skel
70458cbf0aSEnji Cooper
71458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -d /foo/bar
72458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:.*::0:0:User &:/foo/bar:.*" \
73458cbf0aSEnji Cooper		${PW} usershow test
74458cbf0aSEnji Cooper}
75458cbf0aSEnji Cooper
76458cbf0aSEnji Cooper# Test add user with account expiration as an epoch date
77458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_epoch
78458cbf0aSEnji Cooperuser_add_account_expiration_epoch_body() {
79458cbf0aSEnji Cooper	populate_etc_skel
80458cbf0aSEnji Cooper
81458cbf0aSEnji Cooper	DATE=`date -j -v+1d "+%s"`
82458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -e ${DATE}
83458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:.*::0:${DATE}:.*" \
84458cbf0aSEnji Cooper		${PW} usershow test
85458cbf0aSEnji Cooper}
86458cbf0aSEnji Cooper
87458cbf0aSEnji Cooper# Test add user with account expiration as a DD-MM-YYYY date
88458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_date_numeric
89458cbf0aSEnji Cooperuser_add_account_expiration_date_numeric_body() {
90458cbf0aSEnji Cooper	populate_etc_skel
91458cbf0aSEnji Cooper
92458cbf0aSEnji Cooper	DATE=`date -j -v+1d "+%d-%m-%Y"`
93458cbf0aSEnji Cooper	EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
94458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -e ${DATE}
95458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
96458cbf0aSEnji Cooper		${PW} usershow test
97458cbf0aSEnji Cooper}
98458cbf0aSEnji Cooper
99458cbf0aSEnji Cooper# Test add user with account expiration as a DD-MM-YYYY date
100458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_date_month
101458cbf0aSEnji Cooperuser_add_account_expiration_date_month_body() {
102458cbf0aSEnji Cooper	populate_etc_skel
103458cbf0aSEnji Cooper
104458cbf0aSEnji Cooper	DATE=`date -j -v+1d "+%d-%b-%Y"`
105458cbf0aSEnji Cooper	EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
106458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -e ${DATE}
107458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
108458cbf0aSEnji Cooper		${PW} usershow test
109458cbf0aSEnji Cooper}
110458cbf0aSEnji Cooper
111458cbf0aSEnji Cooper# Test add user with account expiration as a relative date
112458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_date_relative
113458cbf0aSEnji Cooperuser_add_account_expiration_date_relative_body() {
114458cbf0aSEnji Cooper	populate_etc_skel
115458cbf0aSEnji Cooper
116458cbf0aSEnji Cooper	EPOCH=`date -j -v+13m "+%s"`
117458cbf0aSEnji Cooper	BUF=`expr $EPOCH + 5`
118458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -e +13o
119458cbf0aSEnji Cooper	TIME=`${PW} usershow test | awk -F ':' '{print $7}'`
120458cbf0aSEnji Cooper	[ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \
121458cbf0aSEnji Cooper		atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds."
122458cbf0aSEnji Cooper}
123458cbf0aSEnji Cooper
124458cbf0aSEnji Cooper# Test add user with password expiration as an epoch date
125458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_epoch
126458cbf0aSEnji Cooperuser_add_password_expiration_epoch_body() {
127458cbf0aSEnji Cooper	populate_etc_skel
128458cbf0aSEnji Cooper
129458cbf0aSEnji Cooper	DATE=`date -j -v+1d "+%s"`
130458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -p ${DATE}
131458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:.*::${DATE}:0:.*" \
132458cbf0aSEnji Cooper		${PW} usershow test
133458cbf0aSEnji Cooper}
134458cbf0aSEnji Cooper
135458cbf0aSEnji Cooper# Test add user with password expiration as a DD-MM-YYYY date
136458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_date_numeric
137458cbf0aSEnji Cooperuser_add_password_expiration_date_numeric_body() {
138458cbf0aSEnji Cooper	populate_etc_skel
139458cbf0aSEnji Cooper
140458cbf0aSEnji Cooper	DATE=`date -j -v+1d "+%d-%m-%Y"`
141458cbf0aSEnji Cooper	EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
142458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -p ${DATE}
143458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
144458cbf0aSEnji Cooper		${PW} usershow test
145458cbf0aSEnji Cooper}
146458cbf0aSEnji Cooper
147458cbf0aSEnji Cooper# Test add user with password expiration as a DD-MMM-YYYY date
148458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_date_month
149458cbf0aSEnji Cooperuser_add_password_expiration_date_month_body() {
150458cbf0aSEnji Cooper	populate_etc_skel
151458cbf0aSEnji Cooper
152458cbf0aSEnji Cooper	DATE=`date -j -v+1d "+%d-%b-%Y"`
153458cbf0aSEnji Cooper	EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
154458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -p ${DATE}
155458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
156458cbf0aSEnji Cooper		${PW} usershow test
157458cbf0aSEnji Cooper}
158458cbf0aSEnji Cooper
159458cbf0aSEnji Cooper# Test add user with password expiration as a relative date
160458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_date_relative
161458cbf0aSEnji Cooperuser_add_password_expiration_date_relative_body() {
162458cbf0aSEnji Cooper	populate_etc_skel
163458cbf0aSEnji Cooper
164458cbf0aSEnji Cooper	EPOCH=`date -j -v+13m "+%s"`
165458cbf0aSEnji Cooper	BUF=`expr $EPOCH + 5`
166458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd test -p +13o
167458cbf0aSEnji Cooper	TIME=`${PW} usershow test | awk -F ':' '{print $6}'`
168458cbf0aSEnji Cooper	[ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \
169458cbf0aSEnji Cooper		atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds."
170458cbf0aSEnji Cooper}
171458cbf0aSEnji Cooper
172458cbf0aSEnji Cooperatf_test_case user_add_name_too_long
173458cbf0aSEnji Cooperuser_add_name_too_long_body() {
174458cbf0aSEnji Cooper	populate_etc_skel
175458cbf0aSEnji Cooper	atf_check -e match:"too long" -s exit:64 \
176458cbf0aSEnji Cooper		${PW} useradd name_very_vert_very_very_very_long
177458cbf0aSEnji Cooper}
178458cbf0aSEnji Cooper
179458cbf0aSEnji Cooperatf_test_case user_add_expiration
180458cbf0aSEnji Cooperuser_add_expiration_body() {
181458cbf0aSEnji Cooper	populate_etc_skel
182458cbf0aSEnji Cooper
183458cbf0aSEnji Cooper	atf_check -s exit:0 \
184458cbf0aSEnji Cooper		${PW} useradd foo -e 20-03-2037
185458cbf0aSEnji Cooper	atf_check -o inline:"foo:*:1001:1001::0:2121120000:User &:/home/foo:/bin/sh\n" \
186458cbf0aSEnji Cooper		-s exit:0 grep "^foo" ${HOME}/master.passwd
187458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} userdel foo
188458cbf0aSEnji Cooper	atf_check -s exit:0 \
189458cbf0aSEnji Cooper		${PW} useradd foo -e 20-03-37
190458cbf0aSEnji Cooper	atf_check -o inline:"foo:*:1001:1001::0:2121120000:User &:/home/foo:/bin/sh\n" \
191458cbf0aSEnji Cooper		-s exit:0 grep "^foo" ${HOME}/master.passwd
192458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} userdel foo
193458cbf0aSEnji Cooper	atf_check -s exit:0 \
194458cbf0aSEnji Cooper		${PW} useradd foo -e 20-Mar-2037
195458cbf0aSEnji Cooper	atf_check -o inline:"foo:*:1001:1001::0:2121120000:User &:/home/foo:/bin/sh\n" \
196458cbf0aSEnji Cooper		-s exit:0 grep "^foo" ${HOME}/master.passwd
197458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} userdel foo
198458cbf0aSEnji Cooper	atf_check -e inline:"pw: Invalid date\n" -s exit:1 \
199458cbf0aSEnji Cooper		${PW} useradd foo -e 20-Foo-2037
200458cbf0aSEnji Cooper	atf_check -e inline:"pw: Invalid date\n" -s exit:1 \
201458cbf0aSEnji Cooper		${PW} useradd foo -e 20-13-2037
202458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo -e "12:00 20-03-2037"
203458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} userdel foo
204458cbf0aSEnji Cooper	atf_check -e inline:"pw: Invalid date\n" -s exit:1 \
205458cbf0aSEnji Cooper		${PW} useradd foo -e "12 20-03-2037"
206458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo -e "20-03-2037	12:00"
207458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} userdel foo
208458cbf0aSEnji Cooper}
209458cbf0aSEnji Cooper
210458cbf0aSEnji Cooperatf_test_case user_add_invalid_user_entry
211458cbf0aSEnji Cooperuser_add_invalid_user_entry_body() {
212458cbf0aSEnji Cooper	touch ${HOME}/master.passwd
213458cbf0aSEnji Cooper	touch ${HOME}/group
214458cbf0aSEnji Cooper
215458cbf0aSEnji Cooper	pwd_mkdb -p -d ${HOME} ${HOME}/master.passwd || \
216458cbf0aSEnji Cooper		atf_fail "generate passwd from master.passwd"
217458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo
218458cbf0aSEnji Cooper	echo "foo1:*:1002" >> ${HOME}/master.passwd
219458cbf0aSEnji Cooper	atf_check -s exit:1 -e match:"Invalid user entry" ${PW} useradd foo2
220458cbf0aSEnji Cooper}
221458cbf0aSEnji Cooper
222458cbf0aSEnji Cooperatf_test_case user_add_invalid_group_entry
223458cbf0aSEnji Cooperuser_add_invalid_group_entry_body() {
224458cbf0aSEnji Cooper	touch ${HOME}/master.passwd
225458cbf0aSEnji Cooper	touch ${HOME}/group
226458cbf0aSEnji Cooper
227458cbf0aSEnji Cooper	pwd_mkdb -p -d ${HOME} ${HOME}/master.passwd || \
228458cbf0aSEnji Cooper		atf_fail "generate passwd from master.passwd"
229458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo
230458cbf0aSEnji Cooper	echo 'foo1:*:1002' >> group
231458cbf0aSEnji Cooper	atf_check -s exit:1 -e match:"Invalid group entry" ${PW} useradd foo2
232458cbf0aSEnji Cooper}
233458cbf0aSEnji Cooper
234458cbf0aSEnji Cooperatf_test_case user_add_password_from_h
235458cbf0aSEnji Cooperuser_add_password_from_h_body() {
236458cbf0aSEnji Cooper	populate_etc_skel
237458cbf0aSEnji Cooper
238458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo -h 0 <<-EOF
239458cbf0aSEnji Cooper	$(echo mypassword)
240458cbf0aSEnji Cooper	EOF
241458cbf0aSEnji Cooper	passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd`
242458cbf0aSEnji Cooper	atf_check -s exit:0 -o inline:$passhash \
243458cbf0aSEnji Cooper		$(atf_get_srcdir)/crypt $passhash "mypassword"
244458cbf0aSEnji Cooper}
245458cbf0aSEnji Cooper
246458cbf0aSEnji Cooperatf_test_case user_add_R
247458cbf0aSEnji Cooperuser_add_R_body() {
248458cbf0aSEnji Cooper	populate_root_etc_skel
249458cbf0aSEnji Cooper
250458cbf0aSEnji Cooper	atf_check -s exit:0 ${RPW} useradd foo
251458cbf0aSEnji Cooper	atf_check -s exit:0 ${RPW} useradd bar -m
252458cbf0aSEnji Cooper	test -d ${HOME}/home || atf_fail "Home parent directory not created"
253458cbf0aSEnji Cooper	test -d ${HOME}/home/bar || atf_fail "Directory not created"
254458cbf0aSEnji Cooper	atf_check -s exit:0 ${RPW} userdel bar
255458cbf0aSEnji Cooper	test -d ${HOME}/home/bar || atf_fail "Directory removed"
256458cbf0aSEnji Cooper	atf_check -s exit:0 ${RPW} useradd bar
257458cbf0aSEnji Cooper	atf_check -s exit:0 ${RPW} userdel bar -r
258458cbf0aSEnji Cooper	[ ! -d ${HOME}/home/bar ] || atf_fail "Directory not removed"
259458cbf0aSEnji Cooper}
260458cbf0aSEnji Cooper
261458cbf0aSEnji Cooperatf_test_case user_add_R_symlink
262458cbf0aSEnji Cooperuser_add_R_symlink_body() {
263458cbf0aSEnji Cooper	populate_root_etc_skel
264458cbf0aSEnji Cooper
265458cbf0aSEnji Cooper	mkdir ${HOME}/usr
266458cbf0aSEnji Cooper	atf_check -s exit:0 ${RPW} useradd foo -m
267458cbf0aSEnji Cooper	test -d ${HOME}/usr/home || atf_fail "Home parent directory not created"
268458cbf0aSEnji Cooper	test -h ${HOME}/home || atf_fail "/home directory is not a symlink"
269458cbf0aSEnji Cooper	atf_check -s exit:0 -o inline:"usr/home\n" readlink ${HOME}/home
270458cbf0aSEnji Cooper}
271458cbf0aSEnji Cooper
272458cbf0aSEnji Cooperatf_test_case user_add_skel
273458cbf0aSEnji Cooperuser_add_skel_body() {
274458cbf0aSEnji Cooper	populate_root_etc_skel
275458cbf0aSEnji Cooper
276458cbf0aSEnji Cooper	mkdir ${HOME}/skel
277458cbf0aSEnji Cooper	echo "a" > ${HOME}/skel/.a
278458cbf0aSEnji Cooper	echo "b" > ${HOME}/skel/b
279458cbf0aSEnji Cooper	mkdir ${HOME}/skel/c
280458cbf0aSEnji Cooper	mkdir ${HOME}/skel/c/d
281458cbf0aSEnji Cooper	mkdir ${HOME}/skel/dot.plop
282458cbf0aSEnji Cooper	echo "c" > ${HOME}/skel/c/d/dot.c
283458cbf0aSEnji Cooper	mkdir ${HOME}/home
284458cbf0aSEnji Cooper	ln -sf /nonexistent ${HOME}/skel/c/foo
285458cbf0aSEnji Cooper	atf_check -s exit:0 ${RPW} useradd foo -k /skel -m
286458cbf0aSEnji Cooper	test -d ${HOME}/home/foo || atf_fail "Directory not created"
287458cbf0aSEnji Cooper	test -f ${HOME}/home/foo/.a || atf_fail "File not created"
288458cbf0aSEnji Cooper	atf_check -o file:${HOME}/skel/.a -s exit:0 cat ${HOME}/home/foo/.a
289458cbf0aSEnji Cooper	atf_check -o file:${HOME}/skel/b -s exit:0 cat ${HOME}/home/foo/b
290458cbf0aSEnji Cooper	test -d ${HOME}/home/foo/c || atf_fail "Dotted directory in skel not copied"
291458cbf0aSEnji Cooper	test -d ${HOME}/home/foo/.plop || atf_fail "Directory in skell not created"
292458cbf0aSEnji Cooper	atf_check -o inline:"/nonexistent\n" -s ignore readlink -f ${HOME}/home/foo/c/foo
293458cbf0aSEnji Cooper	atf_check -o file:${HOME}/skel/c/d/dot.c -s exit:0 cat ${HOME}/home/foo/c/d/.c
294458cbf0aSEnji Cooper}
295458cbf0aSEnji Cooper
296458cbf0aSEnji Cooperatf_test_case user_add_uid0
297458cbf0aSEnji Cooperuser_add_uid0_body() {
298458cbf0aSEnji Cooper	populate_etc_skel
299458cbf0aSEnji Cooper	atf_check -e inline:"pw: WARNING: new account \`foo' has a uid of 0 (superuser access!)\n" \
300458cbf0aSEnji Cooper		-s exit:0 ${PW} useradd foo -u 0 -g 0 -d /root -s /bin/sh -c "Bourne-again Superuser" -o
301458cbf0aSEnji Cooper	atf_check \
302458cbf0aSEnji Cooper		-o inline:"foo:*:0:0::0:0:Bourne-again Superuser:/root:/bin/sh\n" \
303458cbf0aSEnji Cooper		-s exit:0 ${PW} usershow foo
304458cbf0aSEnji Cooper}
305458cbf0aSEnji Cooper
306458cbf0aSEnji Cooperatf_test_case user_add_uid_too_large
307458cbf0aSEnji Cooperuser_add_uid_too_large_body() {
308458cbf0aSEnji Cooper	populate_etc_skel
309458cbf0aSEnji Cooper	atf_check -s exit:64 -e inline:"pw: Bad id '9999999999999': too large\n" \
310458cbf0aSEnji Cooper		${PW} useradd -n test1 -u 9999999999999
311458cbf0aSEnji Cooper}
312458cbf0aSEnji Cooper
313458cbf0aSEnji Cooperatf_test_case user_add_bad_shell
314458cbf0aSEnji Cooperuser_add_bad_shell_body() {
315458cbf0aSEnji Cooper	populate_etc_skel
316458cbf0aSEnji Cooper
317458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo -s sh
318458cbf0aSEnji Cooper	atf_check -s exit:78 -e ignore ${PW} useradd bar -s badshell
319458cbf0aSEnji Cooper}
320458cbf0aSEnji Cooper
321458cbf0aSEnji Cooperatf_test_case user_add_already_exists
322458cbf0aSEnji Cooperuser_add_already_exists_body() {
323458cbf0aSEnji Cooper	populate_etc_skel
324458cbf0aSEnji Cooper
325458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo
326458cbf0aSEnji Cooper	atf_check -s exit:65 \
327458cbf0aSEnji Cooper		-e inline:"pw: login name \`foo' already exists\n" \
328458cbf0aSEnji Cooper		${PW} useradd foo
329458cbf0aSEnji Cooper}
330458cbf0aSEnji Cooper
331458cbf0aSEnji Cooperatf_test_case user_add_w_error
332458cbf0aSEnji Cooperuser_add_w_error_body() {
333458cbf0aSEnji Cooper	populate_etc_skel
334458cbf0aSEnji Cooper
335458cbf0aSEnji Cooper	atf_check -s exit:1 -e match:"pw: Invalid value for default password" \
336458cbf0aSEnji Cooper		${PW} useradd foo -w invalid_value
337458cbf0aSEnji Cooper}
338458cbf0aSEnji Cooper
339458cbf0aSEnji Cooperatf_test_case user_add_w_no
340458cbf0aSEnji Cooperuser_add_w_no_body() {
341458cbf0aSEnji Cooper	populate_etc_skel
342458cbf0aSEnji Cooper
343458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo -w no
344458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^foo:\*" grep "^foo:" $HOME/master.passwd
345458cbf0aSEnji Cooper}
346458cbf0aSEnji Cooper
347458cbf0aSEnji Cooperatf_test_case user_add_w_none
348458cbf0aSEnji Cooperuser_add_w_none_body() {
349458cbf0aSEnji Cooper	populate_etc_skel
350458cbf0aSEnji Cooper
351458cbf0aSEnji Cooper	atf_check -s exit:0 ${PW} useradd foo -w none
352458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^foo::" grep "^foo:" $HOME/master.passwd
353458cbf0aSEnji Cooper}
354458cbf0aSEnji Cooper
355458cbf0aSEnji Cooperatf_test_case user_add_w_random
356458cbf0aSEnji Cooperuser_add_w_random_body() {
357458cbf0aSEnji Cooper	populate_etc_skel
358458cbf0aSEnji Cooper
359458cbf0aSEnji Cooper	password=`${PW} useradd foo -w random | cat`
360458cbf0aSEnji Cooper	passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd`
361458cbf0aSEnji Cooper	atf_check -s exit:0 -o inline:$passhash \
362458cbf0aSEnji Cooper		$(atf_get_srcdir)/crypt $passhash "$password"
363458cbf0aSEnji Cooper}
364458cbf0aSEnji Cooper
365458cbf0aSEnji Cooperatf_test_case user_add_w_yes
366458cbf0aSEnji Cooperuser_add_w_yes_body() {
367458cbf0aSEnji Cooper	populate_etc_skel
368458cbf0aSEnji Cooper	password=`${PW} useradd foo -w random | cat`
369458cbf0aSEnji Cooper	passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd`
370458cbf0aSEnji Cooper	atf_check -s exit:0 -o inline:$passhash \
371458cbf0aSEnji Cooper		$(atf_get_srcdir)/crypt $passhash "$password"
372458cbf0aSEnji Cooper}
373458cbf0aSEnji Cooper
374458cbf0aSEnji Cooperatf_test_case user_add_with_pw_conf
375458cbf0aSEnji Cooperuser_add_with_pw_conf_body()
376458cbf0aSEnji Cooper{
377458cbf0aSEnji Cooper	populate_etc_skel
378458cbf0aSEnji Cooper	atf_check -s exit:0 \
379458cbf0aSEnji Cooper		${PW} useradd -D -C ${HOME}/pw.conf \
380458cbf0aSEnji Cooper		-u 2000,32767 -i 2000,32767
381458cbf0aSEnji Cooper	atf_check -s exit:0 \
382458cbf0aSEnji Cooper		-o inline:"minuid = 2000\nmaxuid = 32767\nmingid = 2000\nmaxgid = 32767\n" \
383458cbf0aSEnji Cooper		grep "^m.*id =" ${HOME}/pw.conf
384458cbf0aSEnji Cooper	atf_check -s exit:0 \
385458cbf0aSEnji Cooper		${PW} useradd foo -C ${HOME}/pw.conf
386458cbf0aSEnji Cooper}
387*d1005f6aSBaptiste Daroussinatf_test_case user_add_defaultgroup
388*d1005f6aSBaptiste Daroussinuser_add_defaultgroup_body()
389*d1005f6aSBaptiste Daroussin{
390*d1005f6aSBaptiste Daroussin	populate_etc_skel
391*d1005f6aSBaptiste Daroussin	echo 'defaultgroup = "plop"' > ${HOME}/pw.conf
392*d1005f6aSBaptiste Daroussin	atf_check -s exit:0 \
393*d1005f6aSBaptiste Daroussin		${PW} groupadd plop -g 442
394*d1005f6aSBaptiste Daroussin	atf_check -s exit:0 \
395*d1005f6aSBaptiste Daroussin		${PW} useradd foo -C ${HOME}/pw.conf
396*d1005f6aSBaptiste Daroussin	atf_check -s exit:0 \
397*d1005f6aSBaptiste Daroussin		-o inline:"foo:*:1001:442::0:0:User &:/home/foo:/bin/sh\n" \
398*d1005f6aSBaptiste Daroussin		${PW} usershow foo
399*d1005f6aSBaptiste Daroussin}
400458cbf0aSEnji Cooper
401458cbf0aSEnji Cooperatf_init_test_cases() {
402458cbf0aSEnji Cooper	atf_add_test_case user_add
403458cbf0aSEnji Cooper	atf_add_test_case user_add_noupdate
404458cbf0aSEnji Cooper	atf_add_test_case user_add_comments
405458cbf0aSEnji Cooper	atf_add_test_case user_add_comments_noupdate
406458cbf0aSEnji Cooper	atf_add_test_case user_add_comments_invalid
407458cbf0aSEnji Cooper	atf_add_test_case user_add_comments_invalid_noupdate
408458cbf0aSEnji Cooper	atf_add_test_case user_add_homedir
409458cbf0aSEnji Cooper	atf_add_test_case user_add_account_expiration_epoch
410458cbf0aSEnji Cooper	atf_add_test_case user_add_account_expiration_date_numeric
411458cbf0aSEnji Cooper	atf_add_test_case user_add_account_expiration_date_month
412458cbf0aSEnji Cooper	atf_add_test_case user_add_account_expiration_date_relative
413458cbf0aSEnji Cooper	atf_add_test_case user_add_password_expiration_epoch
414458cbf0aSEnji Cooper	atf_add_test_case user_add_password_expiration_date_numeric
415458cbf0aSEnji Cooper	atf_add_test_case user_add_password_expiration_date_month
416458cbf0aSEnji Cooper	atf_add_test_case user_add_password_expiration_date_relative
417458cbf0aSEnji Cooper	atf_add_test_case user_add_name_too_long
418458cbf0aSEnji Cooper	atf_add_test_case user_add_expiration
419458cbf0aSEnji Cooper	atf_add_test_case user_add_invalid_user_entry
420458cbf0aSEnji Cooper	atf_add_test_case user_add_invalid_group_entry
421458cbf0aSEnji Cooper	atf_add_test_case user_add_password_from_h
422458cbf0aSEnji Cooper	atf_add_test_case user_add_R
423458cbf0aSEnji Cooper	atf_add_test_case user_add_R_symlink
424458cbf0aSEnji Cooper	atf_add_test_case user_add_skel
425458cbf0aSEnji Cooper	atf_add_test_case user_add_uid0
426458cbf0aSEnji Cooper	atf_add_test_case user_add_uid_too_large
427458cbf0aSEnji Cooper	atf_add_test_case user_add_bad_shell
428458cbf0aSEnji Cooper	atf_add_test_case user_add_already_exists
429458cbf0aSEnji Cooper	atf_add_test_case user_add_w_error
430458cbf0aSEnji Cooper	atf_add_test_case user_add_w_no
431458cbf0aSEnji Cooper	atf_add_test_case user_add_w_none
432458cbf0aSEnji Cooper	atf_add_test_case user_add_w_random
433458cbf0aSEnji Cooper	atf_add_test_case user_add_w_yes
434458cbf0aSEnji Cooper	atf_add_test_case user_add_with_pw_conf
435*d1005f6aSBaptiste Daroussin	atf_add_test_case user_add_defaultgroup
436458cbf0aSEnji Cooper}
437