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