diff options
Diffstat (limited to 'contrib/slapd-modules/ciboolean/tests')
8 files changed, 527 insertions, 0 deletions
diff --git a/contrib/slapd-modules/ciboolean/tests/Rules.mk b/contrib/slapd-modules/ciboolean/tests/Rules.mk new file mode 100644 index 0000000..e64d925 --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/Rules.mk @@ -0,0 +1,23 @@ +sp := $(sp).x +dirstack_$(sp) := $(d) +d := $(dir) + +.PHONY: test + +CLEAN += clients servers tests/progs tests/schema tests/testdata tests/testrun + +test: all clients servers tests/progs + +test: + cd tests; \ + SRCDIR=$(abspath $(LDAP_SRC)) \ + LDAP_BUILD=$(abspath $(LDAP_BUILD)) \ + TOPDIR=$(abspath $(SRCDIR)) \ + LIBTOOL=$(abspath $(LIBTOOL)) \ + $(abspath $(SRCDIR))/tests/run test001-ciboolean + +servers clients tests/progs: + ln -s $(abspath $(LDAP_BUILD))/$@ $@ + +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) diff --git a/contrib/slapd-modules/ciboolean/tests/data/booleantest.schema b/contrib/slapd-modules/ciboolean/tests/data/booleantest.schema new file mode 100644 index 0000000..134516f --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/data/booleantest.schema @@ -0,0 +1,10 @@ +attributetype (1.3.6.1.4.1.4203.1.12.1.1.7 NAME 'IsBusy' + EQUALITY booleanMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 + SINGLE-VALUE) + + +objectclass ( 1.3.6.1.4.1.4203.1.12.1.2.3 NAME 'BusyClass' + SUP top + AUXILIARY + MAY ( IsBusy )) diff --git a/contrib/slapd-modules/ciboolean/tests/data/slapd.conf b/contrib/slapd-modules/ciboolean/tests/data/slapd.conf new file mode 100644 index 0000000..2c90dbd --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/data/slapd.conf @@ -0,0 +1,36 @@ +# provider slapd config -- for testing +# $OpenLDAP$ + +include @SCHEMADIR@/core.schema +include @SCHEMADIR@/cosine.schema +include @SCHEMADIR@/inetorgperson.schema +include data/booleantest.schema + +pidfile @TESTDIR@/slapd.m.pid + +argsfile @TESTDIR@/slapd.m.args + +moduleload ../ciboolean.la + + + +pidfile testrun/slapd.pid + + +####################################################################### +# database definitions +####################################################################### +database mdb +suffix "dc=example,dc=com" + +directory testrun +# root or superuser +rootdn "cn=Manager,dc=example,dc=com" +rootpw secret + + +database config +rootdn "cn=manager,cn=config" +rootpw secret + +database monitor diff --git a/contrib/slapd-modules/ciboolean/tests/data/test001-add.ldif b/contrib/slapd-modules/ciboolean/tests/data/test001-add.ldif new file mode 100644 index 0000000..456ab89 --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/data/test001-add.ldif @@ -0,0 +1,111 @@ +dn: dc=example,dc=com +objectClass: top +objectClass: organization +objectClass: domainRelatedObject +objectClass: dcObject +dc: example +l: Anytown, Michigan +st: Michigan +o: Example, Inc. +o: EX +o: Ex. +description: The Example, Inc. at Anytown +postalAddress: Example, Inc. $ 535 W. William St. $ Anytown, MI 48109 $ US +telephoneNumber: +1 313 555 1817 +associatedDomain: example.com + +dn: ou=people,dc=example,dc=com +objectClass: organizationalUnit +ou: people +description: All domain members + +dn: cn=user01,ou=people,dc=example,dc=com +cn: user01 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 101 +carLicense: 1234ha +sn: user01 +mobile: 12345678 +mobile: 987654321 +IsBusy: FaLse +ou: people +preferredLanguage: English +description: This is user user01 + +dn: cn=user02,ou=people,dc=example,dc=com +cn: user02 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 102 +carLicense: 1234hb +sn: user02 +mobile: 12345678 +mobile: 987654321 +IsBusy: False +ou: people +preferredLanguage: English +description: This is user user02 + +dn: cn=user03,ou=people,dc=example,dc=com +cn: user03 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 103 +carLicense: 1234hc +sn: user03 +mobile: 12345678 +mobile: 987654321 +IsBusy: FALSE +ou: people +preferredLanguage: English +description: This is user user03 + +dn: cn=user04,ou=people,dc=example,dc=com +cn: user04 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 104 +carLicense: 1234ha +sn: user04 +mobile: 12345678 +mobile: 987654321 +IsBusy: TRue +ou: people +preferredLanguage: English +description: This is user user04 + +dn: cn=user05,ou=people,dc=example,dc=com +cn: user05 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 105 +carLicense: 1234hb +sn: user05 +mobile: 12345678 +mobile: 987654321 +IsBusy: True +ou: people +preferredLanguage: English +description: This is user user05 + +dn: cn=user06,ou=people,dc=example,dc=com +cn: user06 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 106 +carLicense: 1234hc +sn: user06 +mobile: 12345678 +mobile: 987654321 +IsBusy: TRUE +ou: people +preferredLanguage: English +description: This is user user03 + diff --git a/contrib/slapd-modules/ciboolean/tests/data/test001-search_1.ldif b/contrib/slapd-modules/ciboolean/tests/data/test001-search_1.ldif new file mode 100644 index 0000000..63aac4d --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/data/test001-search_1.ldif @@ -0,0 +1,45 @@ +dn: cn=user02,ou=people,dc=example,dc=com +cn: user02 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 102 +carLicense: 1234hb +sn: user02 +mobile: 12345678 +mobile: 987654321 +IsBusy: False +ou: people +preferredLanguage: English +description: This is user user02 + +dn: cn=user03,ou=people,dc=example,dc=com +cn: user03 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 103 +carLicense: 1234hc +sn: user03 +mobile: 12345678 +mobile: 987654321 +IsBusy: FALSE +ou: people +preferredLanguage: English +description: This is user user03 + +dn: cn=user06,ou=people,dc=example,dc=com +cn: user06 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 106 +carLicense: 1234hc +sn: user06 +mobile: 12345678 +mobile: 987654321 +ou: people +preferredLanguage: English +description: This is user user03 +IsBusy: false + diff --git a/contrib/slapd-modules/ciboolean/tests/data/test001-search_2.ldif b/contrib/slapd-modules/ciboolean/tests/data/test001-search_2.ldif new file mode 100644 index 0000000..c89aa71 --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/data/test001-search_2.ldif @@ -0,0 +1,45 @@ +dn: cn=user01,ou=people,dc=example,dc=com +cn: user01 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 101 +carLicense: 1234ha +sn: user01 +mobile: 12345678 +mobile: 987654321 +ou: people +preferredLanguage: English +description: This is user user01 +IsBusy: TRUE + +dn: cn=user04,ou=people,dc=example,dc=com +cn: user04 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 104 +carLicense: 1234ha +sn: user04 +mobile: 12345678 +mobile: 987654321 +IsBusy: TRue +ou: people +preferredLanguage: English +description: This is user user04 + +dn: cn=user05,ou=people,dc=example,dc=com +cn: user05 +objectClass: inetOrgPerson +objectClass: BusyClass +userPassword:: UEBzc3cwcmQ= +roomNumber: 105 +carLicense: 1234hb +sn: user05 +mobile: 12345678 +mobile: 987654321 +IsBusy: True +ou: people +preferredLanguage: English +description: This is user user05 + diff --git a/contrib/slapd-modules/ciboolean/tests/run b/contrib/slapd-modules/ciboolean/tests/run new file mode 100755 index 0000000..239bff7 --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/run @@ -0,0 +1,17 @@ +#!/bin/sh +## $OpenLDAP$ +## This work is part of OpenLDAP Software <http://www.openldap.org/>. +## +## Copyright 1998-2022 The OpenLDAP Foundation. +## All rights reserved. +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted only as authorized by the OpenLDAP +## Public License. +## +## A copy of this license is available in the file LICENSE in the +## top-level directory of the distribution or, alternatively, at +## <http://www.OpenLDAP.org/license.html>. + +TOPSRCDIR="$SRCDIR" OBJDIR="${LDAP_BUILD}" SRCDIR="${SRCDIR}/tests" DEFSDIR="${SRCDIR}/scripts" SCRIPTDIR="${TOPDIR}/tests/scripts" "${LDAP_BUILD}/tests/run" $* + diff --git a/contrib/slapd-modules/ciboolean/tests/scripts/test001-ciboolean b/contrib/slapd-modules/ciboolean/tests/scripts/test001-ciboolean new file mode 100755 index 0000000..bc6f229 --- /dev/null +++ b/contrib/slapd-modules/ciboolean/tests/scripts/test001-ciboolean @@ -0,0 +1,240 @@ +#! /bin/sh +# $OpenLDAP$ +## This work is part of OpenLDAP Software <http://www.openldap.org/>. +## +## Copyright 1998-2022 The OpenLDAP Foundation. +## Copyright 2022 Symas Corp. +## +## All rights reserved. +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted only as authorized by the OpenLDAP +## Public License. +## +## A copy of this license is available in the file LICENSE in the +## top-level directory of the distribution or, alternatively, at +## <http://www.OpenLDAP.org/license.html>. +## +## ACKNOWLEDGEMENTS: +## This work was developed in 2022 by Nadezhda Ivanova for Symas Corp. +echo "running defines.sh" +. $SRCDIR/scripts/defines.sh + +echo "" + +rm -rf $TESTDIR + +mkdir -p $TESTDIR $DBDIR1 + +echo "Starting slapd on TCP/IP port $PORT1..." +. $CONFFILTER $BACKEND < data/slapd.conf > $CONF1 +$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & +PID=$! +if test $WAIT != 0 ; then + echo PID $PID + read foo +fi +KILLPIDS="$PID" + +sleep 1 + +echo "Using ldapsearch to check that slapd is running..." +for i in 0 1 2 3 4 5; do + $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ + 'objectclass=*' > /dev/null 2>&1 + RC=$? + if test $RC = 0 ; then + break + fi + echo "Waiting 5 seconds for slapd to start..." + sleep 5 +done +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +echo "Using ldapadd to populate the database..." +$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \ + data/test001-add.ldif > $TESTOUT 2>&1 +RC=$? +if test $RC != 0 ; then + echo "ldapadd failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +cat /dev/null > $SEARCHOUT + +echo "Searching base=\"$BASEDN\"..." +echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT +$LDAPSEARCH -S "" -H $URI1 -b "$BASEDN" >> $SEARCHOUT 2>&1 +RC=$? + +if test $RC != 0 ; then + echo "Search failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +echo "Filtering ldapsearch results..." +$LDIFFILTER < $SEARCHOUT > $SEARCHFLT +echo "Filtering original ldif used to create database..." +$LDIFFILTER < data/test001-add.ldif > $LDIFFLT +echo "Comparing filter output..." +$CMP $SEARCHFLT $LDIFFLT > $CMPOUT + +if test $? != 0 ; then + echo "comparison failed - database population didn't succeed" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit 1 +fi + +# +# Do some modifications +# + +echo "Modifying database \"$BASEDN\" with TRUE..." +$LDAPMODIFY -v -D "cn=Manager,$BASEDN" -H $URI1 -w $PASSWD \ + -M >> $TESTOUT 2>&1 << EOMODS +dn: cn=user01,ou=people,$BASEDN +changetype: modify +replace: IsBusy +IsBusy: TRUE +EOMODS + +RC=$? +if test $RC != 0 ; then + echo "Modify failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +echo "Modifying database \"$BASEDN\" with false..." +$LDAPMODIFY -v -D "cn=Manager,$BASEDN" -H $URI1 -w $PASSWD \ + -M >> $TESTOUT 2>&1 << EOMODS +dn: cn=user06,ou=people,$BASEDN +changetype: modify +replace: IsBusy +IsBusy: false +EOMODS + +RC=$? +if test $RC != 0 ; then + echo "Modify failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +echo "Modifying database \"$BASEDN\"with TRUA..." +$LDAPMODIFY -v -D "cn=Manager,$BASEDN" -H $URI1 -w $PASSWD \ + -M >> $TESTOUT 2>&1 << EOMODS +dn: cn=user02,ou=people,$BASEDN +changetype: modify +replace: IsBusy +IsBusy: TRUA + +EOMODS + +RC=$? +if test $RC != 21 ; then + echo "Modify with an incorrect value failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +cat /dev/null > $SEARCHOUT + +echo " base=\"$BASEDN\"..." +echo "# base=\"$BASEDN\"..." >> $SEARCHOUT +$LDAPSEARCH -S "" -H $URI1 -b "$BASEDN" -M "(IsBusy=false)" '*' ref \ + >> $SEARCHOUT 2>&1 + +RC=$? +if test $RC != 0 ; then + echo "Search failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + + +echo "Filtering ldapsearch results..." +$LDIFFILTER < $SEARCHOUT > $SEARCHFLT +echo "Filtering partial ldif used to create database..." +$LDIFFILTER < data/test001-search_1.ldif > $LDIFFLT +echo "Comparing filter output..." +$CMP $SEARCHFLT $LDIFFLT > $CMPOUT + +if test $? != 0 ; then + echo "comparison failed - search for (IsBusy=false) didn't succeed" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit 1 +fi + +cat /dev/null > $SEARCHOUT + +echo " base=\"$BASEDN\"..." +echo "# base=\"$BASEDN\"..." >> $SEARCHOUT +$LDAPSEARCH -S "" -H $URI1 -b "$BASEDN" -M "(IsBusy=TRUE)" '*' ref \ + >> $SEARCHOUT 2>&1 +RC=$? +if test $RC != 0 ; then + echo "Search failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + + +echo "Filtering ldapsearch results..." +$LDIFFILTER < $SEARCHOUT > $SEARCHFLT +echo "Filtering partial ldif used to create database..." +$LDIFFILTER < data/test001-search_2.ldif > $LDIFFLT +echo "Comparing filter output..." +$CMP $SEARCHFLT $LDIFFLT > $CMPOUT + +if test $? != 0 ; then + echo "comparison failed - search for (IsBusy=TRUE) didn't succeed" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit 1 +fi + +echo "Modifying cn=config, setting olcReadOnly to True" +$LDAPMODIFY -v -D "cn=manager,cn=config" -H $URI1 -w $PASSWD \ + -M >> $TESTOUT 2>&1 << EOMODS +dn: olcDatabase={1}mdb,cn=config +changetype: modify +replace: olcReadOnly +olcReadOnly: True +EOMODS + +RC=$? +if test $RC != 0 ; then + echo "Modify failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +echo "Modifying database \"$BASEDN\" to verify olcReadOnly value" +$LDAPMODIFY -v -D "cn=Manager,$BASEDN" -H $URI1 -w $PASSWD \ + -M >> $TESTOUT 2>&1 << EOMODS +dn: cn=user06,ou=people,$BASEDN +changetype: modify +replace: IsBusy +IsBusy: false +EOMODS + +RC=$? +if test $RC != 53 ; then + echo "Modify failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +test $KILLSERVERS != no && kill -HUP $KILLPIDS + +echo ">>>>> Test succeeded" + +test $KILLSERVERS != no && wait + +exit 0 |