]> git.sur5r.net Git - openldap/blob - tests/scripts/test022-ppolicy
fee6d155fd340b13672cac36e081bd0231f39a9e
[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 if test "$BACKEND" = "ldbm" ; then
25         echo "Test does not support $BACKEND"
26         exit 0
27 fi
28
29 mkdir -p $TESTDIR $DBDIR1
30
31 echo "Starting slapd on TCP/IP port $PORT1..."
32 . $CONFFILTER $BACKEND $MONITORDB < $PPOLICYCONF > $CONF1
33 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
34 PID=$!
35 if test $WAIT != 0 ; then
36     echo PID $PID
37     read foo
38 fi
39 KILLPIDS="$PID"
40
41 USER="uid=nd, ou=People, o=University of Michigan, c=US"
42 PASS=testpassword
43
44 echo "Using ldapsearch to check that slapd is running..."
45 for i in 0 1 2 3 4 5; do
46         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
47                 'objectclass=*' > /dev/null 2>&1
48         RC=$?
49         if test $RC = 0 ; then
50                 break
51         fi
52         echo "Waiting 5 seconds for slapd to start..."
53         sleep 5
54 done
55 if test $RC != 0 ; then
56         echo "ldapsearch failed $(RC)!"
57         test $KILLSERVERS != no && kill -HUP $KILLPIDS
58         exit $RC
59 fi
60
61 echo "Using ldapadd to populate the database..."
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 30 seconds for lockout to reset..."
88 sleep 30
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 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
101         $TESTOUT 2>&1 << EOMODS
102 dn: uid=nd, ou=People, o=University of Michigan, c=US
103 changetype: modify
104 replace: pwdChangedTime
105 pwdChangedTime: 20031231000001Z
106
107 EOMODS
108
109 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS > $SEARCHOUT 2>&1
110 sleep 2
111 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
112 sleep 2
113 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
114 sleep 2
115 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS >> $SEARCHOUT 2>&1
116 RC=$?
117 if test $RC = 0 ; then
118         echo "Password expiration failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 COUNT=`grep "grace logins" $SEARCHOUT | wc -l`
124 if test $COUNT != 3 ; then
125         echo "Password expiration test failed"
126         test $KILLSERVERS != no && kill -HUP $KILLPIDS
127         exit 1
128 fi
129
130 echo "Resetting password to clear expired status"
131 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
132         -w secret -s $PASS \
133         -D "$MANAGERDN" "$USER" >> $TESTOUT 2>&1
134 RC=$?
135 if test $RC != 0 ; then
136         echo "ldappasswd failed ($RC)!"
137         test $KILLSERVERS != no && kill -HUP $KILLPIDS
138         exit $RC
139 fi
140
141 echo "Filling password history..."
142 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w $PASS > \
143         $TESTOUT 2>&1 << EOMODS
144 dn: uid=nd, ou=People, o=University of Michigan,c=US
145 changetype: modify
146 delete: userpassword
147 userpassword: testpassword
148 -
149 replace: userpassword
150 userpassword: 20urgle12-1
151
152 dn: uid=nd, ou=People, o=University of Michigan,c=US
153 changetype: modify
154 delete: userpassword
155 userpassword: 20urgle12-1
156 -
157 replace: userpassword
158 userpassword: 20urgle12-2
159
160 dn: uid=nd, ou=People, o=University of Michigan,c=US
161 changetype: modify
162 delete: userpassword
163 userpassword: 20urgle12-2
164 -
165 replace: userpassword
166 userpassword: 20urgle12-3
167
168 dn: uid=nd, ou=People, o=University of Michigan,c=US
169 changetype: modify
170 delete: userpassword
171 userpassword: 20urgle12-3
172 -
173 replace: userpassword
174 userpassword: 20urgle12-4
175
176 dn: uid=nd, ou=People, o=University of Michigan,c=US
177 changetype: modify
178 delete: userpassword
179 userpassword: 20urgle12-4
180 -
181 replace: userpassword
182 userpassword: 20urgle12-5
183
184 dn: uid=nd, ou=People, o=University of Michigan,c=US
185 changetype: modify
186 delete: userpassword
187 userpassword: 20urgle12-5
188 -
189 replace: userpassword
190 userpassword: 20urgle12-6
191
192 EOMODS
193 RC=$?
194 if test $RC != 0 ; then
195         echo "ldapmodify failed ($RC)!"
196         test $KILLSERVERS != no && kill -HUP $KILLPIDS
197         exit $RC
198 fi
199 echo "Testing password history..."
200 $LDAPMODIFY -v -D "$USER" -h $LOCALHOST -p $PORT1 -w 20urgle12-6 > \
201         $TESTOUT 2>&1 << EOMODS
202 dn: uid=nd, ou=People, o=University of Michigan, c=US
203 changetype: modify
204 delete: userPassword
205 userPassword: 20urgle12-6
206 -
207 replace: userPassword
208 userPassword: 20urgle12-2
209
210 EOMODS
211 RC=$?
212 if test $RC = 0 ; then
213         echo "ldapmodify failed ($RC)!"
214         test $KILLSERVERS != no && kill -HUP $KILLPIDS
215         exit $RC
216 fi
217
218 echo "Testing forced reset..."
219
220 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
221         $TESTOUT 2>&1 << EOMODS
222 dn: uid=nd, ou=People, o=University of Michigan, c=US
223 changetype: modify
224 replace: userPassword
225 userPassword: testpassword
226 -
227 replace: pwdReset
228 pwdReset: TRUE
229
230 EOMODS
231 RC=$?
232 if test $RC != 0 ; then
233         echo "ldapmodify failed ($RC)!"
234         test $KILLSERVERS != no && kill -HUP $KILLPIDS
235         exit $RC
236 fi
237
238 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
239         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
240 RC=$?
241 if test $RC = 0 ; then
242         echo "Forced reset failed ($RC)!"
243         test $KILLSERVERS != no && kill -HUP $KILLPIDS
244         exit $RC
245 fi
246
247 COUNT=`grep "Operations are restricted" $SEARCHOUT | wc -l`
248 if test $COUNT != 1 ; then
249         echo "Forced reset test failed"
250         test $KILLSERVERS != no && kill -HUP $KILLPIDS
251         exit 1
252 fi
253
254 echo "Clearing forced reset..."
255
256 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
257         $TESTOUT 2>&1 << EOMODS
258 dn: uid=nd, ou=People, o=University of Michigan, c=US
259 changetype: modify
260 delete: pwdReset
261
262 EOMODS
263 RC=$?
264 if test $RC != 0 ; then
265         echo "ldapmodify failed ($RC)!"
266         test $KILLSERVERS != no && kill -HUP $KILLPIDS
267         exit $RC
268 fi
269
270 $LDAPSEARCH -e ppolicy -h $LOCALHOST -p $PORT1 -D "$USER" -w $PASS \
271         -b "$BASEDN" -s base > $SEARCHOUT 2>&1
272 RC=$?
273 if test $RC != 0 ; then
274         echo "Clearing forced reset failed ($RC)!"
275         test $KILLSERVERS != no && kill -HUP $KILLPIDS
276         exit $RC
277 fi
278
279 echo "Testing Safe modify..."
280
281 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
282         -w $PASS -s failexpect \
283         -D "$USER" > $TESTOUT 2>&1
284 RC=$?
285 if test $RC = 0 ; then
286         echo "Safe modify test 1 failed ($RC)!"
287         test $KILLSERVERS != no && kill -HUP $KILLPIDS
288         exit $RC
289 fi
290
291 sleep 2
292
293 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
294         -w $PASS -s failexpect -a $PASS \
295         -D "$USER" > $TESTOUT 2>&1
296 RC=$?
297 if test $RC != 0 ; then
298         echo "Safe modify test 2 failed ($RC)!"
299         test $KILLSERVERS != no && kill -HUP $KILLPIDS
300         exit $RC
301 fi
302
303 echo "Testing length requirement..."
304
305 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
306         -w failexpect -a failexpect -s spw \
307         -D "$USER" > $TESTOUT 2>&1
308 RC=$?
309 if test $RC = 0 ; then
310         echo "Length requirement test failed ($RC)!"
311         test $KILLSERVERS != no && kill -HUP $KILLPIDS
312         exit $RC
313 fi
314 COUNT=`grep "Password fails quality" $TESTOUT | wc -l`
315 if test $COUNT != 1 ; then
316         echo "Length requirement test failed"
317         test $KILLSERVERS != no && kill -HUP $KILLPIDS
318         exit 1
319 fi
320
321 test $KILLSERVERS != no && kill -HUP $KILLPIDS
322
323 echo ">>>>> Test succeeded"
324 exit 0