xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapd-modules/variant/tests/scripts/test002-add-delete (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1*e670fd5cSchristos#! /bin/sh
2*e670fd5cSchristos## $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 2016-2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos##
16*e670fd5cSchristos## ACKNOWLEDGEMENTS:
17*e670fd5cSchristos## This module was written in 2016 by Ondřej Kuzník for Symas Corp.
18*e670fd5cSchristos
19*e670fd5cSchristosecho "running defines.sh"
20*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
21*e670fd5cSchristos
22*e670fd5cSchristos. ${SCRIPTDIR}/common.sh
23*e670fd5cSchristos
24*e670fd5cSchristosecho "Adding entry..."
25*e670fd5cSchristos$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
26*e670fd5cSchristos	-f data/test002-01-entry.ldif >> $TESTOUT 2>&1
27*e670fd5cSchristosRC=$?
28*e670fd5cSchristosif test $RC != 0 ; then
29*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
30*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
31*e670fd5cSchristos	exit $RC
32*e670fd5cSchristosfi
33*e670fd5cSchristos
34*e670fd5cSchristosecho "Configuring entry as variant..."
35*e670fd5cSchristos. $CONFFILTER $BACKEND $MONITORDB < data/additional-config.ldif | \
36*e670fd5cSchristos$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
37*e670fd5cSchristos	>> $TESTOUT 2>&1
38*e670fd5cSchristosRC=$?
39*e670fd5cSchristosif test $RC != 0 ; then
40*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
41*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
42*e670fd5cSchristos	exit $RC
43*e670fd5cSchristosfi
44*e670fd5cSchristos
45*e670fd5cSchristosecho "Removing entry..."
46*e670fd5cSchristos$LDAPDELETE -D $MANAGERDN -H $URI1 -w $PASSWD \
47*e670fd5cSchristos	"cn=Gern Jensen,ou=Information Technology Division,ou=People,$BASEDN" \
48*e670fd5cSchristos	>> $TESTOUT 2>&1
49*e670fd5cSchristosRC=$?
50*e670fd5cSchristosif test $RC != 0 ; then
51*e670fd5cSchristos	echo "ldapdelete failed ($RC)!"
52*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
53*e670fd5cSchristos	exit $RC
54*e670fd5cSchristosfi
55*e670fd5cSchristos
56*e670fd5cSchristosecho "Adding entry again (should fail)..."
57*e670fd5cSchristos$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
58*e670fd5cSchristos	-f data/test002-01-entry.ldif >> $TESTOUT 2>&1
59*e670fd5cSchristosRC=$?
60*e670fd5cSchristoscase $RC in
61*e670fd5cSchristos0)
62*e670fd5cSchristos	echo "ldapmodify should have failed ($RC)!"
63*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
64*e670fd5cSchristos	exit 1
65*e670fd5cSchristos	;;
66*e670fd5cSchristos19)
67*e670fd5cSchristos	echo "ldapmodify failed ($RC)"
68*e670fd5cSchristos	;;
69*e670fd5cSchristos*)
70*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
71*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
72*e670fd5cSchristos	exit $RC
73*e670fd5cSchristos	;;
74*e670fd5cSchristosesac
75*e670fd5cSchristos
76*e670fd5cSchristosecho "Adding a regex entry (should fail)..."
77*e670fd5cSchristos$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
78*e670fd5cSchristos	-f data/test002-02-regex.ldif >> $TESTOUT 2>&1
79*e670fd5cSchristosRC=$?
80*e670fd5cSchristoscase $RC in
81*e670fd5cSchristos0)
82*e670fd5cSchristos	echo "ldapmodify should have failed ($RC)!"
83*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
84*e670fd5cSchristos	exit 1
85*e670fd5cSchristos	;;
86*e670fd5cSchristos19)
87*e670fd5cSchristos	echo "ldapmodify failed ($RC)"
88*e670fd5cSchristos	;;
89*e670fd5cSchristos*)
90*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
91*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
92*e670fd5cSchristos	exit $RC
93*e670fd5cSchristos	;;
94*e670fd5cSchristosesac
95*e670fd5cSchristos
96*e670fd5cSchristosecho "Adding entry with offending attributes removed..."
97*e670fd5cSchristosgrep -v '^description:' data/test002-01-entry.ldif | \
98*e670fd5cSchristos$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
99*e670fd5cSchristos	>> $TESTOUT 2>&1
100*e670fd5cSchristosRC=$?
101*e670fd5cSchristosif test $RC != 0 ; then
102*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
103*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
104*e670fd5cSchristos	exit $RC
105*e670fd5cSchristosfi
106*e670fd5cSchristos
107*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
108*e670fd5cSchristos
109*e670fd5cSchristosecho ">>>>> Test succeeded"
110*e670fd5cSchristos
111*e670fd5cSchristostest $KILLSERVERS != no && wait
112*e670fd5cSchristos
113*e670fd5cSchristosexit 0
114