]> git.sur5r.net Git - openldap/blob - tests/scripts/test024-unique
308ef3a8933e03994c61e18c6c52c8de7232f140
[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-2007 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 # NOTE: use special chars in attr value to be used
79 # in internal searches ITS#4212
80 displayName: Dave (ITS#4212)
81 employeeNumber: 69
82 employeeType: contractor
83 givenName: Dave
84 EOTUNIQ1
85
86 RC=$?
87 if test $RC != 0 ; then
88         echo "ldapadd failed ($RC)!"
89         test $KILLSERVERS != no && kill -HUP $KILLPIDS
90         exit $RC
91 fi
92
93 #echo ----------------------
94 #$LDAPSEARCH -S "" -b "o=unique" -h $LOCALHOST -p $PORT1
95
96 echo "Adding a non-unique record..."
97
98 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
99          $TESTOUT 2>&1 << EOTUNIQ2
100 dn: uid=bill,ou=users,o=unique
101 objectClass: inetOrgPerson
102 uid: bill
103 sn: johnson
104 cn: bill
105 businessCategory: rtest
106 carLicense: ABC123
107 departmentNumber: 42
108 displayName: Bill
109 employeeNumber: 5150
110 employeeType: contractor
111 givenName: Bill
112 EOTUNIQ2
113
114 RC=$?
115 if test $RC != 19 ; then
116         echo "unique check failed ($RC)!"
117         test $KILLSERVERS != no && kill -HUP $KILLPIDS
118         exit -1
119 fi
120
121
122 #echo ----------------------
123 #$LDAPSEARCH -S "" -b "o=unique" -h $LOCALHOST -p $PORT1
124
125
126
127 test $KILLSERVERS != no && kill -HUP $KILLPIDS
128
129 echo ">>>>> Test succeeded"
130 exit 0