s4-test: check that a weak password is rejected by kpasswd
[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 newuser="$net newuser"
29
30 . `dirname $0`/subunit.sh
31
32 test_smbclient() {
33         name="$1"
34         cmd="$2"
35         shift
36         shift
37         echo "test: $name"
38         $VALGRIND $smbclient //$SERVER/tmp -c "$cmd" -W "$DOMAIN" $@
39         status=$?
40         if [ x$status = x0 ]; then
41                 echo "success: $name"
42         else
43                 echo "failure: $name"
44         fi
45         return $status
46 }
47
48 CONFIG="--configfile=$PREFIX/dc/etc/smb.conf"
49 export CONFIG
50
51 USERPASS=testPaSS@01%
52
53 testit "create user locally" $VALGRIND $newuser $CONFIG nettestuser $USERPASS $@ || failed=`expr $failed + 1`
54
55 KRB5CCNAME="$PREFIX/tmpuserccache"
56 export KRB5CCNAME
57
58 echo $USERPASS > $PREFIX/tmpuserpassfile
59
60 testit "kinit with user password" $samba4kinit --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
61
62 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
63
64 NEWUSERPASS=testPaSS@02%
65 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`
66
67 echo $NEWUSERPASS > ./tmpuserpassfile
68 testit "kinit with user password" $samba4kinit --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
69
70 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
71
72
73 USERPASS=$NEWUSERPASS
74 WEAKPASS=testpass1
75 NEWUSERPASS=testPaSS@03%
76
77 # password mismatch check doesn't work yet (kpasswd bug, reported to Love)
78 #echo "check that password mismatch gives the right error"
79 #cat > ./tmpkpasswdscript <<EOF
80 #expect Password
81 #password ${USERPASS}\n
82 #expect New password
83 #send ${WEAKPASS}\n
84 #expect New password
85 #send ${NEWUSERPASS}\n
86 #expect password mismatch
87 #EOF
88 #
89 #testit "change user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
90
91
92 echo "check that a weak password is rejected"
93 cat > ./tmpkpasswdscript <<EOF
94 expect Password
95 password ${USERPASS}\n
96 expect New password
97 send ${WEAKPASS}\n
98 expect New password
99 send ${WEAKPASS}\n
100 expect Password does not meet complexity requirements
101 EOF
102
103 testit "change to weak user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
104
105 echo "check that a short password is rejected"
106 cat > ./tmpkpasswdscript <<EOF
107 expect Password
108 password ${USERPASS}\n
109 expect New password
110 send xx1\n
111 expect New password
112 send xx1\n
113 expect Password too short
114 EOF
115
116 testit "change to short user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
117
118
119 echo "check that a strong new password is accepted"
120 cat > ./tmpkpasswdscript <<EOF
121 expect Password
122 password ${USERPASS}\n
123 expect New password
124 send ${NEWUSERPASS}\n
125 expect New password
126 send ${NEWUSERPASS}\n
127 expect Success
128 EOF
129
130 testit "change user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
131
132 test_smbclient "Test login with user kerberos (unforced)" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
133
134
135 NEWUSERPASS=testPaSS@04%
136 testit "set password on user locally" $VALGRIND $net setpassword $CONFIG nettestuser --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed=`expr $failed + 1`
137 USERPASS=$NEWUSERPASS
138
139 NEWUSERPASS=testPaSS@05%
140 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`
141 USERPASS=$NEWUSERPASS
142
143 NEWUSERPASS=testPaSS@06%
144 testit "set password on user locally" $VALGRIND $net setpassword $CONFIG nettestuser --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed=`expr $failed + 1`
145 USERPASS=$NEWUSERPASS
146
147 NEWUSERPASS=testPaSS@07%
148
149 cat > ./tmpkpasswdscript <<EOF
150 expect Password
151 password ${USERPASS}\n
152 expect New password
153 send ${NEWUSERPASS}\n
154 expect New password
155 send ${NEWUSERPASS}\n
156 expect Success
157 EOF
158
159 testit "change user password with kpasswd (after must change flag set)" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
160 USERPASS=$NEWUSERPASS
161
162 test_smbclient "Test login with user kerberos" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
163
164 testit "reset password policies" $VALGRIND $net pwsettings set $CONFIG --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
165
166 NEWUSERPASS=abcdefg
167 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`
168
169 testit "allow non-complex passwords" $VALGRIND $net pwsettings set $CONFIG --complexity=off || failed=`expr $failed + 1`
170
171 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`
172 USERPASS=$NEWUSERPASS
173
174 test_smbclient "test login with non-complex password" 'ls' -k no -Unettestuser@$REALM%$USERPASS || failed=`expr $failed + 1`
175
176 NEWUSERPASS=abc
177 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`
178
179 testit "allow short passwords (length 1)" $VALGRIND $net pwsettings $CONFIG set --min-pwd-length=1 || failed=`expr $failed + 1`
180
181 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`
182 USERPASS="$NEWUSERPASS"
183
184 testit "require minimum password age of 1 day" $VALGRIND $net pwsettings $CONFIG set --min-pwd-age=1 || failed=`expr $failed + 1`
185
186 testit "show password settings" $VALGRIND $net pwsettings $CONFIG show || failed=`expr $failed + 1`
187
188 NEWUSERPASS="testPaSS@08%"
189 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`
190
191 testit "reset password policies" $VALGRIND $net pwsettings $CONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
192
193 testit "del user" $VALGRIND $net user delete nettestuser -U"$USERNAME%$PASSWORD" -k no $@ || failed=`expr $failed + 1`
194
195 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
196 exit $failed