Use the subunit shell library.
[kai/samba.git] / testprogs / blackbox / test_ldb.sh
1 #!/bin/sh
2
3 if [ $# -lt 2 ]; then
4 cat <<EOF
5 Usage: test_ldb.sh PROTOCOL SERVER [OPTIONS]
6 EOF
7 exit 1;
8 fi
9
10
11 p=$1
12 SERVER=$2
13 PREFIX=$3
14 shift 2
15 options="$*"
16
17 . `dirname $0`/subunit.sh
18
19 check() {
20         name="$1"
21         shift
22         cmdline="$*"
23         echo "test: $name"
24         $cmdline
25         status=$?
26         if [ x$status = x0 ]; then
27                 echo "success: $name"
28         else
29                 echo "failure: $name"
30                 failed=`expr $failed + 1`
31         fi
32         return $status
33 }
34
35 check "RootDSE" bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1`
36
37 echo "Getting defaultNamingContext"
38 BASEDN=`bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
39 echo "BASEDN is $BASEDN"
40
41 check "Listing Users" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
42
43 check "Listing Users (sorted)" bin/ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
44
45 check "Listing Groups" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1`
46
47 nentries=`bin/ldbsearch $options -H $p://$SERVER $CONFIGURATION '(|(|(&(!(groupType:1.2.840.113556.1.4.803:=1))(groupType:1.2.840.113556.1.4.803:=2147483648)(groupType:1.2.840.113556.1.4.804:=10))(samAccountType=805306368))(samAccountType=805306369))' sAMAccountName | grep sAMAccountName | wc -l`
48 echo "Found $nentries entries"
49 if [ $nentries -lt 10 ]; then
50 echo "Should have found at least 10 entries"
51 failed=`expr $failed + 1`
52 fi
53
54 echo "Check rootDSE for Controls"
55 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l`
56 if [ $nentries -lt 4 ]; then
57 echo "Should have found at least 4 entries"
58 failed=`expr $failed + 1`
59 fi
60
61 echo "Test Paged Results Control"
62 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l`
63 if [ $nentries -lt 1 ]; then
64 echo "Paged Results Control test returned 0 items"
65 failed=`expr $failed + 1`
66 fi
67
68 echo "Test Server Sort Control"
69 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l`
70 if [ $nentries -lt 1 ]; then
71 echo "Server Sort Control test returned 0 items"
72 failed=`expr $failed + 1`
73 fi
74
75 echo "Test Extended DN Control"
76 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
77 if [ $nentries -lt 1 ]; then
78 echo "Extended DN Control test returned 0 items"
79 failed=`expr $failed + 1`
80 fi
81 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(objectclass=user)' | grep sAMAccountName | wc -l`
82 if [ $nentries -lt 1 ]; then
83 echo "Extended DN Control test returned 0 items"
84 failed=`expr $failed + 1`
85 fi
86 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
87 if [ $nentries -lt 1 ]; then
88 echo "Extended DN Control test returned 0 items"
89 failed=`expr $failed + 1`
90 fi
91
92 echo "Test Domain scope Control"
93 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
94 if [ $nentries -lt 1 ]; then
95 echo "Extended Domain scope Control test returned 0 items"
96 failed=`expr $failed + 1`
97 fi
98
99 echo "Test Attribute Scope Query Control"
100 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l`
101 if [ $nentries -lt 1 ]; then
102 echo "Attribute Scope Query test returned 0 items"
103 failed=`expr $failed + 1`
104 fi
105
106 echo "Test Search Options Control"
107 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l`
108 if [ $nentries -lt 1 ]; then
109 echo "Search Options Control Query test returned 0 items"
110 failed=`expr $failed + 1`
111 fi
112
113 echo "Test Search Options Control with Domain Scope Control"
114 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l`
115 if [ $nentries -lt 1 ]; then
116 echo "Search Options Control Query test returned 0 items"
117 failed=`expr $failed + 1`
118 fi
119
120
121 exit $failed