]> git.sur5r.net Git - openldap/blob - tests/scripts/test030-relay
807ca64956377f6de80f8fd1711cd1b46831047d
[openldap] / tests / scripts / test030-relay
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-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 $BACKRELAY = relayno ; then 
20         echo "relay backend not available, test skipped"
21         exit 0
22 fi 
23
24 if test $RWM = rwmno ; then 
25         echo "Rewrite/remap overlay not available, test skipped"
26         exit 0
27 fi 
28
29 mkdir -p $TESTDIR $DBDIR1
30
31 echo "Starting slapd on TCP/IP port $PORT1..."
32 . $CONFFILTER $BACKEND $MONITORDB < $RWMCONF > $CONF1
33 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
34 PID=$!
35 if test $WAIT != 0 ; then
36     echo PID $PID
37     read foo
38 fi
39 KILLPIDS="$PID"
40
41 echo "Using ldapsearch to check that slapd is running..."
42 for i in 0 1 2 3 4 5; do
43         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
44                 'objectclass=*' > /dev/null 2>&1
45         RC=$?
46         if test $RC = 0 ; then
47                 break
48         fi
49         echo "Waiting 5 seconds for slapd to start..."
50         sleep 5
51 done
52 if test $RC != 0 ; then
53         echo "ldapsearch failed $(RC)!"
54         test $KILLSERVERS != no && kill -HUP $KILLPIDS
55         exit $RC
56 fi
57
58 echo "Using ldapadd to populate the database..."
59 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
60         $LDIFORDERED > $TESTOUT 2>&1
61 RC=$?
62 if test $RC != 0 ; then
63         echo "ldapadd failed ($RC)!"
64         test $KILLSERVERS != no && kill -HUP $KILLPIDS
65         exit $RC
66 fi
67
68 cat /dev/null > $SEARCHOUT
69
70 BASEDN="dc=example,dc=com"
71 echo "searching base=\"$BASEDN\"..."
72 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
73 RC=$?
74 if test $RC != 0 ; then
75         echo "Search failed ($RC)!"
76         test $KILLSERVERS != no && kill -HUP $KILLPIDS
77         exit $RC
78 fi
79
80 BASEDN="o=Example,c=US"
81 echo "searching base=\"$BASEDN\"..."
82 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
83 RC=$?
84 if test $RC != 0 ; then
85         echo "Search failed ($RC)!"
86         test $KILLSERVERS != no && kill -HUP $KILLPIDS
87         exit $RC
88 fi
89
90 BASEDN="o=Esempio,c=IT"
91 echo "searching base=\"$BASEDN\"..."
92 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
93 RC=$?
94 if test $RC != 0 ; then
95         echo "Search failed ($RC)!"
96         test $KILLSERVERS != no && kill -HUP $KILLPIDS
97         exit $RC
98 fi
99
100 BASEDN="o=Beispiel,c=DE"
101 echo "searching base=\"$BASEDN\"..."
102 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
103 RC=$?
104 if test $RC != 0 ; then
105         echo "Search failed ($RC)!"
106         test $KILLSERVERS != no && kill -HUP $KILLPIDS
107         exit $RC
108 fi
109
110 #
111 # Do some modifications
112 #
113
114 BASEDN="o=Beispiel,c=DE"
115 echo "modifying database \"$BASEDN\"..."
116 $LDAPMODIFY -v -D "cn=Manager,$BASEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
117         >> $TESTOUT 2>&1 << EOMODS
118 dn: cn=Added User,ou=Alumni Association,ou=People,$BASEDN
119 changetype: add
120 objectClass: OpenLDAPperson
121 cn: Added User
122 sn: User
123 uid: auser
124 seealso: cn=All Staff,ou=Groups,$BASEDN
125 homephone: +49 1234567890
126 drink: Beer
127 mail: auser@mail.alumni.example.com
128 telephonenumber: +1 313 555 4178
129
130 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
131 changetype: modify
132 add: seeAlso
133 seeAlso: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
134 -
135 add: description
136 description: Just added self in $BASEDN virtual naming context
137 -
138
139 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN
140 changetype: delete
141
142 dn: cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN
143 changetype: modrdn
144 newrdn: cn=John P. Doe
145 deleteoldrdn: 1
146
147 dn: cn=Jane Doe,ou=Alumni Association,ou=People,$BASEDN
148 changetype: modrdn
149 newrdn: cn=Jane Q. Doe
150 deleteoldrdn: 1
151 newsuperior: ou=Information Technology Division,ou=People,$BASEDN
152
153 EOMODS
154
155 if test $RC != 0 ; then
156         echo "Modify failed ($RC)!"
157         test $KILLSERVERS != no && kill -HUP $KILLPIDS
158         exit $RC
159 fi
160
161 BASEDN="o=Esempio,c=IT"
162 echo "searching base=\"$BASEDN\"..."
163 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
164 RC=$?
165 if test $RC != 0 ; then
166         echo "Search failed ($RC)!"
167         test $KILLSERVERS != no && kill -HUP $KILLPIDS
168         exit $RC
169 fi
170
171 echo "Filtering ldapsearch results..."
172 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
173 echo "Filtering original ldif used to create database..."
174 . $LDIFFILTER < $RELAYOUT > $LDIFFLT
175 echo "Comparing filter output..."
176 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
177         
178 if test $? != 0 ; then
179         echo "comparison failed - relay search/modification didn't succeed"
180         test $KILLSERVERS != no && kill -HUP $KILLPIDS
181         exit 1
182 fi
183
184 BASEDN="o=Example,c=US"
185 echo "changing password to database \"$BASEDN\"..."
186 $LDAPPASSWD -h $LOCALHOST -p $PORT1 -D "cn=Manager,$BASEDN" -w $PASSWD \
187         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
188         -s $PASSWD >> $TESTOUT 2>&1
189 RC=$?
190 if test $RC != 0 ; then
191         echo "Passwd ExOp failed ($RC)!"
192         test $KILLSERVERS != no && kill -HUP $KILLPIDS
193         exit $RC
194 fi
195
196 echo "binding with newly changed password to database \"$BASEDN\"..."
197 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
198         -D "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
199         -w $PASSWD >> $TESTOUT 2>&1
200 RC=$?
201 if test $RC != 0 ; then
202         echo "WhoAmI failed ($RC)!"
203         test $KILLSERVERS != no && kill -HUP $KILLPIDS
204         exit $RC
205 fi
206
207 BASEDN="o=Esempio,c=IT"
208 echo "comparing to database \"$BASEDN\"..."
209 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
210         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
211         "seeAlso:cn=All Staff,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
212 RC=$?
213 if test $RC != 6 ; then
214         echo "Compare failed ($RC)!"
215         test $KILLSERVERS != no && kill -HUP $KILLPIDS
216         exit $RC
217 fi
218
219 test $KILLSERVERS != no && kill -HUP $KILLPIDS
220
221 echo ">>>>> Test succeeded"
222 exit 0
223