]> git.sur5r.net Git - openldap/blob - tests/scripts/test023-refint
sync with head
[openldap] / tests / scripts / test023-refint
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2004-2005 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then
17         echo "Test does not support $BACKEND"
18         exit 0
19 fi
20
21 echo "running defines.sh"
22 . $SRCDIR/scripts/defines.sh
23
24 if test $REFINT = refintno; then 
25         echo "Referential Integrity overlay not available, test skipped"
26         exit 0
27 fi 
28
29 mkdir -p $TESTDIR $DBDIR1
30
31 echo "Running slapadd to build slapd database..."
32 . $CONFFILTER $BACKEND $MONITORDB < $REFINTCONF > $CONF1
33 $SLAPADD -f $CONF1 -l $LDIFREFINT
34 RC=$?
35 if test $RC != 0 ; then
36         echo "slapadd failed ($RC)!"
37         exit $RC
38 fi
39
40 echo "Starting slapd on TCP/IP port $PORT1..."
41 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
42 PID=$!
43 if test $WAIT != 0 ; then
44     echo PID $PID
45     read foo
46 fi
47 KILLPIDS="$PID"
48
49 sleep 1
50
51 echo "Testing slapd referential integrity operations..."
52 for i in 0 1 2 3 4 5; do
53         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
54                 'objectclass=*' > /dev/null 2>&1
55         RC=$?
56         if test $RC = 0 ; then
57                 break
58         fi
59         echo "Waiting 5 seconds for slapd to start..."
60         sleep 5
61 done
62
63 if test $RC != 0 ; then
64         echo "ldapsearch failed ($RC)!"
65         test $KILLSERVERS != no && kill -HUP $KILLPIDS
66         exit $RC
67 fi
68
69 echo "Searching unmodified database..."
70
71 $LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
72 RC=$?
73 if test $RC != 0 ; then
74         echo "ldapsearch failed ($RC)!"
75         test $KILLSERVERS != no && kill -HUP $KILLPIDS
76         exit $RC
77 fi
78
79 $EGREP_CMD "(manager|secretary):" $SEARCHOUT | sed "s/george/foster/g" | \
80         sort > $TESTOUT 2>&1
81
82 echo "Testing modrdn..."
83 $LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD > \
84         /dev/null 2>&1 'uid=george,ou=users,o=refint' 'uid=foster'
85 #$LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD  \
86 #       'uid=george,ou=users,o=refint' 'uid=foster'
87
88 RC=$?
89 if test $RC != 0 ; then
90         echo "ldapmodrdn failed ($RC)!"
91         test $KILLSERVERS != no && kill -HUP $KILLPIDS
92         exit $RC
93 fi
94
95 echo "Using ldapsearch to check dependents new rdn..."
96
97 $LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
98
99 RC=$?
100         if test $RC != 0 ; then
101         echo "ldapsearch failed ($RC)!"
102         test $KILLSERVERS != no && kill -HUP $KILLPIDS
103         exit $RC
104 fi
105
106 $EGREP_CMD "(manager|secretary):" $SEARCHOUT | sort > $SEARCHFLT 2>&1
107
108 echo "Comparing ldapsearch results against original..."
109 $CMP $TESTOUT $SEARCHFLT > $CMPOUT
110
111 if test $? != 0 ; then
112         echo "comparison failed - modify operations did not complete correctly"
113         test $KILLSERVERS != no && kill -HUP $KILLPIDS
114         exit 1
115 fi
116
117 echo "Testing delete..."
118 $LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
119         $TESTOUT 2>&1 << EDEL
120 version: 1
121 dn: uid=foster,ou=users,o=refint
122 changetype: delete
123 EDEL
124
125 RC=$?
126 if test $RC != 0 ; then
127         echo "ldapmodify failed ($RC)!"
128         test $KILLSERVERS != no && kill -HUP $KILLPIDS
129         exit $RC
130 fi
131
132 echo "Using ldapsearch to verify dependents have been deleted..."
133 $LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
134
135 RC=$?
136 if test $RC != 0 ; then
137         echo "ldapsearch failed ($RC)!"
138         test $KILLSERVERS != no && kill -HUP $KILLPIDS
139         exit $RC
140 fi
141
142 $EGREP_CMD "(manager|secretary):" $SEARCHOUT > $SEARCHFLT 2>&1
143
144 RC=`grep -c foster $SEARCHFLT`
145 if test $RC != 0 ; then
146         echo "dependent modify failed - dependents were not deleted"
147         test $KILLSERVERS != no && kill -HUP $KILLPIDS
148         exit 1
149 fi
150
151 echo "Additional test records..."
152
153 $LDAPADD -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
154         $TESTOUT 2>&1 << ETEST
155 dn: uid=special,ou=users,o=refint
156 objectClass: inetOrgPerson
157 uid: special
158 sn: special
159 cn: special
160 businessCategory: nothing
161 carLicense: FOO
162 departmentNumber: 933
163 displayName: special
164 employeeNumber: 41491
165 employeeType: vendor
166 givenName: special
167 member: uid=alice,ou=users,o=refint
168 ETEST
169
170 echo "Testing delete when referential attribute is a MUST..."
171 $LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
172         $TESTOUT 2>&1 << EDEL
173 version: 1
174 dn: uid=alice,ou=users,o=refint
175 changetype: delete
176 EDEL
177
178 RC=$?
179 if test $RC != 0 ; then
180         echo "ldapmodify failed ($RC)!"
181         test $KILLSERVERS != no && kill -HUP $KILLPIDS
182         exit $RC
183 fi
184
185 test $KILLSERVERS != no && kill -HUP $KILLPIDS
186
187 echo ">>>>> Test succeeded"
188 exit 0