3 # Import helper functions
4 . $(atf_get_srcdir)/helper_functions.shin
11 atf_check -s exit:0 ${PW} useradd test
12 atf_check -s exit:0 -o match:"^test:.*" \
13 grep "^test:.*" $HOME/master.passwd
16 # Test add user with option -N
17 atf_test_case user_add_noupdate
18 user_add_noupdate_body() {
21 atf_check -s exit:0 -o match:"^test:.*" ${PW} useradd test -N
22 atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
25 # Test add user with comments
26 atf_test_case user_add_comments
27 user_add_comments_body() {
30 atf_check -s exit:0 ${PW} useradd test -c "Test User,work,123,456"
31 atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
32 grep "^test:.*:Test User,work,123,456:" $HOME/master.passwd
35 # Test add user with comments and option -N
36 atf_test_case user_add_comments_noupdate
37 user_add_comments_noupdate_body() {
40 atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
41 ${PW} useradd test -c "Test User,work,123,456" -N
42 atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
45 # Test add user with invalid comments
46 atf_test_case user_add_comments_invalid
47 user_add_comments_invalid_body() {
50 atf_check -s exit:65 -e match:"invalid character" \
51 ${PW} useradd test -c "Test User,work,123:456,456"
52 atf_check -s exit:1 -o empty \
53 grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
56 # Test add user with invalid comments and option -N
57 atf_test_case user_add_comments_invalid_noupdate
58 user_add_comments_invalid_noupdate_body() {
61 atf_check -s exit:65 -e match:"invalid character" \
62 ${PW} useradd test -c "Test User,work,123:456,456" -N
63 atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
66 # Test add user with alternate homedir
67 atf_test_case user_add_homedir
68 user_add_homedir_body() {
71 atf_check -s exit:0 ${PW} useradd test -d /foo/bar
72 atf_check -s exit:0 -o match:"^test:\*:.*::0:0:User &:/foo/bar:.*" \
76 # Test add user with account expiration as an epoch date
77 atf_test_case user_add_account_expiration_epoch
78 user_add_account_expiration_epoch_body() {
81 DATE=`date -j -v+1d "+%s"`
82 atf_check -s exit:0 ${PW} useradd test -e ${DATE}
83 atf_check -s exit:0 -o match:"^test:\*:.*::0:${DATE}:.*" \
87 # Test add user with account expiration as a DD-MM-YYYY date
88 atf_test_case user_add_account_expiration_date_numeric
89 user_add_account_expiration_date_numeric_body() {
92 DATE=`date -j -v+1d "+%d-%m-%Y"`
93 EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
94 atf_check -s exit:0 ${PW} useradd test -e ${DATE}
95 atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
99 # Test add user with account expiration as a DD-MM-YYYY date
100 atf_test_case user_add_account_expiration_date_month
101 user_add_account_expiration_date_month_body() {
104 DATE=`date -j -v+1d "+%d-%b-%Y"`
105 EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
106 atf_check -s exit:0 ${PW} useradd test -e ${DATE}
107 atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
111 # Test add user with account expiration as a relative date
112 atf_test_case user_add_account_expiration_date_relative
113 user_add_account_expiration_date_relative_body() {
116 EPOCH=`date -j -v+13m "+%s"`
117 BUF=`expr $EPOCH + 5`
118 atf_check -s exit:0 ${PW} useradd test -e +13o
119 TIME=`${PW} usershow test | awk -F ':' '{print $7}'`
120 [ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \
121 atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds."
124 # Test add user with password expiration as an epoch date
125 atf_test_case user_add_password_expiration_epoch
126 user_add_password_expiration_epoch_body() {
129 DATE=`date -j -v+1d "+%s"`
130 atf_check -s exit:0 ${PW} useradd test -p ${DATE}
131 atf_check -s exit:0 -o match:"^test:\*:.*::${DATE}:0:.*" \
135 # Test add user with password expiration as a DD-MM-YYYY date
136 atf_test_case user_add_password_expiration_date_numeric
137 user_add_password_expiration_date_numeric_body() {
140 DATE=`date -j -v+1d "+%d-%m-%Y"`
141 EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
142 atf_check -s exit:0 ${PW} useradd test -p ${DATE}
143 atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
147 # Test add user with password expiration as a DD-MMM-YYYY date
148 atf_test_case user_add_password_expiration_date_month
149 user_add_password_expiration_date_month_body() {
152 DATE=`date -j -v+1d "+%d-%b-%Y"`
153 EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
154 atf_check -s exit:0 ${PW} useradd test -p ${DATE}
155 atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
159 # Test add user with password expiration as a relative date
160 atf_test_case user_add_password_expiration_date_relative
161 user_add_password_expiration_date_relative_body() {
164 EPOCH=`date -j -v+13m "+%s"`
165 BUF=`expr $EPOCH + 5`
166 atf_check -s exit:0 ${PW} useradd test -p +13o
167 TIME=`${PW} usershow test | awk -F ':' '{print $6}'`
168 [ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \
169 atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds."
172 atf_test_case user_add_name_too_long
173 user_add_name_too_long_body() {
175 atf_check -e match:"too long" -s exit:64 \
176 ${PW} useradd name_very_vert_very_very_very_long
179 atf_init_test_cases() {
180 atf_add_test_case user_add
181 atf_add_test_case user_add_noupdate
182 atf_add_test_case user_add_comments
183 atf_add_test_case user_add_comments_noupdate
184 atf_add_test_case user_add_comments_invalid
185 atf_add_test_case user_add_comments_invalid_noupdate
186 atf_add_test_case user_add_homedir
187 atf_add_test_case user_add_account_expiration_epoch
188 atf_add_test_case user_add_account_expiration_date_numeric
189 atf_add_test_case user_add_account_expiration_date_month
190 atf_add_test_case user_add_account_expiration_date_relative
191 atf_add_test_case user_add_password_expiration_epoch
192 atf_add_test_case user_add_password_expiration_date_numeric
193 atf_add_test_case user_add_password_expiration_date_month
194 atf_add_test_case user_add_password_expiration_date_relative
195 atf_add_test_case user_add_name_too_long