summaryrefslogtreecommitdiff
path: root/source4/script/tests/test_ldap.sh
blob: f8657de5ec61ba765cdbf922c4fa269e8b28f298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh
# test some simple LDAP and CLDAP operations

if [ $# -lt 3 ]; then
cat <<EOF
Usage: test_ldap.sh SERVER USERNAME PASSWORD
EOF
exit 1;
fi

# see if we support ldaps
if grep HAVE_LIBGNUTLS.1 include/config.h > /dev/null && 
    test -n "$CONFFILE" && grep tls.enabled.=yes $CONFFILE > /dev/null; then
    PROTOCOLS="ldap ldaps"
else
    PROTOCOLS="ldap"
fi

SERVER="$1"
USERNAME="$2"
PASSWORD="$3"

incdir=`dirname $0`
. $incdir/test_functions.sh

for p in $PROTOCOLS; do
 for options in "" "-U$USERNAME%$PASSWORD"; do
    echo "TESTING PROTOCOL $p with options $options"

    testit "RootDSE" bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1`

    echo "Getting defaultNamingContext"
    BASEDN=`bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
    echo "BASEDN is $BASEDN"

    testit "Listing Users" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`

    testit "Listing Groups" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1`

    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`
    echo "Found $nentries entries"
    if [ $nentries -lt 10 ]; then
	echo "Should have found at least 10 entries"
	failed=`expr $failed + 1`
    fi

    echo "Check rootDSE for Controls"
    nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l`
    if [ $nentries -lt 4 ]; then
	echo "Should have found at least 4 entries"
	failed=`expr $failed + 1`
    fi

    echo "Test Paged Results Control"
    nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l`
    if [ $nentries -lt 1 ]; then
	echo "Paged Results Control test returned 0 items"
	failed=`expr $failed + 1`
    fi

    echo "Test Server Sort Control"
    nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l`
    if [ $nentries -lt 1 ]; then
	echo "Server Sort Control test returned 0 items"
	failed=`expr $failed + 1`
    fi

    echo "Test Extended DN Control"
    nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(objectclass=user)' | grep sAMAccountName | wc -l`
    if [ $nentries -lt 1 ]; then
	echo "Extended DN Control test returned 0 items"
	failed=`expr $failed + 1`
    fi

    echo "Test Attribute Scope Query Control"
    nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b 'CN=Administrators,CN=Builtin,DC=samba,DC=example,DC=com' | grep sAMAccountName | wc -l`
   if [ $nentries -lt 1 ]; then
	echo "Attribute Scope Query test returned 0 items"
	failed=`expr $failed + 1`
   fi

 done
done

testit "CLDAP" bin/smbtorture $TORTURE_OPTIONS //$SERVER/_none_ LDAP-CLDAP || failed=`expr $failed + 1`

LDBDIR=lib/ldb
export LDBDIR
testit "ldb tests" $LDBDIR/tests/test-tdb.sh || failed=`expr $failed + 1`

SCRIPTDIR=../testprogs/ejs

testit "ejs ldap test" $SCRIPTDIR/ldap.js $CONFIGURATION $SERVER -U$USERNAME%$PASSWORD || failed=`expr $failed + 1`

testok $0 $failed