Home | History | Annotate | Line # | Download | only in scripts
test083-argon2 revision 1.1
      1 #!/bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 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 echo "running defines.sh"
     17 . $SRCDIR/scripts/defines.sh
     18 
     19 if test $ARGON2 = argon2no; then
     20 	echo "argon2 overlay not available, test skipped"
     21 	exit 0
     22 fi
     23 
     24 USERDN="cn=argon2,$BASEDN"
     25 
     26 CONFDIR=$TESTDIR/slapd.d
     27 mkdir -p $TESTDIR $CONFDIR $DBDIR1
     28 
     29 $SLAPPASSWD -g -n >$CONFIGPWF
     30 
     31 cat > $TESTDIR/config.ldif <<EOF
     32 dn: cn=config
     33 objectClass: olcGlobal
     34 cn: config
     35 olcArgsFile: $TESTDIR/slapd.args
     36 olcPidFile: $TESTDIR/slapd.pid
     37 
     38 dn: cn=schema,cn=config
     39 objectClass: olcSchemaConfig
     40 cn: schema
     41 
     42 include: file://$TESTWD/schema/core.ldif
     43 include: file://$TESTWD/schema/cosine.ldif
     44 include: file://$TESTWD/schema/inetorgperson.ldif
     45 EOF
     46 
     47 if [ "$BACKENDTYPE" = mod ]; then
     48 	cat >> $TESTDIR/config.ldif <<EOF
     49 
     50 dn: cn=module,cn=config
     51 objectClass: olcModuleList
     52 cn: module
     53 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
     54 olcModuleLoad: back_$BACKEND.la
     55 EOF
     56 fi
     57 
     58 if [ "$ARGON2" = argon2yes ]; then
     59 	cat >> $TESTDIR/config.ldif <<EOF
     60 
     61 dn: cn=module,cn=config
     62 objectClass: olcModuleList
     63 cn: module
     64 olcModulePath: $TESTWD/../servers/slapd/pwmods
     65 olcModuleLoad: argon2.la
     66 EOF
     67 fi
     68 
     69 cat >> $TESTDIR/config.ldif <<EOF
     70 
     71 dn: olcDatabase={-1}frontend,cn=config
     72 objectClass: olcDatabaseConfig
     73 objectClass: olcFrontendConfig
     74 olcDatabase: {-1}frontend
     75 olcPasswordHash: {ARGON2}
     76 
     77 dn: olcDatabase=config,cn=config
     78 objectClass: olcDatabaseConfig
     79 olcDatabase: config
     80 olcRootPW:< file://$CONFIGPWF
     81 
     82 dn: olcDatabase={1}$BACKEND,cn=config
     83 objectClass: olcDatabaseConfig
     84 objectClass: olc${BACKEND}Config
     85 olcDatabase: $BACKEND
     86 olcSuffix: $BASEDN
     87 olcRootDN: $MANAGERDN
     88 olcRootPW: $PASSWD
     89 olcDbDirectory: $TESTDIR/db.1.a
     90 EOF
     91 
     92 if [ "$INDEXDB" = indexdb ]; then
     93 	cat >> $TESTDIR/config.ldif <<EOF
     94 olcDbIndex: objectClass eq,pres
     95 olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
     96 EOF
     97 fi
     98 
     99 $SLAPADD -F $CONFDIR -n 0 -l $TESTDIR/config.ldif
    100 
    101 echo "Starting slapd on TCP/IP port $PORT1..."
    102 $SLAPD -F $CONFDIR -h $URI1 -d $LVL > $LOG1 2>&1 &
    103 PID=$!
    104 if test $WAIT != 0 ; then
    105 	echo PID $PID
    106 	read foo
    107 fi
    108 KILLPIDS="$PID"
    109 sleep 1
    110 
    111 echo "Using ldapsearch to check that slapd is running..."
    112 for i in 0 1 2 3 4 5; do
    113 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
    114 		'objectclass=*' > /dev/null 2>&1
    115 	RC=$?
    116 	if test $RC = 0 ; then
    117 		break
    118 	fi
    119 	echo "Waiting 5 seconds for slapd to start..."
    120 	sleep 5
    121 done
    122 if test $RC != 0 ; then
    123 	echo "ldapsearch failed ($RC)!"
    124 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    125 	exit $RC
    126 fi
    127 
    128 echo "Adding basic structure..."
    129 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFPASSWD >/dev/null 2>&1
    130 RC=$?
    131 if test $RC != 0 ; then
    132 	echo "ldapadd failed ($RC)!"
    133 	test $KILLSERVERS != no && kill -HUP $PID
    134 	exit $RC
    135 fi
    136 
    137 BINDPW=secret
    138 echo "Testing ldapwhoami as ${USERDN}..."
    139 $LDAPWHOAMI -H $URI1 -D "$USERDN" -w $BINDPW
    140 
    141 RC=$?
    142 if test $RC != 0 ; then
    143     echo "ldapwhoami failed ($RC)!"
    144     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    145     exit $RC
    146 fi
    147 
    148 test $KILLSERVERS != no && kill -HUP $PID
    149 
    150 echo ">>>>> Test succeeded"
    151 
    152 test $KILLSERVERS != no && wait
    153 
    154 exit 0
    155