]> git.sur5r.net Git - openldap/blob - tests/scripts/test005-modrdn
Revert 1.11, the extra clause breaks test009-referral for back-bdb.
[openldap] / tests / scripts / test005-modrdn
1 #! /bin/sh
2 # $OpenLDAP$
3
4 SRCDIR="."
5 if test $# -ge 1 ; then
6         SRCDIR=$1; shift
7 fi
8 BACKEND=ldbm
9 if test $# -ge 1 ; then
10         BACKEND=$1; shift
11 fi
12 WAIT=0
13 if test $# -ge 1 ; then
14         WAIT=1; shift
15 fi
16
17 echo "running defines.sh"
18 . $SRCDIR/scripts/defines.sh
19
20 echo "Cleaning up in $DBDIR..."
21
22 rm -f $DBDIR/[!C]*
23
24 echo "Running slapadd to build slapd database..."
25 . $CONFFILTER $BACKEND < $CONF > $DBCONF
26 $SLAPADD -f $DBCONF -l $LDIFORDERED
27 RC=$?
28 if test $RC != 0 ; then
29         echo "slapadd failed ($RC)!"
30         exit $RC
31 fi
32
33 echo "Starting slapd on TCP/IP port $PORT..."
34 $SLAPD -f $DBCONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
35 PID=$!
36 if test $WAIT != 0 ; then
37     echo PID $PID
38     read foo
39 fi
40 echo "Testing slapd modrdn operations..."
41
42 # Make sure we can search the database
43 for i in 0 1 2 3 4 5; do
44         $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
45             'objectClass=*' > $INITOUT 2>&1
46         RC=$?
47         if test $RC = 1 ; then
48                 echo "Waiting 5 seconds for slapd to start..."
49                 sleep 5
50         fi
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 $PORT -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 $PORT -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 $PORT \
87             'cn=James A Jones III' > $SEARCHOUT 2>&1
88 RC=$?
89 if test $RC != 0 ; then
90         echo "ldapsearch failed ($RC)!"
91         kill -HUP $PID
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         kill -HUP $PID
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 $PORT \
114             'cn=James A Jones II' > $SEARCHOUT 2>&1
115 RC=$?
116 if test $RC != 0 ; then
117         echo "ldapsearch failed ($RC)!"
118         kill -HUP $PID
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         kill -HUP $PID
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 $PORT \
143             'cn=James A Jones 2' > $SEARCHOUT 2>&1
144 RC=$?
145 if test $RC != 0 ; then
146         kill -HUP $PID
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         kill -HUP $PID
154         exit 1
155 fi
156
157 echo "Using ldapsearch to retrieve all the entries..."
158 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
159             'objectClass=*' > $SEARCHOUT 2>&1
160 RC=$?
161 if test $RC != 0 ; then
162         kill -HUP $PID
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         kill -HUP $PID
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 $PORT -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         kill -HUP $PID
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 $PORT \
199             'cn=James A Jones 1' > $SEARCHOUT 2>&1
200 RC=$?
201 if test $RC != 0 ; then
202         echo "ldapsearch failed ($RC)!"
203         kill -HUP $PID
204         exit $RC
205 fi
206
207
208 LDIF=$MODRDNOUTMASTER3
209
210 echo "Filtering ldapsearch results..."
211 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
212 echo "Filtering original ldif used to create database..."
213 . $LDIFFILTER < $LDIF > $LDIFFLT
214 echo "Comparing filter output..."
215 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
216
217 kill -HUP $PID
218 if test $? != 0 ; then
219         echo "comparison failed - modrdn operations did not complete correctly"
220         exit 1
221 fi
222
223 echo ">>>>> Test succeeded"
224
225
226
227 # echo "modrdn test not yet written"
228
229 exit 0