762b0c37a5e3acf9363d2c646e057a26d1490e53
[samba.git] / source / script / tests / test_smbclient_s3.sh
1 #!/bin/sh
2
3 # this runs the file serving tests that are expected to pass with samba3
4
5 if [ $# != 2 ]; then
6 cat <<EOF
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP
8 EOF
9 exit 1;
10 fi
11
12 BINDIR=`dirname $0`/../../bin
13
14 SERVER="$1"
15 SERVER_IP="$2"
16 SMBCLIENT="$VALGRIND ${SMBCLIENT:-$BINDIR/smbclient} $CONFIGURATION"
17
18 failed=0
19
20 testit() {
21         name="$1"
22         shift
23         cmdline="$*"
24         echo "test: $name"
25         $cmdline
26         status=$?
27         if [ x$status = x0 ]; then
28                 echo "success: $name"
29         else
30                 echo "failure: $name"
31         fi
32         return $status
33 }
34
35 # Test that a noninteractive smbclient does not prompt
36 test_noninteractive_no_prompt()
37 {
38     prompt="smb"
39
40     echo du | \
41         $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp 2>&1 | \
42     grep $prompt
43
44     if [ $? = 0 ] ; then
45         # got a prompt .. fail
46         echo matched interactive prompt in non-interactive mode
47         false
48     else
49         true
50     fi
51 }
52
53 # Test that an interactive smbclient prompts to stdout
54 test_interactive_prompt_stdout()
55 {
56     prompt="smb"
57     tmpfile=/tmp/smbclient.in.$$
58
59     cat > $tmpfile <<EOF
60 du
61 quit
62 EOF
63
64     CLI_FORCE_INTERACTIVE=yes \
65     $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp \
66         < $tmpfile 2>/dev/null | \
67     grep $prompt
68
69     if [ $? = 0 ] ; then
70         # got a prompt .. succeed
71         rm -f $tmpfile
72         true
73     else
74         echo failed to match interactive prompt on stdout
75         rm -f $tmpfile
76         false
77     fi
78 }
79
80 testit "smbclient -L $SERVER_IP" $SMBCLIENT $CONFIGURATION -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
81 testit "smbclient -L $SERVER" $SMBCLIENT $CONFIGURATION -L $SERVER -N -p 139 || failed=`expr $failed + 1`
82
83 testit "noninteractive smbclient does not prompt" \
84     test_noninteractive_no_prompt || \
85     failed=`expr $failed + 1`
86
87 testit "noninteractive smbclient -l does not prompt" \
88    test_noninteractive_no_prompt -l /tmp || \
89     failed=`expr $failed + 1`
90
91 testit "interactive smbclient prompts on stdout" \
92    test_interactive_prompt_stdout || \
93     failed=`expr $failed + 1`
94
95 testit "interactive smbclient -l prompts on stdout" \
96    test_interactive_prompt_stdout -l /tmp || \
97     failed=`expr $failed + 1`
98
99 exit $failed