Home | History | Annotate | Line # | Download | only in scripts
      1      1.1  christos #! /bin/sh
      2      1.1  christos # $OpenLDAP$
      3      1.1  christos ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4      1.1  christos ##
      5      1.1  christos ## Copyright 2016-2021 Ondej Kuznk, Symas Corp.
      6  1.1.1.2  christos ## Copyright 1998-2024 The OpenLDAP Foundation.
      7      1.1  christos ## All rights reserved.
      8      1.1  christos ##
      9      1.1  christos ## Redistribution and use in source and binary forms, with or without
     10      1.1  christos ## modification, are permitted only as authorized by the OpenLDAP
     11      1.1  christos ## Public License.
     12      1.1  christos ##
     13      1.1  christos ## A copy of this license is available in the file LICENSE in the
     14      1.1  christos ## top-level directory of the distribution or, alternatively, at
     15      1.1  christos ## <http://www.OpenLDAP.org/license.html>.
     16      1.1  christos 
     17      1.1  christos echo "running defines.sh"
     18      1.1  christos . $SRCDIR/scripts/defines.sh
     19      1.1  christos 
     20      1.1  christos if test $WITH_TLS = no ; then
     21      1.1  christos     echo "TLS support not available, test skipped"
     22      1.1  christos     exit 0
     23      1.1  christos fi
     24      1.1  christos 
     25      1.1  christos if test $REMOTEAUTH = remoteauthno; then
     26      1.1  christos     echo "RemoteAuth overlay not available, test skipped"
     27      1.1  christos     exit 0
     28      1.1  christos fi
     29      1.1  christos 
     30      1.1  christos mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $TESTDIR/confdir
     31      1.1  christos cp -r $DATADIR/tls $TESTDIR
     32      1.1  christos 
     33      1.1  christos . $CONFFILTER < $DATADIR/remoteauth/default_domain > $TESTDIR/default_domain
     34      1.1  christos 
     35      1.1  christos . $CONFFILTER $BACKEND < $TLSCONF > $CONF1
     36      1.1  christos 
     37      1.1  christos $SLAPPASSWD -g -n >$CONFIGPWF
     38      1.1  christos echo "database config" >>$CONF1
     39      1.1  christos echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF1
     40      1.1  christos echo "TLSCACertificateFile $TESTDIR/tls/ca/certs/testsuiteCA.crt" >>$CONF1
     41      1.1  christos 
     42      1.1  christos $SLAPD -Tt -n 0 -f $CONF1 -F $TESTDIR/confdir -d $LVL > $LOG1 2>&1
     43      1.1  christos RC=$?
     44      1.1  christos if test $RC != 0 ; then
     45      1.1  christos     echo "slaptest failed ($RC)!"
     46      1.1  christos     exit $RC
     47      1.1  christos fi
     48      1.1  christos 
     49      1.1  christos echo -n "Running slapadd to build slapd database... "
     50      1.1  christos $SLAPADD -F $TESTDIR/confdir -l $LDIFORDERED
     51      1.1  christos RC=$?
     52      1.1  christos if test $RC != 0 ; then
     53      1.1  christos     echo "slapadd failed ($RC)!"
     54      1.1  christos     exit $RC
     55      1.1  christos fi
     56      1.1  christos 
     57      1.1  christos echo "DB tweaks..."
     58      1.1  christos $SLAPMODIFY -F $TESTDIR/confdir >>$LOG1 2>&1 <<EOMODS
     59      1.1  christos dn: $MELLIOTDN
     60      1.1  christos changetype: modify
     61      1.1  christos add: o
     62      1.1  christos o: self
     63      1.1  christos -
     64      1.1  christos replace: seeAlso
     65      1.1  christos seeAlso: $BJORNSDN
     66      1.1  christos 
     67      1.1  christos dn: $JOHNDDN
     68      1.1  christos changetype: modify
     69      1.1  christos replace: seeAlso
     70      1.1  christos seeAlso: $BJORNSDN
     71      1.1  christos EOMODS
     72      1.1  christos RC=$?
     73      1.1  christos if test $RC != 0 ; then
     74      1.1  christos     echo "slapmodify failed ($RC)!"
     75      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
     76      1.1  christos     exit $RC
     77      1.1  christos fi
     78      1.1  christos 
     79      1.1  christos echo "Starting slapd on TCP/IP port $PORT1 for configuration..."
     80      1.1  christos $SLAPD -F $TESTDIR/confdir -h $URI1 -d $LVL >> $LOG1 2>&1 &
     81      1.1  christos REMOTEAUTH_PID=$!
     82      1.1  christos if test $WAIT != 0 ; then
     83      1.1  christos     echo REMOTEAUTH_PID $REMOTEAUTH_PID
     84      1.1  christos     read foo
     85      1.1  christos fi
     86      1.1  christos KILLPIDS="$REMOTEAUTH_PID"
     87      1.1  christos 
     88      1.1  christos sleep $SLEEP0
     89      1.1  christos 
     90      1.1  christos for i in 0 1 2 3 4 5; do
     91      1.1  christos     $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
     92      1.1  christos         'objectclass=*' > /dev/null 2>&1
     93      1.1  christos     RC=$?
     94      1.1  christos     if test $RC = 0 ; then
     95      1.1  christos         break
     96      1.1  christos     fi
     97      1.1  christos     echo "Waiting ${SLEEP1} seconds for slapd to start..."
     98      1.1  christos     sleep ${SLEEP1}
     99      1.1  christos done
    100      1.1  christos 
    101      1.1  christos if [ "$REMOTEAUTH" = remoteauthmod ]; then
    102      1.1  christos $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF \
    103      1.1  christos     >> $TESTOUT 2>&1 <<EOMOD
    104      1.1  christos dn: cn=module,cn=config
    105      1.1  christos objectClass: olcModuleList
    106      1.1  christos cn: module
    107      1.1  christos olcModulePath: $TESTWD/../servers/slapd/overlays
    108      1.1  christos olcModuleLoad: remoteauth.la
    109      1.1  christos EOMOD
    110      1.1  christos RC=$?
    111      1.1  christos if test $RC != 0 ; then
    112      1.1  christos     echo "ldapmodify failed ($RC)!"
    113      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    114      1.1  christos     exit $RC
    115      1.1  christos fi
    116      1.1  christos fi
    117      1.1  christos 
    118      1.1  christos echo "Loading test remoteauth configuration..."
    119      1.1  christos . $CONFFILTER $BACKEND < $DATADIR/remoteauth/config.ldif | \
    120      1.1  christos $LDAPADD -v -D cn=config -H $URI1 -y $CONFIGPWF \
    121      1.1  christos     >> $TESTOUT 2>&1
    122      1.1  christos RC=$?
    123      1.1  christos if test $RC != 0 ; then
    124      1.1  christos     echo "ldapadd failed ($RC)!"
    125      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    126      1.1  christos     exit $RC
    127      1.1  christos fi
    128      1.1  christos 
    129      1.1  christos echo -n "Preparing second server on $URI2 and $SURIP3... "
    130      1.1  christos . $CONFFILTER $BACKEND < $TLSCONF | sed -e "s,$DBDIR1,$DBDIR2," > $CONF2
    131      1.1  christos 
    132      1.1  christos echo -n "loading data... "
    133      1.1  christos $SLAPADD -f $CONF2 -l $LDIFORDERED
    134      1.1  christos RC=$?
    135      1.1  christos if test $RC != 0 ; then
    136      1.1  christos     echo "slapadd failed ($RC)!"
    137      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    138      1.1  christos     exit $RC
    139      1.1  christos fi
    140      1.1  christos 
    141      1.1  christos echo -n "tweaking DB contents... "
    142      1.1  christos $SLAPMODIFY -f $CONF2 >>$LOG2 2>&1 <<EOMODS
    143      1.1  christos dn: $BJORNSDN
    144      1.1  christos changetype: modify
    145      1.1  christos replace: userPassword
    146      1.1  christos userPassword: bjorn2
    147      1.1  christos EOMODS
    148      1.1  christos RC=$?
    149      1.1  christos if test $RC != 0 ; then
    150      1.1  christos     echo "slapmodify failed ($RC)!"
    151      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    152      1.1  christos     exit $RC
    153      1.1  christos fi
    154      1.1  christos 
    155      1.1  christos echo "starting up... "
    156      1.1  christos $SLAPD -f $CONF2 -h "$URI2 $SURIP3" -d $LVL > $LOG2 2>&1 &
    157      1.1  christos BACKEND_PID=$!
    158      1.1  christos if test $WAIT != 0 ; then
    159      1.1  christos     echo BACKEND_PID $BACKEND_PID
    160      1.1  christos     read foo
    161      1.1  christos fi
    162      1.1  christos KILLPIDS="$KILLPIDS $BACKEND_PID"
    163      1.1  christos 
    164      1.1  christos for i in 0 1 2 3 4 5; do
    165      1.1  christos     $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
    166      1.1  christos         'objectclass=*' > /dev/null 2>&1
    167      1.1  christos     RC=$?
    168      1.1  christos     if test $RC = 0 ; then
    169      1.1  christos         break
    170      1.1  christos     fi
    171      1.1  christos     echo "Waiting ${SLEEP1} seconds for slapd to start..."
    172      1.1  christos     sleep ${SLEEP1}
    173      1.1  christos done
    174      1.1  christos 
    175      1.1  christos if test $RC != 0 ; then
    176      1.1  christos     echo "failed ($RC)!"
    177      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    178      1.1  christos     exit $RC
    179      1.1  christos fi
    180      1.1  christos 
    181      1.1  christos . $CONFFILTER $BACKEND < $TLSCONF > $CONF1
    182      1.1  christos 
    183      1.1  christos echo "TLSCACertificateFile $TESTDIR/tls/ca/certs/testsuiteCA.crt" >>$CONF1
    184      1.1  christos echo "database config" >>$CONF1
    185      1.1  christos echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF1
    186      1.1  christos 
    187      1.1  christos # We check basic remoteauth operation and generated configuration in these
    188      1.1  christos # circumstances:
    189      1.1  christos # 1. configured online through cn=config (what we set up above)
    190      1.1  christos # 2. the server from 1. restarted (loading from cn=config on startup)
    191      1.1  christos # 3. configured and started through a slapd.conf
    192      1.1  christos #
    193      1.1  christos # All of the above should present the same behaviour and cn=config output
    194      1.1  christos 
    195      1.1  christos echo "Saving generated config before server restart..."
    196      1.1  christos echo "# search output from dynamically configured server..." >> $SERVER1OUT
    197      1.1  christos $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF \
    198      1.1  christos     -b "olcOverlay={0}remoteauth,olcDatabase={1}$BACKEND,cn=config" \
    199      1.1  christos     >> $SERVER1OUT 2>&1
    200      1.1  christos RC=$?
    201      1.1  christos if test $RC != 0 ; then
    202      1.1  christos     echo "ldapsearch failed ($RC)!"
    203      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    204      1.1  christos     exit $RC
    205      1.1  christos fi
    206      1.1  christos 
    207      1.1  christos echo -n "Checking bind handling... "
    208      1.1  christos 
    209      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$BJORNSDN" -w bjorn >/dev/null
    210      1.1  christos RC=$?
    211      1.1  christos if test $RC != 0 ; then
    212      1.1  christos     echo "ldapwhoami failed ($RC)!"
    213      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    214      1.1  christos     exit $RC
    215      1.1  christos fi
    216      1.1  christos echo -n "1 "
    217      1.1  christos 
    218      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$JOHNDDN" -w bjorn2 >/dev/null
    219      1.1  christos RC=$?
    220      1.1  christos if test $RC != 0 ; then
    221      1.1  christos     echo "ldapwhoami failed ($RC)!"
    222      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    223      1.1  christos     exit $RC
    224      1.1  christos fi
    225      1.1  christos echo -n "2 "
    226      1.1  christos 
    227      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$MELLIOTDN" -w bjorn >/dev/null
    228      1.1  christos RC=$?
    229      1.1  christos if test $RC != 0 ; then
    230      1.1  christos     echo "ldapwhoami failed ($RC)!"
    231      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    232      1.1  christos     exit $RC
    233      1.1  christos fi
    234      1.1  christos echo -n "3 "
    235      1.1  christos 
    236      1.1  christos echo "ok"
    237      1.1  christos 
    238      1.1  christos echo "Stopping slapd on TCP/IP port $PORT1..."
    239      1.1  christos kill -HUP $REMOTEAUTH_PID
    240      1.1  christos KILLPIDS="$BACKEND_PID"
    241      1.1  christos sleep $SLEEP0
    242      1.1  christos echo "Starting slapd on TCP/IP port $PORT1..."
    243      1.1  christos $SLAPD -F $TESTDIR/confdir -h $URI1 -d $LVL >> $LOG1 2>&1 &
    244      1.1  christos REMOTEAUTH_PID=$!
    245      1.1  christos if test $WAIT != 0 ; then
    246      1.1  christos     echo REMOTEAUTH_PID $REMOTEAUTH_PID
    247      1.1  christos     read foo
    248      1.1  christos fi
    249      1.1  christos KILLPIDS="$KILLPIDS $REMOTEAUTH_PID"
    250      1.1  christos 
    251      1.1  christos sleep $SLEEP0
    252      1.1  christos 
    253      1.1  christos for i in 0 1 2 3 4 5; do
    254      1.1  christos     $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
    255      1.1  christos         'objectclass=*' > /dev/null 2>&1
    256      1.1  christos     RC=$?
    257      1.1  christos     if test $RC = 0 ; then
    258      1.1  christos         break
    259      1.1  christos     fi
    260      1.1  christos     echo "Waiting ${SLEEP1} seconds for slapd to start..."
    261      1.1  christos     sleep ${SLEEP1}
    262      1.1  christos done
    263      1.1  christos 
    264      1.1  christos echo "Saving generated config after server restart..."
    265      1.1  christos echo "# search output from dynamically configured server after restart..." >> $SERVER2OUT
    266      1.1  christos $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF \
    267      1.1  christos     -b "olcOverlay={0}remoteauth,olcDatabase={1}$BACKEND,cn=config" \
    268      1.1  christos     >> $SERVER2OUT 2>&1
    269      1.1  christos RC=$?
    270      1.1  christos if test $RC != 0 ; then
    271      1.1  christos     echo "ldapsearch failed ($RC)!"
    272      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    273      1.1  christos     exit $RC
    274      1.1  christos fi
    275      1.1  christos 
    276      1.1  christos echo -n "Checking bind handling... "
    277      1.1  christos 
    278      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$BJORNSDN" -w bjorn >/dev/null
    279      1.1  christos RC=$?
    280      1.1  christos if test $RC != 0 ; then
    281      1.1  christos     echo "ldapwhoami failed ($RC)!"
    282      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    283      1.1  christos     exit $RC
    284      1.1  christos fi
    285      1.1  christos echo -n "1 "
    286      1.1  christos 
    287      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$JOHNDDN" -w bjorn2 >/dev/null
    288      1.1  christos RC=$?
    289      1.1  christos if test $RC != 0 ; then
    290      1.1  christos     echo "ldapwhoami failed ($RC)!"
    291      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    292      1.1  christos     exit $RC
    293      1.1  christos fi
    294      1.1  christos echo -n "2 "
    295      1.1  christos 
    296      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$MELLIOTDN" -w bjorn >/dev/null
    297      1.1  christos RC=$?
    298      1.1  christos if test $RC != 0 ; then
    299      1.1  christos     echo "ldapwhoami failed ($RC)!"
    300      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    301      1.1  christos     exit $RC
    302      1.1  christos fi
    303      1.1  christos echo -n "3 "
    304      1.1  christos 
    305      1.1  christos echo "ok"
    306      1.1  christos 
    307      1.1  christos echo "Stopping slapd on TCP/IP port $PORT1..."
    308      1.1  christos kill -HUP $REMOTEAUTH_PID
    309      1.1  christos KILLPIDS="$BACKEND_PID"
    310      1.1  christos sleep $SLEEP0
    311      1.1  christos 
    312      1.1  christos echo "Testing slapd.conf support..."
    313  1.1.1.2  christos sed -e "s,database.*monitor,\\
    314      1.1  christos TLSCACertificateFile $TESTDIR/tls/ca/certs/testsuiteCA.crt\\
    315      1.1  christos \\
    316      1.1  christos #remoteauthmod#moduleload ../servers/slapd/overlays/remoteauth.la\\
    317      1.1  christos include $TESTDIR/remoteauth.conf\\
    318      1.1  christos \\
    319      1.1  christos database monitor," $TLSCONF | . $CONFFILTER $BACKEND >$CONF1
    320      1.1  christos echo "database config" >>$CONF1
    321      1.1  christos echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF1
    322      1.1  christos 
    323      1.1  christos . $CONFFILTER $BACKEND < $DATADIR/remoteauth/remoteauth.conf >$TESTDIR/remoteauth.conf
    324      1.1  christos 
    325      1.1  christos echo "Starting slapd on TCP/IP port $PORT1..."
    326      1.1  christos $SLAPD -f $CONF1 -h $URI1 -d $LVL >> $LOG1 2>&1 &
    327      1.1  christos REMOTEAUTH_PID=$!
    328      1.1  christos if test $WAIT != 0 ; then
    329      1.1  christos     echo REMOTEAUTH_PID $REMOTEAUTH_PID
    330      1.1  christos     read foo
    331      1.1  christos fi
    332      1.1  christos KILLPIDS="$KILLPIDS $REMOTEAUTH_PID"
    333      1.1  christos 
    334      1.1  christos sleep $SLEEP0
    335      1.1  christos 
    336      1.1  christos for i in 0 1 2 3 4 5; do
    337      1.1  christos     $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
    338      1.1  christos         'objectclass=*' > /dev/null 2>&1
    339      1.1  christos     RC=$?
    340      1.1  christos     if test $RC = 0 ; then
    341      1.1  christos         break
    342      1.1  christos     fi
    343      1.1  christos     echo "Waiting ${SLEEP1} seconds for slapd to start..."
    344      1.1  christos     sleep ${SLEEP1}
    345      1.1  christos done
    346      1.1  christos 
    347      1.1  christos echo "Saving generated config from a slapd.conf sourced server..."
    348      1.1  christos echo "# search output from server running from slapd.conf..." >> $SERVER3OUT
    349      1.1  christos $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF \
    350      1.1  christos     -b "olcOverlay={0}remoteauth,olcDatabase={1}$BACKEND,cn=config" \
    351      1.1  christos     >> $SERVER3OUT 2>&1
    352      1.1  christos RC=$?
    353      1.1  christos if test $RC != 0 ; then
    354      1.1  christos     echo "ldapsearch failed ($RC)!"
    355      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    356      1.1  christos     exit $RC
    357      1.1  christos fi
    358      1.1  christos 
    359      1.1  christos echo -n "Checking bind handling... "
    360      1.1  christos 
    361      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$BJORNSDN" -w bjorn >/dev/null
    362      1.1  christos RC=$?
    363      1.1  christos if test $RC != 0 ; then
    364      1.1  christos     echo "ldapwhoami failed ($RC)!"
    365      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    366      1.1  christos     exit $RC
    367      1.1  christos fi
    368      1.1  christos echo -n "1 "
    369      1.1  christos 
    370      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$JOHNDDN" -w bjorn2 >/dev/null
    371      1.1  christos RC=$?
    372      1.1  christos if test $RC != 0 ; then
    373      1.1  christos     echo "ldapwhoami failed ($RC)!"
    374      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    375      1.1  christos     exit $RC
    376      1.1  christos fi
    377      1.1  christos echo -n "2 "
    378      1.1  christos 
    379      1.1  christos $LDAPWHOAMI -H $URI1 -x -D "$MELLIOTDN" -w bjorn >/dev/null
    380      1.1  christos RC=$?
    381      1.1  christos if test $RC != 0 ; then
    382      1.1  christos     echo "ldapwhoami failed ($RC)!"
    383      1.1  christos     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    384      1.1  christos     exit $RC
    385      1.1  christos fi
    386      1.1  christos echo -n "3 "
    387      1.1  christos 
    388      1.1  christos echo "ok"
    389      1.1  christos 
    390      1.1  christos test $KILLSERVERS != no && kill -HUP $KILLPIDS
    391      1.1  christos 
    392      1.1  christos # LDIFFILTER doesn't (un)wrap long lines yet, so the result would differ
    393      1.1  christos #. $CONFFILTER $BACKEND < $DATADIR/remoteauth/config.ldif \
    394      1.1  christos #    | $LDIFFILTER -s a > $SERVER6FLT
    395      1.1  christos 
    396      1.1  christos # We've already filtered out the ordering markers, now sort the entries
    397      1.1  christos echo "Filtering ldapsearch results..."
    398      1.1  christos $LDIFFILTER -s a < $SERVER1OUT > $SERVER1FLT
    399      1.1  christos $LDIFFILTER -s a < $SERVER2OUT > $SERVER2FLT
    400      1.1  christos $LDIFFILTER -s a < $SERVER3OUT > $SERVER3FLT
    401      1.1  christos echo "Filtering expected entries..."
    402      1.1  christos 
    403      1.1  christos echo "Comparing filter output..."
    404      1.1  christos #$CMP $SERVER6FLT $SERVER1FLT > $CMPOUT && \
    405      1.1  christos $CMP $SERVER1FLT $SERVER2FLT > $CMPOUT && \
    406      1.1  christos $CMP $SERVER2FLT $SERVER3FLT > $CMPOUT
    407      1.1  christos 
    408      1.1  christos if test $? != 0 ; then
    409      1.1  christos 	echo "Comparison failed"
    410      1.1  christos 	exit 1
    411      1.1  christos fi
    412      1.1  christos 
    413      1.1  christos echo ">>>>> Test succeeded"
    414      1.1  christos 
    415      1.1  christos test $KILLSERVERS != no && wait
    416      1.1  christos 
    417      1.1  christos exit 0
    418