ldap test, inspired from the samba ldb tests

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20220 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2007-02-15 00:11:18 +00:00
parent 393f98a743
commit 3cb07032b9
8 changed files with 292 additions and 0 deletions

1
tests/ldap/.cvsignore Normal file
View File

@@ -0,0 +1 @@
Makefile.in

48
tests/ldap/Makefile.am Normal file
View File

@@ -0,0 +1,48 @@
# $Id$
include $(top_srcdir)/Makefile.am.common
noinst_DATA = krb5.conf
check_SCRIPTS = $(TESTS) slapd-init
TESTS = check-ldap
port = 49188
do_subst = sed -e 's,[@]srcdir[@],$(srcdir),g' \
-e 's,[@]port[@],$(port),g' \
-e 's,[@]objdir[@],$(top_builddir)/tests/ldap,g' \
-e 's,[@]EGREP[@],$(EGREP),g'
check-ldap: check-ldap.in Makefile
$(do_subst) < $(srcdir)/check-ldap.in > check-ldap.tmp
chmod +x check-ldap.tmp
mv check-ldap.tmp check-ldap
slapd-init: slapd-init.in Makefile
$(do_subst) < $(srcdir)/slapd-init.in > slapd-init.tmp
chmod +x slapd-init.tmp
mv slapd-init.tmp slapd-init
krb5.conf: krb5.conf.in Makefile
$(do_subst) < $(srcdir)/krb5.conf.in > krb5.conf.tmp
mv krb5.conf.tmp krb5.conf
CLEANFILES= \
$(TESTS) \
check-ldap.tmp \
slapd-init.tmp \
current-db* \
krb5.conf krb5.conf.tmp \
modules.conf \
cache.krb5 \
slapd-init \
foopassword \
messages.log \
slapd.pid
EXTRA_DIST = \
check-ldap.in \
init.ldif \
krb5.conf.in

131
tests/ldap/check-ldap.in Normal file
View File

@@ -0,0 +1,131 @@
#!/bin/sh
#
# Copyright (c) 2006 Kungliga Tekniska H<>gskolan
# (Royal Institute of Technology, Stockholm, Sweden).
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the Institute nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Id$
#
srcdir="@srcdir@"
objdir="@objdir@"
EGREP="@EGREP@"
R=TEST.H5L.SE
port=@port@
cache="FILE:${objdir}/cache.krb5"
kinit="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache --no-afslog"
kadmin="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R"
kdc="${TESTS_ENVIRONMENT} ../../kdc/kdc --addresses=localhost -P $port"
testfailed="echo test failed; exit 1"
# If there is no ldap support compile in, disable test
if ${kdc} --builtin-hdb | grep ldap > /dev/null ; then
:
else
echo "no ldap support"
exit 77
fi
#search for all ldap tools
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/libexec:$PATH
export PATH
oldifs=$IFS
IFS=:
set -- $PATH
IFS=$oldifs
for j in slapd slapadd; do
for i in $*; do
test -n "$i" || i="."
if test -x $i/$j; then
continue 2
fi
done
echo "$j missing, not running test"
exit 77
done
sh ${objdir}/slapd-init || exit 1
trap "sh ${srcdir}/slapd-stop ; exit 1;" EXIT
KRB5_CONFIG="${objdir}/krb5.conf"
export KRB5_CONFIG
rm -f current-db*
echo Creating database
${kadmin} \
init \
--realm-max-ticket-life=1day \
--realm-max-renewable-life=1month \
${R} || exit 1
${kadmin} add -p foo --use-defaults foo@${R} || exit 1
echo foo > ${objdir}/foopassword
echo Starting kdc
${kdc} &
kdcpid=$!
sh ${srcdir}/../kdc/wait-kdc.sh
if [ "$?" != 0 ] ; then
kill ${kdcpid}
sh ${srcdir}/slapd-stop
exit 1
fi
trap "kill ${kdcpid}; echo signal killing kdc; sh ${srcdir}/slapd-stop ; exit 1;" EXIT
ec=0
echo "Getting client initial tickets";
${kinit} --password-file=${objdir}/foopassword foo@$R || \
{ ec=1 ; eval "${testfailed}"; }
echo "killing kdc (${kdcpid})"
kill $kdcpid || exit 1
trap "" EXIT
# kill of old slapd
sh ${srcdir}/slapd-stop
rm -rf db schema
exit $ec

8
tests/ldap/init.ldif Normal file
View File

@@ -0,0 +1,8 @@
dn: o=TEST,dc=H5L,dc=SE
objectclass: organization
o: Test
dn: ou=kerberosPrincipals,o=TEST,dc=H5L,dc=SE
objectclass: organizationalUnit
ou: kerberosPrincipals

21
tests/ldap/krb5.conf.in Normal file
View File

@@ -0,0 +1,21 @@
# $Id$
[libdefaults]
default_realm = TEST.H5L.SE
no-addresses = TRUE
[realms]
TEST.H5L.SE = {
kdc = localhost:@port@
}
[kdc]
database = {
dbname = ldapi://ldap-socket:OU=KerberosPrincipals,o=test,DC=h5l,DC=se
realm = TEST.H5L.SE
mkey_file = @objdir@/mkey.file
}
[logging]
kdc = 0-/FILE:@objdir@/messages.log
default = 0-/FILE:@objdir@/messages.log

38
tests/ldap/slapd-init.in Normal file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
srcdir=@srcdir@
rm -rf db
mkdir db
# kill of old slapd if running
sh ${srcdir}/slapd-stop > /dev/null
SCHEMA_NEEDED="hdb core nis cosine inetorgperson openldap"
SCHEMA_PATHS="${srcdir}/../../lib/hdb /etc/ldap/schema /etc/openldap/schema /private/etc/openldap/schema"
test -d schema || mkdir schema
# setup needed schema files
for f in $SCHEMA_NEEDED; do
if [ ! -r schema/$f.schema ]; then
for d in $SCHEMA_PATHS ; do
if [ -r $d/$f.schema ] ; then
cp $d/$f.schema schema/$f.schema
continue 2
fi
done
echo "SKIPPING TESTS: you need the following schema file: $f.schema"
exit 1
fi
done
touch modules.conf || exit 1
slapadd -f ${srcdir}/slapd.conf < ${srcdir}/init.ldif || exit 0
echo "starting slapd"
slapd -d0 -f ${srcdir}/slapd.conf -h ldapi://.%2Fldap-socket &
sleep 4

18
tests/ldap/slapd-stop Normal file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
# $Id$
echo stoping slapd
# kill of old slapd
if [ -f slapd.pid ]; then
kill `cat slapd.pid`
sleep 5
fi
if [ -f slapd.pid ]; then
kill -9 `cat slapd.pid`
rm -f slapd.pid
sleep 5
fi
exit 0

27
tests/ldap/slapd.conf Normal file
View File

@@ -0,0 +1,27 @@
loglevel 0
include schema/core.schema
include schema/cosine.schema
include schema/inetorgperson.schema
include schema/openldap.schema
include schema/nis.schema
include schema/hdb.schema
pidfile slapd.pid
argsfile slapd.args
access to * by * write
allow update_anon bind_anon_dn
include modules.conf
defaultsearchbase "ou=TEST,dc=H5L,dc=SE"
backend bdb
database bdb
suffix "o=TEST,dc=H5L,dc=SE"
directory db
index objectClass eq
index uid eq