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