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