Fix commands in password tests.
[kai/samba.git] / testprogs / blackbox / test_passwords.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-2008 Andrew Bartlett <abartlet@samba.org>
5
6 if [ $# -lt 5 ]; then
7 cat <<EOF
8 Usage: test_passwords.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="$BUILDDIR/bin"
23 smbclient="$samba4bindir/smbclient$EXEEXT"
24 samba4kinit="$samba4bindir/samba4kinit$EXEEXT"
25 net="$samba4bindir/net$EXEEXT"
26 rkpty="$samba4bindir/rkpty$EXEEXT"
27 samba4kpasswd="$samba4bindir/samba4kpasswd$EXEEXT"
28 enableaccount="$PYTHON `dirname $0`/../../source4/setup/enableaccount"
29 setpassword="$PYTHON `dirname $0`/../../source4/setup/setpassword"
30 newuser="$PYTHON `dirname $0`/../../source4/setup/newuser"
31
32 . `dirname $0`/subunit.sh
33
34 test_smbclient() {
35         name="$1"
36         cmd="$2"
37         shift
38         shift
39         echo "test: $name"
40         $VALGRIND $smbclient //$SERVER/tmp -c "$cmd" -W "$DOMAIN" $@
41         status=$?
42         if [ x$status = x0 ]; then
43                 echo "success: $name"
44         else
45                 echo "failure: $name"
46         fi
47         return $status
48 }
49
50 USERPASS=testPaSS@01%
51
52 testit "create user locally" $VALGRIND $newuser nettestuser $USERPASS $@ || failed=`expr $failed + 1`
53
54 KRB5CCNAME="$PREFIX/tmpuserccache"
55 export KRB5CCNAME
56
57 echo $USERPASS > $PREFIX/tmpuserpassfile
58
59 testit "kinit with user password" $samba4kinit --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
60
61 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
62
63 NEWUSERPASS=testPaSS@02%
64 testit "change user password with 'net password change' (unforced)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS  -k no $NEWUSERPASS $@ || failed=`expr $failed + 1`
65
66 echo $NEWUSERPASS > ./tmpuserpassfile
67 testit "kinit with user password" $samba4kinit --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
68
69 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
70
71
72 USERPASS=$NEWUSERPASS
73 NEWUSERPASS=testPaSS@03%
74
75 cat > ./tmpkpasswdscript <<EOF
76 expect Password
77 password ${USERPASS}\n
78 expect New password
79 send ${NEWUSERPASS}\n
80 expect New password
81 send ${NEWUSERPASS}\n
82 expect Success
83 EOF
84
85 testit "change user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
86
87 test_smbclient "Test login with user kerberos (unforced)" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
88
89
90 NEWUSERPASS=testPaSS@04%
91 testit "set password on user locally" $VALGRIND $setpassword nettestuser --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed=`expr $failed + 1`
92 USERPASS=$NEWUSERPASS
93
94 NEWUSERPASS=testPaSS@05%
95 testit "change user password with 'net password change' (after must change flag set)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS -k no $NEWUSERPASS $@ || failed=`expr $failed + 1`
96 USERPASS=$NEWUSERPASS
97
98 NEWUSERPASS=testPaSS@06%
99 testit "set password on user locally" $VALGRIND $setpassword nettestuser --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed=`expr $failed + 1`
100 USERPASS=$NEWUSERPASS
101
102 NEWUSERPASS=testPaSS@07%
103
104 cat > ./tmpkpasswdscript <<EOF
105 expect Password
106 password ${USERPASS}\n
107 expect New password
108 send ${NEWUSERPASS}\n
109 expect New password
110 send ${NEWUSERPASS}\n
111 expect Success
112 EOF
113
114 testit "change user password with kpasswd (after must change flag set)" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
115 USERPASS=$NEWUSERPASS
116
117 test_smbclient "Test login with user kerberos" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
118
119 testit "reset password policies" $VALGRIND $samba4bindir/net pwsettings set --configfile=$PREFIX/dc/etc/smb.conf --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
120
121 NEWUSERPASS=abcdefg
122 testit_expect_failure "try to set a non-complex password (command should not succeed)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS -k no $NEWUSERPASS $@ && failed=`expr $failed + 1`
123
124 testit "allow non-complex passwords" $VALGRIND $samba4bindir/net pwsettings set --configfile=$PREFIX/dc/etc/smb.conf --complexity=off || failed=`expr $failed + 1`
125
126 testit "try to set a non-complex password (command should succeed)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS -k no $NEWUSERPASS $@ || failed=`expr $failed + 1`
127 USERPASS=$NEWUSERPASS
128
129 test_smbclient "test login with non-complex password" 'ls' -k no -Unettestuser@$REALM%$USERPASS || failed=`expr $failed + 1`
130
131 NEWUSERPASS=abc
132 testit_expect_failure "try to set a short password (command should not succeed)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS -k no $NEWUSERPASS $@ && failed=`expr $failed + 1`
133
134 testit "allow short passwords (length 1)" $VALGRIND $samba4bindir/net pwsettings set --configfile=$PREFIX/dc/etc/smb.conf --min-pwd-length=1 || failed=`expr $failed + 1`
135
136 testit "try to set a short password (command should succeed)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS -k no $NEWUSERPASS $@ || failed=`expr $failed + 1`
137 USERPASS=$NEWUSERPASS
138
139 testit "require minimum password age of 1 day" $VALGRIND $samba4bindir/net pwsettings set --configfile=$PREFIX/dc/etc/smb.conf --min-pwd-age=1 || failed=`expr $failed + 1`
140
141 NEWUSERPASS=testPaSS@08%
142 testit_expect_failure "try to change password too quickly (command should not succeed)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS -k no $NEWUSERPASS $@ && failed=`expr $failed + 1`
143
144 testit "reset password policies" $VALGRIND $samba4bindir/net pwsettings set --configfile=$PREFIX/dc/etc/smb.conf --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
145
146 testit "del user" $VALGRIND $net user delete nettestuser -U"$USERNAME%$PASSWORD" -k no $@ || failed=`expr $failed + 1`
147
148 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
149 exit $failed