Merge branch 'master' of ssh://git.samba.org/data/git/samba into arc4
[ira/wip.git] / source4 / 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 ldbadd $LDBDIR/tests/test.ldif 2> /dev/null && {
15     echo "Should have failed to add again - gave $?"
16     exit 1
17 }
18
19 echo "Modifying elements"
20 $VALGRIND ldbmodify $LDBDIR/tests/test-modify.ldif || exit 1
21
22 echo "Showing modified record"
23 $VALGRIND ldbsearch '(uid=uham)'  || exit 1
24
25 echo "Rename entry"
26 OLDDN="cn=Ursula Hampster,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST"
27 NEWDN="cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST"
28 $VALGRIND ldbrename "$OLDDN" "$NEWDN"  || exit 1
29
30 echo "Showing renamed record"
31 $VALGRIND ldbsearch '(uid=uham)' || exit 1
32
33 echo "Starting ldbtest"
34 $VALGRIND ldbtest --num-records 100 --num-searches 10  || exit 1
35
36 if [ $LDB_SPECIALS = 1 ]; then
37  echo "Adding index"
38  $VALGRIND ldbadd $LDBDIR/tests/test-index.ldif  || exit 1
39 fi
40
41 echo "Adding bad attributes - should fail"
42 $VALGRIND ldbadd $LDBDIR/tests/test-wrong_attributes.ldif && {
43     echo "Should fhave failed - gave $?"
44     exit 1
45 }
46
47 echo "testing indexed search"
48 $VALGRIND ldbsearch '(uid=uham)'  || exit 1
49 $VALGRIND ldbsearch '(&(objectclass=person)(objectclass=person)(objectclass=top))' || exit 1
50 $VALGRIND ldbsearch '(&(uid=uham)(uid=uham))'  || exit 1
51 $VALGRIND ldbsearch '(|(uid=uham)(uid=uham))'  || exit 1
52 $VALGRIND ldbsearch '(|(uid=uham)(uid=uham)(objectclass=OpenLDAPperson))'  || exit 1
53 $VALGRIND ldbsearch '(&(uid=uham)(uid=uham)(!(objectclass=xxx)))'  || exit 1
54 $VALGRIND ldbsearch '(&(objectclass=person)(uid=uham)(!(uid=uhamxx)))' uid \* \+ dn  || exit 1
55 $VALGRIND ldbsearch '(&(uid=uham)(uid=uha*)(title=*))' uid || exit 1
56
57 # note that the "((" is treated as an attribute not an expression
58 # this matches the openldap ldapsearch behaviour of looking for a '='
59 # to see if the first argument is an expression or not
60 $VALGRIND ldbsearch '((' uid || exit 1
61 $VALGRIND ldbsearch '(objectclass=)' uid || exit 1
62 $VALGRIND ldbsearch -b 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' -s base "" sn || exit 1
63
64 echo "Test wildcard match"
65 $VALGRIND ldbadd $LDBDIR/tests/test-wildcard.ldif  || exit 1
66 $VALGRIND ldbsearch '(cn=test*multi)'  || exit 1
67 $VALGRIND ldbsearch '(cn=*test*multi*)'  || exit 1
68 $VALGRIND ldbsearch '(cn=*test_multi)'  || exit 1
69 $VALGRIND ldbsearch '(cn=test_multi*)'  || exit 1
70 $VALGRIND ldbsearch '(cn=test*multi*test*multi)'  || exit 1
71 $VALGRIND ldbsearch '(cn=test*multi*test*multi*multi_*)' || exit 1
72
73 echo "Starting ldbtest indexed"
74 $VALGRIND ldbtest --num-records 100 --num-searches 500  || exit 1
75
76 echo "Testing one level search"
77 count=`$VALGRIND ldbsearch -b 'ou=Groups,o=University of Michigan,c=TEST' -s one 'objectclass=*' none |grep '^dn' | wc -l`
78 if [ $count != 3 ]; then
79     echo returned $count records - expected 3
80     exit 1
81 fi
82
83 echo "Testing binary file attribute value"
84 mkdir -p tests/tmp
85 cp $LDBDIR/tests/samba4.png tests/tmp/samba4.png
86 $VALGRIND ldbmodify $LDBDIR/tests/photo.ldif || exit 1
87 count=`$VALGRIND ldbsearch '(cn=Hampster Ursula)' jpegPhoto | grep '^dn' | wc -l`
88 if [ $count != 1 ]; then
89     echo returned $count records - expected 1
90     exit 1
91 fi
92 rm -f tests/tmp/samba4.png
93
94 echo "*TODO* Testing UTF8 upper lower case searches !!"
95
96 echo "Testing compare"
97 count=`$VALGRIND ldbsearch '(cn>=t)' cn | grep '^dn' | wc -l`
98 if [ $count != 2 ]; then
99     echo returned $count records - expected 2
100     echo "this fails on openLdap ..."
101 fi
102
103 count=`$VALGRIND ldbsearch '(cn<=t)' cn | grep '^dn' | wc -l`
104 if [ $count != 13 ]; then
105     echo returned $count records - expected 13
106     echo "this fails on openLdap ..."
107 fi
108
109 checkcount() {
110     count=$1
111     scope=$2
112     basedn=$3
113     expression="$4"
114     n=`bin/ldbsearch -s "$scope" -b "$basedn" "$expression" | grep '^dn' | wc -l`
115     if [ $n != $count ]; then
116         echo "Got $n but expected $count for $expression"
117         bin/ldbsearch "$expression"
118         exit 1
119     fi
120     echo "OK: $count $expression"
121 }
122
123 checkcount 0 'base' '' '(uid=uham)'
124 checkcount 0 'one' '' '(uid=uham)'
125
126 checkcount 1 'base' 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' '(uid=uham)'
127 checkcount 1 'one' 'ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' '(uid=uham)'
128 checkcount 1 'one' 'ou=People,o=University of Michigan,c=TEST' '(ou=ldb  test)'