#!/usr/bin/env bash
#
# Sample Test Script for UltraPossum
#
#  Add a simple entry to the directory and check whether
#  it can be searched.
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#

# $Id: 00protocol,v 1.4.2.1 2005/02/21 04:22:49 taru Exp $

set -e

if test "x$DEBUG" != "x"; then
  set -x
fi

modify()
{
  ( for i in 1 2 3 4 5 6 7 8 9 10
      do
        $1 -x -w $ROOTPW -D $ROOTDN -h $LDAPMASTER -f $TMPFILE && exit 0
        sleep $i
     done
     exit 1
  ) || exit 1
}


########### Add Test

cat >$TMPFILE <<EOF
dn: ou=add,$TESTSUFFIX
objectClass: top
objectClass: organizationalUnit
ou: add

EOF

modify ldapadd
ldapsearch -x -w $ROOTPW -LLL -D $ROOTDN -h $LDAPMASTER -b $TESTSUFFIX ou=add | diff -c $TMPFILE -

############ Modify Test

cat >$TMPFILE <<EOF
dn: cn=people,$TESTSUFFIX
objectClass: top
objectClass: person
cn: people
userPassword: old
sn: people
EOF

modify ldapadd

# modify data
cat >$TMPFILE <<EOF
dn: cn=people,$TESTSUFFIX
changetype: modify
replace: userPassword
userPassword: new
EOF

modify ldapmodify
ldapsearch -x -L -b $TESTSUFFIX -h $LDAPMASTER -D "cn=people,$TESTSUFFIX" -w new cn=people userPassword

############# Delete Test

cat >$TMPFILE <<EOF
cn=people,$TESTSUFFIX
EOF

modify ldapdelete

