]> git.sur5r.net Git - openldap/blob - tests/scripts/test001-slapadd
Happy New Year
[openldap] / tests / scripts / test001-slapadd
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2018 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 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $ADDCONF
23 $SLAPADD -f $ADDCONF -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
32 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
33 PID=$!
34 if test $WAIT != 0 ; then
35     echo PID $PID
36     read foo
37 fi
38 KILLPIDS="$PID"
39
40 sleep 1
41
42 echo "Using ldapsearch to retrieve all the entries..."
43 for i in 0 1 2 3 4 5; do
44         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 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
53 if test $RC != 0 ; then
54         echo "ldapsearch failed ($RC)!"
55         test $KILLSERVERS != no && kill -HUP $KILLPIDS
56         exit $RC
57 fi
58
59 echo "Filtering ldapsearch results..."
60 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
61 echo "Filtering original ldif used to create database..."
62 $LDIFFILTER < $LDIF > $LDIFFLT
63 echo "Comparing filter output..."
64 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
65
66 if test $? != 0 ; then
67         echo "comparison failed - database was not created correctly"
68         echo $SEARCHFLT $LDIFFLT
69         $DIFF $SEARCHFLT $LDIFFLT
70         test $KILLSERVERS != no && kill -HUP $KILLPIDS
71         exit 1
72 fi
73
74 if test $BACKEND = ldif ; then
75         echo "Skipping test of unordered slapadd (unsupported in ldif backend)"
76 else
77
78 kill -HUP $KILLPIDS
79
80 rm -f $DBDIR1/*
81
82 BASE2="ou=test,dc=example,dc=com"
83 sed -e "s;$BASEDN;$BASE2;" $ADDCONF > ${ADDCONF}2
84 mv ${ADDCONF}2 $ADDCONF
85 sed -e "s;$BASEDN;$BASE2;" $CONF1 > ${CONF1}2
86 mv ${CONF1}2 $CONF1
87 echo "Running slapadd with unordered LDIF..."
88 $SLAPADD -f $ADDCONF -l $LDIFUNORDERED
89 RC=$?
90 if test $RC != 0 ; then
91         echo "slapadd failed ($RC)!"
92         exit $RC
93 fi
94
95 echo "Starting slapd on TCP/IP port $PORT1..."
96 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
97 PID=$!
98 if test $WAIT != 0 ; then
99     echo PID $PID
100     read foo
101 fi
102 KILLPIDS="$PID"
103
104 sleep 1
105
106 echo "Using ldapsearch to retrieve all the entries..."
107 for i in 0 1 2 3 4 5; do
108         $LDAPSEARCH -b "$BASE2" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
109         RC=$?
110         if test $RC = 0 ; then
111                 break
112         fi
113         echo "Waiting 5 seconds for slapd to start..."
114         sleep 5
115 done
116
117 if test $RC != 0 ; then
118         echo "ldapsearch failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 echo "Filtering ldapsearch results..."
124 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
125 echo "Filtering original ldif used to create database..."
126 $LDIFFILTER < $LDIFREORDERED > $LDIFFLT
127 echo "Comparing filter output..."
128 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
129
130 if test $? != 0 ; then
131         echo "comparison failed - database was not created correctly"
132         echo $SEARCHFLT $LDIFFLT
133         $DIFF $SEARCHFLT $LDIFFLT
134         test $KILLSERVERS != no && kill -HUP $KILLPIDS
135         exit 1
136 fi
137
138 fi
139
140 test $KILLSERVERS != no && kill -HUP $KILLPIDS
141
142 echo ">>>>> Test succeeded"
143
144 test $KILLSERVERS != no && wait
145
146 exit 0