LDB:ldbsearch - add search filter tests
[mdw/samba.git] / lib / ldb / tests / test-generic.sh
1 #!/bin/sh
2
3 if [ -z "$LDB_SPECIALS" ]; then
4     LDB_SPECIALS=1
5     export LDB_SPECIALS
6 fi
7
8 echo "LDB_URL: $LDB_URL"
9
10 echo "Adding base elements"
11 $VALGRIND ldbadd $LDBDIR/tests/test.ldif || exit 1
12
13 echo "Adding again - should fail"
14 $VALGRIND ldbadd $LDBDIR/tests/test.ldif 2> /dev/null && {
15     echo "Should have failed to add again - gave $?"
16     exit 1
17 }
18
19 echo "Adding LDIF with one already-existing user again - should fail"
20 $VALGRIND ldbadd $LDBDIR/tests/test-dup.ldif 2> /dev/null && {
21     echo "Should have failed to add again - gave $?"
22     exit 1
23 }
24
25 echo "Adding again - should succeed (as previous failed)"
26 $VALGRIND ldbadd $LDBDIR/tests/test-dup-2.ldif || exit 1
27
28 echo "Modifying elements"
29 $VALGRIND ldbmodify $LDBDIR/tests/test-modify.ldif || exit 1
30
31 echo "Modify LDIF with one un-met constraint - should fail"
32 $VALGRIND ldbadd $LDBDIR/tests/test-modify-unmet.ldif 2> /dev/null && {
33     echo "Should have failed to modify - gave $?"
34     exit 1
35 }
36
37 echo "Modify LDIF with after failure of un-met constraint - should also fail"
38 $VALGRIND ldbadd $LDBDIR/tests/test-modify-unmet-2.ldif 2> /dev/null && {
39     echo "Should have failed to modify - gave $?"
40     exit 1
41 }
42
43 echo "Showing modified record"
44 $VALGRIND ldbsearch '(uid=uham)'  || exit 1
45
46 echo "Rename entry with ldbmodify - modrdn"
47 $VALGRIND ldbmodify $LDBDIR/tests/test-modify-modrdn.ldif || exit 1
48
49 echo "Rename entry with ldbrename"
50 OLDDN="cn=Ursula Hampster,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST"
51 NEWDN="cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST"
52 $VALGRIND ldbrename "$OLDDN" "$NEWDN"  || exit 1
53
54 echo "Showing renamed record"
55 $VALGRIND ldbsearch '(uid=uham)' || exit 1
56
57 echo "Starting ldbtest"
58 $VALGRIND ldbtest --num-records 100 --num-searches 10  || exit 1
59
60 if [ $LDB_SPECIALS = 1 ]; then
61  echo "Adding index"
62  $VALGRIND ldbadd $LDBDIR/tests/test-index.ldif  || exit 1
63 fi
64
65 echo "Adding bad attributes - should fail"
66 $VALGRIND ldbadd $LDBDIR/tests/test-wrong_attributes.ldif && {
67     echo "Should fhave failed - gave $?"
68     exit 1
69 }
70
71 echo "Testing indexed search"
72 $VALGRIND ldbsearch '(uid=uham)'  || exit 1
73 $VALGRIND ldbsearch '(&(objectclass=person)(objectclass=person)(objectclass=top))' || exit 1
74 $VALGRIND ldbsearch '(&(uid=uham)(uid=uham))'  || exit 1
75 $VALGRIND ldbsearch '(|(uid=uham)(uid=uham))'  || exit 1
76 $VALGRIND ldbsearch '(|(uid=uham)(uid=uham)(objectclass=OpenLDAPperson))'  || exit 1
77 $VALGRIND ldbsearch '(&(uid=uham)(uid=uham)(!(objectclass=xxx)))'  || exit 1
78 $VALGRIND ldbsearch '(&(objectclass=person)(uid=uham)(!(uid=uhamxx)))' uid \* \+ dn  || exit 1
79 $VALGRIND ldbsearch '(&(uid=uham)(uid=uha*)(title=*))' uid || exit 1
80
81 echo "Testing invalid search expression"
82 $VALGRIND ldbsearch '(&(uid=uham)(title=foo\blah))' uid && exit 1
83
84 # note that the "((" is treated as an attribute not an expression
85 # this matches the openldap ldapsearch behaviour of looking for a '='
86 # to see if the first argument is an expression or not
87 $VALGRIND ldbsearch '((' uid || exit 1
88 $VALGRIND ldbsearch '(objectclass=)' uid || exit 1
89 $VALGRIND ldbsearch -b 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' -s base "" sn || exit 1
90
91 echo "Test wildcard match"
92 $VALGRIND ldbadd $LDBDIR/tests/test-wildcard.ldif  || exit 1
93 $VALGRIND ldbsearch '(cn=test*multi)'  || exit 1
94 $VALGRIND ldbsearch '(cn=*test*multi*)'  || exit 1
95 $VALGRIND ldbsearch '(cn=*test_multi)'  || exit 1
96 $VALGRIND ldbsearch '(cn=test_multi*)'  || exit 1
97 $VALGRIND ldbsearch '(cn=test*multi*test*multi)'  || exit 1
98 $VALGRIND ldbsearch '(cn=test*multi*test*multi*multi_*)' || exit 1
99
100 echo "Starting ldbtest indexed"
101 $VALGRIND ldbtest --num-records 100 --num-searches 500  || exit 1
102
103 echo "Testing one level search"
104 count=`$VALGRIND ldbsearch -b 'ou=Groups,o=University of Michigan,c=TEST' -s one 'objectclass=*' none |grep '^dn' | wc -l`
105 if [ $count != 3 ]; then
106     echo returned $count records - expected 3
107     exit 1
108 fi
109
110 echo "Testing binary file attribute value"
111 $VALGRIND ldbmodify $LDBDIR/tests/photo.ldif || exit 1
112 count=`$VALGRIND ldbsearch '(cn=Hampster Ursula)' jpegPhoto | grep '^dn' | wc -l`
113 if [ $count != 1 ]; then
114     echo returned $count records - expected 1
115     exit 1
116 fi
117
118 echo "*TODO* Testing UTF8 upper lower case searches !!"
119
120 echo "Testing compare"
121 count=`$VALGRIND ldbsearch '(cn>=t)' cn | grep '^dn' | wc -l`
122 if [ $count != 2 ]; then
123     echo returned $count records - expected 2
124     echo "this fails on openLdap ..."
125 fi
126 $VALGRIND ldbsearch '(cn>t)' cn && exit 1 # strictly greater should not work
127
128 count=`$VALGRIND ldbsearch '(cn<=t)' cn | grep '^dn' | wc -l`
129 if [ $count != 13 ]; then
130     echo returned $count records - expected 13
131     echo "this fails on openLdap ..."
132 fi
133 $VALGRIND ldbsearch '(cn<t)' cn && exit 1 # strictly less should not work
134
135 checkcount() {
136     count=$1
137     scope=$2
138     basedn=$3
139     expression="$4"
140     n=`$VALGRIND ldbsearch -s "$scope" -b "$basedn" "$expression" | grep '^dn' | wc -l`
141     if [ $n != $count ]; then
142         echo "Got $n but expected $count for $expression"
143         bin/ldbsearch "$expression"
144         exit 1
145     fi
146     echo "OK: $count $expression"
147 }
148
149 checkcount 0 'base' '' '(uid=uham)'
150 checkcount 0 'one' '' '(uid=uham)'
151
152 checkcount 1 'base' 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' '(uid=uham)'
153 checkcount 1 'one' 'ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' '(uid=uham)'
154 checkcount 1 'one' 'ou=People,o=University of Michigan,c=TEST' '(ou=ldb  test)'