nsswitch:tests: Add test for wbinfo --user-info
[samba.git] / nsswitch / tests / test_wbinfo_user_info.sh
1 #!/bin/sh
2 # Blackbox test for wbinfo lookup for account name and upn
3 # Copyright (c) 2018 Andreas Schneider <asn@samba.org>
4
5 if [ $# -lt 5 ]; then
6 cat <<EOF
7 Usage: $(basename $0) DOMAIN REALM USERNAME1 UPN_NAME1 USERNAME2 UPN_NAME2
8 EOF
9 exit 1;
10 fi
11
12 DOMAIN=$1
13 REALM=$2
14 USERNAME1=$3
15 UPN_NAME1=$4
16 USERNAME2=$5
17 UPN_NAME2=$6
18 shift 6
19
20 failed=0
21
22 samba_bindir="$BINDIR"
23 wbinfo_tool="$VALGRIND $samba_bindir/wbinfo"
24
25 UPN1="$UPN_NAME1@$REALM"
26 UPN2="$UPN_NAME2@$REALM"
27
28 . $(dirname $0)/../../testprogs/blackbox/subunit.sh
29
30 test_user_info()
31 {
32         local cmd out ret user domain upn userinfo
33
34         domain="$1"
35         user="$2"
36         upn="$3"
37
38         if [ $# -lt 3 ]; then
39                 userinfo="$domain/$user"
40         else
41                 userinfo="$upn"
42         fi
43
44         cmd='$wbinfo_tool --user-info $userinfo'
45         eval echo "$cmd"
46         out=$(eval $cmd)
47         ret=$?
48         if [ $ret -ne 0 ]; then
49                 echo "failed to lookup $userinfo"
50                 echo "$out"
51                 return 1
52         fi
53
54         echo "$out" | grep "$domain/$user:.*:.*:.*::/home/$domain/Domain Users/$user"
55         ret=$?
56         if [ $ret != 0 ]; then
57                 echo "failed to lookup $userinfo"
58                 echo "$out"
59                 return 1
60         fi
61
62         return 0
63 }
64
65 testit "name_to_sid.domain.$USERNAME1" $wbinfo_tool --name-to-sid $DOMAIN/$USERNAME1 || failed=$(expr $failed + 1)
66 testit "name_to_sid.upn.$UPN_NAME1" $wbinfo_tool --name-to-sid $UPN1 || failed=$(expr $failed + 1)
67
68 testit "user_info.domain.$USERNAME1" test_user_info $DOMAIN $USERNAME1 || failed=$(expr $failed + 1)
69 testit "user_info.upn.$UPN_NAME1" test_user_info $DOMAIN $USERNAME1 $UPN1 || failed=$(expr $failed + 1)
70
71 testit "name_to_sid.domain.$USERNAME2" $wbinfo_tool --name-to-sid $DOMAIN/$USERNAME2 || failed=$(expr $failed + 1)
72 testit "name_to_sid.upn.$UPN_NAME2" $wbinfo_tool --name-to-sid $UPN2 || failed=$(expr $failed + 1)
73
74 testit "user_info.domain.$USERNAME2" test_user_info $DOMAIN $USERNAME2 || failed=$(expr $failed + 1)
75 testit "user_info.upn.$UPN_NAME2" test_user_info $DOMAIN $USERNAME2 $UPN2 || failed=$(expr $failed + 1)
76
77 USERNAME3="testdenied"
78 UPN_NAME3="testdenied_upn"
79 UPN3="$UPN_NAME3@${REALM}.upn"
80 testit "name_to_sid.upn.$UPN_NAME3" $wbinfo_tool --name-to-sid $UPN3 || failed=$(expr $failed + 1)
81 testit "user_info.upn.$UPN_NAME3" test_user_info $DOMAIN $USERNAME3 $UPN3 || failed=$(expr $failed + 1)
82
83 exit $failed