]> git.sur5r.net Git - openldap/blob - tests/scripts/test022-ppolicy
02576b5e39a882fe3a90164692b4abd3e3fd2ec2
[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-2004 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 30 seconds for lockout to reset..."
83 sleep 30
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 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
96         $TESTOUT 2>&1 << EOMODS
97 dn: uid=nd, dc=example, dc=com
98 changetype: modify
99 replace: pwdChangedTime
100 pwdChangedTime: 20031231000001Z
101
102 EOMODS
103
104 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS > $SEARCHOUT 2>&1
105 sleep 2
106 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
107 sleep 2
108 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
109 sleep 2
110 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
111 RC=$?
112 if test $RC = 0 ; then
113         echo "Password expiration failed ($RC)!"
114         test $KILLSERVERS != no && kill -HUP $KILLPIDS
115         exit $RC
116 fi
117
118 COUNT=`grep "grace logins" $SEARCHOUT | wc -l`
119 if test $COUNT != 3 ; then
120         echo "Password expiration test failed"
121         test $KILLSERVERS != no && kill -HUP $KILLPIDS
122         exit 1
123 fi
124
125 echo "Resetting password to clear expired status"
126 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
127         -w secret -s $PASS \
128         -D "$MANAGERDN" "$USER" >> $TESTOUT 2>&1
129 RC=$?
130 if test $RC != 0 ; then
131         echo "ldappasswd failed ($RC)!"
132         test $KILLSERVERS != no && kill -HUP $KILLPIDS
133         exit $RC
134 fi
135
136 echo "Filling password history..."
137 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w $PASS > \
138         $TESTOUT 2>&1 << EOMODS
139 dn: uid=nd, ou=People, dc=example, dc=com
140 changetype: modify
141 delete: userpassword
142 userpassword: testpassword
143 -
144 replace: userpassword
145 userpassword: 20urgle12-1
146
147 dn: uid=nd, ou=People, dc=example, dc=com
148 changetype: modify
149 delete: userpassword
150 userpassword: 20urgle12-1
151 -
152 replace: userpassword
153 userpassword: 20urgle12-2
154
155 dn: uid=nd, ou=People, dc=example, dc=com
156 changetype: modify
157 delete: userpassword
158 userpassword: 20urgle12-2
159 -
160 replace: userpassword
161 userpassword: 20urgle12-3
162
163 dn: uid=nd, ou=People, dc=example, dc=com
164 changetype: modify
165 delete: userpassword
166 userpassword: 20urgle12-3
167 -
168 replace: userpassword
169 userpassword: 20urgle12-4
170
171 dn: uid=nd, ou=People, dc=example, dc=com
172 changetype: modify
173 delete: userpassword
174 userpassword: 20urgle12-4
175 -
176 replace: userpassword
177 userpassword: 20urgle12-5
178
179 dn: uid=nd, ou=People, dc=example, dc=com
180 changetype: modify
181 delete: userpassword
182 userpassword: 20urgle12-5
183 -
184 replace: userpassword
185 userpassword: 20urgle12-6
186
187 EOMODS
188 RC=$?
189 if test $RC != 0 ; then
190         echo "ldapmodify failed ($RC)!"
191         test $KILLSERVERS != no && kill -HUP $KILLPIDS
192         exit $RC
193 fi
194 echo "Testing password history..."
195 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w 20urgle12-6 > \
196         $TESTOUT 2>&1 << EOMODS
197 dn: uid=nd, ou=People, dc=example, dc=com
198 changetype: modify
199 delete: userPassword
200 userPassword: 20urgle12-6
201 -
202 replace: userPassword
203 userPassword: 20urgle12-2
204
205 EOMODS
206 RC=$?
207 if test $RC = 0 ; then
208         echo "ldapmodify failed ($RC)!"
209         test $KILLSERVERS != no && kill -HUP $KILLPIDS
210         exit $RC
211 fi
212
213 echo "Testing forced reset..."
214
215 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
216         $TESTOUT 2>&1 << EOMODS
217 dn: uid=nd, ou=People, dc=example, dc=com
218 changetype: modify
219 replace: userPassword
220 userPassword: testpassword
221 -
222 replace: pwdReset
223 pwdReset: TRUE
224
225 EOMODS
226 RC=$?
227 if test $RC != 0 ; then
228         echo "ldapmodify failed ($RC)!"
229         test $KILLSERVERS != no && kill -HUP $KILLPIDS
230         exit $RC
231 fi
232
233 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
234         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
235 RC=$?
236 if test $RC = 0 ; then
237         echo "Forced reset failed ($RC)!"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS
239         exit $RC
240 fi
241
242 COUNT=`grep "Operations are restricted" $SEARCHOUT | wc -l`
243 if test $COUNT != 1 ; then
244         echo "Forced reset test failed"
245         test $KILLSERVERS != no && kill -HUP $KILLPIDS
246         exit 1
247 fi
248
249 echo "Clearing forced reset..."
250
251 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
252         $TESTOUT 2>&1 << EOMODS
253 dn: uid=nd, ou=People, dc=example, dc=com
254 changetype: modify
255 delete: pwdReset
256
257 EOMODS
258 RC=$?
259 if test $RC != 0 ; then
260         echo "ldapmodify failed ($RC)!"
261         test $KILLSERVERS != no && kill -HUP $KILLPIDS
262         exit $RC
263 fi
264
265 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
266         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
267 RC=$?
268 if test $RC != 0 ; then
269         echo "Clearing forced reset failed ($RC)!"
270         test $KILLSERVERS != no && kill -HUP $KILLPIDS
271         exit $RC
272 fi
273
274 echo "Testing Safe modify..."
275
276 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
277         -w $PASS -s failexpect \
278         -D "$USER" > $TESTOUT 2>&1
279 RC=$?
280 if test $RC = 0 ; then
281         echo "Safe modify test 1 failed ($RC)!"
282         test $KILLSERVERS != no && kill -HUP $KILLPIDS
283         exit $RC
284 fi
285
286 sleep 2
287
288 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
289         -w $PASS -s failexpect -a $PASS \
290         -D "$USER" > $TESTOUT 2>&1
291 RC=$?
292 if test $RC != 0 ; then
293         echo "Safe modify test 2 failed ($RC)!"
294         test $KILLSERVERS != no && kill -HUP $KILLPIDS
295         exit $RC
296 fi
297
298 echo "Testing length requirement..."
299
300 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
301         -w failexpect -a failexpect -s spw \
302         -D "$USER" > $TESTOUT 2>&1
303 RC=$?
304 if test $RC = 0 ; then
305         echo "Length requirement test failed ($RC)!"
306         test $KILLSERVERS != no && kill -HUP $KILLPIDS
307         exit $RC
308 fi
309 COUNT=`grep "Password fails quality" $TESTOUT | wc -l`
310 if test $COUNT != 1 ; then
311         echo "Length requirement test failed"
312         test $KILLSERVERS != no && kill -HUP $KILLPIDS
313         exit 1
314 fi
315
316 test $KILLSERVERS != no && kill -HUP $KILLPIDS
317
318 echo ">>>>> Test succeeded"
319 exit 0