s4-selftest: expand passdb testing
[samba.git] / testprogs / blackbox / test_pdbtest.sh
1 #!/bin/sh
2 # Blackbox tests for pdbtest
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2012 Andrew Bartlett <abartlet@samba.org>
5
6 if [ $# -lt 2 ]; then
7 cat <<EOF
8 Usage: test_pdbtest.sh SERVER PREFIX SMBCLIENT ENV
9 EOF
10 exit 1;
11 fi
12
13 SERVER=$1
14 PREFIX=$2
15 smbclient=$3
16 ENV=$4
17 shift 4
18 failed=0
19
20 samba4bindir="$BINDIR"
21 pdbtest="$samba4bindir/pdbtest"
22 pdbedit="$samba4bindir/pdbedit"
23 net="$samba4bindir/net"
24 smbpasswd="$samba4bindir/smbpasswd"
25 rkpty="$samba4bindir/rkpty"
26
27 . `dirname $0`/subunit.sh
28
29 test_smbclient() {
30         name="$1"
31         cmd="$2"
32         shift
33         shift
34         echo "test: $name"
35         $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" $@
36         status=$?
37         if [ x$status = x0 ]; then
38                 echo "success: $name"
39         else
40                 echo "failure: $name"
41         fi
42         return $status
43 }
44
45 testit "pdbtest" $BINDIR/pdbtest -u pdbtest || failed=`expr $failed + 1`
46
47 NEWUSERPASS=testPaSS@01%
48
49 echo "set password with pdbedit"
50 cat > ./tmpsmbpasswdscript <<EOF
51 expect new password:
52 send ${NEWUSERPASS}\n
53 expect retype new password:
54 send ${NEWUSERPASS}\n
55 EOF
56
57 testit "create user with pdbedit" $rkpty ./tmpsmbpasswdscript $VALGRIND $pdbedit -a pdbtest --account-desc="pdbedit-test-user" $@ || failed=`expr $failed + 1`
58 USERPASS=$NEWUSERPASS
59
60 test_smbclient "Test login with user (ntlm)" 'ls' -k no -Updbtest%$NEWUSERPASS $@ || failed=`expr $failed + 1`
61
62 testit "modify user"  $VALGRIND $pdbedit --modify pdbtest --drive="D:" $@ || failed=`expr $failed + 1`
63
64 test_smbclient "Test login with user (ntlm)" 'ls' -k no -Updbtest%$NEWUSERPASS $@|| failed=`expr $failed + 1`
65
66 NEWUSERPASS=testPaSS@02%
67
68 echo "set password with smbpasswd"
69 cat > ./tmpsmbpasswdscript <<EOF
70 expect New SMB password:
71 send ${NEWUSERPASS}\n
72 expect Retype new SMB password:
73 send ${NEWUSERPASS}\n
74 EOF
75
76 testit "set user password with smbpasswd" $rkpty ./tmpsmbpasswdscript $smbpasswd -L pdbtest -c $PREFIX/$ENV/etc/smb.conf || failed=`expr $failed + 1`
77 USERPASS=$NEWUSERPASS
78
79 test_smbclient "Test login with user (ntlm)" 'ls' -k no -Updbtest%$NEWUSERPASS $@|| failed=`expr $failed + 1`
80
81 testit "modify user - disabled"  $VALGRIND $net sam set disabled pdbtest yes $@ || failed=`expr $failed + 1`
82
83 testit_expect_failure  "Test login with disabled suer" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -k no -Updbtest@%$USERPASS && failed=`expr $failed + 1`
84
85 testit "modify user - enabled"  $VALGRIND $net sam set disabled pdbtest no $@ || failed=`expr $failed + 1`
86
87 test_smbclient "Test login with re-enabled user (ntlm)" 'ls' -k no -Updbtest%$NEWUSERPASS || failed=`expr $failed + 1`
88
89 testit "modify user - must change password now"  $VALGRIND $net sam set pwdmustchangenow pdbtest yes $@ || failed=`expr $failed + 1`
90
91 testit_expect_failure  "Test login with expired password" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -k no -Updbtest@%$USERPASS && failed=`expr $failed + 1`
92
93 testit "modify user - disable password expiry"  $VALGRIND $net sam set pwnoexp pdbtest yes $@ || failed=`expr $failed + 1`
94
95 test_smbclient "Test login with no expiry (ntlm)" 'ls' -k no -Updbtest%$NEWUSERPASS || failed=`expr $failed + 1`
96
97 testit "del user"  $VALGRIND $pdbedit -x pdbtest $@ || failed=`expr $failed + 1`
98
99 rm ./tmpsmbpasswdscript
100
101 exit $failed