#!/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 2004/10/07 05:59:52 taru Exp $

set -e

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

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

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

EOF

ldapadd -x -w $ROOTPW -D $ROOTDN -h $HOST -f $TMPFILE
ldapsearch -x -w $ROOTPW -LLL -D $ROOTDN -h $HOST -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

ldapadd -x -w $ROOTPW -D $ROOTDN -h $HOST -f $TMPFILE

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

ldapmodify -x -w $ROOTPW -D $ROOTDN -h $HOST -f $TMPFILE 
ldapsearch -x -L -b $TESTSUFFIX -h $HOST -D "cn=people,$TESTSUFFIX" -w new cn=people userPassword

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

ldapdelete -x -h $HOST -w $ROOTPW -D $ROOTDN "ou=add,$TESTSUFFIX" "cn=people,$TESTSUFFIX"

