Merge branch 'v4-0-test' of git://git.samba.org/samba into v4-0-local
[ira/wip.git] / testprogs / blackbox / test_kinit.sh
1 #!/bin/sh
2 # Blackbox tests for kinit and kerberos integration with smbclient etc
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2007 Andrew Bartlett <abartlet@samba.org>
5
6 if [ $# -lt 5 ]; then
7 cat <<EOF
8 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX
9 EOF
10 exit 1;
11 fi
12
13 SERVER=$1
14 USERNAME=$2
15 PASSWORD=$3
16 REALM=$4
17 DOMAIN=$5
18 PREFIX=$6
19 shift 6
20 failed=0
21
22 samba4bindir=`dirname $0`/../../source/bin
23 smbclient=$samba4bindir/smbclient
24 samba4kinit=$samba4bindir/samba4kinit
25 net=$samba4bindir/net
26
27 testit() {
28         name="$1"
29         shift
30         cmdline="$*"
31         echo "test: $name"
32         $cmdline
33         status=$?
34         if [ x$status = x0 ]; then
35                 echo "success: $name"
36         else
37                 echo "failure: $name"
38         fi
39         return $status
40 }
41
42
43 test_smbclient() {
44         name="$1"
45         cmd="$2"
46         shift
47         shift
48         echo "test: $name"
49         $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" -W "$DOMAIN" -U"$USERNAME%$PASSWORD" $@
50         status=$?
51         if [ x$status = x0 ]; then
52                 echo "success: $name"
53         else
54                 echo "failure: $name"
55         fi
56         return $status
57 }
58
59 KRB5CCNAME="$PREFIX/tmpccache"
60 export KRB5CCNAME
61
62 echo $PASSWORD > ./tmppassfile
63 testit "kinit with password" $samba4kinit --password-file=./tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
64 testit "kinit with pkinit" $samba4kinit --request-pac --pk-user=FILE:$PREFIX/dc/private/tls/admincert.pem,$PREFIX/dc/private/tls/adminkey.pem $USERNAME@$REALM || failed=`expr $failed + 1`
65
66 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
67
68 testit "domain join with kerberos ccache" $VALGRIND $net join $DOMAIN $CONFIGURATION  -W "$DOMAIN" -k yes $@ || failed=`expr $failed + 1`
69 testit "check time with kerberos ccache" $VALGRIND $net time $SERVER $CONFIGURATION  -W "$DOMAIN" -k yes $@ || failed=`expr $failed + 1`
70
71 testit "add user with kerberos ccache" $VALGRIND $net user add nettestuser $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
72 USERPASS=testPass@12%
73
74 testit "set user password with kerberos ccache" $VALGRIND $net password set $DOMAIN\\nettestuser $USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
75
76 #KRB5CCNAME=`pwd`/tmpuserccache
77 #export KRB5CCNAME
78 #
79 #testit "kinit with user password" bin/samba4kinit --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
80 #
81 #KRB5CCNAME=`pwd`/tmpccache
82 #export KRB5CCNAME
83
84 testit "del user with kerberos ccache" $VALGRIND $net user delete nettestuser $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
85
86 rm -f tmpccfile tmppassfile tmpuserccache
87 exit $failed