]> git.sur5r.net Git - openldap/blob - tests/scripts/test022-ppolicy
smoothen ppolicy test
[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 set -x
17
18 echo "running defines.sh"
19 . $SRCDIR/scripts/defines.sh
20
21 if test $PPOLICY = ppolicyno; then 
22         echo "Password policy overlay not available, test skipped"
23         exit 0
24 fi 
25
26 mkdir -p $TESTDIR $DBDIR1
27
28 echo "Starting slapd on TCP/IP port $PORT1..."
29 . $CONFFILTER $BACKEND $MONITORDB < $PPOLICYCONF > $CONF1
30 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
31 PID=$!
32 if test $WAIT != 0 ; then
33     echo PID $PID
34     read foo
35 fi
36 KILLPIDS="$PID"
37
38 USER="uid=nd, ou=People, dc=example, dc=com"
39 PASS=testpassword
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 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
60         $LDIFPPOLICY > $TESTOUT 2>&1
61 RC=$?
62 if test $RC != 0 ; then
63         echo "ldapadd failed ($RC)!"
64         test $KILLSERVERS != no && kill -HUP $KILLPIDS
65         exit $RC
66 fi
67
68 echo "Testing account lockout..."
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 -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >>$SEARCHOUT 2>&1
74 sleep 2
75 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w wrongpw >> $SEARCHOUT 2>&1
76 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
77 COUNT=`grep "Account locked" $SEARCHOUT | wc -l`
78 if test $COUNT != 2 ; then
79         echo "Account lockout test failed"
80         test $KILLSERVERS != no && kill -HUP $KILLPIDS
81         exit 1
82 fi
83
84 echo "Waiting 30 seconds for lockout to reset..."
85 sleep 30
86
87 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
88         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
89 RC=$?
90 if test $RC != 0 ; then
91         echo "ldapsearch failed ($RC)!"
92         test $KILLSERVERS != no && kill -HUP $KILLPIDS
93         exit $RC
94 fi
95
96 echo "Testing password expiration..."
97 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
98         $TESTOUT 2>&1 << EOMODS
99 dn: uid=nd, ou=People, dc=example, dc=com
100 changetype: modify
101 replace: pwdChangedTime
102 pwdChangedTime: 20031231000001Z
103
104 EOMODS
105
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 sleep 2
115 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
116         -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
117 RC=$?
118 if test $RC = 0 ; then
119         echo "Password expiration failed ($RC)!"
120         test $KILLSERVERS != no && kill -HUP $KILLPIDS
121         exit $RC
122 fi
123
124 COUNT=`grep "grace logins" $SEARCHOUT | wc -l`
125 if test $COUNT != 3 ; then
126         echo "Password expiration test failed"
127         test $KILLSERVERS != no && kill -HUP $KILLPIDS
128         exit 1
129 fi
130
131 echo "Resetting password to clear expired status"
132 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
133         -w secret -s $PASS \
134         -D "$MANAGERDN" "$USER" >> $TESTOUT 2>&1
135 RC=$?
136 if test $RC != 0 ; then
137         echo "ldappasswd failed ($RC)!"
138         test $KILLSERVERS != no && kill -HUP $KILLPIDS
139         exit $RC
140 fi
141
142 echo "Filling password history..."
143 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w $PASS > \
144         $TESTOUT 2>&1 << EOMODS
145 dn: uid=nd, ou=People, dc=example, dc=com
146 changetype: modify
147 delete: userpassword
148 userpassword: testpassword
149 -
150 replace: userpassword
151 userpassword: 20urgle12-1
152
153 dn: uid=nd, ou=People, dc=example, dc=com
154 changetype: modify
155 delete: userpassword
156 userpassword: 20urgle12-1
157 -
158 replace: userpassword
159 userpassword: 20urgle12-2
160
161 dn: uid=nd, ou=People, dc=example, dc=com
162 changetype: modify
163 delete: userpassword
164 userpassword: 20urgle12-2
165 -
166 replace: userpassword
167 userpassword: 20urgle12-3
168
169 dn: uid=nd, ou=People, dc=example, dc=com
170 changetype: modify
171 delete: userpassword
172 userpassword: 20urgle12-3
173 -
174 replace: userpassword
175 userpassword: 20urgle12-4
176
177 dn: uid=nd, ou=People, dc=example, dc=com
178 changetype: modify
179 delete: userpassword
180 userpassword: 20urgle12-4
181 -
182 replace: userpassword
183 userpassword: 20urgle12-5
184
185 dn: uid=nd, ou=People, dc=example, dc=com
186 changetype: modify
187 delete: userpassword
188 userpassword: 20urgle12-5
189 -
190 replace: userpassword
191 userpassword: 20urgle12-6
192
193 EOMODS
194 RC=$?
195 if test $RC != 0 ; then
196         echo "ldapmodify failed ($RC)!"
197         test $KILLSERVERS != no && kill -HUP $KILLPIDS
198         exit $RC
199 fi
200 echo "Testing password history..."
201 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w 20urgle12-6 > \
202         $TESTOUT 2>&1 << EOMODS
203 dn: uid=nd, ou=People, dc=example, dc=com
204 changetype: modify
205 delete: userPassword
206 userPassword: 20urgle12-6
207 -
208 replace: userPassword
209 userPassword: 20urgle12-2
210
211 EOMODS
212 RC=$?
213 if test $RC = 0 ; then
214         echo "ldapmodify failed ($RC)!"
215         test $KILLSERVERS != no && kill -HUP $KILLPIDS
216         exit $RC
217 fi
218
219 echo "Testing forced reset..."
220
221 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
222         $TESTOUT 2>&1 << EOMODS
223 dn: uid=nd, ou=People, dc=example, dc=com
224 changetype: modify
225 replace: userPassword
226 userPassword: testpassword
227 -
228 replace: pwdReset
229 pwdReset: TRUE
230
231 EOMODS
232 RC=$?
233 if test $RC != 0 ; then
234         echo "ldapmodify failed ($RC)!"
235         test $KILLSERVERS != no && kill -HUP $KILLPIDS
236         exit $RC
237 fi
238
239 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
240         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
241 RC=$?
242 if test $RC = 0 ; then
243         echo "Forced reset failed ($RC)!"
244         test $KILLSERVERS != no && kill -HUP $KILLPIDS
245         exit $RC
246 fi
247
248 COUNT=`grep "Operations are restricted" $SEARCHOUT | wc -l`
249 if test $COUNT != 1 ; then
250         echo "Forced reset test failed"
251         test $KILLSERVERS != no && kill -HUP $KILLPIDS
252         exit 1
253 fi
254
255 echo "Clearing forced reset..."
256
257 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
258         $TESTOUT 2>&1 << EOMODS
259 dn: uid=nd, ou=People, dc=example, dc=com
260 changetype: modify
261 delete: pwdReset
262
263 EOMODS
264 RC=$?
265 if test $RC != 0 ; then
266         echo "ldapmodify failed ($RC)!"
267         test $KILLSERVERS != no && kill -HUP $KILLPIDS
268         exit $RC
269 fi
270
271 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
272         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
273 RC=$?
274 if test $RC != 0 ; then
275         echo "Clearing forced reset failed ($RC)!"
276         test $KILLSERVERS != no && kill -HUP $KILLPIDS
277         exit $RC
278 fi
279
280 echo "Testing Safe modify..."
281
282 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
283         -w $PASS -s failexpect \
284         -D "$USER" > $TESTOUT 2>&1
285 RC=$?
286 if test $RC = 0 ; then
287         echo "Safe modify test 1 failed ($RC)!"
288         test $KILLSERVERS != no && kill -HUP $KILLPIDS
289         exit $RC
290 fi
291
292 sleep 2
293
294 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
295         -w $PASS -s failexpect -a $PASS \
296         -D "$USER" > $TESTOUT 2>&1
297 RC=$?
298 if test $RC != 0 ; then
299         echo "Safe modify test 2 failed ($RC)!"
300         test $KILLSERVERS != no && kill -HUP $KILLPIDS
301         exit $RC
302 fi
303
304 echo "Testing length requirement..."
305
306 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
307         -w failexpect -a failexpect -s spw \
308         -D "$USER" > $TESTOUT 2>&1
309 RC=$?
310 if test $RC = 0 ; then
311         echo "Length requirement test failed ($RC)!"
312         test $KILLSERVERS != no && kill -HUP $KILLPIDS
313         exit $RC
314 fi
315 COUNT=`grep "Password fails quality" $TESTOUT | wc -l`
316 if test $COUNT != 1 ; then
317         echo "Length requirement test failed"
318         test $KILLSERVERS != no && kill -HUP $KILLPIDS
319         exit 1
320 fi
321
322 test $KILLSERVERS != no && kill -HUP $KILLPIDS
323
324 echo ">>>>> Test succeeded"
325 exit 0