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