test037-manage revision 1.1.1.1
1#! /bin/sh
2# $OpenLDAP: pkg/ldap/tests/scripts/test037-manage,v 1.12.2.5 2008/02/11 23:26:51 kurt Exp $
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2008 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
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19if test $BACKEND = "ldif" ; then 
20	echo "LDIF backend does not support manageDIT control, test skipped"
21	exit 0
22fi 
23
24mkdir -p $TESTDIR $DBDIR1
25
26echo "Running slapadd to build slapd database..."
27. $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
28$SLAPADD -f $CONF1 -l $LDIFORDERED
29RC=$?
30if test $RC != 0 ; then
31	echo "slapadd failed ($RC)!"
32	exit $RC
33fi
34
35echo "Starting slapd on TCP/IP port $PORT1..."
36$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
37PID=$!
38if test $WAIT != 0 ; then
39    echo PID $PID
40    read foo
41fi
42KILLPIDS="$PID"
43
44sleep 1
45
46echo "Testing slapd Manage operations..."
47for i in 0 1 2 3 4 5; do
48	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
49		'objectclass=*' > /dev/null 2>&1
50	RC=$?
51	if test $RC = 0 ; then
52		break
53	fi
54	echo "Waiting 5 seconds for slapd to start..."
55	sleep 5
56done
57
58if test $RC != 0 ; then
59	echo "ldapsearch failed ($RC)!"
60	test $KILLSERVERS != no && kill -HUP $KILLPIDS
61	exit $RC
62fi
63
64echo "Testing modify, add, and delete..."
65$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
66	-e \!relax > \
67	$TESTOUT 2>&1 << EOMODS
68version: 1
69#
70# Working Tests
71#
72
73#
74# ObjectClass tests
75#
76
77dn: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,
78 dc=com
79# add obsolete auxiliary objectclass
80changetype: modify
81add: objectClass
82objectClass: obsoletePerson
83
84dn: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,
85 dc=com
86# add obsolete attribute
87changetype: modify
88add: testObsolete
89testObsolete: TRUE
90
91#
92# create/modify timestamp test
93#
94
95dn: ou=Groups,dc=example,dc=com
96# change creatorsName
97changetype: modify
98replace: creatorsName
99creatorsName: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
100
101dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
102# change modifiersName
103changetype: modify
104replace: modifiersName
105modifiersName: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
106
107dn: dc=example,dc=com
108# change timestamps
109changetype: modify
110replace: modifyTimestamp
111modifyTimestamp: 19700101000000Z
112-
113replace: createTimestamp
114createTimestamp: 19700101000000Z
115-
116
117dn: cn=All Staff,ou=Groups,dc=example,dc=com
118# change entryUUID
119changetype: modify
120replace: entryUUID
121entryUUID: badbadba-dbad-1029-92f7-badbadbadbad
122
123dn: cn=All Staff,dc=example,dc=com
124changetype: add
125objectClass: groupOfNames
126cn: All Staff
127member:
128creatorsName: cn=Someone
129createTimestamp: 19700101000000Z
130modifiersName: cn=Someone Else
131modifyTimestamp: 19700101000000Z
132entryUUID: badbadef-dbad-1029-92f7-badbadbadbad
133EOMODS
134
135RC=$?
136if test $RC != 0 ; then
137	echo "ldapmodify failed ($RC)!"
138	test $KILLSERVERS != no && kill -HUP $KILLPIDS
139	exit $RC
140fi
141
142echo "Testing modify, add, and delete..."
143$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
144	-e \!relax > \
145	$TESTOUT 2>&1 << EOMODS
146version: 1
147#
148# Non-working tests
149#
150
151dn: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,
152 dc=com
153# update structural object class of entry via objectClass replace
154changetype: modify
155replace: objectClass
156objectClass: obsoletePerson
157-
158replace: structuralObjectClass
159structuralObjectClass: testPerson
160
161dn: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com
162# update structural object class of entry via objectClass add
163changetype: modify
164add: objectClass
165objectClass: testPerson
166-
167replace: structuralObjectClass
168structuralObjectClass: testPerson
169
170dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
171# update structural object class of entry via objectClass delete/add
172changetype: modify
173delete: objectClass
174objectClass: OpenLDAPperson
175-
176add: objectClass
177objectClass: testPerson
178-
179delete: structuralObjectClass
180-
181add: structuralObjectClass
182structuralObjectClass: testPerson
183EOMODS
184
185RC=$?
186if test $RC != 0 ; then
187	echo "ldapmodify failed ($RC)!  IGNORED"
188#	test $KILLSERVERS != no && kill -HUP $KILLPIDS
189#	exit $RC
190fi
191
192echo "Using ldapsearch to retrieve all the entries..."
193$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
194    'objectClass=*' '*' creatorsName modifiersName > $SEARCHOUT 2>&1
195RC=$?
196if test $RC != 0 ; then
197	test $KILLSERVERS != no && kill -HUP $KILLPIDS
198	echo "ldapsearch failed ($RC)!"
199	exit $RC
200fi
201
202$LDAPSEARCH -S "" -b "$BASEDN" -s base -h $LOCALHOST -p $PORT1 \
203    'objectClass=*' '*' creatorsName createTimestamp \
204    modifiersName modifyTimestamp >> $SEARCHOUT 2>&1
205RC=$?
206if test $RC != 0 ; then
207	test $KILLSERVERS != no && kill -HUP $KILLPIDS
208	echo "ldapsearch failed ($RC)!"
209	exit $RC
210fi
211
212$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
213    '(cn=All Staff)' '*' entryUUID >> $SEARCHOUT 2>&1
214RC=$?
215test $KILLSERVERS != no && kill -HUP $KILLPIDS
216if test $RC != 0 ; then
217	echo "ldapsearch failed ($RC)!"
218	exit $RC
219fi
220
221LDIF=$MANAGEOUT
222
223echo "Filtering ldapsearch results..."
224. $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
225echo "Filtering original ldif used to create database..."
226. $LDIFFILTER < $LDIF > $LDIFFLT
227echo "Comparing filter output..."
228$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
229
230if test $? != 0 ; then
231	echo "comparison failed - manage operations did not complete correctly"
232	exit 1
233fi
234
235echo ">>>>> Test succeeded"
236
237test $KILLSERVERS != no && wait
238
239exit 0
240