]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:tests: Add smbspool test using kerberos authentication: test_smbspool_krb.sh
authorPavel Filipenský <pfilipensky@samba.org>
Sun, 24 Sep 2023 13:03:35 +0000 (15:03 +0200)
committerPavel Filipensky <pfilipensky@samba.org>
Tue, 17 Oct 2023 18:23:32 +0000 (18:23 +0000)
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/script/tests/test_smbspool_krb.sh [new file with mode: 0755]

diff --git a/source3/script/tests/test_smbspool_krb.sh b/source3/script/tests/test_smbspool_krb.sh
new file mode 100755 (executable)
index 0000000..a4aeeab
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/sh
+
+if [ $# -lt 3 ]; then
+       cat <<EOF
+Usage: test_smbspool_krb.sh SERVER USERNAME PASSWORD REALM
+EOF
+       exit 1
+fi
+
+SERVER="$1"
+USERNAME="$2"
+PASSWORD="$3"
+REALM="$4"
+
+incdir=$(dirname "$0")/../../../testprogs/blackbox
+. $incdir/subunit.sh
+. $incdir/common_test_fns.inc
+
+samba_bindir="$BINDIR"
+samba_smbspool="$samba_bindir/smbspool"
+
+samba_kinit=kinit
+if test -x "${BINDIR}/samba4kinit"; then
+       samba_kinit=${BINDIR}/samba4kinit
+fi
+
+samba_kdestroy=kdestroy
+if test -x "${BINDIR}/samba4kdestroy"; then
+       samba_kdestroy=${BINDIR}/samba4kdestroy
+fi
+
+KRB5CCNAME_PATH="${PREFIX}/ccache_smbclient_kerberos"
+KRB5CCNAME="FILE:${KRB5CCNAME_PATH}"
+export KRB5CCNAME
+
+test_smbspool_authinforequired_negotiate()
+{
+       cmd='$samba_smbspool smb://$SERVER/print3 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps 2>&1'
+
+       AUTH_INFO_REQUIRED="negotiate"
+       export AUTH_INFO_REQUIRED
+       eval echo "$cmd"
+       out=$(eval "$cmd")
+       ret=$?
+       unset AUTH_INFO_REQUIRED
+
+       if [ $ret != 0 ]; then
+               echo "$out"
+               echo "failed to execute $samba_smbspool"
+               return 1
+       fi
+
+       return 0
+}
+
+test_smbspool_authinforequired_negative()
+{
+       cmd='$samba_smbspool smb://$SERVER/print3 200 $USERNAME "Testprint" 1 "options" $SRCDIR/testdata/printing/example.ps 2>&1'
+
+       AUTH_INFO_REQUIRED="negotiate"
+       export AUTH_INFO_REQUIRED
+       eval echo "$cmd"
+       out=$(eval "$cmd")
+       ret=$?
+       unset AUTH_INFO_REQUIRED
+
+       if [ $ret = 0 ]; then
+               echo "$out"
+               echo "Unexpected success to execute $samba_smbspool"
+               return 1
+       fi
+
+       return 0
+}
+
+kerberos_kinit "$samba_kinit" "${USERNAME}@${REALM}" "${PASSWORD}"
+testit "smbspool krb5 AuthInfoRequired=negotiate" \
+       test_smbspool_authinforequired_negotiate ||
+       failed=$((failed + 1))
+
+$samba_kdestroy
+rm -rf "$KRB5CCNAME_PATH"
+
+# smbspool should fail after destroying kerberos credentials
+testit "smbspool krb5 AuthInfoRequired=negotiate negative test" \
+       test_smbspool_authinforequired_negative ||
+       failed=$((failed + 1))
+
+
+testok "$0" "$failed"