Only try to detect the events lib dir if it wasn't set earlier.
[ab/samba.git/.git] / source4 / nsswitch / tests / test_wbinfo.sh
1 #!/bin/sh
2 # Blackbox test for wbinfo
3 if [ $# -lt 4 ]; then
4 cat <<EOF
5 Usage: test_wbinfo.sh DOMAIN USERNAME PASSWORD TARGET
6 EOF
7 exit 1;
8 fi
9
10 DOMAIN=$1
11 USERNAME=$2
12 PASSWORD=$3
13 TARGET=$4
14 shift 4
15
16 failed=0
17 samba4bindir=`dirname $0`/../../bin
18 wbinfo=$samba4bindir/wbinfo
19
20 . `dirname $0`/../../../testprogs/blackbox/subunit.sh
21
22 testfail() {
23         name="$1"
24         shift
25         cmdline="$*"
26         echo "test: $name"
27         $cmdline
28         status=$?
29         if [ x$status = x0 ]; then
30                 echo "failure: $name"
31         else
32                 echo "success: $name"
33         fi
34         return $status
35 }
36
37 knownfail() {
38         name="$1"
39         shift
40         cmdline="$*"
41         echo "test: $name"
42         $cmdline
43         status=$?
44         if [ x$status = x0 ]; then
45                 echo "failure: $name [unexpected success]"
46                                 status=1
47         else
48                 echo "knownfail: $name"
49                                 status=0
50         fi
51         return $status
52 }
53
54
55 testit "wbinfo -u against $TARGET" $wbinfo -u || failed=`expr $failed + 1`
56 # Does not work yet
57 knownfail "wbinfo -g against $TARGET" $wbinfo -g || failed=`expr $failed + 1`
58 knownfail "wbinfo -N against $TARGET" $wbinfo -N || failed=`expr $failed + 1`
59 knownfail "wbinfo -I against $TARGET" $wbinfo -I || failed=`expr $failed + 1`
60 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
61 admin_sid=`$wbinfo -n "$DOMAIN/$USERNAME" | cut -d " " -f1`
62 echo "$DOMAIN/$USERNAME resolved to $admin_sid"
63
64 testit "wbinfo -s $admin_sid against $TARGET" $wbinfo -s $admin_sid || failed=`expr $failed + 1`
65 admin_name=`wbinfo -s $admin_sid | cut -d " " -f1| tr a-z A-Z`
66 echo "$admin_sid resolved to $admin_name"
67
68 tested_name=`echo $DOMAIN/$USERNAME | tr a-z A-Z`
69
70 echo "test: wbinfo -s check for sane mapping"
71 if test x$admin_name != x$tested_name; then
72         echo "$admin_name does not match $tested_name"
73         echo "failure: wbinfo -s check for sane mapping"
74         failed=`expr $failed + 1`
75 else
76         echo "success: wbinfo -s check for sane mapping"
77 fi
78
79 testit "wbinfo -n on the returned name against $TARGET" $wbinfo -n $admin_name || failed=`expr $failed + 1`
80 test_sid=`$wbinfo -n $tested_name | cut -d " " -f1`
81
82 echo "test: wbinfo -n check for sane mapping"
83 if test x$admin_sid != x$test_sid; then
84         echo "$admin_sid does not match $test_sid"
85         echo "failure: wbinfo -n check for sane mapping"
86         failed=`expr $failed + 1`
87 else
88         echo "success: wbinfo -n check for sane mapping"
89 fi
90
91 testit "wbinfo -U against $TARGET" $wbinfo -U 30000 || failed=`expr $failed + 1`
92
93 echo "test: wbinfo -U check for sane mapping"
94 sid_for_30000=`$wbinfo -U 30000`
95 if test x$sid_for_30000 != "xS-1-22-1-30000"; then
96         echo "uid 30000 mapped to $sid_for_30000, not S-1-22-1-30000"
97         echo "failure: wbinfo -U check for sane mapping"
98         failed=`expr $failed + 1`
99 else
100         echo "success: wbinfo -U check for sane mapping"
101 fi
102
103 admin_uid=`wbinfo -U $admin_sid`
104
105 testit "wbinfo -G against $TARGET" $wbinfo -G 30000 || failed=`expr $failed + 1`
106
107 echo "test: wbinfo -G check for sane mapping"
108 sid_for_30000=`$wbinfo -G 30000`
109 if test x$sid_for_30000 != "xS-1-22-2-30000"; then
110         echo "gid 30000 mapped to $sid_for_30000, not S-1-22-2-30000"
111         echo "failure: wbinfo -G check for sane mapping"
112         failed=`expr $failed + 1`
113 else
114         echo "success: wbinfo -G check for sane mapping"
115 fi
116
117 testit "wbinfo -S against $TARGET" $wbinfo -S "S-1-22-1-30000" || failed=`expr $failed + 1`
118
119 echo "test: wbinfo -S check for sane mapping"
120 uid_for_sid=`$wbinfo -S S-1-22-1-30000`
121 if test 0$uid_for_sid -ne 30000; then
122         echo "S-1-22-1-30000 mapped to $uid_for_sid, not 30000"
123         echo "failure: wbinfo -S check for sane mapping"
124         failed=`expr $failed + 1`
125 else
126         echo "success: wbinfo -S check for sane mapping"
127 fi
128
129 testfail "wbinfo -S against $TARGET using invalid SID" $wbinfo -S "S-1-22-2-30000" && failed=`expr $failed + 1`
130
131 testit "wbinfo -Y against $TARGET" $wbinfo -Y "S-1-22-2-30000" || failed=`expr $failed + 1`
132
133 echo "test: wbinfo -Y check for sane mapping"
134 gid_for_sid=`$wbinfo -Y S-1-22-2-30000`
135 if test 0$gid_for_sid -ne 30000; then
136         echo "S-1-22-2-30000 mapped to $gid_for_sid, not 30000"
137         echo "failure: wbinfo -Y check for sane mapping"
138         failed=`expr $failed + 1`
139 else
140         echo "success: wbinfo -Y check for sane mapping"
141 fi
142
143 testfail "wbinfo -Y against $TARGET using invalid SID" $wbinfo -Y "S-1-22-1-30000" && failed=`expr $failed + 1`
144
145 testit "wbinfo -t against $TARGET" $wbinfo -t || failed=`expr $failed + 1`
146
147 testit "wbinfo  --trusted-domains against $TARGET" $wbinfo --trusted-domains || failed=`expr $failed + 1`
148 testit "wbinfo --all-domains against $TARGET" $wbinfo --all-domains || failed=`expr $failed + 1`
149 testit "wbinfo --own-domain against $TARGET" $wbinfo --own-domain || failed=`expr $failed + 1`
150
151 echo "test: wbinfo --own-domain against $TARGET check output"
152 own_domain=`wbinfo --own-domain`
153 if test x$own_domain = x$DOMAIN; then
154         echo "success: wbinfo --own-domain against $TARGET check output"
155 else
156         echo "Own domain reported as $own_domain instead of $DOMAIN"
157         echo "failure: wbinfo --own-domain against $TARGET check output"
158 fi
159
160 # this does not work
161 knownfail "wbinfo --sequence against $TARGET" $wbinfo --sequence
162 knownfail "wbinfo -D against $TARGET" $wbinfo -D $DOMAIN || failed=`expr $failed + 1`
163
164 testit "wbinfo -i against $TARGET" $wbinfo -i "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
165
166 # this does not work
167 knownfail "wbinfo --uid-info against $TARGET" $wbinfo --uid-info $admin_sid
168 knownfail "wbinfo --group-info against $TARGET" $wbinfo --group-info "S-1-22-2-0"
169 knownfail "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME"
170
171 testit "wbinfo --user-domgroups against $TARGET" $wbinfo --user-domgroups $admin_sid || failed=`expr $failed + 1`
172
173 testit "wbinfo --user-sids against $TARGET" $wbinfo --user-sids $admin_sid || failed=`expr $failed + 1`
174
175 testit "wbinfo -a against $TARGET with domain creds" $wbinfo -a "$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
176
177 # this does not work
178 knwonfail "wbinfo --getdcname against $TARGET" $wbinfo --getdcname=$DOMAIN
179
180 testit "wbinfo -p against $TARGET" $wbinfo -p || failed=`expr $failed + 1`
181
182 testit "wbinfo -K against $TARGET with domain creds" $wbinfo -K "$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
183
184 testit "wbinfo --separator against $TARGET" $wbinfo --separator || failed=`expr $failed + 1`
185
186 exit $failed
187