r23964: Update blackbox selftest scripts to cover more code, and to more
[samba.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 testit() {
23         name="$1"
24         shift
25         cmdline="$*"
26         echo "test: $name"
27         $cmdline
28         status=$?
29         if [ x$status = x0 ]; then
30                 echo "success: $name"
31         else
32                 echo "failure: $name"
33         fi
34         return $status
35 }
36
37
38 test_smbclient() {
39         name="$1"
40         cmd="$2"
41         shift
42         shift
43         echo "test: $name"
44         $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" -W "$DOMAIN" -U"$USERNAME%$PASSWORD" $@
45         status=$?
46         if [ x$status = x0 ]; then
47                 echo "success: $name"
48         else
49                 echo "failure: $name"
50         fi
51         return $status
52 }
53
54 KRB5CCNAME=`pwd`/tmpccache
55 export KRB5CCNAME
56
57 echo $PASSWORD > ./tmppassfile
58 testit "kinit with password" bin/samba4kinit --password-file=./tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
59 testit "kinit with pkinit" bin/samba4kinit --request-pac --pk-user=FILE:$PREFIX/dc/private/tls/admincert.pem,$PREFIX/dc/private/tls/adminkey.pem $USERNAME@$REALM || failed=`expr $failed + 1`
60
61 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
62
63 testit "domain join with kerberos ccache" $VALGRIND bin/net join $DOMAIN $CONFIGURATION  -W "$DOMAIN" -k yes $@ || failed=`expr $failed + 1`
64
65 testit "add user with kerberos ccache" $VALGRIND bin/net user add nettestuser $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
66 USERPASS=testPass@12%
67
68 testit "set user password with kerberos ccache" $VALGRIND bin/net password set $DOMAIN\\nettestuser $USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
69
70 #KRB5CCNAME=`pwd`/tmpuserccache
71 #export KRB5CCNAME
72 #
73 #testit "kinit with user password" bin/samba4kinit --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
74 #
75 #KRB5CCNAME=`pwd`/tmpccache
76 #export KRB5CCNAME
77
78 testit "del user with kerberos ccache" $VALGRIND bin/net user delete nettestuser $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
79
80 rm -f tmpccfile tmppassfile tmpuserccache
81 exit $failed