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