]> git.sur5r.net Git - openldap/blob - tests/scripts/test027-emptydn
some TESTDIR fixes
[openldap] / tests / scripts / test027-emptydn
1 #! /bin/sh
2 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 ##
4 ## Copyright 2004-2005 The OpenLDAP Foundation.
5 ## All rights reserved.
6 ##
7 ## Redistribution and use in source and binary forms, with or without
8 ## modification, are permitted only as authorized by the OpenLDAP
9 ## Public License.
10 ##
11 ## A copy of this license is available in the file LICENSE in the
12 ## top-level directory of the distribution or, alternatively, at
13 ## <http://www.OpenLDAP.org/license.html>.
14
15 echo "running defines.sh"
16 . $SRCDIR/scripts/defines.sh
17
18 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
19
20 . $CONFFILTER $BACKEND $MONITORDB < $EMPTYDNCONF > $CONF1
21
22 echo "Running slapadd to build \"dc=example,dc=com\" slapd database..."
23 $SLAPADD -f $CONF1 -n 1 -l $LDIFEMPTYDN1
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Running slapadd to build empty DN slapd database..."
31 $SLAPADD -f $CONF1 -b "" -l $LDIFEMPTYDN2
32 RC=$?
33 if test $RC != 0 ; then
34         echo "slapadd failed ($RC)!"
35         exit $RC
36 fi
37
38 echo "Starting slapd on TCP/IP port $PORT1..."
39 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
40 PID=$!
41 if test $WAIT != 0 ; then
42     echo PID $PID
43     read foo
44 fi
45 KILLPIDS="$PID"
46
47 echo "Testing slapd empty DN handling..."
48 for i in 0 1 2 3 4 5; do
49         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
50                 'objectclass=*' > /dev/null 2>&1
51         RC=$?
52         if test $RC = 0 ; then
53                 break
54         fi
55         echo "Waiting 5 seconds for slapd to start..."
56         sleep 5
57 done
58
59 if test $RC != 0 ; then
60         echo "ldapsearch failed ($RC)!"
61         test $KILLSERVERS != no && kill -HUP $KILLPIDS
62         exit $RC
63 fi
64
65 echo "Searching database..."
66
67 $LDAPSEARCH -b "" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
68
69 RC=$?
70 if test $RC != 0 ; then
71         echo "ldapsearch failed ($RC)!"
72         test $KILLSERVERS != no && kill -HUP $KILLPIDS
73         exit $RC
74 fi
75
76 test $KILLSERVERS != no && kill -HUP $KILLPIDS
77 wait
78
79 LDIFOUT=$EMPTYDNOUT1
80
81 echo "Filtering ldapsearch results..."
82 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
83 echo "Comparing ldapsearch results against original..."
84 $CMP $SEARCHFLT $LDIFOUT > $CMPOUT
85
86 if test $? != 0 ; then
87         echo "comparison failed - empty DN write operations did not complete correctly"
88         exit 1
89 fi
90
91 echo "Comparison of database generated via slapadd succeeded"
92
93 echo "Cleaning up database directories..."
94 /bin/rm -rf $TESTDIR/db.*
95
96 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
97
98 echo "Starting slapd on TCP/IP port $PORT1..."
99 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
100 PID=$!
101 if test $WAIT != 0 ; then
102     echo PID $PID
103     read foo
104 fi
105 KILLPIDS="$PID"
106
107 echo "Testing slapd empty DN handling..."
108 for i in 0 1 2 3 4 5; do
109         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
110                 'objectclass=*' > /dev/null 2>&1
111         RC=$?
112         if test $RC = 0 ; then
113                 break
114         fi
115         echo "Waiting 5 seconds for slapd to start..."
116         sleep 5
117 done
118
119 if test $RC != 0 ; then
120         echo "ldapsearch failed ($RC)!"
121         test $KILLSERVERS != no && kill -HUP $KILLPIDS
122         exit $RC
123 fi
124
125 echo "Loading database..."
126 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
127         -f $LDIFEMPTYDN1 > /dev/null 2>&1
128 $LDAPADD -D "$EMPTYDNDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
129         -f $LDIFEMPTYDN2 > /dev/null 2>&1
130
131 $LDAPMODIFY -D "$EMPTYDNDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
132         > /dev/null 2>&1 << EOF
133 dn: o=Beispiel,c=DE
134 changetype: delete
135
136 dn: c=DE
137 changetype: delete
138 EOF
139
140 echo "Searching database..."
141
142 $LDAPSEARCH -b "" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
143
144 RC=$?
145 if test $RC != 0 ; then
146         echo "ldapsearch failed ($RC)!"
147         test $KILLSERVERS != no && kill -HUP $KILLPIDS
148         exit $RC
149 fi
150
151 test $KILLSERVERS != no && kill -HUP $KILLPIDS
152
153 LDIFOUT=$EMPTYDNOUT2
154
155 echo "Filtering ldapsearch results..."
156 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
157 echo "Comparing ldapsearch results against original..."
158 $CMP $SEARCHFLT $LDIFOUT > $CMPOUT
159
160 if test $? != 0 ; then
161         echo "comparison failed - empty DN write operations did not complete correctly"
162         exit 1
163 fi
164
165 #####
166
167 echo ">>>>> Test succeeded"
168 exit 0