]> git.sur5r.net Git - openldap/blob - tests/scripts/test032-chain
244d2ae63aa1cd58554950e8b2099119dd0910dd
[openldap] / tests / scripts / test032-chain
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-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 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $BACKLDAP = "ldapno" ; then 
20         echo "LDAP backend not available, test skipped"
21         exit 0
22 fi 
23
24 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
25
26 echo "Running slapadd to build slapd database..."
27 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $ADDCONF
28 . $CONFFILTER < $LDIFCHAIN1 > $SEARCHOUT
29 $SLAPADD -f $ADDCONF -l $SEARCHOUT
30 RC=$?
31 if test $RC != 0 ; then
32         echo "slapadd 1 failed ($RC)!"
33         exit $RC
34 fi
35
36 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $ADDCONF
37 . $CONFFILTER < $LDIFCHAIN2 > $SEARCHOUT
38 $SLAPADD -f $ADDCONF -l $SEARCHOUT
39 RC=$?
40 if test $RC != 0 ; then
41         echo "slapadd 2 failed ($RC)!"
42         exit $RC
43 fi
44
45 echo "Starting first slapd on TCP/IP port $PORT1..."
46 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $CONF1
47 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
48 PID1=$!
49 if test $WAIT != 0 ; then
50     echo PID $PID1
51     read foo
52 fi
53
54 echo "Starting second slapd on TCP/IP port $PORT2..."
55 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $CONF2
56 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
57 PID2=$!
58 if test $WAIT != 0 ; then
59     echo PID $PID2
60     read foo
61 fi
62
63 KILLPIDS="$PID1 $PID2"
64
65 echo "Using ldapsearch to check that first slapd is running..."
66 for i in 0 1 2 3 4 5; do
67         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
68                 'objectclass=*' > /dev/null 2>&1
69         RC=$?
70         if test $RC = 0 ; then
71                 break
72         fi
73         echo "Waiting 5 seconds for slapd to start..."
74         sleep 5
75 done
76
77 echo "Using ldapsearch to check that second slapd is running..."
78 for i in 0 1 2 3 4 5; do
79         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
80                 'objectclass=*' > /dev/null 2>&1
81         RC=$?
82         if test $RC = 0 ; then
83                 break
84         fi
85         echo "Waiting 5 seconds for slapd to start..."
86         sleep 5
87 done
88
89 BASE="dc=example,dc=com"
90 echo "Testing ldapsearch as anonymous for \"$BASE\" on first slapd..."
91 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
92          > $SEARCHOUT 2>&1
93
94 RC=$?
95 if test $RC != 0 ; then
96         echo "ldapsearch failed ($RC)!"
97         test $KILLSERVERS != no && kill -HUP $KILLPIDS
98         exit $RC
99 fi
100
101 echo "Testing ldapsearch as anonymous for \"$BASE\" on second slapd..."
102 $LDAPSEARCH -h $LOCALHOST -p $PORT2 -b "$BASE" \
103          >> $SEARCHOUT 2>&1
104
105 RC=$?
106 if test $RC != 0 ; then
107         echo "ldapsearch failed ($RC)!"
108         test $KILLSERVERS != no && kill -HUP $KILLPIDS
109         exit $RC
110 fi
111
112 echo "Filtering ldapsearch results..."
113 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
114 echo "Filtering original ldif used to create database..."
115 . $LDIFFILTER < $CHAINOUT > $LDIFFLT
116 echo "Comparing filter output..."
117 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
118         
119 if test $? != 0 ; then
120         echo "comparison failed - chained search as anonymous didn't succeed"
121         test $KILLSERVERS != no && kill -HUP $KILLPIDS
122         exit 1
123 fi
124
125 test $KILLSERVERS != no && kill -HUP $KILLPIDS
126
127 echo ">>>>> Test succeeded"
128 exit 0
129