Home | History | Annotate | Line # | Download | only in scripts
test071-dirsync revision 1.1
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2021 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 # requires MSAD_URI, MSAD_SUFFIX, MSAD_ADMINDN, MSAD_ADMINPW
     20 if test -z "$MSAD_URI"; then
     21 	echo "No MSAD envvars set, test skipped"
     22 	exit 0
     23 fi
     24 if test $SYNCPROV = syncprovno; then 
     25 	echo "Syncrepl provider overlay not available, test skipped"
     26 	exit 0
     27 fi 
     28 
     29 mkdir -p $TESTDIR $DBDIR2
     30 
     31 URI1=$MSAD_URI
     32 BASEDN="ou=OpenLDAPtest,$MSAD_SUFFIX"
     33 DC=`echo $MSAD_SUFFIX | sed -e 's/dc=//' -e 's/,.*//'`
     34 
     35 #
     36 # Test replication:
     37 # - populate MSAD over ldap
     38 # - start consumer
     39 # - perform some modifies and deletes
     40 # - attempt to modify the consumer (referral)
     41 # - retrieve database over ldap and compare against expected results
     42 #
     43 
     44 # Notes:
     45 # We use a separate OU under the MSAD suffix to contain our test objects,
     46 # since we can't just wipe out the entire directory when starting over.
     47 # The replication search filter is thus more convoluted than would normally
     48 # be needed. Typically it would only need (|(objectclass=user)(objectclass=group))
     49 #
     50 # MSAD does referential integrity by default, so to get 1-to-1 modifications
     51 # we must add users before creating groups that reference them, and we
     52 # should delete group memberships before deleting users. If we delete
     53 # users first, MSAD will automatically remove them from their groups,
     54 # but won't notify us of these changed groups.
     55 # We could use the refint overlay to duplicate this behavior, but that's
     56 # beyond the scope of this test.
     57 
     58 echo "Using ldapsearch to check that MSAD is running..."
     59 $LDAPSEARCH -D $MSAD_ADMINDN -w $MSAD_ADMINPW -s base -b "$MSAD_SUFFIX" -H $MSAD_URI 'objectclass=*' > /dev/null 2>&1
     60 RC=$?
     61 if test $RC != 0 ; then
     62 	echo "ldapsearch failed ($RC)!"
     63 	exit $RC
     64 fi
     65 
     66 echo "Using ldapdelete to delete old MSAD test tree, if any..."
     67 $LDAPDELETE -D "$MSAD_ADMINDN" -H $MSAD_URI -w $MSAD_ADMINPW -r "$BASEDN"
     68 RC=$?
     69 
     70 echo "Using ldapadd to create the test context entry in MSAD..."
     71 sed -e "s/dc=example,dc=com/$MSAD_SUFFIX/" < $LDIFDIRSYNCCP | \
     72 	$LDAPADD -D "$MSAD_ADMINDN" -H $MSAD_URI -w $MSAD_ADMINPW > /dev/null 2>&1
     73 
     74 RC=$?
     75 if test $RC != 0 ; then
     76 	echo "ldapadd failed ($RC)!"
     77 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     78 	exit $RC
     79 fi
     80 
     81 echo "Starting consumer slapd on TCP/IP port $PORT2..."
     82 . $CONFFILTER $BACKEND < $DIRSYNC1CONF | . $CONFDIRSYNC > $CONF2
     83 $SLAPADD -f $CONF2 <<EOMODS
     84 dn: $MSAD_SUFFIX
     85 dc: $DC
     86 objectclass: organization
     87 objectclass: dcObject
     88 o: OpenLDAP Testing
     89 
     90 EOMODS
     91 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
     92 CONSUMERPID=$!
     93 if test $WAIT != 0 ; then
     94     echo CONSUMERPID $CONSUMERPID
     95     read foo
     96 fi
     97 KILLPIDS="$KILLPIDS $CONSUMERPID"
     98 
     99 sleep 1
    100 
    101 echo "Using ldapsearch to check that consumer slapd is running..."
    102 for i in 0 1 2 3 4 5; do
    103 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
    104 		'objectclass=*' > /dev/null 2>&1
    105 	RC=$?
    106 	if test $RC = 0 ; then
    107 		break
    108 	fi
    109 	echo "Waiting 5 seconds for slapd to start..."
    110 	sleep 5
    111 done
    112 
    113 if test $RC != 0 ; then
    114 	echo "ldapsearch failed ($RC)!"
    115 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    116 	exit $RC
    117 fi
    118 
    119 
    120 echo "Using ldapsearch to check that consumer received context entry..."
    121 for i in 0 1 2 3 4 5; do
    122 	$LDAPSEARCH -s base -b "$BASEDN" -H $URI2 \
    123 		'objectclass=*' > /dev/null 2>&1
    124 	RC=$?
    125 	if test $RC = 0 ; then
    126 		break
    127 	fi
    128 	echo "Waiting 5 seconds for syncrepl to catch up..."
    129 	sleep 5
    130 done
    131 
    132 if test $RC != 0 ; then
    133 	echo "ldapsearch failed ($RC)!"
    134 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    135 	exit $RC
    136 fi
    137 
    138 echo "Using ldapadd to populate MSAD..."
    139 sed -e "s/dc=example,dc=com/$BASEDN/" < $LDIFDIRSYNCNOCP | \
    140 	$LDAPADD -D "$MSAD_ADMINDN" -H $MSAD_URI -w $MSAD_ADMINPW > /dev/null 2>&1
    141 RC=$?
    142 if test $RC != 0 ; then
    143 	echo "ldapadd failed ($RC)!"
    144 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    145 	exit $RC
    146 fi
    147 
    148 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    149 sleep $SLEEP1
    150 
    151 echo "Using ldapmodify to modify provider directory..."
    152 
    153 #
    154 # Do some modifications
    155 #
    156 
    157 $LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
    158 	$TESTOUT 2>&1 << EOMODS
    159 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, $BASEDN
    160 changetype: modify
    161 add: carLicense
    162 carLicense: Orange Juice
    163 -
    164 delete: sn
    165 sn: Jones
    166 -
    167 add: sn
    168 sn: Jones
    169 
    170 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, $BASEDN
    171 changetype: modify
    172 replace: carLicense
    173 carLicense: Iced Tea
    174 carLicense: Mad Dog 20/20
    175 
    176 dn: cn=ITD Staff,ou=Groups,$BASEDN
    177 changetype: modify
    178 delete: uniquemember
    179 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, $BASEDN
    180 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, $BASEDN
    181 -
    182 add: uniquemember
    183 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, $BASEDN
    184 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, $BASEDN
    185 
    186 dn: cn=All Staff,ou=Groups,$BASEDN
    187 changetype: modify
    188 replace: description
    189 description: The whole universe
    190 -
    191 delete: member
    192 member: cn=James A Jones 2,ou=Information Technology Division,ou=People,$BASEDN
    193 
    194 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, $BASEDN
    195 changetype: add
    196 objectclass: inetorgperson
    197 objectclass: domainrelatedobject
    198 cn: Gern Jensen
    199 sn: Jensen
    200 uid: gjensen
    201 title: Chief Investigator, ITD
    202 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
    203 seealso: cn=All Staff, ou=Groups, $BASEDN
    204 carLicense: Coffee
    205 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
    206 description: Very odd
    207 facsimiletelephonenumber: +1 313 555 7557
    208 telephonenumber: +1 313 555 8343
    209 mail: gjensen@mailgw.example.com
    210 homephone: +1 313 555 8844
    211 associateddomain: test.openldap.org
    212 
    213 dn: ou=Retired, ou=People, $BASEDN
    214 changetype: add
    215 objectclass: organizationalUnit
    216 ou: Retired
    217 
    218 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, $BASEDN
    219 changetype: add
    220 objectclass: inetorgperson
    221 objectclass: domainrelatedobject
    222 cn: Rosco P. Coltrane
    223 sn: Coltrane
    224 uid: rosco
    225 associateddomain: test.openldap.org
    226 
    227 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, $BASEDN
    228 changetype: modrdn
    229 newrdn: cn=Rosco P. Coltrane
    230 deleteoldrdn: 1
    231 newsuperior: ou=Retired, ou=People, $BASEDN
    232 
    233 dn: ou=testdomain1,$BASEDN
    234 changetype: modrdn
    235 newrdn: ou=itsdomain1
    236 deleteoldrdn: 1
    237 
    238 dn: ou=itsdomain1,$BASEDN
    239 changetype: modify
    240 replace: description
    241 description: Example, Inc. ITS test domain
    242 
    243 EOMODS
    244 
    245 RC=$?
    246 if test $RC != 0 ; then
    247 	echo "ldapmodify failed ($RC)!"
    248 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    249 	exit $RC
    250 fi
    251 
    252 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    253 sleep $SLEEP1
    254 
    255 echo "Performing modrdn alone on the provider..."
    256 $LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
    257 	$TESTOUT 2>&1 << EOMODS
    258 dn: ou=testdomain2,$BASEDN
    259 changetype: modrdn
    260 newrdn: ou=itsdomain2
    261 deleteoldrdn: 1
    262 
    263 EOMODS
    264 
    265 RC=$?
    266 if test $RC != 0 ; then
    267 	echo "ldapmodify failed ($RC)!"
    268 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    269 	exit $RC
    270 fi
    271 
    272 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    273 sleep $SLEEP1
    274 
    275 echo "Performing modify alone on the provider..."
    276 $LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
    277 	$TESTOUT 2>&1 << EOMODS
    278 dn: ou=itsdomain2,$BASEDN
    279 changetype: modify
    280 replace: description
    281 description: Example, Inc. itsdomain2 test domain
    282 
    283 EOMODS
    284 
    285 RC=$?
    286 if test $RC != 0 ; then
    287 	echo "ldapmodify failed ($RC)!"
    288 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    289 	exit $RC
    290 fi
    291 
    292 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    293 sleep $SLEEP1
    294 
    295 echo "Performing larger modify on the provider..."
    296 $LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
    297 	$TESTOUT 2>&1 << EOMODS
    298 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, $BASEDN
    299 changetype: delete
    300 
    301 dn: cn=Alumni Assoc Staff,ou=Groups,$BASEDN
    302 changetype: modify
    303 replace: description
    304 description: blablabla
    305 -
    306 replace: member
    307 member: cn=Manager,$BASEDN
    308 member: cn=Dorothy Stevens,ou=Alumni Association,ou=People,$BASEDN
    309 member: cn=James A Jones 1,ou=Alumni Association,ou=People,$BASEDN
    310 member: cn=Jane Doe,ou=Alumni Association,ou=People,$BASEDN
    311 member: cn=Jennifer Smith,ou=Alumni Association,ou=People,$BASEDN
    312 member: cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN
    313 member: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
    314 
    315 EOMODS
    316 
    317 RC=$?
    318 if test $RC != 0 ; then
    319 	echo "ldapmodify failed ($RC)!"
    320 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    321 	exit $RC
    322 fi
    323 
    324 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    325 sleep $SLEEP1
    326 
    327 OPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp"
    328 
    329 echo "Using ldapsearch to read all the entries from the provider..."
    330 $LDAPSEARCH -D $MSAD_ADMINDN -w $MSAD_ADMINPW -S "" -H $MSAD_URI -b "$MSAD_SUFFIX" -E \!dirsync=0/0 -o ldif_wrap=120 \
    331 	'(associatedDomain=test.openldap.org)' > $PROVIDEROUT 2>&1
    332 RC=$?
    333 
    334 if test $RC != 0 ; then
    335 	echo "ldapsearch failed at provider ($RC)!"
    336 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    337 	exit $RC
    338 fi
    339 
    340 echo "Using ldapsearch to read all the entries from the consumer..."
    341 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 -o ldif_wrap=120 \
    342 	'(objectclass=*)' > $CONSUMEROUT 2>&1
    343 RC=$?
    344 
    345 if test $RC != 0 ; then
    346 	echo "ldapsearch failed at consumer ($RC)!"
    347 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    348 	exit $RC
    349 fi
    350 
    351 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    352 
    353 echo "Filtering provider results..."
    354 $LDIFFILTER -s a < $PROVIDEROUT | sed -e 's/CN=/cn=/g' -e 's/OU=/ou=/g' -e 's/DC=/dc=/g' > $PROVIDERFLT
    355 echo "Filtering consumer results..."
    356 $LDIFFILTER -s a < $CONSUMEROUT > $CONSUMERFLT
    357 
    358 echo "Comparing retrieved entries from provider and consumer..."
    359 $CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT
    360 
    361 if test $? != 0 ; then
    362 	echo "test failed - provider and consumer databases differ"
    363 	exit 1
    364 fi
    365 
    366 echo ">>>>> Test succeeded"
    367 
    368 test $KILLSERVERS != no && wait
    369 
    370 exit 0
    371