[PATCH] DRAFT: Add new test which covers force user bug
Jeremy Allison
jra at samba.org
Wed Dec 9 19:29:28 UTC 2015
On Tue, Dec 08, 2015 at 04:50:33PM +0100, Robin Hack wrote:
> Hi Andrew.
>
> Thank you for your time.
>
> New patch is attached.
Pushed to master. Thanks a *LOT* Robin. Helping
improve our tests is a thankless task and we're
really glad to have you help us with it !
Cheers,
Jeremy.
> * test were moved to map_to_guest env.
> * test were renamed to samba3.blackbox.smbclient.forceuser
>
> On Fri, Dec 4, 2015 at 9:26 PM, Andrew Bartlett <abartlet at samba.org> wrote:
>
> >
> > > Attached file is my first try to rewrite test to shape acceptable by
> > > Samba
> > > upstream. Please. Be patient. It's not easy to add new tests to Samba
> > > upstream testsuite :(.
> >
> > We also welcome contributions to how we build tests. I'm open to
> > reasonable extra dependencies (with the understanding that we use
> > subunit v1 as our test reporting language)
>
> What I miss now is some glue library for tests written in shell.
> For example: run_cmd_nooutput() can be shared among tests etc..
> Actually some perl setup library would be nice too. What do you think?
>
>
> > Can you run those against a specific share in the existing map_to_guest
> > environment, rather than needing a whole new environment?
> >
> > Yes :). Thank you for hint. I moved test in attached patch to map_to_guest.
>
>
> > Also please take care where you place your test. The python block
> > currently covering "for env in ["fileserver"] extends to below the TAR
> > tests, and you have moved those tests into "forceuser".
> >
> > Thank you.
> test.py file is little bit mystery for me now. I moved test to maptoguest
> env. I hope that for loop should be here and I also hope I didn't broke it
> again.
>
> > Other than that, it looks like you are on the right track, and I'm
> > really keen to help you improve our testsuite.
> >
> Great!
>
> Have nice day.
> From a04224b06ee8618c40c5ba28bd72abeac8d1e545 Mon Sep 17 00:00:00 2001
> From: Robin Hack <rhack at redhat.com>
> Date: Fri, 4 Dec 2015 14:50:56 +0100
> Subject: [PATCH] samba3.blackbox.smbclient.forceuser: Add new test for force
> user option.
>
> Test covers commit
> a85d6eb355e8277fe69db6e5837a7f65f57d9c1d
>
> BUG: https://bugzilla.samba.org/show_bug.cgi?id=9878
> RH BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1077651
>
> Signed-off-by: Robin Hack <rhack at redhat.com>
> ---
> selftest/target/Samba3.pm | 29 +++++++++++++++
> source3/script/tests/test_forceuser.sh | 66 ++++++++++++++++++++++++++++++++++
> source3/selftest/tests.py | 6 ++--
> 3 files changed, 99 insertions(+), 2 deletions(-)
> create mode 100755 source3/script/tests/test_forceuser.sh
>
> diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
> index 94612b2..a602d1b 100755
> --- a/selftest/target/Samba3.pm
> +++ b/selftest/target/Samba3.pm
> @@ -790,11 +790,36 @@ $ret->{USERNAME} = KTEST\\Administrator
> sub setup_maptoguest($$)
> {
> my ($self, $path) = @_;
> + my $prefix_abs = abs_path($path);
>
> print "PROVISIONING maptoguest...";
>
> + my @dirs = ();
> +
> + mkdir($prefix_abs, 0777);
> + my $share_dir="$prefix_abs/share";
> + push(@dirs, $share_dir);
> +
> + my $force_user_not_work_dir = "$share_dir/force_user_not_work";
> + push(@dirs, $force_user_not_work_dir);
> +
> + my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
> + chomp $unix_name;
> +
> +
> my $options = "
> map to guest = bad user
> +
> +# BUG: https://bugzilla.samba.org/show_bug.cgi?id=9878
> +# BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1077651
> +[force_user_not_work]
> + path = $force_user_not_work_dir
> + comment = force user test share with map to guest set to bad user
> + valid users = \@$unix_name
> + force user = $unix_name
> + force group = everyone
> + write list = $unix_name
> + create mask = 0644
> ";
>
> my $vars = $self->provision($path,
> @@ -804,6 +829,9 @@ map to guest = bad user
>
> $vars or return undef;
>
> + mkdir($_, 0777) foreach(@dirs);
> + chmod(0777, $_) foreach(@dirs);
> +
> if (not $self->check_or_start($vars, "yes", "no", "yes")) {
> return undef;
> }
> @@ -1552,6 +1580,7 @@ pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/
> print GROUP "nobody:x:$gid_nobody:
> nogroup:x:$gid_nogroup:nobody
> $unix_name-group:x:$unix_gids[0]:
> +$unix_name:x:$unix_gids[0]:
> domusers:X:$gid_domusers:
> domadmins:X:$gid_domadmins:
> userdup:x:$gid_userdup:$unix_name
> diff --git a/source3/script/tests/test_forceuser.sh b/source3/script/tests/test_forceuser.sh
> new file mode 100755
> index 0000000..46fe251
> --- /dev/null
> +++ b/source3/script/tests/test_forceuser.sh
> @@ -0,0 +1,66 @@
> +#!/bin/sh
> +#
> +# Blackbox test for share with force user settings
> +#
> +
> +if [ $# -lt 6 ]; then
> +cat <<EOF
> +Usage: test_forceuser.sh SERVER DOMAIN USERNAME PASSWORD LOCAL_PATH SMBCLIENT <smbclient arguments>
> +EOF
> +exit 1;
> +fi
> +
> +SERVER="$1"
> +DOMAIN="$2"
> +USERNAME="$3"
> +PASSWORD="$4"
> +LOCAL_PATH="$5"
> +SMBCLIENT="$6"
> +SMBCLIENT="$VALGRIND ${SMBCLIENT}"
> +shift 6
> +ADDARGS="$*"
> +failed=0
> +
> +
> +incdir=`dirname $0`/../../../testprogs/blackbox
> +. $incdir/subunit.sh
> +
> +
> +run_cmd_nooutput() {
> + CMD="$1"
> +
> + out=`eval ${CMD} &> TESTOUT`
> + if [ $? != 0 ] ; then
> + cat TESTOUT
> + rm -f TESTOUT
> + echo "command failed"
> + false
> + return
> + fi
> +
> + rm -f TESTOUT
> + true
> + return
> +}
> +
> +test_force_user_not_work()
> +{
> + SMB_SHARE="force_user_not_work"
> + run_cmd_nooutput "${SMBCLIENT} //${SERVER}/${SMB_SHARE} -U$USERNAME%$PASSWORD -c 'put TESTFILE'"
> +}
> +
> +# Setup
> +pushd "${LOCAL_PATH}" > /dev/null
> +rm -f TESTFILE
> +echo "hello samba!" > TESTFILE
> +
> +# Test
> +testit "force user not works when map to guest is set" \
> + test_force_user_not_work || failed=`expr $failed + 1`
> +
> +# Cleanup
> +rm -f TESTFILE
> +popd > /dev/null
> +
> +# Results
> +testok $0 $failed
> diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
> index 9c68943..0909da2 100755
> --- a/source3/selftest/tests.py
> +++ b/source3/selftest/tests.py
> @@ -154,8 +154,10 @@ plantestsuite("samba3.ntlm_auth.krb5(ktest:local)", "ktest:local", [os.path.join
> for env in ["maptoguest", "simpleserver"]:
> plantestsuite("samba3.blackbox.smbclient_auth.plain (%s) local creds" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_auth.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', smbclient3, configuration + " --option=clientntlmv2auth=no --option=clientlanmanauth=yes"])
>
> -env = "maptoguest"
> -plantestsuite("samba3.blackbox.smbclient_auth.plain (%s) bad username" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_auth.sh"), '$SERVER', '$SERVER_IP', 'notmy$USERNAME', '$PASSWORD', smbclient3, configuration + " --option=clientntlmv2auth=no --option=clientlanmanauth=yes"])
> +for env in ["maptoguest"]:
> + plantestsuite("samba3.blackbox.smbclient_auth.plain (%s) bad username" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_auth.sh"), '$SERVER', '$SERVER_IP', 'notmy$USERNAME', '$PASSWORD', smbclient3, configuration + " --option=clientntlmv2auth=no --option=clientlanmanauth=yes"])
> + plantestsuite("samba3.blackbox.smbclient.forceuser (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_forceuser.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH', smbclient3])
> +
>
> # plain
> for env in ["nt4_dc"]:
> --
> 1.9.3
>
More information about the samba-technical
mailing list