]> git.sur5r.net Git - openldap/blob - tests/scripts/test023-refint
parametrize all directories
[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 echo "Testing slapd referential integrity operations..."
50 for i in 0 1 2 3 4 5; do
51         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
52                 'objectclass=*' > /dev/null 2>&1
53         RC=$?
54         if test $RC = 0 ; then
55                 break
56         fi
57         echo "Waiting 5 seconds for slapd to start..."
58         sleep 5
59 done
60
61 if test $RC != 0 ; then
62         echo "ldapsearch failed ($RC)!"
63         test $KILLSERVERS != no && kill -HUP $KILLPIDS
64         exit $RC
65 fi
66
67 echo "Searching unmodified database..."
68
69 $LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
70 RC=$?
71 if test $RC != 0 ; then
72         echo "ldapsearch failed ($RC)!"
73         test $KILLSERVERS != no && kill -HUP $KILLPIDS
74         exit $RC
75 fi
76
77 $EGREP_CMD "(manager|secretary):" $SEARCHOUT | sed "s/george/foster/g" | \
78         sort > $TESTOUT 2>&1
79
80 echo "Testing modrdn..."
81 $LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD > \
82         /dev/null 2>&1 'uid=george,ou=users,o=refint' 'uid=foster'
83 #$LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD  \
84 #       'uid=george,ou=users,o=refint' 'uid=foster'
85
86 RC=$?
87 if test $RC != 0 ; then
88         echo "ldapmodrdn failed ($RC)!"
89         test $KILLSERVERS != no && kill -HUP $KILLPIDS
90         exit $RC
91 fi
92
93 echo "Using ldapsearch to check dependents new rdn..."
94
95 $LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
96
97 RC=$?
98         if test $RC != 0 ; then
99         echo "ldapsearch failed ($RC)!"
100         test $KILLSERVERS != no && kill -HUP $KILLPIDS
101         exit $RC
102 fi
103
104 $EGREP_CMD "(manager|secretary):" $SEARCHOUT | sort > $SEARCHFLT 2>&1
105
106 echo "Comparing ldapsearch results against original..."
107 $CMP $TESTOUT $SEARCHFLT > $CMPOUT
108
109 if test $? != 0 ; then
110         echo "comparison failed - modify operations did not complete correctly"
111         test $KILLSERVERS != no && kill -HUP $KILLPIDS
112         exit 1
113 fi
114
115 echo "Testing delete..."
116 $LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
117         $TESTOUT 2>&1 << EDEL
118 version: 1
119 dn: uid=foster,ou=users,o=refint
120 changetype: delete
121 EDEL
122
123 RC=$?
124 if test $RC != 0 ; then
125         echo "ldapmodify failed ($RC)!"
126         test $KILLSERVERS != no && kill -HUP $KILLPIDS
127         exit $RC
128 fi
129
130 echo "Using ldapsearch to verify dependents have been deleted..."
131 $LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
132
133 RC=$?
134 if test $RC != 0 ; then
135         echo "ldapsearch failed ($RC)!"
136         test $KILLSERVERS != no && kill -HUP $KILLPIDS
137         exit $RC
138 fi
139
140 $EGREP_CMD "(manager|secretary):" $SEARCHOUT > $SEARCHFLT 2>&1
141
142 RC=`grep -c foster $SEARCHFLT`
143 if test $RC != 0 ; then
144         echo "dependent modify failed - dependents were not deleted"
145         test $KILLSERVERS != no && kill -HUP $KILLPIDS
146         exit 1
147 fi
148
149 echo "Additional test records..."
150
151 $LDAPADD -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
152         $TESTOUT 2>&1 << ETEST
153 dn: uid=special,ou=users,o=refint
154 objectClass: inetOrgPerson
155 uid: special
156 sn: special
157 cn: special
158 businessCategory: nothing
159 carLicense: FOO
160 departmentNumber: 933
161 displayName: special
162 employeeNumber: 41491
163 employeeType: vendor
164 givenName: special
165 member: uid=alice,ou=users,o=refint
166 ETEST
167
168 echo "Testing delete when referential attribute is a MUST..."
169 $LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
170         $TESTOUT 2>&1 << EDEL
171 version: 1
172 dn: uid=alice,ou=users,o=refint
173 changetype: delete
174 EDEL
175
176 RC=$?
177 if test $RC != 0 ; then
178         echo "ldapmodify failed ($RC)!"
179         test $KILLSERVERS != no && kill -HUP $KILLPIDS
180         exit $RC
181 fi
182
183 test $KILLSERVERS != no && kill -HUP $KILLPIDS
184
185 echo ">>>>> Test succeeded"
186 exit 0