3 # Blackbox test for smbget.
8 Usage: test_smbget SERVER SERVER_IP DOMAIN REALM USERNAME PASSWORD WORKDIR SMBGET
20 DOMAIN_USER_PASSWORD
=${8}
22 SMBGET
="$VALGRIND ${10}"
25 TMPDIR
="$SELFTEST_TMPDIR"
27 incdir
=$
(dirname $0)/..
/..
/..
/testprogs
/blackbox
29 .
"${incdir}/common_test_fns.inc"
31 samba_kinit
=$
(system_or_builddir_binary kinit
"${BINDIR}" samba4kinit
)
36 dd if=/dev
/urandom bs
=1024 count
=128 of
=testfile
39 dd if=/dev
/urandom bs
=1024 count
=128 of
=dir
1/testfile1
41 dd if=/dev
/urandom bs
=1024 count
=128 of
=dir
2/testfile2
48 rm -rf dir1 dir2 testfile
54 rm -rf dir1 dir2 testfile dir001 dir004 readable_file
57 test_singlefile_guest
()
60 echo "$SMBGET --verbose --guest smb://$SERVER_IP/smbget/testfile"
61 $SMBGET --verbose --guest smb
://$SERVER_IP/smbget
/testfile
63 echo 'ERROR: RC does not match, expected: 0'
66 cmp --silent $WORKDIR/testfile .
/testfile
68 echo 'ERROR: file content does not match'
77 $SMBGET --verbose -U${SERVER}/${USERNAME}%$PASSWORD smb
://$SERVER_IP/smbget
/testfile
79 echo 'ERROR: RC does not match, expected: 0'
82 cmp --silent $WORKDIR/testfile .
/testfile
84 echo 'ERROR: file content does not match'
90 test_singlefile_U_UPN
()
94 ${SMBGET} --verbose -U"${DOMAIN_USER}@${REALM}%${DOMAIN_USER_PASSWORD}" \
95 "smb
://${SERVER_IP}/smbget
/testfile
"
97 if [ ${ret} -ne 0 ]; then
98 echo 'ERROR: RC does not match, expected: 0'
102 cmp --silent "${WORKDIR}/testfile
" ./testfile
104 if [ ${ret} -ne 0 ]; then
105 echo 'ERROR: file content does not match'
112 test_singlefile_U_domain()
116 ${SMBGET} --verbose -U"${DOMAIN}/${DOMAIN_USER}%${DOMAIN_USER_PASSWORD}" \
117 "smb://${SERVER_IP}/smbget/testfile"
119 if [ ${ret} -ne 0 ]; then
120 echo 'ERROR: RC does not match, expected: 0'
124 cmp --silent "${WORKDIR}/testfile" .
/testfile
126 if [ ${ret} -ne 0 ]; then
127 echo 'ERROR: file content does not match'
134 test_singlefile_smburl
()
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'
142 cmp --silent $WORKDIR/testfile .
/testfile
143 if [ $?
-ne 0 ]; then
144 echo 'ERROR: file content does not match'
150 test_singlefile_smburl2
()
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'
158 cmp --silent $WORKDIR/testfile .
/testfile
159 if [ $?
-ne 0 ]; then
160 echo 'ERROR: file content does not match'
166 test_singlefile_authfile
()
169 cat >"${TMPDIR}/authfile" << EOF
170 username = ${SERVER}/${USERNAME}
173 $SMBGET --verbose --authentication-file="${TMPDIR}/authfile" smb
://$SERVER_IP/smbget
/testfile
175 rm -f $TMPDIR/authfile
176 if [ $rc -ne 0 ]; then
177 echo 'ERROR: RC does not match, expected: 0'
180 cmp --silent $WORKDIR/testfile .
/testfile
181 if [ $?
-ne 0 ]; then
182 echo 'ERROR: file content does not match'
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'
197 cmp --silent $WORKDIR/testfile .
/testfile
&&
198 cmp --silent $WORKDIR/dir
1/testfile1 .
/dir
1/testfile1
&&
199 cmp --silent $WORKDIR/dir
2/testfile2 .
/dir
2/testfile2
200 if [ $?
-ne 0 ]; then
201 echo 'ERROR: file content does not match'
208 test_recursive_existing_dir
()
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'
218 cmp --silent $WORKDIR/testfile .
/testfile
&&
219 cmp --silent $WORKDIR/dir
1/testfile1 .
/dir
1/testfile1
&&
220 cmp --silent $WORKDIR/dir
2/testfile2 .
/dir
2/testfile2
221 if [ $?
-ne 0 ]; then
222 echo 'ERROR: file content does not match'
229 test_recursive_with_empty
()
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
/
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'
244 cmp --silent $WORKDIR/testfile .
/testfile
&&
245 cmp --silent $WORKDIR/dir
1/testfile1 .
/dir
1/testfile1
&&
246 cmp --silent $WORKDIR/dir
2/testfile2 .
/dir
2/testfile2
247 if [ $?
-ne 0 ]; then
248 echo 'ERROR: file content does not match'
252 if [ ! -d dir001
/dir002
/dir003
] ||
[ ! -d dir004
/dir005
/dir006
]; then
253 echo 'ERROR: empty directories are not present'
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'
271 cmp --silent $WORKDIR/testfile .
/testfile
272 if [ $?
-ne 0 ]; then
273 echo 'ERROR: file content does not match'
280 test_resume_modified
()
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'
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'
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'
309 echo "modified" >>testfile
310 # touch source to trigger new download
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'
319 cmp --silent $WORKDIR/testfile .
/testfile
320 if [ $?
-ne 0 ]; then
321 echo 'ERROR: file content does not match'
328 # Test accessing an msdfs path.
333 ${SMBGET} --verbose "-U${SERVER}/${USERNAME}%${PASSWORD}" \
334 "smb
://${SERVER}/msdfs-share
/deeppath
/msdfs-src
2/readable_file
"
336 if [ ${ret} -ne 0 ]; then
337 echo "ERROR
: smbget failed with
${ret}"
344 test_msdfs_link_domain()
348 ${SMBGET} --verbose "-U${DOMAIN}/${DOMAIN_USER}%${DOMAIN_USER_PASSWORD}" \
349 "smb://${SERVER}/msdfs-share/deeppath/msdfs-src2/readable_file"
351 if [ ${ret} -ne 0 ]; then
352 echo "ERROR: smbget failed with ${ret}"
359 test_msdfs_link_upn
()
363 ${SMBGET} --verbose "-U${DOMAIN_USER}@${REALM}%${DOMAIN_USER_PASSWORD}" \
364 "smb
://${SERVER}/msdfs-share
/deeppath
/msdfs-src
2/readable_file
"
366 if [ ${ret} -ne 0 ]; then
367 echo "ERROR
: smbget failed with
${ret}"
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.
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'
387 cmp --silent $WORKDIR/testfile ./testfile
388 if [ $? -ne 0 ]; then
389 echo 'ERROR: file content does not match'
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'
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'
407 cmp --silent $WORKDIR/testfile ./testfile
408 if [ $? -ne 0 ]; then
409 echo 'ERROR: file content does not match'
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'
419 cmp --silent $WORKDIR/testfile ./testfile
420 if [ $? -ne 0 ]; then
421 echo 'ERROR: file content does not match'
432 KRB5CCNAME_PATH="${TMPDIR}/smget_krb5ccache
"
433 rm -f "${KRB5CCNAME_PATH}"
435 KRB5CCNAME="FILE
:${KRB5CCNAME_PATH}"
437 kerberos_kinit "${samba_kinit}" \
438 "${DOMAIN_USER}@${REALM}" "${DOMAIN_USER_PASSWORD}"
439 if [ $? -ne 0 ]; then
440 echo 'Failed to get Kerberos ticket'
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'
451 cmp --silent $WORKDIR/testfile ./testfile
452 if [ $? -ne 0 ]; then
453 echo 'ERROR: file content does not match'
457 rm -f "${KRB5CCNAME_PATH}"
462 test_kerberos_trust()
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'
474 cmp --silent $WORKDIR/testfile ./testfile
475 if [ $? -ne 0 ]; then
476 echo 'ERROR: file content does not match'
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()
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'
503 # cmp --silent $WORKDIR/testfile ./testfile
504 # if [ $? -ne 0 ]; then
505 # echo 'ERROR: file content does not match'
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))