nsswitch: Use own credential cache for wbinfo tests
[Samba.git] / nsswitch / tests / test_wbinfo.sh
blob69cc437f8216583015d3d295029bd4aabcb46f11
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
10 DOMAIN=$1
11 USERNAME=$2
12 PASSWORD=$3
13 TARGET=$4
14 shift 4
16 failed=0
17 samba4bindir="$BINDIR"
18 wbinfo="$VALGRIND $samba4bindir/wbinfo"
20 . `dirname $0`/../../testprogs/blackbox/subunit.sh
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"
34 return $status
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
51 return $status
54 KRB5CCNAME_PATH="$PREFIX/test_wbinfo_krb5ccache"
55 rm -f $KRB5CCNAME_PATH
57 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
58 export KRB5CCNAME
60 # List users
61 testit "wbinfo -u against $TARGET" $wbinfo -u || failed=`expr $failed + 1`
62 # List groups
63 testit "wbinfo -g against $TARGET" $wbinfo -g || failed=`expr $failed + 1`
64 # Convert netbios name to IP
65 # Does not work yet
66 testit "wbinfo -N against $TARGET" $wbinfo -N $NETBIOSNAME || failed=`expr $failed + 1`
67 # Convert IP to netbios name
68 # Does not work yet
69 testit "wbinfo -I against $TARGET" $wbinfo -I $SERVER_IP || failed=`expr $failed + 1`
71 # Convert name to SID
72 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
73 admin_sid=`$wbinfo -n "$DOMAIN/$USERNAME" | cut -d " " -f1`
74 echo "$DOMAIN/$USERNAME resolved to $admin_sid"
76 testit "wbinfo -s $admin_sid against $TARGET" $wbinfo -s $admin_sid || failed=`expr $failed + 1`
77 admin_name=`$wbinfo -s $admin_sid | cut -d " " -f1| tr a-z A-Z`
78 echo "$admin_sid resolved to $admin_name"
80 tested_name=`echo $DOMAIN/$USERNAME | tr a-z A-Z`
82 echo "test: wbinfo -s check for sane mapping"
83 if test x$admin_name != x$tested_name; then
84 echo "$admin_name does not match $tested_name"
85 echo "failure: wbinfo -s check for sane mapping"
86 failed=`expr $failed + 1`
87 else
88 echo "success: wbinfo -s check for sane mapping"
91 testit "wbinfo -n on the returned name against $TARGET" $wbinfo -n $admin_name || failed=`expr $failed + 1`
92 test_sid=`$wbinfo -n $tested_name | cut -d " " -f1`
94 echo "test: wbinfo -n check for sane mapping"
95 if test x$admin_sid != x$test_sid; then
96 echo "$admin_sid does not match $test_sid"
97 echo "failure: wbinfo -n check for sane mapping"
98 failed=`expr $failed + 1`
99 else
100 echo "success: wbinfo -n check for sane mapping"
103 testit "wbinfo -U against $TARGET" $wbinfo -U 30000 || failed=`expr $failed + 1`
105 echo "test: wbinfo -U check for sane mapping"
106 sid_for_30000=`$wbinfo -U 30000`
107 if test x$sid_for_30000 != "xS-1-22-1-30000"; then
108 echo "uid 30000 mapped to $sid_for_30000, not S-1-22-1-30000"
109 echo "failure: wbinfo -U check for sane mapping"
110 failed=`expr $failed + 1`
111 else
112 echo "success: wbinfo -U check for sane mapping"
115 admin_uid=`$wbinfo -S $admin_sid`
117 testit "wbinfo -G against $TARGET" $wbinfo -G 30000 || failed=`expr $failed + 1`
119 echo "test: wbinfo -G check for sane mapping"
120 sid_for_30000=`$wbinfo -G 30000`
121 if test x$sid_for_30000 != "xS-1-22-2-30000"; then
122 echo "gid 30000 mapped to $sid_for_30000, not S-1-22-2-30000"
123 echo "failure: wbinfo -G check for sane mapping"
124 failed=`expr $failed + 1`
125 else
126 echo "success: wbinfo -G check for sane mapping"
129 testit "wbinfo -S against $TARGET" $wbinfo -S "S-1-22-1-30000" || failed=`expr $failed + 1`
131 echo "test: wbinfo -S check for sane mapping"
132 uid_for_sid=`$wbinfo -S S-1-22-1-30000`
133 if test 0$uid_for_sid -ne 30000; then
134 echo "S-1-22-1-30000 mapped to $uid_for_sid, not 30000"
135 echo "failure: wbinfo -S check for sane mapping"
136 failed=`expr $failed + 1`
137 else
138 echo "success: wbinfo -S check for sane mapping"
141 testfail "wbinfo -S against $TARGET using invalid SID" $wbinfo -S "S-1-22-2-30000" && failed=`expr $failed + 1`
143 testit "wbinfo -Y against $TARGET" $wbinfo -Y "S-1-22-2-30000" || failed=`expr $failed + 1`
145 echo "test: wbinfo -Y check for sane mapping"
146 gid_for_sid=`$wbinfo -Y S-1-22-2-30000`
147 if test 0$gid_for_sid -ne 30000; then
148 echo "S-1-22-2-30000 mapped to $gid_for_sid, not 30000"
149 echo "failure: wbinfo -Y check for sane mapping"
150 failed=`expr $failed + 1`
151 else
152 echo "success: wbinfo -Y check for sane mapping"
155 testfail "wbinfo -Y against $TARGET using invalid SID" $wbinfo -Y "S-1-22-1-30000" && failed=`expr $failed + 1`
157 testit "wbinfo -t against $TARGET" $wbinfo -t || failed=`expr $failed + 1`
159 #didn't really work anyway
160 testit "wbinfo --trusted-domains against $TARGET" $wbinfo --trusted-domains || failed=`expr $failed + 1`
161 testit "wbinfo --all-domains against $TARGET" $wbinfo --all-domains || failed=`expr $failed + 1`
163 testit "wbinfo --own-domain against $TARGET" $wbinfo --own-domain || failed=`expr $failed + 1`
165 echo "test: wbinfo --own-domain against $TARGET check output"
166 own_domain=`$wbinfo --own-domain`
167 if test x$own_domain = x$DOMAIN; then
168 echo "success: wbinfo --own-domain against $TARGET check output"
169 else
170 echo "Own domain reported as $own_domain instead of $DOMAIN"
171 echo "failure: wbinfo --own-domain against $TARGET check output"
172 failed=`expr $failed + 1`
175 # this does not work
176 knownfail "wbinfo --sequence against $TARGET" $wbinfo --sequence
178 # this is stubbed out now
179 testit "wbinfo -D against $TARGET" $wbinfo -D $DOMAIN || failed=`expr $failed + 1`
181 testit "wbinfo -i against $TARGET" $wbinfo -i "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
183 echo "test: wbinfo --group-info against $TARGET"
184 gid=`$wbinfo --group-info "$DOMAIN/Domain users" | cut -d: -f3`
185 if test x$? = x0; then
186 echo "success: wbinfo --group-info against $TARGET"
187 else
188 echo "failure: wbinfo --group-info against $TARGET"
189 failed=`expr $failed + 1`
192 test_name="wbinfo -i against $TARGET"
193 subunit_start_test "$test_name"
194 passwd_line=`$wbinfo -i "$DOMAIN/$USERNAME"`
195 if test x$? = x0; then
196 subunit_pass_test "$test_name"
197 else
198 subunit_fail_test "$test_name"
199 failed=`expr $failed + 1`
202 test_name="confirm output of wbinfo -i against $TARGET"
203 subunit_start_test "$test_name"
205 # The full name (GECOS) is based on name (the RDN, in this case CN)
206 # and displayName in winbindd_ads, and is based only on displayName in
207 # winbindd_msrpc and winbindd_rpc. Allow both versions.
208 expected_line="$DOMAIN/administrator:*:$admin_uid:$gid:Administrator:/home/$DOMAIN/administrator:/bin/false"
209 expected2_line="$DOMAIN/administrator:*:$admin_uid:$gid::/home/$DOMAIN/administrator:/bin/false"
211 if test x$passwd_line = x"$expected_line" -o x$passwd_line = x"$expected2_line"; then
212 subunit_pass_test "$test_name"
213 else
214 echo "expected '$expected_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
215 failed=`expr $failed + 1`
218 test_name="wbinfo --uid-info against $TARGET"
219 subunit_start_test "$test_name"
220 passwd_line=`$wbinfo --uid-info=$admin_uid`
221 if test x$? = x0; then
222 subunit_pass_test "$test_name"
223 else
224 subunit_fail_test "$test_name"
225 failed=`expr $failed + 1`
228 test_name="confirm output of wbinfo --uid-info against $TARGET"
229 subunit_start_test "$test_name"
230 if test x$passwd_line = x"$expected_line" -o x$passwd_line = x"$expected2_line"; then
231 subunit_pass_test "$test_name"
232 else
233 echo "expected '$expected_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
234 failed=`expr $failed + 1`
237 testfail "wbinfo --group-info against $TARGET with $USERNAME" $wbinfo --group-info $USERNAME && failed=`expr $failed + 1`
239 testit "wbinfo --gid-info against $TARGET" $wbinfo --gid-info $gid || failed=`expr $failed + 1`
241 testit "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
243 testit "wbinfo --user-domgroups against $TARGET" $wbinfo --user-domgroups $admin_sid || failed=`expr $failed + 1`
245 testit "wbinfo --user-sids against $TARGET" $wbinfo --user-sids $admin_sid || failed=`expr $failed + 1`
247 testit "wbinfo -a against $TARGET with domain creds" $wbinfo -a "$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
249 testit "wbinfo --getdcname against $TARGET" $wbinfo --getdcname=$DOMAIN
251 testit "wbinfo -p against $TARGET" $wbinfo -p || failed=`expr $failed + 1`
253 testit "wbinfo -K against $TARGET with domain creds" $wbinfo --krb5ccname=$KRB5CCNAME --krb5auth="$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
255 testit "wbinfo --separator against $TARGET" $wbinfo --separator || failed=`expr $failed + 1`
257 rm -f $KRB5CCNAME_PATH
259 exit $failed