]> git.sur5r.net Git - openldap/blob - tests/scripts/test033-glue-syncrepl
Happy New Year
[openldap] / tests / scripts / test033-glue-syncrepl
1 #! /bin/sh
2 # $OpenLDAP$ */
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2018 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
24 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR1C $DBDIR2A $DBDIR2B
25
26 echo "Running slapadd to build glued slapd databases..."
27 . $CONFFILTER $BACKEND $MONITORDB < $GLUECONF > $CONF1
28 $SLAPADD -d $LVL -f $CONF1 -l $LDIFORDERED > $SLAPADDLOG1 2>&1
29 RC=$?
30 if test $RC != 0 ; then
31         echo "slapadd failed ($RC)!"
32         exit $RC
33 fi
34
35 rm -rf $DBDIR1A/* $DBDIR1B/*
36 cp -pr $DBDIR1C $DBDIR2C
37
38 echo "Starting slapd 1 on TCP/IP port $PORT1..."
39 . $CONFFILTER $BACKEND $MONITORDB < $GLUESYNCCONF1 > $CONF1
40 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43     echo PID $PID
44     read foo
45 fi
46 KILLPIDS="$PID"
47
48 sleep 1
49
50 echo "Using ldapsearch to check that slapd 1 is running..."
51 for i in 0 1 2 3 4 5; do
52         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
53                 '(objectclass=*)' > /dev/null 2>&1
54         RC=$?
55         if test $RC = 0 ; then
56                 break
57         fi
58         echo "Waiting 5 seconds for slapd to start..."
59         sleep 5
60 done
61
62 echo "Starting slapd 2 on TCP/IP port $PORT2..."
63 . $CONFFILTER $BACKEND $MONITORDB < $GLUESYNCCONF2 > $CONF2
64 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
65 PID=$!
66 if test $WAIT != 0 ; then
67     echo PID $PID
68     read foo
69 fi
70 KILLPIDS="$KILLPIDS $PID"
71
72 sleep 1
73
74 echo "Using ldapsearch to check that slapd 2 is running..."
75 for i in 0 1 2 3 4 5; do
76         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
77                 '(objectclass=*)' > /dev/null 2>&1
78         RC=$?
79         if test $RC = 0 ; then
80                 break
81         fi
82         echo "Waiting 5 seconds for slapd to start..."
83         sleep 5
84 done
85
86 SUBTREE1="ou=Information Technology Division,ou=People,dc=example,dc=com"
87 SUBTREE2="ou=Groups,dc=example,dc=com"
88
89 echo "Using ldapadd to populate subtree=\"${SUBTREE1}\" on port $PORT1..."
90 $LDAPADD -D "cn=Manager 1,$BASEDN" -w $PASSWD -h $LOCALHOST -p $PORT1 \
91         -f $LDIFORDERED -c \
92         > /dev/null 2>&1
93 RC=$?
94 case $RC in
95 0)
96         echo "ldapadd should have failed ($RC)!"
97         test $KILLSERVERS != no && kill -HUP $KILLPIDS
98         exit -1
99         ;;
100 10|68)
101         # Fine if we get alreadyExists or referrals
102         ;;
103 *)
104         echo "ldapadd failed ($RC)!"
105         test $KILLSERVERS != no && kill -HUP $KILLPIDS
106         exit $RC
107         ;;
108 esac
109
110 echo "Using ldapadd to populate subtree=\"${SUBTREE2}\" on port $PORT2..."
111 $LDAPADD -D "cn=Manager 2,$BASEDN" -w $PASSWD -h $LOCALHOST -p $PORT2 \
112         -f $LDIFORDERED -c \
113         > /dev/null 2>&1
114 RC=$?
115 case $RC in
116 0)
117         echo "ldapadd should have failed ($RC)!"
118         test $KILLSERVERS != no && kill -HUP $KILLPIDS
119         exit -1
120         ;;
121 10|68)
122         # Fine if we get alreadyExists or referrals
123         ;;
124 *)
125         echo "ldapadd failed ($RC)!"
126         test $KILLSERVERS != no && kill -HUP $KILLPIDS
127         exit $RC
128         ;;
129 esac
130
131 echo "Waiting $SLEEP1 seconds for shadow subtrees to sync..."
132 sleep $SLEEP1
133
134 echo "Filtering original ldif used to create database..."
135 $LDIFFILTER < $GLUESYNCOUT > $LDIFFLT
136
137 for P in $PORT1 $PORT2 ; do
138         echo "Using ldapsearch to read all the entries from port $P..."
139         $LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $P \
140                 -S "" '(objectclass=*)' > "${SEARCHOUT}.${P}" 2>&1
141         RC=$?
142
143         if test $RC != 0 ; then
144                 echo "ldapsearch failed ($RC)!"
145                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
146                 exit $RC
147         fi
148
149         echo "Filtering ldapsearch results..."
150         $LDIFFILTER < "${SEARCHOUT}.${P}" > $SEARCHFLT
151         echo "Comparing filter output..."
152         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
153
154         if test $? != 0 ; then
155                 echo "comparison failed - database was not created correctly"
156                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
157                 exit 1
158         fi
159 done
160
161 echo "Testing ldapdelete propagation..."
162 $LDAPDELETE -D "cn=Manager 1,$BASEDN" -w $PASSWD -H $URI1 "$BABSDN" \
163         > $TESTOUT 2>&1
164 RC=$?
165 if test $RC != 0 ; then
166         echo "ldapdelete failed ($RC)!"
167         test $KILLSERVERS != no && kill -HUP $KILLPIDS
168         exit $RC
169 fi
170
171 # This usually propagates immediately
172 sleep 1
173
174 $LDAPSEARCH -H $URI2 -b "$BABSDN" > $TESTOUT 2>&1
175 RC=$?
176 if test $RC = 0 && test $BACKEND != null ; then
177         echo "ldapsearch should have failed ($RC)!"
178         test $KILLSERVERS != no && kill -HUP $KILLPIDS
179         exit -1
180 fi
181
182 test $KILLSERVERS != no && kill -HUP $KILLPIDS
183
184 echo ">>>>> Test succeeded"
185
186 test $KILLSERVERS != no && wait
187
188 exit 0