]> git.sur5r.net Git - openldap/blob - tests/scripts/test005-modrdn
Import newsuperior test from HEAD
[openldap] / tests / scripts / test005-modrdn
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2005 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 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
23 $SLAPADD -f $CONF1 -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
32 PID=$!
33 if test $WAIT != 0 ; then
34     echo PID $PID
35     read foo
36 fi
37 KILLPIDS="$PID"
38
39 echo "Testing slapd modrdn operations..."
40
41 # Make sure we can search the database
42 for i in 0 1 2 3 4 5; do
43         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
44             'objectClass=*' > $INITOUT 2>&1
45         RC=$?
46         if test $RC = 0 ; then
47                 break
48         fi
49         echo "Waiting 5 seconds for slapd to start..."
50         sleep 5
51 done
52
53 if test $RC != 0 ; then
54         echo "ldapsearch failed ($RC)!"
55         kill -HUP $PID
56         exit $RC
57 fi
58
59 # -r used to do remove of old rdn
60
61 echo "Testing modrdn(deleteoldrdn=0)..."
62 $LDAPMODRDN -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
63         $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US' 'cn=James A Jones III'
64
65 RC=$?
66 if test $RC != 0 ; then
67         echo "ldapmodrdn failed ($RC)!"
68         kill -HUP $PID
69         exit $RC
70 fi
71
72 echo "Testing modrdn(deleteoldrdn=1)..."
73 $LDAPMODRDN -D "$MANAGERDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
74         $TESTOUT 2>&1 'cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US' 'cn=James A Jones II'
75
76 RC=$?
77 if test $RC != 0 ; then
78         echo "ldapmodrdn failed ($RC)!"
79         kill -HUP $PID
80         exit $RC
81 fi
82
83 # Ensure the new rdn's can be found
84
85 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones III)..."
86 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
87             'cn=James A Jones III' > $SEARCHOUT 2>&1
88 RC=$?
89 if test $RC != 0 ; then
90         echo "ldapsearch failed ($RC)!"
91         test $KILLSERVERS != no && kill -HUP $KILLPIDS
92         exit $RC
93 fi
94
95
96 LDIF=$MODRDNOUTMASTER1
97
98 echo "Filtering ldapsearch results..."
99 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
100 echo "Filtering original ldif used to create database..."
101 . $LDIFFILTER < $LDIF > $LDIFFLT
102 echo "Comparing filter output..."
103 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
104
105 if test $? != 0 ; then
106         echo "comparison failed - modrdn operations did not complete correctly"
107         test $KILLSERVERS != no && kill -HUP $KILLPIDS
108         exit 1
109 fi
110
111
112 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones II)..."
113 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
114             'cn=James A Jones II' > $SEARCHOUT 2>&1
115 RC=$?
116 if test $RC != 0 ; then
117         echo "ldapsearch failed ($RC)!"
118         test $KILLSERVERS != no && kill -HUP $KILLPIDS
119         exit $RC
120 fi
121
122
123 LDIF=$MODRDNOUTMASTER2
124
125 echo "Filtering ldapsearch results..."
126 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
127 echo "Filtering original ldif used to create database..."
128 . $LDIFFILTER < $LDIF > $LDIFFLT
129 echo "Comparing filter output..."
130 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
131
132 if test $? != 0 ; then
133         echo "comparison failed - modrdn operations did not complete correctly"
134         test $KILLSERVERS != no && kill -HUP $KILLPIDS
135         exit 1
136 fi
137
138 # Ensure that you cannot find the entry for which the rdn was deleted as
139 # an attribute.
140
141 echo "Using ldapsearch to retrieve entries using removed rdn (cn=James A Jones 2)..."
142 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
143             'cn=James A Jones 2' > $SEARCHOUT 2>&1
144 RC=$?
145 if test $RC != 0 ; then
146         test $KILLSERVERS != no && kill -HUP $KILLPIDS
147         echo "ldapsearch failed ($RC)!"
148         exit $RC
149 fi
150 $CMP $SEARCHOUT - < /dev/null > $CMPOUT
151 if test $? != 0 ; then
152         echo "failure: ldapsearch found attribute that was to be removed!"
153         test $KILLSERVERS != no && kill -HUP $KILLPIDS
154         exit 1
155 fi
156
157 echo "Using ldapsearch to retrieve all the entries..."
158 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
159             'objectClass=*' > $SEARCHOUT 2>&1
160 RC=$?
161 if test $RC != 0 ; then
162         test $KILLSERVERS != no && kill -HUP $KILLPIDS
163         echo "ldapsearch failed ($RC)!"
164         exit $RC
165 fi
166
167 LDIF=$MODRDNOUTMASTER0
168
169 echo "Filtering ldapsearch results..."
170 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
171 echo "Filtering original ldif used to create database..."
172 . $LDIFFILTER < $LDIF > $LDIFFLT
173 echo "Comparing filter output..."
174 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
175
176 if test $? != 0 ; then
177         echo "comparison failed - modrdn operations did not complete correctly"
178         test $KILLSERVERS != no && kill -HUP $KILLPIDS
179         exit 1
180 fi
181
182
183 echo "Testing modrdn(deleteoldrdn=1), modrdn with new rdn already an att val..."
184 $LDAPMODRDN -D "$MANAGERDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD > \
185         /dev/null 2>&1 'cn=James A Jones III, ou=Alumni Association, ou=People, o=University of Michigan, c=US' 'cn=James A Jones 1'
186
187 RC=$?
188 if test $RC != 0 ; then
189         echo "ldapmodrdn failed ($RC)!"
190         test $KILLSERVERS != no && kill -HUP $KILLPIDS
191         exit $RC
192 fi
193
194 # Test that you can use modrdn with an attribute value which was previously
195 # present
196
197 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones 1)..."
198 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
199             'cn=James A Jones 1' > $SEARCHOUT 2>&1
200 RC=$?
201
202 if test $RC != 0 ; then
203         echo "ldapsearch failed ($RC)!"
204         exit $RC
205 fi
206
207 LDIF=$MODRDNOUTMASTER3
208
209 echo "Filtering ldapsearch results..."
210 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
211 echo "Filtering original ldif used to create database..."
212 . $LDIFFILTER < $LDIF > $LDIFFLT
213 echo "Comparing filter output..."
214 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
215
216 if test $? != 0 ; then
217         echo "comparison failed - modrdn operations did not complete correctly"
218         exit 1
219 fi
220
221 echo "Testing modrdn with newSuperior as child of target "
222 $LDAPMODRDN -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
223         $TESTOUT 2>&1  -s 'cn=Sub1, ou=FooBar, cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan,c=us' \
224         'cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US' 'cn=James A Jones 1'
225
226 RC=$?
227 if test $RC -eq 0 ; then
228         echo "ldapmodrdn succeeded, should have failed!"
229         test $KILLSERVERS != no && kill -HUP $KILLPIDS
230         exit 1
231 fi
232
233 test $KILLSERVERS != no && kill -HUP $KILLPIDS
234
235 echo ">>>>> Test succeeded"
236 exit 0