nsswitch: Add testcase for checking output of wbinfo --sid-to-name
[nivanova/samba-autobuild/.git] / nsswitch / tests / test_wbinfo_name_lookup.sh
1 #!/bin/sh
2 # Blackbox test for wbinfo name lookup
3 if [ $# -lt 2 ]; then
4 cat <<EOF
5 Usage: test_wbinfo.sh DOMAIN DC_USERNAME
6 EOF
7 exit 1;
8 fi
9
10 DOMAIN=$1
11 REALM=$2
12 DC_USERNAME=$3
13 shift 3
14
15 failed=0
16 sambabindir="$BINDIR"
17 wbinfo="$VALGRIND $sambabindir/wbinfo"
18
19 . `dirname $0`/../../testprogs/blackbox/subunit.sh
20
21 # Correct query is expected to work
22 testit "name-to-sid.single-separator" \
23        $wbinfo -n $DOMAIN/$DC_USERNAME || \
24         failed=$(expr $failed + 1)
25
26 testit "name-to-sid.at_domain" \
27        $wbinfo -n $DOMAIN/ || \
28         failed=$(expr $failed + 1)
29
30 testit "name-to-sid.upn" \
31        $wbinfo -n $DC_USERNAME@$REALM || \
32         failed=$(expr $failed + 1)
33
34 testit "name-to-sid.realm-user" \
35        $wbinfo -n $REALM/$DC_USERNAME || \
36         failed=$(expr $failed + 1)
37
38 # For the name-to-sid.realm-user query, ensure
39 # that this does not change subsequent sid-to-name
40 # queries.
41 sid=$($wbinfo -n $REALM/$DC_USERNAME | sed -e 's/ .*//')
42 out=$($wbinfo -s $sid | sed -e 's/ .//')
43 # winbindd returns usernames in lowercase
44 lcuser=$(echo $DC_USERNAME | tr A-Z a-z)
45 testit "Verify DOMAIN/USER output" \
46        test "$out" = "$DOMAIN/$lcuser" || \
47         failed=$(expr $failed + 1)
48
49 # Two separator characters should fail
50 testit_expect_failure "name-to-sid.double-separator" \
51                       $wbinfo -n $DOMAIN//$DC_USERNAME || \
52         failed=$(expr $failed + 1)
53
54 # Invalid domain is expected to fail
55 testit_expect_failure "name-to-sid.invalid-domain" \
56                       $wbinfo -n INVALID/$DC_USERNAME || \
57         failed=$(expr $failed + 1)
58
59 # Invalid domain with two separator characters is expected to fail
60 testit_expect_failure "name-to-sid.double-separator-invalid-domain" \
61                       $wbinfo -n INVALID//$DC_USERNAME || \
62         failed=$(expr $failed + 1)
63
64 exit $failed