test057-memberof-refint revision 1.1.1.2 1 1.1 lukem #! /bin/sh
2 1.1.1.2 adam # OpenLDAP: pkg/ldap/tests/scripts/test057-memberof-refint,v 1.3.2.6 2010/04/19 19:14:36 quanah Exp
3 1.1 lukem ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 1.1 lukem ##
5 1.1.1.2 adam ## Copyright 1998-2010 The OpenLDAP Foundation.
6 1.1 lukem ## Portions Copyright 2008 Red Hat, Inc.
7 1.1 lukem ## All rights reserved.
8 1.1 lukem ##
9 1.1 lukem ## Redistribution and use in source and binary forms, with or without
10 1.1 lukem ## modification, are permitted only as authorized by the OpenLDAP
11 1.1 lukem ## Public License.
12 1.1 lukem ##
13 1.1 lukem ## A copy of this license is available in the file LICENSE in the
14 1.1 lukem ## top-level directory of the distribution or, alternatively, at
15 1.1 lukem ## <http://www.OpenLDAP.org/license.html>.
16 1.1 lukem
17 1.1 lukem echo "running defines.sh"
18 1.1 lukem . $SRCDIR/scripts/defines.sh
19 1.1 lukem
20 1.1 lukem if test $MEMBEROF = memberofno; then
21 1.1 lukem echo "Memberof overlay not available, test skipped"
22 1.1 lukem exit 0
23 1.1 lukem fi
24 1.1 lukem
25 1.1 lukem if test $REFINT = refintno; then
26 1.1 lukem echo "Referential Integrity overlay not available, test skipped"
27 1.1 lukem exit 0
28 1.1 lukem fi
29 1.1 lukem
30 1.1.1.2 adam if test $BACKEND = bdb; then
31 1.1.1.2 adam echo "$BACKEND backend does not support subtree rename, test skipped"
32 1.1 lukem exit 0
33 1.1 lukem fi
34 1.1 lukem
35 1.1 lukem mkdir -p $TESTDIR $DBDIR1 $TESTDIR/confdir
36 1.1 lukem
37 1.1 lukem $SLAPPASSWD -g -n >$CONFIGPWF
38 1.1 lukem echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
39 1.1 lukem
40 1.1 lukem echo "Starting slapd on TCP/IP port $PORT1..."
41 1.1 lukem . $CONFFILTER $BACKEND $MONITORDB < $NAKEDCONF > $CONF1
42 1.1 lukem $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
43 1.1 lukem PID=$!
44 1.1 lukem if test $WAIT != 0 ; then
45 1.1 lukem echo PID $PID
46 1.1 lukem read foo
47 1.1 lukem fi
48 1.1 lukem KILLPIDS="$PID"
49 1.1 lukem
50 1.1 lukem sleep 1
51 1.1 lukem for i in 0 1 2 3 4 5; do
52 1.1 lukem $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
53 1.1 lukem 'objectclass=*' > /dev/null 2>&1
54 1.1 lukem RC=$?
55 1.1 lukem if test $RC = 0 ; then
56 1.1 lukem break
57 1.1 lukem fi
58 1.1 lukem echo "Waiting 5 seconds for slapd to start..."
59 1.1 lukem sleep 5
60 1.1 lukem done
61 1.1 lukem if test $RC != 0 ; then
62 1.1 lukem echo "ldapsearch failed ($RC)!"
63 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
64 1.1 lukem exit $RC
65 1.1 lukem fi
66 1.1 lukem
67 1.1 lukem cat /dev/null > $TESTOUT
68 1.1 lukem
69 1.1.1.2 adam bdbInclude="# " nullExclude=""
70 1.1.1.2 adam case $BACKEND in
71 1.1.1.2 adam bdb | hdb) bdbInclude="" ;;
72 1.1.1.2 adam null) nullExclude="# " ;;
73 1.1.1.2 adam esac
74 1.1.1.2 adam
75 1.1 lukem if [ "$MEMBEROF" = memberofmod ]; then
76 1.1 lukem echo "Inserting memberof overlay on producer..."
77 1.1 lukem $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
78 1.1 lukem dn: cn=module,cn=config
79 1.1 lukem objectClass: olcModuleList
80 1.1 lukem cn: module
81 1.1 lukem olcModulePath: ../servers/slapd/overlays
82 1.1 lukem olcModuleLoad: memberof.la
83 1.1 lukem olcModuleLoad: refint.la
84 1.1 lukem EOF
85 1.1 lukem RC=$?
86 1.1 lukem if test $RC != 0 ; then
87 1.1 lukem echo "ldapadd failed for moduleLoad ($RC)!"
88 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
89 1.1 lukem exit $RC
90 1.1 lukem fi
91 1.1 lukem fi
92 1.1 lukem
93 1.1 lukem echo "Running ldapadd to build slapd config database..."
94 1.1 lukem $LDAPADD -h $LOCALHOST -p $PORT1 -D 'cn=config' -w `cat $CONFIGPWF` \
95 1.1 lukem >> $TESTOUT 2>&1 <<EOF
96 1.1 lukem dn: olcDatabase={1}$BACKEND,cn=config
97 1.1 lukem objectClass: olcDatabaseConfig
98 1.1.1.2 adam ${nullExclude}objectClass: olc${BACKEND}Config
99 1.1 lukem olcDatabase: {1}$BACKEND
100 1.1 lukem olcSuffix: $BASEDN
101 1.1 lukem olcRootDN: cn=Manager,$BASEDN
102 1.1 lukem olcRootPW:: c2VjcmV0
103 1.1 lukem olcMonitoring: TRUE
104 1.1.1.2 adam ${nullExclude}olcDbDirectory: $TESTDIR/db.1.a/
105 1.1.1.2 adam ${bdbInclude}olcDbCacheSize: 1000
106 1.1.1.2 adam ${bdbInclude}olcDbIndex: objectClass eq
107 1.1.1.2 adam ${bdbInclude}olcDbIndex: cn pres,eq,sub
108 1.1.1.2 adam ${bdbInclude}olcDbIndex: uid pres,eq,sub
109 1.1.1.2 adam ${bdbInclude}olcDbIndex: sn pres,eq,sub
110 1.1.1.2 adam ${bdbInclude}olcDbMode: 384
111 1.1 lukem
112 1.1 lukem # {0}memberof, {1}$BACKEND, config
113 1.1 lukem dn: olcOverlay={0}memberof,olcDatabase={1}$BACKEND,cn=config
114 1.1 lukem objectClass: olcOverlayConfig
115 1.1 lukem objectClass: olcMemberOf
116 1.1 lukem olcOverlay: {0}memberof
117 1.1 lukem olcMemberOfRefInt: TRUE
118 1.1 lukem olcMemberOfGroupOC: groupOfNames
119 1.1 lukem olcMemberOfMemberAD: member
120 1.1 lukem olcMemberOfMemberOfAD: memberOf
121 1.1 lukem
122 1.1 lukem # {1}refint, {1}$BACKEND, config
123 1.1 lukem dn: olcOverlay={1}refint,olcDatabase={1}$BACKEND,cn=config
124 1.1 lukem objectClass: olcOverlayConfig
125 1.1 lukem objectClass: olcRefintConfig
126 1.1 lukem olcOverlay: {1}refint
127 1.1 lukem olcRefintAttribute: member
128 1.1 lukem olcRefintAttribute: memberOf
129 1.1 lukem EOF
130 1.1 lukem RC=$?
131 1.1 lukem if test $RC != 0 ; then
132 1.1 lukem echo "ldapadd failed ($RC)!"
133 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
134 1.1 lukem exit $RC
135 1.1 lukem fi
136 1.1 lukem
137 1.1 lukem echo "Running ldapadd to build slapd database..."
138 1.1 lukem $LDAPADD -h $LOCALHOST -p $PORT1 \
139 1.1 lukem -D "cn=Manager,$BASEDN" -w secret \
140 1.1 lukem >> $TESTOUT 2>&1 << EOF
141 1.1 lukem dn: $BASEDN
142 1.1 lukem objectClass: organization
143 1.1 lukem objectClass: dcObject
144 1.1 lukem o: Example, Inc.
145 1.1 lukem dc: example
146 1.1 lukem
147 1.1 lukem dn: ou=People,$BASEDN
148 1.1 lukem objectClass: organizationalUnit
149 1.1 lukem ou: People
150 1.1 lukem
151 1.1 lukem dn: ou=Groups,$BASEDN
152 1.1 lukem objectClass: organizationalUnit
153 1.1 lukem ou: Groups
154 1.1 lukem
155 1.1 lukem dn: cn=Roger Rabbit,ou=People,$BASEDN
156 1.1 lukem objectClass: inetOrgPerson
157 1.1 lukem cn: Roger Rabbit
158 1.1 lukem sn: Rabbit
159 1.1 lukem
160 1.1 lukem dn: cn=Baby Herman,ou=People,$BASEDN
161 1.1 lukem objectClass: inetOrgPerson
162 1.1 lukem cn: Baby Herman
163 1.1 lukem sn: Herman
164 1.1 lukem
165 1.1 lukem dn: cn=Cartoonia,ou=Groups,$BASEDN
166 1.1 lukem objectClass: groupOfNames
167 1.1 lukem cn: Cartoonia
168 1.1 lukem member: cn=Roger Rabbit,ou=People,$BASEDN
169 1.1 lukem member: cn=Baby Herman,ou=People,$BASEDN
170 1.1 lukem EOF
171 1.1 lukem RC=$?
172 1.1 lukem if test $RC != 0 ; then
173 1.1 lukem echo "ldapadd failed ($RC)!"
174 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
175 1.1 lukem exit $RC
176 1.1 lukem fi
177 1.1 lukem
178 1.1 lukem echo "Search the entire database..."
179 1.1 lukem echo "# Search the entire database..." >> $SEARCHOUT
180 1.1 lukem $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
181 1.1 lukem '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
182 1.1 lukem RC=$?
183 1.1 lukem if test $RC != 0 ; then
184 1.1 lukem echo "ldapsearch failed ($RC)!"
185 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
186 1.1 lukem exit $RC
187 1.1 lukem fi
188 1.1 lukem
189 1.1 lukem echo "Running ldapmodify to rename subtree..."
190 1.1 lukem $LDAPMODIFY -h $LOCALHOST -p $PORT1 \
191 1.1 lukem -D "cn=Manager,$BASEDN" -w secret \
192 1.1 lukem >> $TESTOUT 2>&1 << EOF
193 1.1 lukem dn: ou=People,$BASEDN
194 1.1 lukem changetype: modrdn
195 1.1 lukem newrdn: ou=Toons
196 1.1 lukem deleteoldrdn:1
197 1.1 lukem newsuperior: $BASEDN
198 1.1 lukem EOF
199 1.1 lukem
200 1.1 lukem # refint runs in a background thread, so it most likely won't complete
201 1.1 lukem # before the modify returns. Give it some time to execute.
202 1.1 lukem sleep 1
203 1.1 lukem
204 1.1 lukem echo "Re-search the entire database..."
205 1.1 lukem echo "# Re-search the entire database..." >> $SEARCHOUT
206 1.1 lukem $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
207 1.1 lukem '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
208 1.1 lukem RC=$?
209 1.1 lukem if test $RC != 0 ; then
210 1.1 lukem echo "ldapsearch failed ($RC)!"
211 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
212 1.1 lukem exit $RC
213 1.1 lukem fi
214 1.1 lukem
215 1.1 lukem echo "Running ldapmodify to rename subtree..."
216 1.1 lukem $LDAPMODIFY -h $LOCALHOST -p $PORT1 \
217 1.1 lukem -D "cn=Manager,$BASEDN" -w secret \
218 1.1 lukem >> $TESTOUT 2>&1 << EOF
219 1.1 lukem dn: ou=Groups,$BASEDN
220 1.1 lukem changetype: modrdn
221 1.1 lukem newrdn: ou=Studios
222 1.1 lukem deleteoldrdn:1
223 1.1 lukem newsuperior: $BASEDN
224 1.1 lukem EOF
225 1.1 lukem
226 1.1 lukem sleep 1
227 1.1 lukem
228 1.1 lukem echo "Re-search the entire database..."
229 1.1 lukem echo "# Re-search the entire database..." >> $SEARCHOUT
230 1.1 lukem $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
231 1.1 lukem '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
232 1.1 lukem RC=$?
233 1.1 lukem if test $RC != 0 ; then
234 1.1 lukem echo "ldapsearch failed ($RC)!"
235 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
236 1.1 lukem exit $RC
237 1.1 lukem fi
238 1.1 lukem
239 1.1 lukem echo "Running ldapdelete to remove a member..."
240 1.1 lukem $LDAPMODIFY -h $LOCALHOST -p $PORT1 \
241 1.1 lukem -D "cn=Manager,$BASEDN" -w secret \
242 1.1 lukem >> $TESTOUT 2>&1 << EOF
243 1.1 lukem dn: cn=Baby Herman,ou=Toons,$BASEDN
244 1.1 lukem changetype: delete
245 1.1 lukem EOF
246 1.1 lukem
247 1.1 lukem sleep 1
248 1.1 lukem
249 1.1 lukem echo "Re-search the entire database..."
250 1.1 lukem echo "# Re-search the entire database..." >> $SEARCHOUT
251 1.1 lukem $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
252 1.1 lukem '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
253 1.1 lukem RC=$?
254 1.1 lukem if test $RC != 0 ; then
255 1.1 lukem echo "ldapsearch failed ($RC)!"
256 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
257 1.1 lukem exit $RC
258 1.1 lukem fi
259 1.1 lukem
260 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
261 1.1 lukem
262 1.1 lukem LDIF=$MEMBEROFREFINTOUT
263 1.1 lukem
264 1.1 lukem echo "Filtering ldapsearch results..."
265 1.1.1.2 adam $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
266 1.1 lukem echo "Filtering original ldif used to create database..."
267 1.1.1.2 adam $LDIFFILTER < $LDIF > $LDIFFLT
268 1.1 lukem echo "Comparing filter output..."
269 1.1 lukem $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
270 1.1 lukem
271 1.1 lukem if test $? != 0 ; then
272 1.1 lukem echo "Comparison failed"
273 1.1 lukem exit 1
274 1.1 lukem fi
275 1.1 lukem
276 1.1 lukem echo ">>>>> Test succeeded"
277 1.1 lukem
278 1.1 lukem test $KILLSERVERS != no && wait
279 1.1 lukem
280 1.1 lukem exit 0
281