Debian Codegraph @

tests/scripts/test078-persistent-sessionlog

raw
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2024 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 $SYNCPROV = syncprovno; then
20 echo "Syncrepl provider overlay not available, test skipped"
21 exit 0
22 fi
23 if test $ACCESSLOG = accesslogno; then
24 echo "Accesslog overlay not available, test skipped"
25 exit 0
26 fi
27
28 MMR=2
29
30 XDIR=$TESTDIR/srv
31 TMP=$TESTDIR/tmp
32
33 mkdir -p $TESTDIR
34
35 $SLAPPASSWD -g -n >$CONFIGPWF
36
37 if test x"$SYNCMODE" = x ; then
38 SYNCMODE=rp
39 fi
40 case "$SYNCMODE" in
41 ro)
42 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
43 ;;
44 rp)
45 SYNCTYPE="type=refreshAndPersist interval=00:00:00:03"
46 ;;
47 *)
48 echo "unknown sync mode $SYNCMODE"
49 exit 1;
50 ;;
51 esac
52
53 #
54 # Test delta-sync mmr
55 # - start servers
56 # - configure over ldap
57 # - populate over ldap
58 # - configure syncrepl over ldap
59 # - break replication
60 # - modify each server separately
61 # - restore replication
62 # - compare results
63 #
64
65 nullExclude=""
66 test $BACKEND = null && nullExclude="# "
67
68 KILLPIDS=
69
70 echo "Initializing server configurations..."
71 n=1
72 while [ $n -le $MMR ]; do
73
74 DBDIR=${XDIR}$n/db
75 CFDIR=${XDIR}$n/slapd.d
76
77 mkdir -p ${XDIR}$n $DBDIR.1 $DBDIR.2 $CFDIR
78
79 o=`expr 3 - $n`
80 cat > $TMP <<EOF
81 dn: cn=config
82 objectClass: olcGlobal
83 cn: config
84 olcServerID: $n
85
86 EOF
87
88 if [ "$SYNCPROV" = syncprovmod -o "$ACCESSLOG" = accesslogmod ]; then
89 cat <<EOF >> $TMP
90 dn: cn=module,cn=config
91 objectClass: olcModuleList
92 cn: module
93 olcModulePath: $TESTWD/../servers/slapd/overlays
94 EOF
95 if [ "$SYNCPROV" = syncprovmod ]; then
96 echo "olcModuleLoad: syncprov.la" >> $TMP
97 fi
98 if [ "$ACCESSLOG" = accesslogmod ]; then
99 echo "olcModuleLoad: accesslog.la" >> $TMP
100 fi
101 echo "" >> $TMP
102 fi
103
104 if [ "$BACKENDTYPE" = mod ]; then
105 cat <<EOF >> $TMP
106 dn: cn=module,cn=config
107 objectClass: olcModuleList
108 cn: module
109 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
110 olcModuleLoad: back_$BACKEND.la
111
112 EOF
113 fi
114 MYURI=`eval echo '$URI'$n`
115 PROVIDERURI=`eval echo '$URI'$o`
116 if test $INDEXDB = indexdb ; then
117 INDEX1="olcDbIndex: objectClass,entryCSN,reqStart,reqDN,reqResult eq"
118 INDEX2="olcDbIndex: objectClass,entryCSN,entryUUID eq"
119 else
120 INDEX1=
121 INDEX2=
122 fi
123 cat >> $TMP <<EOF
124 dn: cn=schema,cn=config
125 objectclass: olcSchemaconfig
126 cn: schema
127
128 include: file://$ABS_SCHEMADIR/core.ldif
129
130 include: file://$ABS_SCHEMADIR/cosine.ldif
131
132 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
133
134 include: file://$ABS_SCHEMADIR/openldap.ldif
135
136 include: file://$ABS_SCHEMADIR/nis.ldif
137
138 dn: olcDatabase={0}config,cn=config
139 objectClass: olcDatabaseConfig
140 olcDatabase: {0}config
141 olcRootPW:< file://$CONFIGPWF
142
143 dn: olcDatabase={1}$BACKEND,cn=config
144 objectClass: olcDatabaseConfig
145 ${nullExclude}objectClass: olc${BACKEND}Config
146 olcDatabase: {1}$BACKEND
147 olcSuffix: cn=log
148 ${nullExclude}olcDbDirectory: ${DBDIR}.1
149 olcRootDN: $MANAGERDN
150 $INDEX1
151
152 dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
153 objectClass: olcOverlayConfig
154 objectClass: olcSyncProvConfig
155 olcOverlay: syncprov
156 olcSpNoPresent: TRUE
157 olcSpReloadHint: TRUE
158
159 dn: olcDatabase={2}$BACKEND,cn=config
160 objectClass: olcDatabaseConfig
161 ${nullExclude}objectClass: olc${BACKEND}Config
162 olcDatabase: {2}$BACKEND
163 olcSuffix: $BASEDN
164 ${nullExclude}olcDbDirectory: ${DBDIR}.2
165 olcRootDN: $MANAGERDN
166 olcRootPW: $PASSWD
167 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
168 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE retry="3 +" timeout=3
169 olcMirrorMode: TRUE
170 $INDEX2
171
172 dn: olcOverlay=syncprov,olcDatabase={2}$BACKEND,cn=config
173 objectClass: olcOverlayConfig
174 objectClass: olcSyncProvConfig
175 olcOverlay: syncprov
176 olcSpSessionlogSource: cn=log
177
178 dn: olcOverlay=accesslog,olcDatabase={2}$BACKEND,cn=config
179 objectClass: olcOverlayConfig
180 objectClass: olcAccessLogConfig
181 olcOverlay: accesslog
182 olcAccessLogDB: cn=log
183 olcAccessLogOps: writes
184 olcAccessLogSuccess: TRUE
185
186 EOF
187 $SLAPADD -F $CFDIR -n 0 -d-1< $TMP > $TESTOUT 2>&1
188 RC=$?
189 if test $RC != 0 ; then
190 echo "slapadd failed ($RC)!"
191 exit $RC
192 fi
193
194 PORT=`eval echo '$PORT'$n`
195 echo "Starting server $n on TCP/IP port $PORT..."
196 cd ${XDIR}${n}
197 LOG=`eval echo '$LOG'$n`
198 $SLAPD -F slapd.d -h $MYURI -d $LVL > $LOG 2>&1 &
199 PID=$!
200 if test $WAIT != 0 ; then
201 echo PID $PID
202 read foo
203 fi
204 KILLPIDS="$PID $KILLPIDS"
205 cd $TESTWD
206
207 echo "Using ldapsearch to check that server $n is running..."
208 for i in 0 1 2 3 4 5; do
209 $LDAPSEARCH -s base -b "" -H $MYURI \
210 'objectclass=*' > /dev/null 2>&1
211 RC=$?
212 if test $RC = 0 ; then
213 break
214 fi
215 echo "Waiting 5 seconds for slapd to start..."
216 sleep 5
217 done
218
219 if test $RC != 0 ; then
220 echo "ldapsearch failed ($RC)!"
221 test $KILLSERVERS != no && kill -HUP $KILLPIDS
222 exit $RC
223 fi
224
225 if [ $n = 1 ]; then
226 echo "Using ldapadd for context on server 1..."
227 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDCP \
228 >> $TESTOUT 2>&1
229 RC=$?
230 if test $RC != 0 ; then
231 echo "ldapadd failed for server $n database ($RC)!"
232 test $KILLSERVERS != no && kill -HUP $KILLPIDS
233 exit $RC
234 fi
235 fi
236
237 n=`expr $n + 1`
238 done
239
240 echo "Using ldapadd to populate server 1..."
241 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDNOCP \
242 >> $TESTOUT 2>&1
243 RC=$?
244 if test $RC != 0 ; then
245 echo "ldapadd failed for server 1 database ($RC)!"
246 test $KILLSERVERS != no && kill -HUP $KILLPIDS
247 exit $RC
248 fi
249
250 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
251 sleep $SLEEP1
252
253 n=1
254 while [ $n -le $MMR ]; do
255 URI=`eval echo '$URI'$n`
256
257 echo "Using ldapsearch to read all the entries from server $n..."
258 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
259 'objectclass=*' > $TESTDIR/server$n.out 2>&1
260 RC=$?
261
262 if test $RC != 0 ; then
263 echo "ldapsearch failed at server $n ($RC)!"
264 test $KILLSERVERS != no && kill -HUP $KILLPIDS
265 exit $RC
266 fi
267 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
268 n=`expr $n + 1`
269 done
270
271 n=2
272 while [ $n -le $MMR ]; do
273 echo "Comparing retrieved entries from server 1 and server $n..."
274 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
275
276 if test $? != 0 ; then
277 echo "test failed - server 1 and server $n databases differ"
278 test $KILLSERVERS != no && kill -HUP $KILLPIDS
279 exit 1
280 fi
281 n=`expr $n + 1`
282 done
283
284 echo "Using ldapadd to populate server 2..."
285 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
286 >> $TESTOUT 2>&1
287 RC=$?
288 if test $RC != 0 ; then
289 echo "ldapadd failed for server 2 database ($RC)!"
290 test $KILLSERVERS != no && kill -HUP $KILLPIDS
291 exit $RC
292 fi
293
294 THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
295 sleep 1
296 for i in 1 2 3; do
297 $LDAPSEARCH -S "" -b "$THEDN" -H $URI1 \
298 -s base '(objectClass=*)' entryCSN > "${PROVIDEROUT}.$i" 2>&1
299 RC=$?
300
301 if test $RC = 0 ; then
302 break
303 fi
304
305 if test $RC != 32 ; then
306 echo "ldapsearch failed at slave ($RC)!"
307 test $KILLSERVERS != no && kill -HUP $KILLPIDS
308 exit $RC
309 fi
310
311 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
312 sleep $SLEEP1
313 done
314
315 n=1
316 while [ $n -le $MMR ]; do
317 URI=`eval echo '$URI'$n`
318
319 echo "Using ldapsearch to read all the entries from server $n..."
320 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
321 'objectclass=*' > $TESTDIR/server$n.out 2>&1
322 RC=$?
323
324 if test $RC != 0 ; then
325 echo "ldapsearch failed at server $n ($RC)!"
326 test $KILLSERVERS != no && kill -HUP $KILLPIDS
327 exit $RC
328 fi
329 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
330 n=`expr $n + 1`
331 done
332
333 n=2
334 while [ $n -le $MMR ]; do
335 echo "Comparing retrieved entries from server 1 and server $n..."
336 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
337
338 if test $? != 0 ; then
339 echo "test failed - server 1 and server $n databases differ"
340 test $KILLSERVERS != no && kill -HUP $KILLPIDS
341 exit 1
342 fi
343 n=`expr $n + 1`
344 done
345
346 echo "Retrieving syncrepl cookie..."
347 cookie=`$LDAPRSEARCH -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
348 -E "sync=ro" 'objectclass=*' 1.1 | grep cookie | sed "s/.*cookie: //"`
349
350 if test -z "$cookie"; then
351 echo "Failed to retrieve cookie from server!"
352 test $KILLSERVERS != no && kill -HUP $KILLPIDS
353 exit 1
354 fi
355
356 echo "Deleting an entry from server 1..."
357 $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD \
358 "cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN" \
359 >> $TESTOUT 2>&1
360 RC=$?
361 if test $RC != 0 ; then
362 echo "ldapdelete failed for server 1 database ($RC)!"
363 test $KILLSERVERS != no && kill -HUP $KILLPIDS
364 exit $RC
365 fi
366
367
368 echo "Restarting servers..."
369 kill -HUP $KILLPIDS
370 wait
371 KILLPIDS=""
372 n=1
373 while [ $n -le $MMR ]; do
374 o=`expr 3 - $n`
375 MYURI=`eval echo '$URI'$n`
376 PROVIDERURI=`eval echo '$URI'$o`
377
378 echo "Starting server $n again..."
379 cd ${XDIR}${n}
380 LOG=`eval echo '$LOG'$n`
381 echo "RESTART" >> $LOG
382 #if test $n = 2; then
383 #echo $SLAPD -F slapd.d -h $MYURI -d $LVL
384 #else
385 $SLAPD -F slapd.d -h $MYURI -d $LVL > $LOG 2>&1 &
386 #fi
387 PID=$!
388 if test $WAIT != 0 ; then
389 echo PID $PID
390 read foo
391 fi
392 KILLPIDS="$PID $KILLPIDS"
393 cd $TESTWD
394
395 echo "Using ldapsearch to check that server $n is running..."
396 for i in 0 1 2 3 4 5; do
397 $LDAPSEARCH -s base -b "" -H $MYURI \
398 'objectclass=*' > /dev/null 2>&1
399 RC=$?
400 if test $RC = 0 ; then
401 break
402 fi
403 echo "Waiting 5 seconds for slapd to start..."
404 sleep 5
405 done
406
407 echo "Breaking replication between server $n and $o..."
408 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
409 dn: olcDatabase={2}$BACKEND,cn=config
410 changetype: modify
411 replace: olcSyncRepl
412 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
413 credentials=InvalidPw searchbase="$BASEDN" $SYNCTYPE retry="3 +" timeout=3
414 -
415 replace: olcMirrorMode
416 olcMirrorMode: TRUE
417
418 EOF
419 RC=$?
420 if test $RC != 0 ; then
421 echo "ldapmodify failed for server $n config ($RC)!"
422 test $KILLSERVERS != no && kill -HUP $KILLPIDS
423 exit $RC
424 fi
425 n=`expr $n + 1`
426 done
427
428 echo "Using ldapmodify to force conflicts between server 1 and 2..."
429 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
430 >> $TESTOUT 2>&1 << EOF
431 dn: $THEDN
432 changetype: modify
433 add: description
434 description: Amazing
435
436 EOF
437 RC=$?
438 if test $RC != 0 ; then
439 echo "ldapmodify failed for server 1 database ($RC)!"
440 test $KILLSERVERS != no && kill -HUP $KILLPIDS
441 exit $RC
442 fi
443
444 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
445 >> $TESTOUT 2>&1 << EOF
446 dn: $THEDN
447 changetype: modify
448 add: description
449 description: Stupendous
450
451 EOF
452 RC=$?
453 if test $RC != 0 ; then
454 echo "ldapmodify failed for server 2 database ($RC)!"
455 test $KILLSERVERS != no && kill -HUP $KILLPIDS
456 exit $RC
457 fi
458
459 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
460 >> $TESTOUT 2>&1 << EOF
461 dn: $THEDN
462 changetype: modify
463 delete: description
464 description: Outstanding
465 -
466 add: description
467 description: Mindboggling
468
469 EOF
470 RC=$?
471 if test $RC != 0 ; then
472 echo "ldapmodify failed for server 1 database ($RC)!"
473 test $KILLSERVERS != no && kill -HUP $KILLPIDS
474 exit $RC
475 fi
476
477 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
478 >> $TESTOUT 2>&1 << EOF
479 dn: $THEDN
480 changetype: modify
481 delete: description
482 description: OutStanding
483 -
484 add: description
485 description: Bizarre
486
487 EOF
488 RC=$?
489 if test $RC != 0 ; then
490 echo "ldapmodify failed for server 2 database ($RC)!"
491 test $KILLSERVERS != no && kill -HUP $KILLPIDS
492 exit $RC
493 fi
494
495 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
496 >> $TESTOUT 2>&1 << EOF
497 dn: $THEDN
498 changetype: modify
499 add: carLicense
500 carLicense: 123-XYZ
501 -
502 add: employeeNumber
503 employeeNumber: 32
504
505 EOF
506 RC=$?
507 if test $RC != 0 ; then
508 echo "ldapmodify failed for server 1 database ($RC)!"
509 test $KILLSERVERS != no && kill -HUP $KILLPIDS
510 exit $RC
511 fi
512
513 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
514 >> $TESTOUT 2>&1 << EOF
515 dn: $THEDN
516 changetype: modify
517 add: employeeType
518 employeeType: deadwood
519 -
520 add: employeeNumber
521 employeeNumber: 64
522
523 EOF
524 RC=$?
525 if test $RC != 0 ; then
526 echo "ldapmodify failed for server 2 database ($RC)!"
527 test $KILLSERVERS != no && kill -HUP $KILLPIDS
528 exit $RC
529 fi
530
531 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
532 >> $TESTOUT 2>&1 << EOF
533 dn: $THEDN
534 changetype: modify
535 replace: sn
536 sn: Replaced later
537 -
538 replace: sn
539 sn: Surname
540 EOF
541 RC=$?
542 if test $RC != 0 ; then
543 echo "ldapmodify failed for server 1 database ($RC)!"
544 test $KILLSERVERS != no && kill -HUP $KILLPIDS
545 exit $RC
546 fi
547
548 echo "Deleting an entry from both servers..."
549 $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD \
550 "cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN" \
551 >> $TESTOUT 2>&1
552 RC=$?
553 if test $RC != 0 ; then
554 echo "ldapdelete failed for server 1 database ($RC)!"
555 test $KILLSERVERS != no && kill -HUP $KILLPIDS
556 exit $RC
557 fi
558
559 $LDAPDELETE -D "$MANAGERDN" -H $URI2 -w $PASSWD \
560 "cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN" \
561 >> $TESTOUT 2>&1
562 RC=$?
563 if test $RC != 0 ; then
564 echo "ldapdelete failed for server 2 database ($RC)!"
565 test $KILLSERVERS != no && kill -HUP $KILLPIDS
566 exit $RC
567 fi
568
569 echo "Restoring replication between server 1 and 2..."
570 n=1
571 while [ $n -le $MMR ]; do
572 o=`expr 3 - $n`
573 MYURI=`eval echo '$URI'$n`
574 PROVIDERURI=`eval echo '$URI'$o`
575 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
576 dn: olcDatabase={2}$BACKEND,cn=config
577 changetype: modify
578 replace: olcSyncRepl
579 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
580 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE retry="3 +" timeout=3
581 -
582 replace: olcMirrorMode
583 olcMirrorMode: TRUE
584
585 EOF
586 RC=$?
587 if test $RC != 0 ; then
588 echo "ldapmodify failed for server $n config ($RC)!"
589 test $KILLSERVERS != no && kill -HUP $KILLPIDS
590 exit $RC
591 fi
592 n=`expr $n + 1`
593 done
594
595 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
596 sleep $SLEEP1
597
598 echo 2 >$TESTDIR/repl.test
599 echo 1 >>$TESTDIR/repl.test
600
601 n=1
602 while [ $n -le $MMR ]; do
603 URI=`eval echo '$URI'$n`
604
605 echo "Using ldapsearch to read all the entries from server $n..."
606 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
607 'objectclass=*' > $TESTDIR/server$n.out 2>&1
608 RC=$?
609
610 if test $RC != 0 ; then
611 echo "ldapsearch failed at server $n ($RC)!"
612 test $KILLSERVERS != no && kill -HUP $KILLPIDS
613 exit $RC
614 fi
615 $LDIFFILTER -s a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
616
617 echo "Checking server $n can remember which entries have been deleted even after it's been restarted..."
618 $LDAPRSEARCH -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
619 -E "sync=ro/$cookie" 'objectclass=*' 1.1 | awk '/syncUUIDs/ {count++} END {print count}' >$TESTDIR/repl.out
620 $LDAPRSEARCH -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
621 -E "sync=ro/$cookie" 'objectclass=*' 1.1 | grep SyncDone | awk '/refreshDeletes=1/ {count++} END {print count}' >>$TESTDIR/repl.out
622
623 $CMP $TESTDIR/repl.out $TESTDIR/repl.test > $CMPOUT
624
625 if test $? != 0 ; then
626 echo "test failed - server did not respond with delete phase"
627 test $KILLSERVERS != no && kill -HUP $KILLPIDS
628 exit 1
629 fi
630 n=`expr $n + 1`
631 done
632
633 n=2
634 while [ $n -le $MMR ]; do
635 echo "Comparing retrieved entries from server 1 and server $n..."
636 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
637
638 if test $? != 0 ; then
639 echo "test failed - server 1 and server $n databases differ"
640 test $KILLSERVERS != no && kill -HUP $KILLPIDS
641 exit 1
642 fi
643 n=`expr $n + 1`
644 done
645
646 test $KILLSERVERS != no && kill -HUP $KILLPIDS
647
648 echo ">>>>> Test succeeded"
649
650 test $KILLSERVERS != no && wait
651
652 exit 0