ctdb-daemon: Use ctdb_parse_node_address() in ctdbd
[samba4-gss.git] / lib / ldb / tests / test-generic.sh
blob03ac91455eb9d8618b589f59e00b13bed4c8db6c
1 #!/bin/sh
3 if [ -z "$LDB_SPECIALS" ]; then
4 LDB_SPECIALS=1
5 export LDB_SPECIALS
6 fi
8 echo "LDB_URL: $LDB_URL"
10 echo "Adding base elements"
11 $VALGRIND ldbadd $LDBDIR/tests/test.ldif || exit 1
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
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
25 echo "Adding again - should succeed (as previous failed)"
26 $VALGRIND ldbadd $LDBDIR/tests/test-dup-2.ldif || exit 1
28 echo "Modifying elements"
29 $VALGRIND ldbmodify $LDBDIR/tests/test-modify.ldif || exit 1
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
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
43 echo "Showing modified record"
44 $VALGRIND ldbsearch '(uid=uham)' || exit 1
46 echo "Rename entry with ldbmodify - modrdn"
47 $VALGRIND ldbmodify $LDBDIR/tests/test-modify-modrdn.ldif || exit 1
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
54 echo "Showing renamed record"
55 $VALGRIND ldbsearch '(uid=uham)' || exit 1
57 echo "Starting ldbtest"
58 $VALGRIND ldbtest --num-records 100 --num-searches 10 || exit 1
60 if [ $LDB_SPECIALS = 1 ]; then
61 echo "Adding index"
62 $VALGRIND ldbadd $LDBDIR/tests/test-index.ldif || exit 1
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
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
81 echo "Testing invalid search expression"
82 $VALGRIND ldbsearch '(&(uid=uham)(title=foo\blah))' uid && exit 1
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' --scope=base "" sn || exit 1
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
100 echo "Starting ldbtest indexed"
101 $VALGRIND ldbtest --num-records 100 --num-searches 500 || exit 1
103 echo "Testing one level search"
104 count=$($VALGRIND ldbsearch -b 'ou=Groups,o=University of Michigan,c=TEST' --scope=one 'objectclass=*' none | grep '^dn' | wc -l)
105 if [ $count != 3 ]; then
106 echo returned $count records - expected 3
107 exit 1
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
118 echo "*TODO* Testing UTF8 upper lower case searches !!"
120 echo "Testing compare"
121 count=$($VALGRIND ldbsearch '(cn>=t)' cn | grep '^dn' | wc -l)
122 if [ $count != 1 ]; then
123 # only "cn: test_multi_test_multi_test_multi" (comes after "t")
124 # upper-cased words come before "t" - hence excluded
125 echo returned $count records - expected 1
126 exit 1
128 $VALGRIND ldbsearch '(cn>t)' cn && exit 1 # strictly greater should not work
130 count=$($VALGRIND ldbsearch '(cn<=t)' cn | grep '^dn' | wc -l)
131 if [ $count != 18 ]; then
132 # everything except "cn: test_multi_test_multi_test_multi" (comes after "t")
133 # upper-cased letters come before "t" - hence included
134 echo returned $count records - expected 18
135 exit 1
137 $VALGRIND ldbsearch '(cn<t)' cn && exit 1 # strictly less should not work
139 checkcount()
141 count=$1
142 scope=$2
143 basedn=$3
144 expression="$4"
145 n=$($VALGRIND ldbsearch --scope="$scope" -b "$basedn" "$expression" | grep '^dn' | wc -l)
146 if [ $n != $count ]; then
147 echo "Got $n but expected $count for $expression"
148 exit 1
150 echo "OK: $count $expression"
153 checkcount 0 'base' '' '(uid=uham)'
154 checkcount 0 'one' '' '(uid=uham)'
156 checkcount 1 'base' 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' '(uid=uham)'
157 checkcount 1 'one' 'ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' '(uid=uham)'
158 checkcount 1 'one' 'ou=People,o=University of Michigan,c=TEST' '(ou=ldb test)'