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
)
32 samba_texpect
="${BINDIR}/texpect"
37 dd if=/dev
/urandom bs
=1024 count
=128 of
=testfile
40 dd if=/dev
/urandom bs
=1024 count
=128 of
=dir
1/testfile1
42 dd if=/dev
/urandom bs
=1024 count
=128 of
=dir
2/testfile2
49 rm -rf dir1 dir2 testfile
55 rm -rf dir1 dir2 testfile dir001 dir004 readable_file
58 test_singlefile_guest
()
61 echo "$SMBGET --verbose --guest smb://$SERVER_IP/smbget_guest/testfile"
62 $SMBGET --verbose --guest smb
://$SERVER_IP/smbget_guest
/testfile
64 echo 'ERROR: RC does not match, expected: 0'
67 cmp --silent $WORKDIR/testfile .
/testfile
69 echo 'ERROR: file content does not match'
78 $SMBGET --verbose -U${SERVER}/${USERNAME}%$PASSWORD smb
://$SERVER_IP/smbget
/testfile
80 echo 'ERROR: RC does not match, expected: 0'
83 cmp --silent $WORKDIR/testfile .
/testfile
85 echo 'ERROR: file content does not match'
91 test_singlefile_U_UPN
()
95 ${SMBGET} --verbose -U"${DOMAIN_USER}@${REALM}%${DOMAIN_USER_PASSWORD}" \
96 "smb
://${SERVER_IP}/smbget
/testfile
"
98 if [ ${ret} -ne 0 ]; then
99 echo 'ERROR: RC does not match, expected: 0'
103 cmp --silent "${WORKDIR}/testfile
" ./testfile
105 if [ ${ret} -ne 0 ]; then
106 echo 'ERROR: file content does not match'
113 test_singlefile_U_domain()
117 ${SMBGET} --verbose -U"${DOMAIN}/${DOMAIN_USER}%${DOMAIN_USER_PASSWORD}" \
118 "smb://${SERVER_IP}/smbget/testfile"
120 if [ ${ret} -ne 0 ]; then
121 echo 'ERROR: RC does not match, expected: 0'
125 cmp --silent "${WORKDIR}/testfile" .
/testfile
127 if [ ${ret} -ne 0 ]; then
128 echo 'ERROR: file content does not match'
135 test_singlefile_smburl
()
138 $SMBGET --workgroup $DOMAIN smb
://${DOMAIN_USER}:$DOMAIN_USER_PASSWORD@
$SERVER_IP/smbget
/testfile
139 if [ $?
-ne 0 ]; then
140 echo 'ERROR: RC does not match, expected: 0'
143 cmp --silent $WORKDIR/testfile .
/testfile
144 if [ $?
-ne 0 ]; then
145 echo 'ERROR: file content does not match'
151 test_singlefile_smburl2
()
154 $SMBGET "smb://$DOMAIN;${DOMAIN_USER}:$DOMAIN_USER_PASSWORD@$SERVER_IP/smbget/testfile"
155 if [ $?
-ne 0 ]; then
156 echo 'ERROR: RC does not match, expected: 0'
159 cmp --silent $WORKDIR/testfile .
/testfile
160 if [ $?
-ne 0 ]; then
161 echo 'ERROR: file content does not match'
167 test_singlefile_smburl_interactive
()
171 tmpfile
="$(mktemp --tmpdir="${TMPDIR}" expect_XXXXXXXXXX)"
173 cat >"${tmpfile}" <<EOF
175 send ${DOMAIN_USER_PASSWORD}\n
178 USER
="hanswurst" ${samba_texpect} "${tmpfile}" ${SMBGET} "smb://${DOMAIN};${DOMAIN_USER}@${SERVER_IP}/smbget
/testfile
"
181 if [ ${ret} -ne 0 ]; then
182 echo 'ERROR: RC does not match, expected: 0'
185 cmp --silent $WORKDIR/testfile ./testfile
187 if [ ${ret} -ne 0 ]; then
188 echo 'ERROR: file content does not match'
194 test_singlefile_authfile()
197 cat >"${TMPDIR}/authfile
" << EOF
198 username = ${SERVER}/${USERNAME}
201 $SMBGET --verbose --authentication-file="${TMPDIR}/authfile
" smb://$SERVER_IP/smbget/testfile
203 rm -f $TMPDIR/authfile
204 if [ $rc -ne 0 ]; then
205 echo 'ERROR: RC does not match, expected: 0'
208 cmp --silent $WORKDIR/testfile ./testfile
209 if [ $? -ne 0 ]; then
210 echo 'ERROR: file content does not match'
219 $SMBGET --verbose --recursive -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/
220 if [ $? -ne 0 ]; then
221 echo 'ERROR: RC does not match, expected: 0'
225 cmp --silent $WORKDIR/testfile ./testfile &&
226 cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 &&
227 cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
228 if [ $? -ne 0 ]; then
229 echo 'ERROR: file content does not match'
236 test_recursive_existing_dir()
240 $SMBGET --verbose --recursive -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/
241 if [ $? -ne 0 ]; then
242 echo 'ERROR: RC does not match, expected: 0'
246 cmp --silent $WORKDIR/testfile ./testfile &&
247 cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 &&
248 cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
249 if [ $? -ne 0 ]; then
250 echo 'ERROR: file content does not match'
257 test_recursive_with_empty()
260 # create some additional empty directories
261 mkdir -p $WORKDIR/dir001/dir002/dir003
262 mkdir -p $WORKDIR/dir004/dir005/dir006
263 $SMBGET --verbose --recursive -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/
265 rm -rf $WORKDIR/dir001
266 rm -rf $WORKDIR/dir004
267 if [ $rc -ne 0 ]; then
268 echo 'ERROR: RC does not match, expected: 0'
272 cmp --silent $WORKDIR/testfile ./testfile &&
273 cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 &&
274 cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
275 if [ $? -ne 0 ]; then
276 echo 'ERROR: file content does not match'
280 if [ ! -d dir001/dir002/dir003 ] || [ ! -d dir004/dir005/dir006 ]; then
281 echo 'ERROR: empty directories are not present'
291 cp $WORKDIR/testfile .
292 truncate -s 1024 testfile
293 $SMBGET --verbose --resume -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
294 if [ $? -ne 0 ]; then
295 echo 'ERROR: RC does not match, expected: 0'
299 cmp --silent $WORKDIR/testfile ./testfile
300 if [ $? -ne 0 ]; then
301 echo 'ERROR: file content does not match'
308 test_resume_modified()
311 dd if=/dev/urandom bs=1024 count=2 of=testfile
312 $SMBGET --verbose --resume -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
313 if [ $? -ne 1 ]; then
314 echo 'ERROR: RC does not match, expected: 1'
324 $SMBGET --verbose -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
325 if [ $? -ne 0 ]; then
326 echo 'ERROR: RC does not match, expected: 0'
330 # secondary download should pass
331 $SMBGET --verbose --update -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
332 if [ $? -ne 0 ]; then
333 echo 'ERROR: RC does not match, expected: 0'
337 echo "modified
" >>testfile
338 # touch source to trigger new download
340 touch -m $WORKDIR/testfile
341 $SMBGET --verbose --update -U${SERVER}/${USERNAME}%$PASSWORD smb://$SERVER_IP/smbget/testfile
342 if [ $? -ne 0 ]; then
343 echo 'ERROR: RC does not match, expected: 0'
347 cmp --silent $WORKDIR/testfile ./testfile
348 if [ $? -ne 0 ]; then
349 echo 'ERROR: file content does not match'
356 # Test accessing an msdfs path.
361 ${SMBGET} --verbose "-U${SERVER}/${USERNAME}%${PASSWORD}" \
362 "smb://${SERVER}/msdfs-share/deeppath/msdfs-src2/readable_file"
364 if [ ${ret} -ne 0 ]; then
365 echo "ERROR: smbget failed with ${ret}"
372 test_msdfs_link_domain
()
376 ${SMBGET} --verbose "-U${DOMAIN}/${DOMAIN_USER}%${DOMAIN_USER_PASSWORD}" \
377 "smb
://${SERVER}/msdfs-share
/deeppath
/msdfs-src
2/readable_file
"
379 if [ ${ret} -ne 0 ]; then
380 echo "ERROR
: smbget failed with
${ret}"
387 test_msdfs_link_upn()
391 ${SMBGET} --verbose "-U${DOMAIN_USER}@${REALM}%${DOMAIN_USER_PASSWORD}" \
392 "smb://${SERVER}/msdfs-share/deeppath/msdfs-src2/readable_file"
394 if [ ${ret} -ne 0 ]; then
395 echo "ERROR: smbget failed with ${ret}"
402 # Tests --limit-rate. Getting the testfile (128K in size) with --limit-rate 100
403 # (that is 100KB/s) should take at least 1 sec to complete.
407 echo "$SMBGET --verbose --guest --limit-rate 100 smb://$SERVER_IP/smbget_guest/testfile"
408 time_begin
=$
(date +%s
)
409 $SMBGET --verbose --guest --limit-rate 100 smb
://$SERVER_IP/smbget_guest
/testfile
410 if [ $?
-ne 0 ]; then
411 echo 'ERROR: RC does not match, expected: 0'
415 cmp --silent $WORKDIR/testfile .
/testfile
416 if [ $?
-ne 0 ]; then
417 echo 'ERROR: file content does not match'
420 if [ $
((time_end
- time_begin
)) -lt 1 ]; then
421 echo 'ERROR: It should take at least 1s to transfer 128KB with rate 100KB/s'
430 $SMBGET --verbose --encrypt -U${SERVER}/${USERNAME}%$PASSWORD smb
://$SERVER_IP/smbget
/testfile
431 if [ $?
-ne 0 ]; then
432 echo 'ERROR: RC does not match, expected: 0'
435 cmp --silent $WORKDIR/testfile .
/testfile
436 if [ $?
-ne 0 ]; then
437 echo 'ERROR: file content does not match'
442 $SMBGET --verbose --client-protection=encrypt
-U${SERVER}/${USERNAME}%$PASSWORD smb
://$SERVER_IP/smbget
/testfile
443 if [ $?
-ne 0 ]; then
444 echo 'ERROR: RC does not match, expected: 0'
447 cmp --silent $WORKDIR/testfile .
/testfile
448 if [ $?
-ne 0 ]; then
449 echo 'ERROR: file content does not match'
460 KRB5CCNAME_PATH
="${TMPDIR}/smget_krb5ccache"
461 rm -f "${KRB5CCNAME_PATH}"
463 KRB5CCNAME
="FILE:${KRB5CCNAME_PATH}"
465 kerberos_kinit
"${samba_kinit}" \
466 "${DOMAIN_USER}@${REALM}" "${DOMAIN_USER_PASSWORD}"
467 if [ $?
-ne 0 ]; then
468 echo 'Failed to get Kerberos ticket'
472 $SMBGET --verbose --use-krb5-ccache="${KRB5CCNAME}" \
473 smb
://$SERVER/smbget
/testfile
474 if [ $?
-ne 0 ]; then
475 echo 'ERROR: RC does not match, expected: 0'
479 cmp --silent $WORKDIR/testfile .
/testfile
480 if [ $?
-ne 0 ]; then
481 echo 'ERROR: file content does not match'
485 rm -f "${KRB5CCNAME_PATH}"
490 test_kerberos_trust
()
494 $SMBGET --verbose --use-kerberos=required \
495 -U"${TRUST_F_BOTH_USERNAME}@${TRUST_F_BOTH_REALM}%${TRUST_F_BOTH_PASSWORD}" \
496 smb
://$SERVER.
${REALM}/smbget
/testfile
497 if [ $?
-ne 0 ]; then
498 echo 'ERROR: RC does not match, expected: 0'
502 cmp --silent $WORKDIR/testfile .
/testfile
503 if [ $?
-ne 0 ]; then
504 echo 'ERROR: file content does not match'
512 # This test does not work, as we can't tell the libsmb code that the
513 # principal is an enterprise principal. We need support for enterprise
514 # principals in kerberos_kinit_password_ext() and a way to pass it via the
515 # credenitals structure and commandline options.
516 # It works if you do: kinit -E testdenied_upn@${REALM}.upn
518 # test_kerberos_upn_denied()
521 # clear_download_area
523 # $SMBGET --verbose --use-kerberos=required \
524 # -U"testdenied_upn@${REALM}.upn%${DC_PASSWORD}" \
525 # "smb://${SERVER}.${REALM}/smbget/testfile" -d10
526 # if [ $? -ne 0 ]; then
527 # echo 'ERROR: RC does not match, expected: 0'
531 # cmp --silent $WORKDIR/testfile ./testfile
532 # if [ $? -ne 0 ]; then
533 # echo 'ERROR: file content does not match'
545 testit
"download single file as guest" test_singlefile_guest ||
546 failed
=$
(expr $failed + 1)
548 testit
"download single file with -U" test_singlefile_U ||
549 failed
=$
(expr $failed + 1)
551 testit
"download single file with --update and domain" test_singlefile_U_domain ||
552 failed
=$
((failed
+ 1))
554 testit
"download single file with --update and UPN" test_singlefile_U_UPN ||
555 failed
=$
((failed
+ 1))
557 testit
"download single file with smb URL" test_singlefile_smburl ||
558 failed
=$
(expr $failed + 1)
560 testit
"download single file with smb URL including domain" \
561 test_singlefile_smburl2 ||
562 failed
=$
(expr $failed + 1)
564 testit
"download single file with smb URL interactive" \
565 test_singlefile_smburl_interactive ||
566 failed
=$
(expr $failed + 1)
568 testit
"download single file with authfile" test_singlefile_authfile ||
569 failed
=$
(expr $failed + 1)
571 testit
"recursive download" test_recursive_U ||
572 failed
=$
(expr $failed + 1)
574 testit
"recursive download (existing target dir)" test_recursive_existing_dir ||
575 failed
=$
(expr $failed + 1)
577 testit
"recursive download with empty directories" test_recursive_with_empty ||
578 failed
=$
(expr $failed + 1)
580 testit
"resume download" test_resume ||
581 failed
=$
(expr $failed + 1)
583 testit
"resume download (modified file)" test_resume_modified ||
584 failed
=$
(expr $failed + 1)
586 testit
"update" test_update ||
587 failed
=$
(expr $failed + 1)
589 testit
"msdfs" test_msdfs_link ||
590 failed
=$
((failed
+ 1))
592 testit
"msdfs.domain" test_msdfs_link_domain ||
593 failed
=$
((failed
+ 1))
595 testit
"msdfs.upn" test_msdfs_link_upn ||
596 failed
=$
((failed
+ 1))
598 testit
"limit rate" test_limit_rate ||
599 failed
=$
((failed
+ 1))
601 testit
"encrypt" test_encrypt ||
602 failed
=$
((failed
+ 1))
604 testit
"kerberos" test_kerberos ||
605 failed
=$
((failed
+ 1))
607 testit
"kerberos_trust" test_kerberos_trust ||
608 failed
=$
((failed
+ 1))
610 # testit "kerberos_upn_denied" test_kerberos_upn_denied ||
611 # failed=$((failed + 1))