s3:smbspool: Fix cmdline argument handling
[metze/samba/wip.git] / source3 / script / tests / test_smbspool.sh
1 #!/bin/sh
2
3 if [ $# -lt 4 ]; then
4 cat <<EOF
5 Usage: test_smbclient_basic.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD
6 EOF
7 exit 1;
8 fi
9
10 SERVER="$1"
11 SERVER_IP="$2"
12 USERNAME="$3"
13 PASSWORD="$4"
14 TARGET_ENV="$5"
15 shift 5
16 ADDARGS="$@"
17
18 incdir=`dirname $0`/../../../testprogs/blackbox
19 . $incdir/subunit.sh
20 . $incdir/common_test_fns.inc
21
22 samba_bindir="$BINDIR"
23 samba_vlp="$samba_bindir/vlp"
24 samba_smbspool="$samba_bindir/smbspool"
25 samba_smbspool_krb5="$samba_bindir/smbspool_krb5_wrapper"
26
27 test_smbspool_noargs()
28 {
29         cmd='$1 2>&1'
30         eval echo "$cmd"
31         out=$(eval $cmd)
32         ret=$?
33
34         if [ $ret != 0 ]; then
35                 echo "$out"
36                 echo "failed to execute $1"
37         fi
38
39         echo "$out" | grep 'network smb "Unknown" "Windows Printer via SAMBA"'
40         ret=$?
41         if [ $ret != 0 ] ; then
42                 echo "$out"
43                 return 1
44         fi
45 }
46
47 test_smbspool_authinforequired_none()
48 {
49         cmd='$samba_smbspool_krb5 smb://$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps 2>&1'
50
51         AUTH_INFO_REQUIRED="none"
52         export AUTH_INFO_REQUIRED
53         eval echo "$cmd"
54         out=$(eval $cmd)
55         ret=$?
56         unset AUTH_INFO_REQUIRED
57
58         if [ $ret != 0 ]; then
59                 echo "$out"
60                 echo "failed to execute $smbspool_krb5"
61         fi
62
63         echo "$out" | grep 'ATTR: auth-info-required=negotiate'
64         ret=$?
65         if [ $ret != 0 ] ; then
66                 echo "$out"
67                 return 1
68         fi
69 }
70
71 #
72 # The test enviornment uses 'vlp' (virtual lp) as the printing backend.
73 #
74 # When using the vlp backend the print job is only written to the database.
75 # The job needs to removed manually using 'vlp lprm' command!
76 #
77 # This calls the 'vlp' command to check if the print job has been successfully
78 # added to the database and also makes sure the temorary print file has been
79 # created.
80 #
81 # The function removes the print job from the vlp database if successful.
82 #
83 test_vlp_verify()
84 {
85         tdbfile="$PREFIX_ABS/$TARGET_ENV/lockdir/vlp.tdb"
86         if [ ! -w $tdbfile ]; then
87                 echo "vlp tdbfile $tdbfile doesn't exist or is not writeable!"
88                 return 1
89         fi
90
91         cmd='$samba_vlp tdbfile=$tdbfile lpq print1 2>&1'
92         eval echo "$cmd"
93         out=$(eval $cmd)
94         ret=$?
95         if [ $ret != 0 ]; then
96                 echo "failed to get print queue with $samba_vlp"
97                 echo "$out"
98         fi
99
100         jobid=$(echo "$out" | awk '/[0-9]+/ { print $1 };')
101         if [ $jobid -lt 1000 || $jobid -gt 2000 ]; then
102                 echo "failed to get jobid"
103                 echo "$out"
104                 return 1
105         fi
106
107         file=$(echo "$out" | awk '/[0-9]+/ { print $6 };')
108         if [ ! -r $PREFIX_ABS/$TARGET_ENV/share/$file ]; then
109                 echo "$file doesn't exist"
110                 echo "$out"
111                 return 1
112         fi
113
114         $samba_vlp "tdbfile=$tdbfile" lprm print1 $jobid
115         ret=$?
116         if [ $ret != 0 ] ; then
117                 echo "Failed to remove jobid $jobid from $tdbfile"
118                 return 1
119         fi
120 }
121
122 testit "smbspool no args" \
123         test_smbspool_noargs $samba_smbspool || \
124         failed=$(expr $failed + 1)
125
126 testit "smbspool_krb5_wrapper no args" \
127         test_smbspool_noargs $samba_smbspool_krb5 || \
128         failed=$(expr $failed + 1)
129
130 testit "smbspool_krb5_wrapper AuthInfoRequired=none" \
131         test_smbspool_authinforequired_none || \
132         failed=$(expr $failed + 1)
133
134 testit "smbspool print example.ps" \
135         $samba_smbspool smb://$USERNAME:$PASSWORD@$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps || \
136         failed=$(expr $failed + 1)
137
138 testit "vlp verify example.ps" \
139         test_vlp_verify \
140         || failed=$(expr $failed + 1)
141
142 testit "smbspool print example.ps via stdin" \
143         $samba_smbspool smb://$USERNAME:$PASSWORD@$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" < $SRCDIR/testdata/printing/example.ps || \
144         failed=$(expr $failed + 1)
145
146 testit "vlp verify example.ps" \
147         test_vlp_verify \
148         || failed=$(expr $failed + 1)
149
150 DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
151 export DEVICE_URI
152 testit "smbspool print DEVICE_URI example.ps" \
153         $samba_smbspool 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps || \
154         failed=$(expr $failed + 1)
155 unset DEVICE_URI
156
157 testit "vlp verify example.ps" \
158         test_vlp_verify \
159         || failed=$(expr $failed + 1)
160
161 DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
162 export DEVICE_URI
163 testit "smbspool print DEVICE_URI example.ps via stdin" \
164         $samba_smbspool 200 $USERNAME "Testprint" 1 "options" < $SRCDIR/testdata/printing/example.ps || \
165         failed=$(expr $failed + 1)
166 unset DEVICE_URI
167
168 testit "vlp verify example.ps" \
169         test_vlp_verify \
170         || failed=$(expr $failed + 1)
171
172 AUTH_INFO_REQUIRED="username,password"
173 export AUTH_INFO_REQUIRED
174 testit "smbspool_krb5(username,password) print example.ps" \
175         $samba_smbspool_krb5 smb://$USERNAME:$PASSWORD@$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps || \
176         failed=$(expr $failed + 1)
177
178 testit "vlp verify example.ps" \
179         test_vlp_verify || \
180         failed=$(expr $failed + 1)
181 unset AUTH_INFO_REQUIRED
182
183 exit $failed