]> git.sur5r.net Git - openldap/blob - tests/scripts/test022-ppolicy
fe3fa1a1634723102de280b05f862632915eb692
[openldap] / tests / scripts / test022-ppolicy
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2005 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $PPOLICY = ppolicyno; then 
20         echo "Password policy overlay not available, test skipped"
21         exit 0
22 fi 
23
24 mkdir -p $TESTDIR $DBDIR1
25
26 echo "Starting slapd on TCP/IP port $PORT1..."
27 . $CONFFILTER $BACKEND $MONITORDB < $PPOLICYCONF > $CONF1
28 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
29 PID=$!
30 if test $WAIT != 0 ; then
31     echo PID $PID
32     read foo
33 fi
34 KILLPIDS="$PID"
35
36 USER="uid=nd, ou=People, dc=example, dc=com"
37 PASS=testpassword
38
39 echo "Using ldapsearch to check that slapd is running..."
40 for i in 0 1 2 3 4 5; do
41         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
42                 'objectclass=*' > /dev/null 2>&1
43         RC=$?
44         if test $RC = 0 ; then
45                 break
46         fi
47         echo "Waiting 5 seconds for slapd to start..."
48         sleep 5
49 done
50 if test $RC != 0 ; then
51         echo "ldapsearch failed $(RC)!"
52         test $KILLSERVERS != no && kill -HUP $KILLPIDS
53         exit $RC
54 fi
55
56 echo "Using ldapadd to populate the database..."
57 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
58         $LDIFPPOLICY > $TESTOUT 2>&1
59 RC=$?
60 if test $RC != 0 ; then
61         echo "ldapadd failed ($RC)!"
62         test $KILLSERVERS != no && kill -HUP $KILLPIDS
63         exit $RC
64 fi
65
66 echo "Testing account lockout..."
67 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >$SEARCHOUT 2>&1
68 sleep 2
69 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >>$SEARCHOUT 2>&1
70 sleep 2
71 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >>$SEARCHOUT 2>&1
72 sleep 2
73 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >> $SEARCHOUT 2>&1
74 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
75 COUNT=`grep "Account locked" $SEARCHOUT | wc -l`
76 if test $COUNT != 2 ; then
77         echo "Account lockout test failed"
78         test $KILLSERVERS != no && kill -HUP $KILLPIDS
79         exit 1
80 fi
81
82 echo "Waiting 20 seconds for lockout to reset..."
83 sleep 20
84
85 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
86         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
87 RC=$?
88 if test $RC != 0 ; then
89         echo "ldapsearch failed ($RC)!"
90         test $KILLSERVERS != no && kill -HUP $KILLPIDS
91         exit $RC
92 fi
93
94 echo "Testing password expiration"
95 echo "Waiting 20 seconds for password to expire..."
96 sleep 20
97
98 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
99         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
100 sleep 2
101 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
102         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
103 sleep 2
104 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
105         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
106 sleep 2
107 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
108         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
109 RC=$?
110 if test $RC = 0 ; then
111         echo "Password expiration failed ($RC)!"
112         test $KILLSERVERS != no && kill -HUP $KILLPIDS
113         exit $RC
114 fi
115
116 COUNT=`grep "grace logins" $SEARCHOUT | wc -l`
117 if test $COUNT != 3 ; then
118         echo "Password expiration test failed"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit 1
121 fi
122
123 echo "Resetting password to clear expired status"
124 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
125         -w secret -s $PASS \
126         -D "$MANAGERDN" "$USER" >> $TESTOUT 2>&1
127 RC=$?
128 if test $RC != 0 ; then
129         echo "ldappasswd failed ($RC)!"
130         test $KILLSERVERS != no && kill -HUP $KILLPIDS
131         exit $RC
132 fi
133
134 echo "Filling password history..."
135 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w $PASS > \
136         $TESTOUT 2>&1 << EOMODS
137 dn: uid=nd, ou=People, dc=example, dc=com
138 changetype: modify
139 delete: userpassword
140 userpassword: testpassword
141 -
142 replace: userpassword
143 userpassword: 20urgle12-1
144
145 dn: uid=nd, ou=People, dc=example, dc=com
146 changetype: modify
147 delete: userpassword
148 userpassword: 20urgle12-1
149 -
150 replace: userpassword
151 userpassword: 20urgle12-2
152
153 dn: uid=nd, ou=People, dc=example, dc=com
154 changetype: modify
155 delete: userpassword
156 userpassword: 20urgle12-2
157 -
158 replace: userpassword
159 userpassword: 20urgle12-3
160
161 dn: uid=nd, ou=People, dc=example, dc=com
162 changetype: modify
163 delete: userpassword
164 userpassword: 20urgle12-3
165 -
166 replace: userpassword
167 userpassword: 20urgle12-4
168
169 dn: uid=nd, ou=People, dc=example, dc=com
170 changetype: modify
171 delete: userpassword
172 userpassword: 20urgle12-4
173 -
174 replace: userpassword
175 userpassword: 20urgle12-5
176
177 dn: uid=nd, ou=People, dc=example, dc=com
178 changetype: modify
179 delete: userpassword
180 userpassword: 20urgle12-5
181 -
182 replace: userpassword
183 userpassword: 20urgle12-6
184
185 EOMODS
186 RC=$?
187 if test $RC != 0 ; then
188         echo "ldapmodify failed ($RC)!"
189         test $KILLSERVERS != no && kill -HUP $KILLPIDS
190         exit $RC
191 fi
192 echo "Testing password history..."
193 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w 20urgle12-6 > \
194         $TESTOUT 2>&1 << EOMODS
195 dn: uid=nd, ou=People, dc=example, dc=com
196 changetype: modify
197 delete: userPassword
198 userPassword: 20urgle12-6
199 -
200 replace: userPassword
201 userPassword: 20urgle12-2
202
203 EOMODS
204 RC=$?
205 if test $RC = 0 ; then
206         echo "ldapmodify failed ($RC)!"
207         test $KILLSERVERS != no && kill -HUP $KILLPIDS
208         exit $RC
209 fi
210
211 echo "Testing forced reset..."
212
213 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
214         $TESTOUT 2>&1 << EOMODS
215 dn: uid=nd, ou=People, dc=example, dc=com
216 changetype: modify
217 replace: userPassword
218 userPassword: testpassword
219 -
220 replace: pwdReset
221 pwdReset: TRUE
222
223 EOMODS
224 RC=$?
225 if test $RC != 0 ; then
226         echo "ldapmodify failed ($RC)!"
227         test $KILLSERVERS != no && kill -HUP $KILLPIDS
228         exit $RC
229 fi
230
231 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
232         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
233 RC=$?
234 if test $RC = 0 ; then
235         echo "Forced reset failed ($RC)!"
236         test $KILLSERVERS != no && kill -HUP $KILLPIDS
237         exit $RC
238 fi
239
240 COUNT=`grep "Operations are restricted" $SEARCHOUT | wc -l`
241 if test $COUNT != 1 ; then
242         echo "Forced reset test failed"
243         test $KILLSERVERS != no && kill -HUP $KILLPIDS
244         exit 1
245 fi
246
247 echo "Clearing forced reset..."
248
249 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
250         $TESTOUT 2>&1 << EOMODS
251 dn: uid=nd, ou=People, dc=example, dc=com
252 changetype: modify
253 delete: pwdReset
254
255 EOMODS
256 RC=$?
257 if test $RC != 0 ; then
258         echo "ldapmodify failed ($RC)!"
259         test $KILLSERVERS != no && kill -HUP $KILLPIDS
260         exit $RC
261 fi
262
263 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
264         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
265 RC=$?
266 if test $RC != 0 ; then
267         echo "Clearing forced reset failed ($RC)!"
268         test $KILLSERVERS != no && kill -HUP $KILLPIDS
269         exit $RC
270 fi
271
272 echo "Testing Safe modify..."
273
274 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
275         -w $PASS -s failexpect \
276         -D "$USER" > $TESTOUT 2>&1
277 RC=$?
278 if test $RC = 0 ; then
279         echo "Safe modify test 1 failed ($RC)!"
280         test $KILLSERVERS != no && kill -HUP $KILLPIDS
281         exit $RC
282 fi
283
284 sleep 2
285
286 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
287         -w $PASS -s failexpect -a $PASS \
288         -D "$USER" > $TESTOUT 2>&1
289 RC=$?
290 if test $RC != 0 ; then
291         echo "Safe modify test 2 failed ($RC)!"
292         test $KILLSERVERS != no && kill -HUP $KILLPIDS
293         exit $RC
294 fi
295
296 echo "Testing length requirement..."
297
298 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
299         -w failexpect -a failexpect -s spw \
300         -D "$USER" > $TESTOUT 2>&1
301 RC=$?
302 if test $RC = 0 ; then
303         echo "Length requirement test failed ($RC)!"
304         test $KILLSERVERS != no && kill -HUP $KILLPIDS
305         exit $RC
306 fi
307 COUNT=`grep "Password fails quality" $TESTOUT | wc -l`
308 if test $COUNT != 1 ; then
309         echo "Length requirement test failed"
310         test $KILLSERVERS != no && kill -HUP $KILLPIDS
311         exit 1
312 fi
313
314 echo "Testing hashed length requirement..."
315
316 $LDAPMODIFY -h $LOCALHOST -p $PORT1 -D "$USER" -w failexpect > \
317         $TESTOUT 2>&1 << EOMODS
318 dn: uid=nd, ou=People, o=University of Michigan, c=US
319 changetype: modify
320 delete: userPassword
321 userPassword: failexpect
322 -
323 add: userPassword
324 userPassword: {MD5}xxxxxx
325
326 EOMODS
327 RC=$?
328 if test $RC = 0 ; then
329         echo "Hashed length requirement test failed ($RC)!"
330         test $KILLSERVERS != no && kill -HUP $KILLPIDS
331         exit $RC
332 fi
333 COUNT=`grep "Password fails quality" $TESTOUT | wc -l`
334 if test $COUNT != 1 ; then
335         echo "Hashed length requirement test failed"
336         test $KILLSERVERS != no && kill -HUP $KILLPIDS
337         exit 1
338 fi
339
340 test $KILLSERVERS != no && kill -HUP $KILLPIDS
341
342 echo ">>>>> Test succeeded"
343 exit 0