1#! /bin/sh
2## $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 2016-2021 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## ACKNOWLEDGEMENTS:
17## This module was written in 2016 by Ond��ej Kuzn��k for Symas Corp.
18
19echo "running defines.sh"
20. $SRCDIR/scripts/defines.sh
21
22. ${SCRIPTDIR}/common.sh
23
24echo "Adding entries (should fail this time)..."
25$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
26	-c -f data/test002-entry.ldif >> $TESTOUT 2>&1
27RC=$?
28case $RC in
290)
30	echo "ldapmodify should have failed ($RC)!"
31	test $KILLSERVERS != no && kill -HUP $KILLPIDS
32	exit 1
33	;;
3419)
35	echo "ldapmodify failed ($RC)"
36	;;
37*)
38	echo "ldapmodify failed ($RC)!"
39	test $KILLSERVERS != no && kill -HUP $KILLPIDS
40	exit $RC
41	;;
42esac
43
44echo "Adding other entries (should fail)..."
45$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
46	-f data/test002-fail.ldif >> $TESTOUT 2>&1
47RC=$?
48case $RC in
490)
50	echo "ldapmodify should have failed ($RC)!"
51	test $KILLSERVERS != no && kill -HUP $KILLPIDS
52	exit 1
53	;;
5419)
55	echo "ldapmodify failed ($RC)"
56	;;
57*)
58	echo "ldapmodify failed ($RC)!"
59	test $KILLSERVERS != no && kill -HUP $KILLPIDS
60	exit $RC
61	;;
62esac
63
64$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
65	-f data/test002-transformed-rdn.ldif >> $TESTOUT 2>&1
66RC=$?
67case $RC in
680)
69	echo "ldapmodify should have failed ($RC)!"
70	test $KILLSERVERS != no && kill -HUP $KILLPIDS
71	exit 1
72	;;
7332)
74	echo "ldapmodify failed ($RC)"
75	;;
76*)
77	echo "ldapmodify failed ($RC)!"
78	test $KILLSERVERS != no && kill -HUP $KILLPIDS
79	exit $RC
80	;;
81esac
82
83echo "Configuring new value..."
84. $CONFFILTER $BACKEND $MONITORDB < data/test002-config.ldif | \
85$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
86	>> $TESTOUT 2>&1
87RC=$?
88if test $RC != 0 ; then
89	echo "ldapmodify failed ($RC)!"
90	test $KILLSERVERS != no && kill -HUP $KILLPIDS
91	exit $RC
92fi
93
94echo "Adding some of the entries again..."
95$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
96	-f data/test002-entry.ldif >> $TESTOUT 2>&1
97RC=$?
98if test $RC != 0 ; then
99	echo "ldapmodify failed ($RC)!"
100	test $KILLSERVERS != no && kill -HUP $KILLPIDS
101	exit $RC
102fi
103
104echo "Saving search output..."
105$LDAPSEARCH -H $URI1 -b "$BASEDN" \
106	"(|(cn=Gern Jensen)(ou=New Unit))" \
107	>> $SEARCHOUT 2>&1
108RC=$?
109if test $RC != 0 ; then
110	echo "ldapsearch failed ($RC)!"
111	test $KILLSERVERS != no && kill -HUP $KILLPIDS
112	exit $RC
113fi
114
115echo "Removing entry..."
116$LDAPDELETE -D $MANAGERDN -H $URI1 -w $PASSWD \
117	"cn=Gern Jensen,ou=Information Technology Division,ou=People,$BASEDN" \
118	"ou=New Unit,$BASEDN" \
119	>> $TESTOUT 2>&1
120RC=$?
121if test $RC != 0 ; then
122	echo "ldapdelete failed ($RC)!"
123	test $KILLSERVERS != no && kill -HUP $KILLPIDS
124	exit $RC
125fi
126
127test $KILLSERVERS != no && kill -HUP $KILLPIDS
128
129LDIF=data/test002-entry.ldif
130
131echo "Filtering ldapsearch results..."
132$LDIFFILTER -s ae < $SEARCHOUT > $SEARCHFLT
133echo "Filtering expected entries..."
134$LDIFFILTER -s ae < $LDIF | grep -v '^changetype:' > $LDIFFLT
135echo "Comparing filter output..."
136$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
137
138if test $? != 0 ; then
139	echo "Comparison failed"
140	exit 1
141fi
142
143echo ">>>>> Test succeeded"
144
145test $KILLSERVERS != no && wait
146
147exit 0
148