xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test055-valregex (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test055-valregex,v 1.2.2.2 2009/01/22 00:01:20 kurt Exp
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2009 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
16case "$BACKEND" in
17bdb|hdb)
18	;;
19*)
20	echo "Test does not support $BACKEND backend"
21	exit 0
22esac
23
24echo "running defines.sh"
25. $SRCDIR/scripts/defines.sh
26LVL=acl
27
28mkdir -p $TESTDIR $DBDIR1
29
30echo "Running slapadd to build slapd database..."
31. $CONFFILTER $BACKEND $MONITORDB < $VALREGEXCONF > $CONF1
32$SLAPADD -f $CONF1 -l $LDIFORDERED
33RC=$?
34if test $RC != 0 ; then
35	echo "slapadd failed ($RC)!"
36	exit $RC
37fi
38
39echo "Starting slapd on TCP/IP port $PORT1..."
40$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41PID=$!
42if test $WAIT != 0 ; then
43    echo PID $PID
44    read foo
45fi
46KILLPIDS="$PID"
47
48sleep 1
49
50echo "Testing attribute value regex subsitution..."
51for i in 0 1 2 3 4 5; do
52	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
53		'objectclass=*' > /dev/null 2>&1
54	RC=$?
55	if test $RC = 0 ; then
56		break
57	fi
58	echo "Waiting 5 seconds for slapd to start..."
59	sleep 5
60done
61
62if test $RC != 0 ; then
63	echo "ldapsearch failed ($RC)!"
64	test $KILLSERVERS != no && kill -HUP $KILLPIDS
65	exit $RC
66fi
67
68cat /dev/null > $SEARCHOUT
69
70echo "# Try an attribute vale regex that match, but substitute does not"
71echo "# this should fail"
72$LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
73	$TESTOUT 2>&1 << EOMODS
74dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
75changetype: modify
76replace: sn
77sn: foobarbuz
78EOMODS
79RC=$?
80case $RC in
8150)
82	echo "ldapmodify failed as expected"
83	;;
840)
85	echo "ldapmodify should have failed ($RC)!"
86	test $KILLSERVERS != no && kill -HUP $KILLPIDS
87	exit -1
88	;;
89*)
90	echo "ldapmodify failed ($RC)!"
91	test $KILLSERVERS != no && kill -HUP $KILLPIDS
92	exit $RC
93	;;
94esac
95
96echo "# Try an attribute vale regex that match and substitute does"
97echo "# this should succeed"
98$LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
99	$TESTOUT 2>&1 << EOMODS
100dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
101changetype: modify
102replace: sn
103sn: James A Jones 1
104EOMODS
105RC=$?
106
107test $KILLSERVERS != no && kill -HUP $KILLPIDS
108
109case $RC in
1100)
111	echo "ldapmodify succeed as expected"
112	;;
113*)
114	echo "ldapmodify failed ($RC)!"
115	exit $RC
116	;;
117esac
118
119echo ">>>>> Test succeeded"
120
121test $KILLSERVERS != no && wait
122
123exit 0
124