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