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