]> git.sur5r.net Git - openldap/blob - tests/scripts/test024-unique
sync with head
[openldap] / tests / scripts / test024-unique
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2004-2005 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 $UNIQUE = uniqueno; then 
20         echo "Attribute Uniqueness overlay not available, test skipped"
21         exit 0
22 fi 
23
24 mkdir -p $TESTDIR $DBDIR1
25
26 echo "Running slapadd to build slapd database..."
27 . $CONFFILTER $BACKEND $MONITORDB < $UNIQUECONF > $CONF1
28 $SLAPADD -f $CONF1 -l $LDIFUNIQUE
29 RC=$?
30 if test $RC != 0 ; then
31         echo "slapadd failed ($RC)!"
32         exit $RC
33 fi
34
35 echo "Starting slapd on TCP/IP port $PORT1..."
36 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
37 PID=$!
38 if test $WAIT != 0 ; then
39     echo PID $PID
40     read foo
41 fi
42 KILLPIDS="$PID"
43
44 sleep 1
45
46 echo "Testing slapd attribute uniqueness operations..."
47 for i in 0 1 2 3 4 5; do
48         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
49                 'objectclass=*' > /dev/null 2>&1
50         RC=$?
51         if test $RC = 0 ; then
52                 break
53         fi
54         echo "Waiting 5 seconds for slapd to start..."
55         sleep 5
56 done
57
58 if test $RC != 0 ; then
59         echo "ldapsearch failed ($RC)!"
60         test $KILLSERVERS != no && kill -HUP $KILLPIDS
61         exit $RC
62 fi
63
64 echo "Adding a unique record..."
65
66 #$LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
67 #       $TESTOUT 2>&1 << EOTUNIQ1
68 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
69         > /dev/null << EOTUNIQ1
70 dn: uid=dave,ou=users,o=unique
71 objectClass: inetOrgPerson
72 uid: dave
73 sn: nothere
74 cn: dave
75 businessCategory: otest
76 carLicense: TEST
77 departmentNumber: 42
78 displayName: Dave
79 employeeNumber: 69
80 employeeType: contractor
81 givenName: Dave
82 EOTUNIQ1
83
84 RC=$?
85 if test $RC != 0 ; then
86         echo "ldapadd failed ($RC)!"
87         test $KILLSERVERS != no && kill -HUP $KILLPIDS
88         exit $RC
89 fi
90
91 #echo ----------------------
92 #$LDAPSEARCH -S "" -b "o=unique" -h $LOCALHOST -p $PORT1
93
94 echo "Adding a non-unique record..."
95
96 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
97          $TESTOUT 2>&1 << EOTUNIQ2
98 dn: uid=bill,ou=users,o=unique
99 objectClass: inetOrgPerson
100 uid: bill
101 sn: johnson
102 cn: bill
103 businessCategory: rtest
104 carLicense: ABC123
105 departmentNumber: 42
106 displayName: Bill
107 employeeNumber: 5150
108 employeeType: contractor
109 givenName: Bill
110 EOTUNIQ2
111
112 RC=$?
113 if test $RC != 19 ; then
114         echo "unique check failed ($RC)!"
115         test $KILLSERVERS != no && kill -HUP $KILLPIDS
116         exit -1
117 fi
118
119
120 #echo ----------------------
121 #$LDAPSEARCH -S "" -b "o=unique" -h $LOCALHOST -p $PORT1
122
123
124
125 test $KILLSERVERS != no && kill -HUP $KILLPIDS
126
127 echo ">>>>> Test succeeded"
128 exit 0