]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pw/tests/pw_useradd.sh
Merge llvm 3.6.0rc4 from ^/vendor/llvm/dist, merge clang 3.6.0rc4 from
[FreeBSD/FreeBSD.git] / usr.sbin / pw / tests / pw_useradd.sh
1 # $FreeBSD$
2
3 # Import helper functions
4 . $(atf_get_srcdir)/helper_functions.shin
5
6 # Test add user
7 atf_test_case user_add
8 user_add_body() {
9         populate_etc_skel
10
11         atf_check -s exit:0 ${PW} useradd test
12         atf_check -s exit:0 -o match:"^test:.*" \
13                 grep "^test:.*" $HOME/master.passwd
14 }
15
16 # Test add user with option -N
17 atf_test_case user_add_noupdate
18 user_add_noupdate_body() {
19         populate_etc_skel
20
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
23 }
24
25 # Test add user with comments
26 atf_test_case user_add_comments
27 user_add_comments_body() {
28         populate_etc_skel
29
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
33 }
34
35 # Test add user with comments and option -N
36 atf_test_case user_add_comments_noupdate
37 user_add_comments_noupdate_body() {
38         populate_etc_skel
39
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
43 }
44
45 # Test add user with invalid comments
46 atf_test_case user_add_comments_invalid
47 user_add_comments_invalid_body() {
48         populate_etc_skel
49
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
54 }
55
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() {
59         populate_etc_skel
60
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
64 }
65
66 # Test add user with alternate homedir
67 atf_test_case user_add_homedir
68 user_add_homedir_body() {
69         populate_etc_skel
70
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:.*" \
73                 ${PW} usershow test
74 }
75
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() {
79         populate_etc_skel
80
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}:.*" \
84                 ${PW} usershow test
85 }
86
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() {
90         populate_etc_skel
91
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 &:.*" \
96                 ${PW} usershow test
97 }
98
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() {
102         populate_etc_skel
103
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 &:.*" \
108                 ${PW} usershow test
109 }
110
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() {
114         populate_etc_skel
115
116         EPOCH=`date -j -v+13m "+%s"`
117         atf_check -s exit:0 ${PW} useradd test -e +13o
118         atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
119                 ${PW} usershow test
120 }
121
122 # Test add user with password expiration as an epoch date
123 atf_test_case user_add_password_expiration_epoch
124 user_add_password_expiration_epoch_body() {
125         populate_etc_skel
126
127         DATE=`date -j -v+1d "+%s"`
128         atf_check -s exit:0 ${PW} useradd test -p ${DATE}
129         atf_check -s exit:0 -o match:"^test:\*:.*::${DATE}:0:.*" \
130                 ${PW} usershow test
131 }
132
133 # Test add user with password expiration as a DD-MM-YYYY date
134 atf_test_case user_add_password_expiration_date_numeric
135 user_add_password_expiration_date_numeric_body() {
136         populate_etc_skel
137
138         DATE=`date -j -v+1d "+%d-%m-%Y"`
139         EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
140         atf_check -s exit:0 ${PW} useradd test -p ${DATE}
141         atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
142                 ${PW} usershow test
143 }
144
145 # Test add user with password expiration as a DD-MMM-YYYY date
146 atf_test_case user_add_password_expiration_date_month
147 user_add_password_expiration_date_month_body() {
148         populate_etc_skel
149
150         DATE=`date -j -v+1d "+%d-%b-%Y"`
151         EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
152         atf_check -s exit:0 ${PW} useradd test -p ${DATE}
153         atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
154                 ${PW} usershow test
155 }
156
157 # Test add user with password expiration as a relative date
158 atf_test_case user_add_password_expiration_date_relative
159 user_add_password_expiration_date_relative_body() {
160         populate_etc_skel
161
162         EPOCH=`date -j -v+13m "+%s"`
163         atf_check -s exit:0 ${PW} useradd test -p +13o
164         atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
165                 ${PW} usershow test
166 }
167
168 atf_init_test_cases() {
169         atf_add_test_case user_add
170         atf_add_test_case user_add_noupdate
171         atf_add_test_case user_add_comments
172         atf_add_test_case user_add_comments_noupdate
173         atf_add_test_case user_add_comments_invalid 
174         atf_add_test_case user_add_comments_invalid_noupdate
175         atf_add_test_case user_add_homedir
176         atf_add_test_case user_add_account_expiration_epoch
177         atf_add_test_case user_add_account_expiration_date_numeric
178         atf_add_test_case user_add_account_expiration_date_month
179         atf_add_test_case user_add_account_expiration_date_relative
180         atf_add_test_case user_add_password_expiration_epoch
181         atf_add_test_case user_add_password_expiration_date_numeric
182         atf_add_test_case user_add_password_expiration_date_month
183         atf_add_test_case user_add_password_expiration_date_relative
184 }