xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapd-modules/datamorph/tests/scripts/test003-search (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
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 "Testing searches against regular entries..."
25echo "# Testing searches against regular entries..." >> $SEARCHOUT
26$LDAPSEARCH -b "$BASEDN" -H $URI1 "(|(ou=Groups)(st=*))" \
27	>> $SEARCHOUT 2>&1
28RC=$?
29if test $RC != 0 ; then
30	echo "ldapsearch failed ($RC)!"
31	test $KILLSERVERS != no && kill -HUP $KILLPIDS
32	exit $RC
33fi
34
35echo "Testing searches listing transformed attributes..."
36echo >> $SEARCHOUT
37echo "# Testing searches listing transformed attributes..." >> $SEARCHOUT
38$LDAPSEARCH -b "ou=Information Technology Division,ou=People,$BASEDN" -s one \
39	-H $URI1 >> $SEARCHOUT 2>&1
40RC=$?
41if test $RC != 0 ; then
42	echo "ldapsearch failed ($RC)!"
43	test $KILLSERVERS != no && kill -HUP $KILLPIDS
44	exit $RC
45fi
46
47echo "Testing searches filtering on transformed attributes..."
48echo >> $SEARCHOUT
49echo "# Testing searches filtering on transformed attributes..." >> $SEARCHOUT
50$LDAPSEARCH -b "$BASEDN" -H $URI1 \
51	"(|(enumerated=bjensen)(&(signed=-19858)(signed<=0)(signed>=-20000)))" \
52	enumerated signed \
53	>> $SEARCHOUT 2>&1
54RC=$?
55if test $RC != 0 ; then
56	echo "ldapsearch failed ($RC)!"
57	test $KILLSERVERS != no && kill -HUP $KILLPIDS
58	exit $RC
59fi
60
61echo "Reconfiguring transformation definition..."
62. $CONFFILTER $BACKEND $MONITORDB < data/test003-config.ldif | \
63$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
64	>> $TESTOUT 2>&1
65RC=$?
66if test $RC != 0 ; then
67	echo "ldapmodify failed ($RC)!"
68	test $KILLSERVERS != no && kill -HUP $KILLPIDS
69	exit $RC
70fi
71
72echo "Testing searches filtering on the new values..."
73echo >> $SEARCHOUT
74echo "# Testing searches filtering on the new values..." >> $SEARCHOUT
75$LDAPSEARCH -b "$BASEDN" -H $URI1 \
76	"(|(enumerated=not a value)(enumerated=jaj)(&(signed=45678)(!(signed>=50000))(signed>=44444)))" \
77	enumerated signed \
78	>> $SEARCHOUT 2>&1
79RC=$?
80if test $RC != 0 ; then
81	echo "ldapsearch failed ($RC)!"
82	test $KILLSERVERS != no && kill -HUP $KILLPIDS
83	exit $RC
84fi
85
86test $KILLSERVERS != no && kill -HUP $KILLPIDS
87
88LDIF=data/test003-out.ldif
89
90echo "Filtering ldapsearch results..."
91$LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
92echo "Filtering expected entries..."
93$LDIFFILTER -s e < $LDIF > $LDIFFLT
94echo "Comparing filter output..."
95$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
96
97if test $? != 0 ; then
98	echo "Comparison failed"
99	exit 1
100fi
101
102echo ">>>>> Test succeeded"
103
104test $KILLSERVERS != no && wait
105
106exit 0
107