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