1 #!/bin/sh 2 # $OpenLDAP$ 3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4 ## 5 ## Copyright 2016-2021 Ondej Kuznk, Symas Corp. 6 ## Copyright 2021-2024 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 17 echo "running defines.sh" 18 . $SRCDIR/scripts/defines.sh 19 20 if test $OTP = otpno; then 21 echo "OTP overlay not available, test skipped" 22 exit 0 23 fi 24 25 export URI1 MANAGERDN PASSWD BABSDN BJORNSDN 26 27 OTP_DATA=$DATADIR/otp/totp.ldif 28 29 mkdir -p $TESTDIR $DBDIR1 30 31 for python in python3 python2 python2.7 python27 python ""; do 32 if test x"$python" = x; then 33 echo "Useable Python environment not found, skipping test" 34 exit 0 35 fi 36 37 "$python" "$0".py --check >>$TESTOUT 2>&1 38 RC=$? 39 case $RC in 40 0) 41 break;; 42 1) 43 echo "$python is missing some required modules, skipping" 44 python="" 45 continue;; 46 127) 47 ;; 48 esac 49 done 50 51 echo "Running slapadd to build slapd database..." 52 . $CONFFILTER $BACKEND < $CONF > $ADDCONF 53 $SLAPADD -f $ADDCONF -l $LDIFORDERED 54 RC=$? 55 if test $RC != 0 ; then 56 echo "slapadd failed ($RC)!" 57 exit $RC 58 fi 59 60 mkdir $TESTDIR/confdir 61 . $CONFFILTER $BACKEND < $CONF > $CONF1 62 63 $SLAPPASSWD -g -n >$CONFIGPWF 64 echo "database config" >>$CONF1 65 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF1 66 67 echo "Starting slapd on TCP/IP port $PORT1..." 68 $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL > $LOG1 2>&1 & 69 PID=$! 70 if test $WAIT != 0 ; then 71 echo PID $PID 72 read foo 73 fi 74 KILLPIDS="$PID" 75 76 sleep $SLEEP0 77 78 for 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} 87 done 88 89 if [ "$OTP" = otpmod ]; then 90 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF \ 91 >> $TESTOUT 2>&1 <<EOMOD 92 dn: cn=module,cn=config 93 objectClass: olcModuleList 94 cn: module 95 olcModulePath: $TESTWD/../servers/slapd/overlays 96 olcModuleLoad: otp.la 97 EOMOD 98 RC=$? 99 if test $RC != 0 ; then 100 echo "ldapmodify failed ($RC)!" 101 test $KILLSERVERS != no && kill -HUP $KILLPIDS 102 exit $RC 103 fi 104 fi 105 106 echo "Loading test otp configuration..." 107 $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \ 108 >> $TESTOUT 2>&1 <<EOMOD 109 dn: olcOverlay={0}otp,olcDatabase={1}$BACKEND,cn=config 110 changetype: add 111 objectClass: olcOverlayConfig 112 EOMOD 113 RC=$? 114 if test $RC != 0 ; then 115 echo "ldapmodify failed ($RC)!" 116 test $KILLSERVERS != no && kill -HUP $KILLPIDS 117 exit $RC 118 fi 119 120 echo "Provisioning tokens and configuration..." 121 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 122 >> $TESTOUT 2>&1 < $OTP_DATA 123 RC=$? 124 if test $RC != 0 ; then 125 echo "ldapmodify failed ($RC)!" 126 test $KILLSERVERS != no && kill -HUP $KILLPIDS 127 exit $RC 128 fi 129 130 "$python" "$0".py 131 RC=$? 132 133 test $KILLSERVERS != no && kill -HUP $KILLPIDS 134 135 if test $RC != 0 ; then 136 echo "Test failed ($RC)!" 137 else 138 echo ">>>>> Test succeeded" 139 fi 140 141 test $KILLSERVERS != no && wait 142 143 exit $RC 144