]> git.sur5r.net Git - openldap/blob - tests/scripts/test022-ppolicy
add was failing because not compliant with schema
[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-2008 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 /dev/null > $TESTOUT
59
60 echo "Using ldapadd to populate the database..."
61 # may need "-e relax" for draft 09, but not yet.
62 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
63         $LDIFPPOLICY >> $TESTOUT 2>&1
64 RC=$?
65 if test $RC != 0 ; then
66         echo "ldapadd failed ($RC)!"
67         test $KILLSERVERS != no && kill -HUP $KILLPIDS
68         exit $RC
69 fi
70
71 echo "Testing account lockout..."
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 -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >>$SEARCHOUT 2>&1
77 sleep 2
78 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >> $SEARCHOUT 2>&1
79 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
80 COUNT=`grep "Account locked" $SEARCHOUT | wc -l`
81 if test $COUNT != 2 ; then
82         echo "Account lockout test failed"
83         test $KILLSERVERS != no && kill -HUP $KILLPIDS
84         exit 1
85 fi
86
87 echo "Waiting 20 seconds for lockout to reset..."
88 sleep 20
89
90 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
91         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
92 RC=$?
93 if test $RC != 0 ; then
94         echo "ldapsearch failed ($RC)!"
95         test $KILLSERVERS != no && kill -HUP $KILLPIDS
96         exit $RC
97 fi
98
99 echo "Testing password expiration"
100 echo "Waiting 20 seconds for password to expire..."
101 sleep 20
102
103 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
104         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
105 sleep 2
106 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
107         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
108 sleep 2
109 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
110         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
111 sleep 2
112 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
113         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
114 RC=$?
115 if test $RC = 0 ; then
116         echo "Password expiration failed ($RC)!"
117         test $KILLSERVERS != no && kill -HUP $KILLPIDS
118         exit 1
119 fi
120
121 COUNT=`grep "grace logins" $SEARCHOUT | wc -l`
122 if test $COUNT != 3 ; then
123         echo "Password expiration test failed"
124         test $KILLSERVERS != no && kill -HUP $KILLPIDS
125         exit 1
126 fi
127
128 echo "Resetting password to clear expired status"
129 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
130         -w secret -s $PASS \
131         -D "$MANAGERDN" "$USER" >> $TESTOUT 2>&1
132 RC=$?
133 if test $RC != 0 ; then
134         echo "ldappasswd failed ($RC)!"
135         test $KILLSERVERS != no && kill -HUP $KILLPIDS
136         exit $RC
137 fi
138
139 echo "Filling password history..."
140 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w $PASS >> \
141         $TESTOUT 2>&1 << EOMODS
142 dn: uid=nd, ou=People, dc=example, dc=com
143 changetype: modify
144 delete: userpassword
145 userpassword: testpassword
146 -
147 replace: userpassword
148 userpassword: 20urgle12-1
149
150 dn: uid=nd, ou=People, dc=example, dc=com
151 changetype: modify
152 delete: userpassword
153 userpassword: 20urgle12-1
154 -
155 replace: userpassword
156 userpassword: 20urgle12-2
157
158 dn: uid=nd, ou=People, dc=example, dc=com
159 changetype: modify
160 delete: userpassword
161 userpassword: 20urgle12-2
162 -
163 replace: userpassword
164 userpassword: 20urgle12-3
165
166 dn: uid=nd, ou=People, dc=example, dc=com
167 changetype: modify
168 delete: userpassword
169 userpassword: 20urgle12-3
170 -
171 replace: userpassword
172 userpassword: 20urgle12-4
173
174 dn: uid=nd, ou=People, dc=example, dc=com
175 changetype: modify
176 delete: userpassword
177 userpassword: 20urgle12-4
178 -
179 replace: userpassword
180 userpassword: 20urgle12-5
181
182 dn: uid=nd, ou=People, dc=example, dc=com
183 changetype: modify
184 delete: userpassword
185 userpassword: 20urgle12-5
186 -
187 replace: userpassword
188 userpassword: 20urgle12-6
189
190 EOMODS
191 RC=$?
192 if test $RC != 0 ; then
193         echo "ldapmodify failed ($RC)!"
194         test $KILLSERVERS != no && kill -HUP $KILLPIDS
195         exit $RC
196 fi
197 echo "Testing password history..."
198 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w 20urgle12-6 >> \
199         $TESTOUT 2>&1 << EOMODS
200 dn: uid=nd, ou=People, dc=example, dc=com
201 changetype: modify
202 delete: userPassword
203 userPassword: 20urgle12-6
204 -
205 replace: userPassword
206 userPassword: 20urgle12-2
207
208 EOMODS
209 RC=$?
210 if test $RC = 0 ; then
211         echo "ldapmodify failed ($RC)!"
212         test $KILLSERVERS != no && kill -HUP $KILLPIDS
213         exit 1
214 fi
215
216 echo "Testing forced reset..."
217
218 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
219         $TESTOUT 2>&1 << EOMODS
220 dn: uid=nd, ou=People, dc=example, dc=com
221 changetype: modify
222 replace: userPassword
223 userPassword: testpassword
224 -
225 replace: pwdReset
226 pwdReset: TRUE
227
228 EOMODS
229 RC=$?
230 if test $RC != 0 ; then
231         echo "ldapmodify failed ($RC)!"
232         test $KILLSERVERS != no && kill -HUP $KILLPIDS
233         exit $RC
234 fi
235
236 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
237         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
238 RC=$?
239 if test $RC = 0 ; then
240         echo "Forced reset failed ($RC)!"
241         test $KILLSERVERS != no && kill -HUP $KILLPIDS
242         exit 1
243 fi
244
245 COUNT=`grep "Operations are restricted" $SEARCHOUT | wc -l`
246 if test $COUNT != 1 ; then
247         echo "Forced reset test failed"
248         test $KILLSERVERS != no && kill -HUP $KILLPIDS
249         exit 1
250 fi
251
252 echo "Clearing forced reset..."
253
254 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
255         $TESTOUT 2>&1 << EOMODS
256 dn: uid=nd, ou=People, dc=example, dc=com
257 changetype: modify
258 delete: pwdReset
259
260 EOMODS
261 RC=$?
262 if test $RC != 0 ; then
263         echo "ldapmodify failed ($RC)!"
264         test $KILLSERVERS != no && kill -HUP $KILLPIDS
265         exit $RC
266 fi
267
268 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
269         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
270 RC=$?
271 if test $RC != 0 ; then
272         echo "Clearing forced reset failed ($RC)!"
273         test $KILLSERVERS != no && kill -HUP $KILLPIDS
274         exit $RC
275 fi
276
277 echo "Testing Safe modify..."
278
279 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
280         -w $PASS -s failexpect \
281         -D "$USER" >> $TESTOUT 2>&1
282 RC=$?
283 if test $RC = 0 ; then
284         echo "Safe modify test 1 failed ($RC)!"
285         test $KILLSERVERS != no && kill -HUP $KILLPIDS
286         exit 1
287 fi
288
289 sleep 2
290
291 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
292         -w $PASS -s failexpect -a $PASS \
293         -D "$USER" >> $TESTOUT 2>&1
294 RC=$?
295 if test $RC != 0 ; then
296         echo "Safe modify test 2 failed ($RC)!"
297         test $KILLSERVERS != no && kill -HUP $KILLPIDS
298         exit $RC
299 fi
300
301 echo "Testing length requirement..."
302
303 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
304         -w failexpect -a failexpect -s spw \
305         -D "$USER" > ${TESTOUT}.2 2>&1
306 RC=$?
307 cat ${TESTOUT}.2 >> $TESTOUT
308 if test $RC = 0 ; then
309         echo "Length requirement test failed ($RC)!"
310         test $KILLSERVERS != no && kill -HUP $KILLPIDS
311         exit 1
312 fi
313 COUNT=`grep "Password fails quality" ${TESTOUT}.2 | wc -l`
314 if test $COUNT != 1 ; then
315         echo "Length requirement test failed"
316         test $KILLSERVERS != no && kill -HUP $KILLPIDS
317         exit 1
318 fi
319
320 echo "Testing hashed length requirement..."
321
322 $LDAPMODIFY -h $LOCALHOST -p $PORT1 -D "$USER" -w failexpect > \
323         ${TESTOUT}.2 2>&1 << EOMODS
324 dn: $USER
325 changetype: modify
326 delete: userPassword
327 userPassword: failexpect
328 -
329 add: userPassword
330 userPassword: {MD5}xxxxxx
331
332 EOMODS
333 RC=$?
334 cat ${TESTOUT}.2 >> $TESTOUT
335 if test $RC = 0 ; then
336         echo "Hashed length requirement test failed ($RC)!"
337         test $KILLSERVERS != no && kill -HUP $KILLPIDS
338         exit 1
339 fi
340 COUNT=`grep "Password fails quality" ${TESTOUT}.2 | wc -l`
341 if test $COUNT != 1 ; then
342         echo "Hashed length requirement test failed"
343         test $KILLSERVERS != no && kill -HUP $KILLPIDS
344         exit 1
345 fi
346
347 echo "Testing multiple password add/modify checks..."
348
349 $LDAPMODIFY -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD >> \
350         $TESTOUT 2>&1 << EOMODS
351 dn: cn=Add Should Fail, ou=People, dc=example, dc=com
352 changetype: add
353 objectClass: inetOrgPerson
354 cn: Add Should Fail
355 sn: Fail
356 userPassword: firstpw
357 userPassword: secondpw
358 EOMODS
359 RC=$?
360 if test $RC = 0 ; then
361         echo "Multiple password add test failed ($RC)!"
362         test $KILLSERVERS != no && kill -HUP $KILLPIDS
363         exit 1
364 fi
365
366 $LDAPMODIFY -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD >> \
367         $TESTOUT 2>&1 << EOMODS
368 dn: $USER
369 changetype: modify
370 add: userPassword
371 userPassword: firstpw
372 userPassword: secondpw
373 EOMODS
374 RC=$?
375 if test $RC = 0 ; then
376         echo "Multiple password modify add test failed ($RC)!"
377         test $KILLSERVERS != no && kill -HUP $KILLPIDS
378         exit 1
379 fi
380
381 $LDAPMODIFY -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD >> \
382         $TESTOUT 2>&1 << EOMODS
383 dn: $USER
384 changetype: modify
385 replace: userPassword
386 userPassword: firstpw
387 userPassword: secondpw
388 EOMODS
389 RC=$?
390 if test $RC = 0 ; then
391         echo "Multiple password modify replace test failed ($RC)!"
392         test $KILLSERVERS != no && kill -HUP $KILLPIDS
393         exit 1
394 fi
395
396 test $KILLSERVERS != no && kill -HUP $KILLPIDS
397
398 echo ">>>>> Test succeeded"
399
400 test $KILLSERVERS != no && wait
401
402 exit 0