s3:tests: test_smbspool.sh should be calling smbspool_argv_wrapper
[samba.git] / source3 / script / tests / test_smbspool.sh
1 #!/bin/sh
2
3 if [ $# -lt 4 ]; then
4         cat <<EOF
5 Usage: test_smbspool.sh SERVER SERVER_IP USERNAME PASSWORD TARGET_ENV
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_argv_wrapper="$samba_bindir/smbspool_argv_wrapper"
26 samba_smbtorture3="$samba_bindir/smbtorture3"
27 samba_smbspool_krb5="$samba_bindir/smbspool_krb5_wrapper"
28
29 test_smbspool_noargs()
30 {
31         cmd='$1 2>&1'
32         eval echo "$cmd"
33         out=$(eval $cmd)
34         ret=$?
35
36         if [ $ret != 0 ]; then
37                 echo "$out"
38                 echo "failed to execute $1"
39         fi
40
41         echo "$out" | grep 'network smb "Unknown" "Windows Printer via SAMBA"'
42         ret=$?
43         if [ $ret != 0 ]; then
44                 echo "$out"
45                 return 1
46         fi
47 }
48
49 test_smbspool_authinforequired_none()
50 {
51         cmd='$samba_smbspool_krb5 smb://$SERVER_IP/print4 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps 2>&1'
52
53         AUTH_INFO_REQUIRED="none"
54         export AUTH_INFO_REQUIRED
55         eval echo "$cmd"
56         out=$(eval $cmd)
57         ret=$?
58         unset AUTH_INFO_REQUIRED
59
60         if [ $ret != 0 ]; then
61                 echo "$out"
62                 echo "failed to execute $smbspool_krb5"
63                 return 1
64         fi
65
66         return 0
67 }
68
69 test_smbspool_authinforequired_unknown()
70 {
71         cmd='$samba_smbspool_krb5 smb://$SERVER_IP/print4 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps 2>&1'
72
73         # smbspool_krb5_wrapper must ignore AUTH_INFO_REQUIRED unknown to him and pass the task to smbspool
74         # smbspool must fail with NT_STATUS_ACCESS_DENIED (22)
75         # "jjf4wgmsbc0" is just a random string
76         AUTH_INFO_REQUIRED="jjf4wgmsbc0"
77         export AUTH_INFO_REQUIRED
78         eval echo "$cmd"
79         out=$(eval $cmd)
80         ret=$?
81         unset AUTH_INFO_REQUIRED
82
83         case "$ret" in
84         2) return 0 ;;
85         *)
86                 echo "ret=$ret"
87                 echo "$out"
88                 echo "failed to test $smbspool_krb5 against unknown value of AUTH_INFO_REQUIRED"
89                 return 1
90                 ;;
91         esac
92 }
93
94 #
95 # The test environment uses 'vlp' (virtual lp) as the printing backend.
96 #
97 # When using the vlp backend the print job is only written to the database.
98 # The job needs to removed manually using 'vlp lprm' command!
99 #
100 # This calls the 'vlp' command to check if the print job has been successfully
101 # added to the database and also makes sure the temporary print file has been
102 # created.
103 #
104 # The function removes the print job from the vlp database if successful.
105 #
106 test_vlp_verify()
107 {
108         tdbfile="$PREFIX_ABS/$TARGET_ENV/lockdir/vlp.tdb"
109         if [ ! -w $tdbfile ]; then
110                 echo "vlp tdbfile $tdbfile doesn't exist or is not writeable!"
111                 return 1
112         fi
113
114         cmd='$samba_vlp tdbfile=$tdbfile lpq print1 2>&1'
115         eval echo "$cmd"
116         out=$(eval $cmd)
117         ret=$?
118         if [ $ret != 0 ]; then
119                 echo "failed to get print queue with $samba_vlp"
120                 echo "$out"
121         fi
122
123         jobid=$(echo "$out" | awk '/[0-9]+/ { print $1 };')
124         if [ -z "$jobid" ] || [ $jobid -lt 100 ] || [ $jobid -gt 2000 ]; then
125                 echo "Invalid jobid: $jobid"
126                 echo "$out"
127                 return 1
128         fi
129
130         file=$(echo "$out" | awk '/[0-9]+/ { print $6 };')
131         if [ ! -r $PREFIX_ABS/$TARGET_ENV/share/$file ]; then
132                 echo "$file doesn't exist"
133                 echo "$out"
134                 return 1
135         fi
136
137         $samba_vlp "tdbfile=$tdbfile" lprm print1 $jobid
138         ret=$?
139         if [ $ret != 0 ]; then
140                 echo "Failed to remove jobid $jobid from $tdbfile"
141                 return 1
142         fi
143 }
144
145 test_delete_on_close()
146 {
147         tdbfile="$PREFIX_ABS/$TARGET_ENV/lockdir/vlp.tdb"
148         if [ ! -w $tdbfile ]; then
149                 echo "vlp tdbfile $tdbfile doesn't exist or is not writeable!"
150                 return 1
151         fi
152
153         cmd='$samba_vlp tdbfile=$tdbfile lpq print1 2>&1'
154         eval echo "$cmd"
155         out=$(eval $cmd)
156         ret=$?
157         if [ $ret != 0 ]; then
158                 echo "failed to lpq jobs on print1 with $samba_vlp"
159                 echo "$out"
160                 return 1
161         fi
162
163         num_jobs=$(echo "$out" | wc -l)
164         #
165         # Now run the test DELETE-PRINT from smbtorture3
166         #
167         cmd='$samba_smbtorture3 //$SERVER_IP/print1 -U$USERNAME%$PASSWORD DELETE-PRINT 2>&1'
168         eval echo "$cmd"
169         out_t=$(eval $cmd)
170         ret=$?
171         if [ $ret != 0 ]; then
172                 echo "failed to run DELETE-PRINT on print1"
173                 echo "$out_t"
174                 return 1
175         fi
176
177         cmd='$samba_vlp tdbfile=$tdbfile lpq print1 2>&1'
178         eval echo "$cmd"
179         out1=$(eval $cmd)
180         ret=$?
181         if [ $ret != 0 ]; then
182                 echo "(2) failed to lpq jobs on print1 with $samba_vlp"
183                 echo "$out1"
184                 return 1
185         fi
186         num_jobs1=$(echo "$out1" | wc -l)
187
188         #
189         # Number of jobs should not change. Job
190         # should not have made it to backend.
191         #
192         if [ "$num_jobs1" -ne "$num_jobs" ]; then
193                 echo "delete-on-close fail $num_jobs1 -ne $num_jobs"
194                 echo "$out"
195                 echo "$out_t"
196                 echo "$out1"
197                 return 1
198         fi
199
200         return 0
201 }
202
203 testit "smbspool no args" \
204         test_smbspool_noargs $samba_smbspool ||
205         failed=$(expr $failed + 1)
206
207 testit "smbspool_krb5_wrapper no args" \
208         test_smbspool_noargs $samba_smbspool_krb5 ||
209         failed=$(expr $failed + 1)
210
211 testit "smbspool_krb5_wrapper AuthInfoRequired=none" \
212         test_smbspool_authinforequired_none ||
213         failed=$(expr $failed + 1)
214
215 testit "smbspool_krb5_wrapper AuthInfoRequired=(sth unknown)" \
216         test_smbspool_authinforequired_unknown ||
217         failed=$(expr $failed + 1)
218
219 testit "smbspool print example.ps" \
220         $samba_smbspool smb://$USERNAME:$PASSWORD@$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps ||
221         failed=$(expr $failed + 1)
222
223 testit "vlp verify example.ps" \
224         test_vlp_verify ||
225         failed=$(expr $failed + 1)
226
227 testit "smbspool print example.ps via stdin" \
228         $samba_smbspool smb://$USERNAME:$PASSWORD@$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" <$SRCDIR/testdata/printing/example.ps ||
229         failed=$(expr $failed + 1)
230
231 testit "vlp verify example.ps" \
232         test_vlp_verify ||
233         failed=$(expr $failed + 1)
234
235 DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
236 export DEVICE_URI
237 testit "smbspool print DEVICE_URI example.ps" \
238         $samba_smbspool 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps ||
239         failed=$(expr $failed + 1)
240 unset DEVICE_URI
241
242 testit "vlp verify example.ps" \
243         test_vlp_verify ||
244         failed=$(expr $failed + 1)
245
246 DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
247 export DEVICE_URI
248 testit "smbspool print DEVICE_URI example.ps via stdin" \
249         $samba_smbspool 200 $USERNAME "Testprint" 1 "options" <$SRCDIR/testdata/printing/example.ps ||
250         failed=$(expr $failed + 1)
251 unset DEVICE_URI
252
253 testit "vlp verify example.ps" \
254         test_vlp_verify ||
255         failed=$(expr $failed + 1)
256
257 DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
258 export DEVICE_URI
259 testit "smbspool print sanitized Device URI in argv0 example.ps" \
260         $samba_argv_wrapper $samba_smbspool smb://$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps ||
261         failed=$(expr $failed + 1)
262 unset DEVICE_URI
263
264 testit "vlp verify example.ps" \
265         test_vlp_verify ||
266         failed=$(expr $failed + 1)
267
268 DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
269 export DEVICE_URI
270 testit "smbspool print sanitized Device URI in argv0 example.ps via stdin" \
271         $samba_argv_wrapper $samba_smbspool smb://$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" <$SRCDIR/testdata/printing/example.ps ||
272         failed=$(expr $failed + 1)
273 unset DEVICE_URI
274
275 testit "vlp verify example.ps" \
276         test_vlp_verify ||
277         failed=$(expr $failed + 1)
278
279 AUTH_INFO_REQUIRED="username,password"
280 export AUTH_INFO_REQUIRED
281 testit "smbspool_krb5(username,password) print example.ps" \
282         $samba_smbspool_krb5 smb://$USERNAME:$PASSWORD@$SERVER_IP/print1 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps ||
283         failed=$(expr $failed + 1)
284
285 testit "vlp verify example.ps" \
286         test_vlp_verify ||
287         failed=$(expr $failed + 1)
288 unset AUTH_INFO_REQUIRED
289
290 testit "delete on close" \
291         test_delete_on_close ||
292         failed=$(expr $failed + 1)
293
294 exit $failed