1#!/bin/sh 2# $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 2016-2021 Ondřej Kuzník, Symas Corp. 6## Copyright 2021 The OpenLDAP Foundation. 7## All rights reserved. 8## 9## Redistribution and use in source and binary forms, with or without 10## modification, are permitted only as authorized by the OpenLDAP 11## Public License. 12## 13## A copy of this license is available in the file LICENSE in the 14## top-level directory of the distribution or, alternatively, at 15## <http://www.OpenLDAP.org/license.html>. 16 17echo "running defines.sh" 18. $SRCDIR/scripts/defines.sh 19 20if test $OTP = otpno; then 21 echo "OTP overlay not available, test skipped" 22 exit 0 23fi 24 25for python in python3 python2 python2.7 python27 python ""; do 26 if test x"$python" = x; then 27 echo "Useable Python environment not found, skipping test" 28 exit 0 29 fi 30 31 "$python" "$0".py --check >>$TESTOUT 2>&1 32 RC=$? 33 case $RC in 34 0) 35 break;; 36 1) 37 echo "$python is missing some required modules, skipping" 38 python="" 39 continue;; 40 127) 41 ;; 42 esac 43done 44 45export URI1 MANAGERDN PASSWD BABSDN BJORNSDN 46 47OTP_DATA=$DATADIR/otp/totp.ldif 48 49mkdir -p $TESTDIR $DBDIR1 50 51echo "Running slapadd to build slapd database..." 52. $CONFFILTER $BACKEND < $CONF > $ADDCONF 53$SLAPADD -f $ADDCONF -l $LDIFORDERED 54RC=$? 55if test $RC != 0 ; then 56 echo "slapadd failed ($RC)!" 57 exit $RC 58fi 59 60mkdir $TESTDIR/confdir 61. $CONFFILTER $BACKEND < $CONF > $CONF1 62 63$SLAPPASSWD -g -n >$CONFIGPWF 64echo "database config" >>$CONF1 65echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF1 66 67echo "Starting slapd on TCP/IP port $PORT1..." 68$SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL > $LOG1 2>&1 & 69PID=$! 70if test $WAIT != 0 ; then 71 echo PID $PID 72 read foo 73fi 74KILLPIDS="$PID" 75 76sleep $SLEEP0 77 78for i in 0 1 2 3 4 5; do 79 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 80 'objectclass=*' > /dev/null 2>&1 81 RC=$? 82 if test $RC = 0 ; then 83 break 84 fi 85 echo "Waiting ${SLEEP1} seconds for slapd to start..." 86 sleep ${SLEEP1} 87done 88 89if [ "$OTP" = otpmod ]; then 90$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF \ 91 >> $TESTOUT 2>&1 <<EOMOD 92dn: cn=module,cn=config 93objectClass: olcModuleList 94cn: module 95olcModulePath: $TESTWD/../servers/slapd/overlays 96olcModuleLoad: otp.la 97EOMOD 98RC=$? 99if test $RC != 0 ; then 100 echo "ldapmodify failed ($RC)!" 101 test $KILLSERVERS != no && kill -HUP $KILLPIDS 102 exit $RC 103fi 104fi 105 106echo "Loading test otp configuration..." 107$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \ 108 >> $TESTOUT 2>&1 <<EOMOD 109dn: olcOverlay={0}otp,olcDatabase={1}$BACKEND,cn=config 110changetype: add 111objectClass: olcOverlayConfig 112EOMOD 113RC=$? 114if test $RC != 0 ; then 115 echo "ldapmodify failed ($RC)!" 116 test $KILLSERVERS != no && kill -HUP $KILLPIDS 117 exit $RC 118fi 119 120echo "Provisioning tokens and configuration..." 121$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 122 >> $TESTOUT 2>&1 < $OTP_DATA 123RC=$? 124if test $RC != 0 ; then 125 echo "ldapmodify failed ($RC)!" 126 test $KILLSERVERS != no && kill -HUP $KILLPIDS 127 exit $RC 128fi 129 130"$python" "$0".py 131RC=$? 132 133test $KILLSERVERS != no && kill -HUP $KILLPIDS 134 135if test $RC != 0 ; then 136 echo "Test failed ($RC)!" 137else 138 echo ">>>>> Test succeeded" 139fi 140 141test $KILLSERVERS != no && wait 142 143exit $RC 144