its8521 8.51 KB
Newer Older
1
2
3
4
#! /bin/sh
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
5
## Copyright 1998-2019 The OpenLDAP Foundation.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.

echo "running defines.sh"
. $SRCDIR/scripts/defines.sh

if test $SYNCPROV = syncprovno; then
	echo "Syncrepl provider overlay not available, test skipped"
	exit 0
fi

24
25
26
27
28
29
echo ""
echo "  This test tracks a case where a consumer fails to replicate from the provider"
echo "  when the provider is dynamically configured for replication."
echo "  See http://www.openldap.org/its/index.cgi/?findid=8521 and"
echo "  See http://www.openldap.org/its/index.cgi/?findid=8281 for more information."
echo ""
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

PRODIR=$TESTDIR/pro
CONDIR=$TESTDIR/con1
CFPRO=$PRODIR/slapd.d
CFCON=$CONDIR/slapd.d

mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $PRODIR $CONDIR $CFPRO $CFCON

$SLAPPASSWD -g -n >$CONFIGPWF

ITS=8521
ITSDIR=$DATADIR/regressions/its$ITS

echo "Starting provider slapd on TCP/IP port $PORT1..."
. $CONFFILTER $BACKEND $MONITORDB < $ITSDIR/slapd-provider.ldif > $CONFLDIF
$SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
$SLAPD -F $CFPRO -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
PID=$!
if test $WAIT != 0 ; then
	echo PID $PID
	read foo
fi
KILLPIDS="$PID"

sleep 1

echo "Using ldapsearch to check that provider slapd is running..."
for i in 0 1 2 3 4 5; do
	$LDAPSEARCH -s base -b "" -H $URI1 \
		'objectclass=*' > /dev/null 2>&1
	RC=$?
	if test $RC = 0 ; then
		break
	fi
	echo "Waiting 5 seconds for slapd to start..."
	sleep 5
done

if test $RC != 0 ; then
	echo "ldapsearch failed ($RC)!"
	test $KILLSERVERS != no && kill -HUP $KILLPIDS
	exit $RC
fi

echo "Starting consumer slapd on TCP/IP port $PORT2..."
. $CONFFILTER $BACKEND $MONITORDB < $ITSDIR/slapd-consumer.ldif > $CONFLDIF
$SLAPADD -F $CFCON -n 0 -l $CONFLDIF
$SLAPD -F $CFCON -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
SLAVEPID=$!
if test $WAIT != 0 ; then
	echo SLAVEPID $SLAVEPID
	read foo
fi
KILLPIDS="$KILLPIDS $SLAVEPID"

sleep 1

echo "Using ldapsearch to check that consumer slapd is running..."
for i in 0 1 2 3 4 5; do
	$LDAPSEARCH -s base -b "" -H $URI2 \
		'objectclass=*' > /dev/null 2>&1
	RC=$?
	if test $RC = 0 ; then
		break
	fi
	echo "Waiting 5 seconds for slapd to start..."
	sleep 5
done

if test $RC != 0 ; then
	echo "ldapsearch failed ($RC)!"
	test $KILLSERVERS != no && kill -HUP $KILLPIDS
	exit $RC
fi

echo "Setting serverID on provider..."
$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
dn: cn=config
changetype: modify
add: olcServerId
olcServerId: 1
EOF
RC=$?

if test $RC != 0 ; then
	echo "ldapmodify failed ($RC)!"
	test $KILLSERVERS != no && kill -HUP $KILLPIDS
	exit $RC
fi

echo "Populating database on provider..."
$LDAPADD -D $MANAGERDN -H $URI1 -w $PASSWD << EOMODS >> $TESTOUT 2>&1
dn: dc=example,dc=com
changetype: add
objectClass: domain
objectClass: top
dc: example

dn: ou=LDAPRoles,dc=example,dc=com
objectClass: top
objectClass: organizationalUnit
ou: LDAPRoles

dn: dc=users,dc=example,dc=com
changetype: add
dc: users
objectClass: domain
objectClass: top

139
dn: uid=johndoe,dc=users,dc=example,dc=com
140
changetype: add
141
objectClass: inetOrgPerson
142
objectClass: top
143
sn: Doe
144
cn: Johndoe
145
uid: johndoe
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

dn: cn=replicator,ou=LDAPRoles,dc=example,dc=com
objectClass: top
objectClass: simpleSecurityObject
objectClass: organizationalRole
userPassword: secret
cn: replicator
EOMODS

RC=$?
if test $RC != 0 ; then
	echo "ldapadd failed ($RC)!"
	test $KILLSERVERS != no && kill -HUP $KILLPIDS
	exit $RC
fi

if [ "$SYNCPROV" = syncprovmod ]; then
	echo "Configuring syncprov module on the provider..."
	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulePath: $TESTWD/../servers/slapd/overlays
olcModuleLoad: syncprov.la
EOF
	RC=$?
	if test $RC != 0 ; then
		echo "ldapadd failed for moduleLoad ($RC)!"
		test $KILLSERVERS != no && kill -HUP $KILLPIDS
		exit $RC
	fi
fi

echo "Configuring replication on the provider..."
$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcConfig
objectClass: top
objectClass: olcSyncprovConfig
olcOverlay: syncprov
olcSpSessionLog: 10000
olcSpCheckpoint: 100 10

dn: olcDatabase={1}$BACKEND,cn=config
changetype: modify
add: olcLimits
olcLimits: dn.exact="cn=replicator,ou=LDAPRoles,dc=example,dc=com"
  time.soft=unlimited time.hard=unlimited size.soft=unlimited
  size.hard=unlimited

dn: olcDatabase={1}$BACKEND,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to dn.subtree="dc=example,dc=com"  by self write
  by dn.exact="cn=replicator,ou=LDAPRoles,dc=example,dc=com" read
  by anonymous auth by * read
EOF

RC=$?
if test $RC != 0 ; then
	echo "ldapmodify failed ($RC)!"
	test $KILLSERVERS != no && kill -HUP $KILLPIDS
	exit $RC
fi

echo "Configuring replication on the consumer..."
$LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
dn: olcDatabase={1}$BACKEND,cn=config
changetype: modify
add: olcSyncrepl
olcSyncrepl: rid=100 provider=$URI1 bindmethod=simple
  binddn="cn=replicator,ou=LDAPRoles,dc=example,dc=com" credentials=secret
220
221
  type=refreshAndPersist searchbase="dc=example,dc=com" filter="(objectclass=*)"
  scope=sub schemachecking=on interval=5 retry="5 +" sizeLimit=unlimited
222
223
224
225
226
227
228
229
230
231
232
  timelimit=unlimited
-

EOF
RC=$?
if test $RC != 0 ; then
  echo "ldapmodify failed for olcSyncrepl configuration ($RC)!"
  test $KILLSERVERS != no && kill -HUP $KILLPIDS
  exit $RC
fi

233
echo "Sleeping 10 seconds to allow replication to initiate..."
234
235
sleep 10

236
237
238
239
echo "Using ldapsearch to read all the entries from the provider..."
$LDAPSEARCH -S "" -D $MANAGERDN -w $PASSWD -b "$BASEDN" -H $URI1 \
        '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
RC=$?
240
241

if test $RC != 0 ; then
242
243
244
        echo "ldapsearch failed at provider ($RC)!"
        test $KILLSERVERS != no && kill -HUP $KILLPIDS
        exit $RC
245
246
fi

247
248
249
250
echo "Using ldapsearch to read all the entries from the consumer..."
$LDAPSEARCH -S "" -D $MANAGERDN -w $PASSWD -b "$BASEDN" -H $URI2 \
        '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
RC=$?
251

252
253
if test $RC != 32 ; then
        echo "ldapsearch should have failed with error 32.  Got $RC instead!"
254
255
256
	echo "This is a regression of ITS8281"
        test $KILLSERVERS != no && kill -HUP $KILLPIDS
        exit $RC
257
258
259
fi


260
261
262
263
echo "Filtering provider results..."
$LDIFFILTER < $MASTEROUT > $MASTERFLT
echo "Filtering consumer results..."
$LDIFFILTER < $SLAVEOUT > $SLAVEFLT
264

265
266
267
echo "Comparing retrieved entries from provider and consumer..."
$CMP $MASTERFLT $SLAVEFLT > $CMPOUT

Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
268
if test $? = 0 ; then
269
270
        echo "test failed - provider and consumer databases match"
	echo "This is a regression of ITS8281"
271
	test $KILLSERVERS != no && kill -HUP $KILLPIDS
272
        exit 1
273
274
fi

275
276
277
278
279
280
281
282
283
284
echo "Modifying provider to force generation of a contextCSN"
$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \
        $TESTOUT 2>&1 << EOMODS
dn: uid=Johndoe,dc=users,dc=example,dc=com
changetype: modify
replace: cn
cn: John Doe
EOMODS

echo "Sleeping 30 seconds to allow consumer to reconnect and replicate..."
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
sleep 30

echo "Using ldapsearch to read all the entries from the provider..."
$LDAPSEARCH -S "" -D $MANAGERDN -w $PASSWD -b "$BASEDN" -H $URI1 \
        '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
RC=$?

if test $RC != 0 ; then
        echo "ldapsearch failed at provider ($RC)!"
        test $KILLSERVERS != no && kill -HUP $KILLPIDS
        exit $RC
fi

echo "Using ldapsearch to read all the entries from the consumer..."
$LDAPSEARCH -S "" -D $MANAGERDN -w $PASSWD -b "$BASEDN" -H $URI2 \
        '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
RC=$?

if test $RC != 0 ; then
        echo "ldapsearch failed at consumer ($RC)!"
        test $KILLSERVERS != no && kill -HUP $KILLPIDS
        exit $RC
fi


echo "Filtering provider results..."
$LDIFFILTER < $MASTEROUT > $MASTERFLT
echo "Filtering consumer results..."
$LDIFFILTER < $SLAVEOUT > $SLAVEFLT

echo "Comparing retrieved entries from provider and consumer..."
$CMP $MASTERFLT $SLAVEFLT > $CMPOUT

if test $? != 0 ; then
        echo "test failed - provider and consumer databases differ"
320
	test $KILLSERVERS != no && kill -HUP $KILLPIDS
321
322
323
        exit 1
fi

324
325
test $KILLSERVERS != no && kill -HUP $KILLPIDS

326
327
328
329
330
331
echo
echo ">>>>> Test succeeded"

test $KILLSERVERS != no && wait

exit 0