| 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 | DSADM=`command -v dsadm` |
| 20 | if test -z "$DSADM"; then |
| 21 | echo "DSEE dsadm not in path, test skipped" |
| 22 | exit 0 |
| 23 | fi |
| 24 | |
| 25 | mkdir -p $TESTDIR $DBDIR2 |
| 26 | |
| 27 | # |
| 28 | # Test replication: |
| 29 | # - start provider |
| 30 | # - start consumer |
| 31 | # - populate over ldap |
| 32 | # - perform some modifies and deleted |
| 33 | # - attempt to modify the consumer (referral) |
| 34 | # - retrieve database over ldap and compare against expected results |
| 35 | # |
| 36 | |
| 37 | DSEEPW=secret21 |
| 38 | DSEEDN="cn=Directory Manager" |
| 39 | DSEEPWF=$TESTDIR/dseepw |
| 40 | |
| 41 | echo "secret21" > $DSEEPWF |
| 42 | |
| 43 | echo "Setting up DSEE provider slapd on TCP/IP port $PORT1..." |
| 44 | dsadm create -p $PORT1 -w $DSEEPWF $DBDIR1 |
| 45 | dsadm start $DBDIR1 |
| 46 | dsconf create-suffix -c -p $PORT1 -w $DSEEPWF $BASEDN |
| 47 | dsconf set-server-prop -p $PORT1 -w $DSEEPWF moddn-enabled:on |
| 48 | dsconf set-server-prop -p $PORT1 -w $DSEEPWF retro-cl-enabled:on |
| 49 | dsadm restart $DBDIR1 |
| 50 | KILLPIDS=`basename $DBDIR1/locks/server/*` |
| 51 | |
| 52 | sleep 1 |
| 53 | |
| 54 | echo "Using ldapsearch to check that provider slapd is running..." |
| 55 | for i in 0 1 2 3 4 5; do |
| 56 | $LDAPSEARCH -s base -b "$BASEDN" -H $URI1 \ |
| 57 | 'objectclass=*' > /dev/null 2>&1 |
| 58 | RC=$? |
| 59 | if test $RC = 0 ; then |
| 60 | break |
| 61 | fi |
| 62 | echo "Waiting 5 seconds for slapd to start..." |
| 63 | sleep 5 |
| 64 | done |
| 65 | |
| 66 | if test $RC != 0 ; then |
| 67 | echo "ldapsearch failed ($RC)!" |
| 68 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 69 | exit $RC |
| 70 | fi |
| 71 | |
| 72 | echo "Starting consumer slapd on TCP/IP port $PORT2..." |
| 73 | . $CONFFILTER $BACKEND < $DSEESYNC1CONF > $CONF2 |
| 74 | $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 & |
| 75 | CONSUMERPID=$! |
| 76 | if test $WAIT != 0 ; then |
| 77 | echo CONSUMERPID $CONSUMERPID |
| 78 | read foo |
| 79 | fi |
| 80 | KILLPIDS="$KILLPIDS $CONSUMERPID" |
| 81 | |
| 82 | sleep 1 |
| 83 | |
| 84 | echo "Using ldapsearch to check that consumer slapd is running..." |
| 85 | for i in 0 1 2 3 4 5; do |
| 86 | $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \ |
| 87 | 'objectclass=*' > /dev/null 2>&1 |
| 88 | RC=$? |
| 89 | if test $RC = 0 ; then |
| 90 | break |
| 91 | fi |
| 92 | echo "Waiting 5 seconds for slapd to start..." |
| 93 | sleep 5 |
| 94 | done |
| 95 | |
| 96 | if test $RC != 0 ; then |
| 97 | echo "ldapsearch failed ($RC)!" |
| 98 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 99 | exit $RC |
| 100 | fi |
| 101 | |
| 102 | # using LDIFDIRSYNCNOCP to avoid custom OpenLDAP schema |
| 103 | echo "Using ldapadd to populate the provider directory..." |
| 104 | $LDAPADD -D "$DSEEDN" -H $URI1 -w $DSEEPW < \ |
| 105 | $LDIFDIRSYNCNOCP > /dev/null 2>&1 |
| 106 | RC=$? |
| 107 | if test $RC != 0 ; then |
| 108 | echo "ldapadd failed ($RC)!" |
| 109 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 110 | exit $RC |
| 111 | fi |
| 112 | |
| 113 | echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." |
| 114 | sleep $SLEEP1 |
| 115 | |
| 116 | echo "Using ldapmodify to modify provider directory..." |
| 117 | |
| 118 | # |
| 119 | # Do some modifications |
| 120 | # |
| 121 | |
| 122 | $LDAPMODIFY -v -D "$DSEEDN" -H $URI1 -w $DSEEPW > \ |
| 123 | $TESTOUT 2>&1 << EOMODS |
| 124 | dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com |
| 125 | changetype: modify |
| 126 | add: carLicense |
| 127 | carLicense: Orange Juice |
| 128 | - |
| 129 | delete: sn |
| 130 | sn: Jones |
| 131 | - |
| 132 | add: sn |
| 133 | sn: Jones |
| 134 | |
| 135 | dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com |
| 136 | changetype: modify |
| 137 | replace: carLicense |
| 138 | carLicense: Iced Tea |
| 139 | carLicense: Mad Dog 20/20 |
| 140 | |
| 141 | dn: cn=ITD Staff,ou=Groups,dc=example,dc=com |
| 142 | changetype: modify |
| 143 | delete: uniquemember |
| 144 | uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com |
| 145 | uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com |
| 146 | - |
| 147 | add: uniquemember |
| 148 | uniquemember: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com |
| 149 | uniquemember: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com |
| 150 | |
| 151 | dn: cn=All Staff,ou=Groups,dc=example,dc=com |
| 152 | changetype: modify |
| 153 | delete: description |
| 154 | |
| 155 | dn: cn=Gern Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com |
| 156 | changetype: add |
| 157 | objectclass: inetOrgPerson |
| 158 | cn: Gern Jensen |
| 159 | sn: Jensen |
| 160 | uid: gjensen |
| 161 | title: Chief Investigator, ITD |
| 162 | postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103 |
| 163 | seealso: cn=All Staff,ou=Groups,dc=example,dc=com |
| 164 | carLicense: Coffee |
| 165 | homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104 |
| 166 | description: Very odd |
| 167 | facsimiletelephonenumber: +1 313 555 7557 |
| 168 | telephonenumber: +1 313 555 8343 |
| 169 | mail: [email protected] |
| 170 | homephone: +1 313 555 8844 |
| 171 | |
| 172 | dn: ou=Retired,ou=People,dc=example,dc=com |
| 173 | changetype: add |
| 174 | objectclass: organizationalUnit |
| 175 | ou: Retired |
| 176 | |
| 177 | dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com |
| 178 | changetype: add |
| 179 | objectclass: inetOrgPerson |
| 180 | cn: Rosco P. Coltrane |
| 181 | sn: Coltrane |
| 182 | uid: rosco |
| 183 | |
| 184 | dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com |
| 185 | changetype: modrdn |
| 186 | newrdn: cn=Rosco P. Coltrane |
| 187 | deleteoldrdn: 1 |
| 188 | newsuperior: ou=Retired,ou=People,dc=example,dc=com |
| 189 | |
| 190 | dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com |
| 191 | changetype: delete |
| 192 | |
| 193 | dn: ou=testdomain1,dc=example,dc=com |
| 194 | changetype: modrdn |
| 195 | newrdn: ou=itsdomain1 |
| 196 | deleteoldrdn: 1 |
| 197 | |
| 198 | dn: ou=itsdomain1,dc=example,dc=com |
| 199 | changetype: modify |
| 200 | replace: description |
| 201 | description: Example, Inc. ITS test domain |
| 202 | |
| 203 | EOMODS |
| 204 | |
| 205 | RC=$? |
| 206 | if test $RC != 0 ; then |
| 207 | echo "ldapmodify failed ($RC)!" |
| 208 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 209 | exit $RC |
| 210 | fi |
| 211 | |
| 212 | echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." |
| 213 | sleep $SLEEP1 |
| 214 | |
| 215 | echo "Performing modrdn alone on the provider..." |
| 216 | $LDAPMODIFY -v -D "$DSEEDN" -H $URI1 -w $DSEEPW > \ |
| 217 | $TESTOUT 2>&1 << EOMODS |
| 218 | dn: ou=testdomain2,dc=example,dc=com |
| 219 | changetype: modrdn |
| 220 | newrdn: ou=itsdomain2 |
| 221 | deleteoldrdn: 1 |
| 222 | |
| 223 | EOMODS |
| 224 | |
| 225 | RC=$? |
| 226 | if test $RC != 0 ; then |
| 227 | echo "ldapmodify failed ($RC)!" |
| 228 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 229 | exit $RC |
| 230 | fi |
| 231 | |
| 232 | echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." |
| 233 | sleep $SLEEP1 |
| 234 | |
| 235 | echo "Performing modify alone on the provider..." |
| 236 | $LDAPMODIFY -v -D "$DSEEDN" -H $URI1 -w $DSEEPW > \ |
| 237 | $TESTOUT 2>&1 << EOMODS |
| 238 | dn: ou=itsdomain2,dc=example,dc=com |
| 239 | changetype: modify |
| 240 | replace: description |
| 241 | description: Example, Inc. itsdomain2 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 larger modify on the provider..." |
| 256 | $LDAPMODIFY -v -D "$DSEEDN" -H $URI1 -w $DSEEPW > \ |
| 257 | $TESTOUT 2>&1 << EOMODS |
| 258 | dn: cn=Alumni Assoc Staff,ou=Groups,dc=example,dc=com |
| 259 | changetype: modify |
| 260 | replace: cn |
| 261 | cn: Alumni Assoc Staff |
| 262 | - |
| 263 | replace: description |
| 264 | description: blablabla |
| 265 | - |
| 266 | replace: member |
| 267 | member: cn=Manager,dc=example,dc=com |
| 268 | member: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com |
| 269 | member: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com |
| 270 | member: cn=Jane Doe,ou=Alumni Association,ou=People,dc=example,dc=com |
| 271 | member: cn=Jennifer Smith,ou=Alumni Association,ou=People,dc=example,dc=com |
| 272 | member: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com |
| 273 | member: cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com |
| 274 | |
| 275 | EOMODS |
| 276 | |
| 277 | RC=$? |
| 278 | if test $RC != 0 ; then |
| 279 | echo "ldapmodify failed ($RC)!" |
| 280 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 281 | exit $RC |
| 282 | fi |
| 283 | |
| 284 | echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." |
| 285 | sleep $SLEEP1 |
| 286 | |
| 287 | OPATTRS="creatorsName createTimestamp modifiersName modifyTimestamp" |
| 288 | |
| 289 | echo "Using ldapsearch to read all the entries from the provider..." |
| 290 | $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ |
| 291 | -D "$DSEEDN" -w $DSEEPW \ |
| 292 | '(objectclass=*)' '*' $OPATTRS > $PROVIDEROUT 2>&1 |
| 293 | RC=$? |
| 294 | |
| 295 | if test $RC != 0 ; then |
| 296 | echo "ldapsearch failed at provider ($RC)!" |
| 297 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 298 | exit $RC |
| 299 | fi |
| 300 | |
| 301 | echo "Using ldapsearch to read all the entries from the consumer..." |
| 302 | $LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \ |
| 303 | '(objectclass=*)' '*' $OPATTRS > $CONSUMEROUT 2>&1 |
| 304 | RC=$? |
| 305 | |
| 306 | if test $RC != 0 ; then |
| 307 | echo "ldapsearch failed at consumer ($RC)!" |
| 308 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 309 | exit $RC |
| 310 | fi |
| 311 | |
| 312 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 313 | |
| 314 | echo "Filtering provider results..." |
| 315 | $LDIFFILTER -s a < $PROVIDEROUT > $PROVIDERFLT |
| 316 | echo "Filtering consumer results..." |
| 317 | $LDIFFILTER -s a < $CONSUMEROUT > $CONSUMERFLT |
| 318 | |
| 319 | echo "Comparing retrieved entries from provider and consumer..." |
| 320 | $CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT |
| 321 | |
| 322 | if test $? != 0 ; then |
| 323 | echo "test failed - provider and consumer databases differ" |
| 324 | exit 1 |
| 325 | fi |
| 326 | |
| 327 | echo ">>>>> Test succeeded" |
| 328 | |
| 329 | test $KILLSERVERS != no && wait |
| 330 | |
| 331 | exit 0 |