]> git.sur5r.net Git - openldap/blob - tests/scripts/test027-emptydn
1b752f84b314fa436fae09612e3909907bd8bca6
[openldap] / tests / scripts / test027-emptydn
1 #! /bin/sh
2 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 ##
4 ## Copyright 2004 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 -n 2 -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 "Comparing ldapsearch results against original..."
82 $CMP $SEARCHOUT $LDIFOUT > $CMPOUT
83
84 if test $? != 0 ; then
85         echo "comparison failed - empty DN write operations did not complete correctly"
86         exit 1
87 fi
88
89 echo "Comparison of database generated via slapadd succeeded"
90
91 echo "Cleaning up database directories..."
92 /bin/rm -rf testrun/db.*
93
94 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
95
96 echo "Starting slapd on TCP/IP port $PORT1..."
97 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
98 PID=$!
99 if test $WAIT != 0 ; then
100     echo PID $PID
101     read foo
102 fi
103 KILLPIDS="$PID"
104
105 echo "Testing slapd empty DN handling..."
106 for i in 0 1 2 3 4 5; do
107         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
108                 'objectclass=*' > /dev/null 2>&1
109         RC=$?
110         if test $RC = 0 ; then
111                 break
112         fi
113         echo "Waiting 5 seconds for slapd to start..."
114         sleep 5
115 done
116
117 if test $RC != 0 ; then
118         echo "ldapsearch failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 echo "Loading database..."
124 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
125         -f $LDIFEMPTYDN1 > /dev/null 2>&1
126 $LDAPADD -D "$EMPTYDNDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
127         -f $LDIFEMPTYDN2 > /dev/null 2>&1
128
129 $LDAPMODIFY -D "$EMPTYDNDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
130         > /dev/null 2>&1 << EOF
131 dn: o=Beispiel,c=DE
132 changetype: delete
133
134 dn: c=DE
135 changetype: delete
136 EOF
137
138 echo "Searching database..."
139
140 $LDAPSEARCH -b "" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
141
142 RC=$?
143 if test $RC != 0 ; then
144         echo "ldapsearch failed ($RC)!"
145         test $KILLSERVERS != no && kill -HUP $KILLPIDS
146         exit $RC
147 fi
148
149 test $KILLSERVERS != no && kill -HUP $KILLPIDS
150
151 LDIFOUT=$EMPTYDNOUT2
152
153 echo "Comparing ldapsearch results against original..."
154 $CMP $SEARCHOUT $LDIFOUT > $CMPOUT
155
156 if test $? != 0 ; then
157         echo "comparison failed - empty DN write operations did not complete correctly"
158         exit 1
159 fi
160
161 #####
162
163 echo ">>>>> Test succeeded"
164 exit 0