s3:tests: Remove the non-working test_kerberos_upn_denied of smbget
[Samba.git] / source3 / script / tests / test_smbget.sh
blob1956fc5b38e3c8b0840922c293aec55c621fd375
1 #!/usr/bin/env bash
3 # Blackbox test for smbget.
6 if [ $# -lt 8 ]; then
7 cat <<EOF
8 Usage: test_smbget SERVER SERVER_IP DOMAIN REALM USERNAME PASSWORD WORKDIR SMBGET
9 EOF
10 exit 1
13 SERVER=${1}
14 SERVER_IP=${2}
15 DOMAIN=${3}
16 REALM=${4}
17 USERNAME=${5}
18 PASSWORD=${6}
19 DOMAIN_USER=${7}
20 DOMAIN_USER_PASSWORD=${8}
21 WORKDIR=${9}
22 SMBGET="$VALGRIND ${10}"
23 shift 10
25 TMPDIR="$SELFTEST_TMPDIR"
27 incdir=$(dirname $0)/../../../testprogs/blackbox
28 . $incdir/subunit.sh
29 . "${incdir}/common_test_fns.inc"
31 samba_kinit=$(system_or_builddir_binary kinit "${BINDIR}" samba4kinit)
33 create_test_data()
35 pushd $WORKDIR
36 dd if=/dev/urandom bs=1024 count=128 of=testfile
37 chmod 644 testfile
38 mkdir dir1
39 dd if=/dev/urandom bs=1024 count=128 of=dir1/testfile1
40 mkdir dir2
41 dd if=/dev/urandom bs=1024 count=128 of=dir2/testfile2
42 popd
45 remove_test_data()
47 pushd $WORKDIR
48 rm -rf dir1 dir2 testfile
49 popd
52 clear_download_area()
54 rm -rf dir1 dir2 testfile dir001 dir004 readable_file
57 test_singlefile_guest()
59 clear_download_area
60 echo "$SMBGET --verbose --guest smb://$SERVER_IP/smbget/testfile"
61 $SMBGET --verbose --guest smb://$SERVER_IP/smbget/testfile
62 if [ $? -ne 0 ]; then
63 echo 'ERROR: RC does not match, expected: 0'
64 return 1
66 cmp --silent $WORKDIR/testfile ./testfile
67 if [ $? -ne 0 ]; then
68 echo 'ERROR: file content does not match'
69 return 1
71 return 0
74 test_singlefile_U()
76 clear_download_area
77 $SMBGET --verbose -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
78 if [ $? -ne 0 ]; then
79 echo 'ERROR: RC does not match, expected: 0'
80 return 1
82 cmp --silent $WORKDIR/testfile ./testfile
83 if [ $? -ne 0 ]; then
84 echo 'ERROR: file content does not match'
85 return 1
87 return 0
90 test_singlefile_U_UPN()
92 clear_download_area
94 ${SMBGET} --verbose -U"${DOMAIN_USER}@${REALM}%${DOMAIN_USER_PASSWORD}" \
95 "smb://${SERVER_IP}/smbget/testfile"
96 ret=${?}
97 if [ ${ret} -ne 0 ]; then
98 echo 'ERROR: RC does not match, expected: 0'
99 return 1
102 cmp --silent "${WORKDIR}/testfile" ./testfile
103 ret=${?}
104 if [ ${ret} -ne 0 ]; then
105 echo 'ERROR: file content does not match'
106 return 1
109 return 0
112 test_singlefile_U_domain()
114 clear_download_area
116 ${SMBGET} --verbose -U"${DOMAIN}/${DOMAIN_USER}%${DOMAIN_USER_PASSWORD}" \
117 "smb://${SERVER_IP}/smbget/testfile"
118 ret=${?}
119 if [ ${ret} -ne 0 ]; then
120 echo 'ERROR: RC does not match, expected: 0'
121 return 1
124 cmp --silent "${WORKDIR}/testfile" ./testfile
125 ret=${?}
126 if [ ${ret} -ne 0 ]; then
127 echo 'ERROR: file content does not match'
128 return 1
131 return 0
134 test_singlefile_smburl()
136 clear_download_area
137 $SMBGET --workgroup $DOMAIN smb://${DOMAIN_USER}:$DOMAIN_USER_PASSWORD@$SERVER_IP/smbget/testfile
138 if [ $? -ne 0 ]; then
139 echo 'ERROR: RC does not match, expected: 0'
140 return 1
142 cmp --silent $WORKDIR/testfile ./testfile
143 if [ $? -ne 0 ]; then
144 echo 'ERROR: file content does not match'
145 return 1
147 return 0
150 test_singlefile_smburl2()
152 clear_download_area
153 $SMBGET "smb://$DOMAIN;${DOMAIN_USER}:$DOMAIN_USER_PASSWORD@$SERVER_IP/smbget/testfile"
154 if [ $? -ne 0 ]; then
155 echo 'ERROR: RC does not match, expected: 0'
156 return 1
158 cmp --silent $WORKDIR/testfile ./testfile
159 if [ $? -ne 0 ]; then
160 echo 'ERROR: file content does not match'
161 return 1
163 return 0
166 test_singlefile_authfile()
168 clear_download_area
169 cat >"${TMPDIR}/authfile" << EOF
170 username = ${SERVER}/${USERNAME}
171 password = $PASSWORD
173 $SMBGET --verbose --authentication-file="${TMPDIR}/authfile" smb://$SERVER_IP/smbget/testfile
174 rc=$?
175 rm -f $TMPDIR/authfile
176 if [ $rc -ne 0 ]; then
177 echo 'ERROR: RC does not match, expected: 0'
178 return 1
180 cmp --silent $WORKDIR/testfile ./testfile
181 if [ $? -ne 0 ]; then
182 echo 'ERROR: file content does not match'
183 return 1
185 return 0
188 test_recursive_U()
190 clear_download_area
191 $SMBGET --verbose --recursive -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/
192 if [ $? -ne 0 ]; then
193 echo 'ERROR: RC does not match, expected: 0'
194 return 1
197 cmp --silent $WORKDIR/testfile ./testfile &&
198 cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 &&
199 cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
200 if [ $? -ne 0 ]; then
201 echo 'ERROR: file content does not match'
202 return 1
205 return 0
208 test_recursive_existing_dir()
210 clear_download_area
211 mkdir dir1
212 $SMBGET --verbose --recursive -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/
213 if [ $? -ne 0 ]; then
214 echo 'ERROR: RC does not match, expected: 0'
215 return 1
218 cmp --silent $WORKDIR/testfile ./testfile &&
219 cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 &&
220 cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
221 if [ $? -ne 0 ]; then
222 echo 'ERROR: file content does not match'
223 return 1
226 return 0
229 test_recursive_with_empty()
230 { # see Bug 13199
231 clear_download_area
232 # create some additional empty directories
233 mkdir -p $WORKDIR/dir001/dir002/dir003
234 mkdir -p $WORKDIR/dir004/dir005/dir006
235 $SMBGET --verbose --recursive -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/
236 rc=$?
237 rm -rf $WORKDIR/dir001
238 rm -rf $WORKDIR/dir004
239 if [ $rc -ne 0 ]; then
240 echo 'ERROR: RC does not match, expected: 0'
241 return 1
244 cmp --silent $WORKDIR/testfile ./testfile &&
245 cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 &&
246 cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
247 if [ $? -ne 0 ]; then
248 echo 'ERROR: file content does not match'
249 return 1
252 if [ ! -d dir001/dir002/dir003 ] || [ ! -d dir004/dir005/dir006 ]; then
253 echo 'ERROR: empty directories are not present'
254 return 1
257 return 0
260 test_resume()
262 clear_download_area
263 cp $WORKDIR/testfile .
264 truncate -s 1024 testfile
265 $SMBGET --verbose --resume -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
266 if [ $? -ne 0 ]; then
267 echo 'ERROR: RC does not match, expected: 0'
268 return 1
271 cmp --silent $WORKDIR/testfile ./testfile
272 if [ $? -ne 0 ]; then
273 echo 'ERROR: file content does not match'
274 return 1
277 return 0
280 test_resume_modified()
282 clear_download_area
283 dd if=/dev/urandom bs=1024 count=2 of=testfile
284 $SMBGET --verbose --resume -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
285 if [ $? -ne 1 ]; then
286 echo 'ERROR: RC does not match, expected: 1'
287 return 1
290 return 0
293 test_update()
295 clear_download_area
296 $SMBGET --verbose -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
297 if [ $? -ne 0 ]; then
298 echo 'ERROR: RC does not match, expected: 0'
299 return 1
302 # secondary download should pass
303 $SMBGET --verbose --update -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
304 if [ $? -ne 0 ]; then
305 echo 'ERROR: RC does not match, expected: 0'
306 return 1
309 echo "modified" >>testfile
310 # touch source to trigger new download
311 sleep 2
312 touch -m $WORKDIR/testfile
313 $SMBGET --verbose --update -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
314 if [ $? -ne 0 ]; then
315 echo 'ERROR: RC does not match, expected: 0'
316 return 1
319 cmp --silent $WORKDIR/testfile ./testfile
320 if [ $? -ne 0 ]; then
321 echo 'ERROR: file content does not match'
322 return 1
325 return 0
328 # Test accessing an msdfs path.
329 test_msdfs_link()
331 clear_download_area
333 ${SMBGET} --verbose "-U${SERVER}/${USERNAME}%${PASSWORD}" \
334 "smb://${SERVER}/msdfs-share/deeppath/msdfs-src2/readable_file"
335 ret=$?
336 if [ ${ret} -ne 0 ]; then
337 echo "ERROR: smbget failed with ${ret}"
338 return 1
341 return 0
344 test_msdfs_link_domain()
346 clear_download_area
348 ${SMBGET} --verbose "-U${DOMAIN}/${DOMAIN_USER}%${DOMAIN_USER_PASSWORD}" \
349 "smb://${SERVER}/msdfs-share/deeppath/msdfs-src2/readable_file"
350 ret=$?
351 if [ ${ret} -ne 0 ]; then
352 echo "ERROR: smbget failed with ${ret}"
353 return 1
356 return 0
359 test_msdfs_link_upn()
361 clear_download_area
363 ${SMBGET} --verbose "-U${DOMAIN_USER}@${REALM}%${DOMAIN_USER_PASSWORD}" \
364 "smb://${SERVER}/msdfs-share/deeppath/msdfs-src2/readable_file"
365 ret=$?
366 if [ ${ret} -ne 0 ]; then
367 echo "ERROR: smbget failed with ${ret}"
368 return 1
371 return 0
374 # Tests --limit-rate. Getting the testfile (128K in size) with --limit-rate 100
375 # (that is 100KB/s) should take at least 1 sec to complete.
376 test_limit_rate()
378 clear_download_area
379 echo "$SMBGET --verbose --guest --limit-rate 100 smb://$SERVER_IP/smbget/testfile"
380 time_begin=$(date +%s)
381 $SMBGET --verbose --guest --limit-rate 100 smb://$SERVER_IP/smbget/testfile
382 if [ $? -ne 0 ]; then
383 echo 'ERROR: RC does not match, expected: 0'
384 return 1
386 time_end=$(date +%s)
387 cmp --silent $WORKDIR/testfile ./testfile
388 if [ $? -ne 0 ]; then
389 echo 'ERROR: file content does not match'
390 return 1
392 if [ $((time_end - time_begin)) -lt 1 ]; then
393 echo 'ERROR: It should take at least 1s to transfer 128KB with rate 100KB/s'
394 return 1
396 return 0
399 test_encrypt()
401 clear_download_area
402 $SMBGET --verbose --encrypt -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
403 if [ $? -ne 0 ]; then
404 echo 'ERROR: RC does not match, expected: 0'
405 return 1
407 cmp --silent $WORKDIR/testfile ./testfile
408 if [ $? -ne 0 ]; then
409 echo 'ERROR: file content does not match'
410 return 1
413 clear_download_area
414 $SMBGET --verbose --client-protection=encrypt -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
415 if [ $? -ne 0 ]; then
416 echo 'ERROR: RC does not match, expected: 0'
417 return 1
419 cmp --silent $WORKDIR/testfile ./testfile
420 if [ $? -ne 0 ]; then
421 echo 'ERROR: file content does not match'
422 return 1
425 return 0
428 test_kerberos()
430 clear_download_area
432 KRB5CCNAME_PATH="${TMPDIR}/smget_krb5ccache"
433 rm -f "${KRB5CCNAME_PATH}"
435 KRB5CCNAME="FILE:${KRB5CCNAME_PATH}"
436 export KRB5CCNAME
437 kerberos_kinit "${samba_kinit}" \
438 "${DOMAIN_USER}@${REALM}" "${DOMAIN_USER_PASSWORD}"
439 if [ $? -ne 0 ]; then
440 echo 'Failed to get Kerberos ticket'
441 return 1
444 $SMBGET --verbose --use-krb5-ccache="${KRB5CCNAME}" \
445 smb://$SERVER/smbget/testfile
446 if [ $? -ne 0 ]; then
447 echo 'ERROR: RC does not match, expected: 0'
448 return 1
451 cmp --silent $WORKDIR/testfile ./testfile
452 if [ $? -ne 0 ]; then
453 echo 'ERROR: file content does not match'
454 return 1
457 rm -f "${KRB5CCNAME_PATH}"
459 return 0
462 test_kerberos_trust()
464 clear_download_area
466 $SMBGET --verbose --use-kerberos=required \
467 -U"${TRUST_F_BOTH_USERNAME}@${TRUST_F_BOTH_REALM}%${TRUST_F_BOTH_PASSWORD}" \
468 smb://$SERVER.${REALM}/smbget/testfile
469 if [ $? -ne 0 ]; then
470 echo 'ERROR: RC does not match, expected: 0'
471 return 1
474 cmp --silent $WORKDIR/testfile ./testfile
475 if [ $? -ne 0 ]; then
476 echo 'ERROR: file content does not match'
477 return 1
480 return 0
483 # TODO FIXME
484 # This test does not work, as we can't tell the libsmb code that the
485 # principal is an enterprice principal. We need support for enterprise
486 # principals in kerberos_kinit_password_ext() and a way to pass it via the
487 # credenitals structure and commandline options.
488 # It works if you do: kinit -E testdenied_upn@${REALM}.upn
490 # test_kerberos_upn_denied()
492 # set -x
493 # clear_download_area
495 # $SMBGET --verbose --use-kerberos=required \
496 # -U"testdenied_upn@${REALM}.upn%${DC_PASSWORD}" \
497 # "smb://${SERVER}.${REALM}/smbget/testfile" -d10
498 # if [ $? -ne 0 ]; then
499 # echo 'ERROR: RC does not match, expected: 0'
500 # return 1
501 # fi
503 # cmp --silent $WORKDIR/testfile ./testfile
504 # if [ $? -ne 0 ]; then
505 # echo 'ERROR: file content does not match'
506 # return 1
507 # fi
509 # return 0
512 create_test_data
514 pushd $TMPDIR
516 failed=0
517 testit "download single file as guest" test_singlefile_guest ||
518 failed=$(expr $failed + 1)
520 testit "download single file with -U" test_singlefile_U ||
521 failed=$(expr $failed + 1)
523 testit "download single file with --update and domain" test_singlefile_U_domain ||
524 failed=$((failed + 1))
526 testit "download single file with --update and UPN" test_singlefile_U_UPN ||
527 failed=$((failed + 1))
529 testit "download single file with smb URL" test_singlefile_smburl ||
530 failed=$(expr $failed + 1)
532 testit "download single file with smb URL including domain" \
533 test_singlefile_smburl2 ||
534 failed=$(expr $failed + 1)
536 testit "download single file with authfile" test_singlefile_authfile ||
537 failed=$(expr $failed + 1)
539 testit "recursive download" test_recursive_U ||
540 failed=$(expr $failed + 1)
542 testit "recursive download (existing target dir)" test_recursive_existing_dir ||
543 failed=$(expr $failed + 1)
545 testit "recursive download with empty directories" test_recursive_with_empty ||
546 failed=$(expr $failed + 1)
548 testit "resume download" test_resume ||
549 failed=$(expr $failed + 1)
551 testit "resume download (modified file)" test_resume_modified ||
552 failed=$(expr $failed + 1)
554 testit "update" test_update ||
555 failed=$(expr $failed + 1)
557 testit "msdfs" test_msdfs_link ||
558 failed=$((failed + 1))
560 testit "msdfs.domain" test_msdfs_link_domain ||
561 failed=$((failed + 1))
563 testit "msdfs.upn" test_msdfs_link_upn ||
564 failed=$((failed + 1))
566 testit "limit rate" test_limit_rate ||
567 failed=$((failed + 1))
569 testit "encrypt" test_encrypt ||
570 failed=$((failed + 1))
572 testit "kerberos" test_kerberos ||
573 failed=$((failed + 1))
575 testit "kerberos_trust" test_kerberos_trust ||
576 failed=$((failed + 1))
578 # testit "kerberos_upn_denied" test_kerberos_upn_denied ||
579 # failed=$((failed + 1))
581 clear_download_area
583 popd # TMPDIR
585 remove_test_data
587 exit $failed