]> git.sur5r.net Git - openldap/blob - tests/scripts/test022-ppolicy
More LDAP_DEVEL cleanup
[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-2006 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 sleep 1
40
41 echo "Using ldapsearch to check that slapd is running..."
42 for i in 0 1 2 3 4 5; do
43         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
44                 'objectclass=*' > /dev/null 2>&1
45         RC=$?
46         if test $RC = 0 ; then
47                 break
48         fi
49         echo "Waiting 5 seconds for slapd to start..."
50         sleep 5
51 done
52 if test $RC != 0 ; then
53         echo "ldapsearch failed ($RC)!"
54         test $KILLSERVERS != no && kill -HUP $KILLPIDS
55         exit $RC
56 fi
57
58 echo "Using ldapadd to populate the database..."
59 # may need "-e relax" for draft 09, but not yet.
60 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
61         $LDIFPPOLICY > $TESTOUT 2>&1
62 RC=$?
63 if test $RC != 0 ; then
64         echo "ldapadd failed ($RC)!"
65         test $KILLSERVERS != no && kill -HUP $KILLPIDS
66         exit $RC
67 fi
68
69 echo "Testing account lockout..."
70 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >$SEARCHOUT 2>&1
71 sleep 2
72 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >>$SEARCHOUT 2>&1
73 sleep 2
74 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >>$SEARCHOUT 2>&1
75 sleep 2
76 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >> $SEARCHOUT 2>&1
77 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
78 COUNT=`grep "Account locked" $SEARCHOUT | wc -l`
79 if test $COUNT != 2 ; then
80         echo "Account lockout test failed"
81         test $KILLSERVERS != no && kill -HUP $KILLPIDS
82         exit 1
83 fi
84
85 echo "Waiting 20 seconds for lockout to reset..."
86 sleep 20
87
88 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
89         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
90 RC=$?
91 if test $RC != 0 ; then
92         echo "ldapsearch failed ($RC)!"
93         test $KILLSERVERS != no && kill -HUP $KILLPIDS
94         exit $RC
95 fi
96
97 echo "Testing password expiration"
98 echo "Waiting 20 seconds for password to expire..."
99 sleep 20
100
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 sleep 2
110 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
111         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
112 RC=$?
113 if test $RC = 0 ; then
114         echo "Password expiration failed ($RC)!"
115         test $KILLSERVERS != no && kill -HUP $KILLPIDS
116         exit 1
117 fi
118
119 COUNT=`grep "grace logins" $SEARCHOUT | wc -l`
120 if test $COUNT != 3 ; then
121         echo "Password expiration test failed"
122         test $KILLSERVERS != no && kill -HUP $KILLPIDS
123         exit 1
124 fi
125
126 echo "Resetting password to clear expired status"
127 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
128         -w secret -s $PASS \
129         -D "$MANAGERDN" "$USER" >> $TESTOUT 2>&1
130 RC=$?
131 if test $RC != 0 ; then
132         echo "ldappasswd failed ($RC)!"
133         test $KILLSERVERS != no && kill -HUP $KILLPIDS
134         exit $RC
135 fi
136
137 echo "Filling password history..."
138 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w $PASS > \
139         $TESTOUT 2>&1 << EOMODS
140 dn: uid=nd, ou=People, dc=example, dc=com
141 changetype: modify
142 delete: userpassword
143 userpassword: testpassword
144 -
145 replace: userpassword
146 userpassword: 20urgle12-1
147
148 dn: uid=nd, ou=People, dc=example, dc=com
149 changetype: modify
150 delete: userpassword
151 userpassword: 20urgle12-1
152 -
153 replace: userpassword
154 userpassword: 20urgle12-2
155
156 dn: uid=nd, ou=People, dc=example, dc=com
157 changetype: modify
158 delete: userpassword
159 userpassword: 20urgle12-2
160 -
161 replace: userpassword
162 userpassword: 20urgle12-3
163
164 dn: uid=nd, ou=People, dc=example, dc=com
165 changetype: modify
166 delete: userpassword
167 userpassword: 20urgle12-3
168 -
169 replace: userpassword
170 userpassword: 20urgle12-4
171
172 dn: uid=nd, ou=People, dc=example, dc=com
173 changetype: modify
174 delete: userpassword
175 userpassword: 20urgle12-4
176 -
177 replace: userpassword
178 userpassword: 20urgle12-5
179
180 dn: uid=nd, ou=People, dc=example, dc=com
181 changetype: modify
182 delete: userpassword
183 userpassword: 20urgle12-5
184 -
185 replace: userpassword
186 userpassword: 20urgle12-6
187
188 EOMODS
189 RC=$?
190 if test $RC != 0 ; then
191         echo "ldapmodify failed ($RC)!"
192         test $KILLSERVERS != no && kill -HUP $KILLPIDS
193         exit $RC
194 fi
195 echo "Testing password history..."
196 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w 20urgle12-6 > \
197         $TESTOUT 2>&1 << EOMODS
198 dn: uid=nd, ou=People, dc=example, dc=com
199 changetype: modify
200 delete: userPassword
201 userPassword: 20urgle12-6
202 -
203 replace: userPassword
204 userPassword: 20urgle12-2
205
206 EOMODS
207 RC=$?
208 if test $RC = 0 ; then
209         echo "ldapmodify failed ($RC)!"
210         test $KILLSERVERS != no && kill -HUP $KILLPIDS
211         exit 1
212 fi
213
214 echo "Testing forced reset..."
215
216 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
217         $TESTOUT 2>&1 << EOMODS
218 dn: uid=nd, ou=People, dc=example, dc=com
219 changetype: modify
220 replace: userPassword
221 userPassword: testpassword
222 -
223 replace: pwdReset
224 pwdReset: TRUE
225
226 EOMODS
227 RC=$?
228 if test $RC != 0 ; then
229         echo "ldapmodify failed ($RC)!"
230         test $KILLSERVERS != no && kill -HUP $KILLPIDS
231         exit $RC
232 fi
233
234 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
235         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
236 RC=$?
237 if test $RC = 0 ; then
238         echo "Forced reset failed ($RC)!"
239         test $KILLSERVERS != no && kill -HUP $KILLPIDS
240         exit 1
241 fi
242
243 COUNT=`grep "Operations are restricted" $SEARCHOUT | wc -l`
244 if test $COUNT != 1 ; then
245         echo "Forced reset test failed"
246         test $KILLSERVERS != no && kill -HUP $KILLPIDS
247         exit 1
248 fi
249
250 echo "Clearing forced reset..."
251
252 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
253         $TESTOUT 2>&1 << EOMODS
254 dn: uid=nd, ou=People, dc=example, dc=com
255 changetype: modify
256 delete: pwdReset
257
258 EOMODS
259 RC=$?
260 if test $RC != 0 ; then
261         echo "ldapmodify failed ($RC)!"
262         test $KILLSERVERS != no && kill -HUP $KILLPIDS
263         exit $RC
264 fi
265
266 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
267         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
268 RC=$?
269 if test $RC != 0 ; then
270         echo "Clearing forced reset failed ($RC)!"
271         test $KILLSERVERS != no && kill -HUP $KILLPIDS
272         exit $RC
273 fi
274
275 echo "Testing Safe modify..."
276
277 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
278         -w $PASS -s failexpect \
279         -D "$USER" > $TESTOUT 2>&1
280 RC=$?
281 if test $RC = 0 ; then
282         echo "Safe modify test 1 failed ($RC)!"
283         test $KILLSERVERS != no && kill -HUP $KILLPIDS
284         exit 1
285 fi
286
287 sleep 2
288
289 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
290         -w $PASS -s failexpect -a $PASS \
291         -D "$USER" > $TESTOUT 2>&1
292 RC=$?
293 if test $RC != 0 ; then
294         echo "Safe modify test 2 failed ($RC)!"
295         test $KILLSERVERS != no && kill -HUP $KILLPIDS
296         exit $RC
297 fi
298
299 echo "Testing length requirement..."
300
301 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
302         -w failexpect -a failexpect -s spw \
303         -D "$USER" > $TESTOUT 2>&1
304 RC=$?
305 if test $RC = 0 ; then
306         echo "Length requirement test failed ($RC)!"
307         test $KILLSERVERS != no && kill -HUP $KILLPIDS
308         exit 1
309 fi
310 COUNT=`grep "Password fails quality" $TESTOUT | wc -l`
311 if test $COUNT != 1 ; then
312         echo "Length requirement test failed"
313         test $KILLSERVERS != no && kill -HUP $KILLPIDS
314         exit 1
315 fi
316
317 echo "Testing hashed length requirement..."
318
319 $LDAPMODIFY -h $LOCALHOST -p $PORT1 -D "$USER" -w failexpect > \
320         $TESTOUT 2>&1 << EOMODS
321 dn: $USER
322 changetype: modify
323 delete: userPassword
324 userPassword: failexpect
325 -
326 add: userPassword
327 userPassword: {MD5}xxxxxx
328
329 EOMODS
330 RC=$?
331 if test $RC = 0 ; then
332         echo "Hashed length requirement test failed ($RC)!"
333         test $KILLSERVERS != no && kill -HUP $KILLPIDS
334         exit 1
335 fi
336 COUNT=`grep "Password fails quality" $TESTOUT | wc -l`
337 if test $COUNT != 1 ; then
338         echo "Hashed length requirement test failed"
339         test $KILLSERVERS != no && kill -HUP $KILLPIDS
340         exit 1
341 fi
342
343 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344
345 echo ">>>>> Test succeeded"
346
347 test $KILLSERVERS != no && wait
348
349 exit 0