1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-18 08:23:51 +03:00

samba-tool:testparm: Test that --section-name works without --parameter-name

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14143

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Rowland Penny <rpenny@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Joseph Sutton
2021-04-29 20:17:09 +12:00
committed by Andrew Bartlett
parent 52744d35a3
commit 33bb6ad356
2 changed files with 40 additions and 1 deletions

View File

@@ -17,6 +17,9 @@
"""Tests for samba.netcmd."""
import os
import tempfile
from io import StringIO
from samba.netcmd import Command
from samba.netcmd.testparm import cmd_testparm
@@ -24,7 +27,7 @@ from samba.netcmd.main import cmd_sambatool
import samba.tests
class NetCmdTestCase(samba.tests.TestCase):
class NetCmdTestCase(samba.tests.TestCaseInTempDir):
def run_netcmd(self, cmd_klass, args, retcode=0):
cmd = cmd_klass(outf=StringIO(), errf=StringIO())
@@ -48,6 +51,33 @@ class NetCmdTestCase(samba.tests.TestCase):
class TestParmTests(NetCmdTestCase):
def setUp(self):
super().setUp()
# Override these global parameters in case their default values are
# invalid.
contents = """[global]
netbios name = test
lock dir = /
pid directory = /
[tmp]
path = /
"""
self.smbconf = self.create_smbconf(contents)
def create_smbconf(self, contents):
smbconf = tempfile.NamedTemporaryFile(mode='w',
dir=self.tempdir,
delete=False)
self.addCleanup(os.remove, smbconf.name)
try:
smbconf.write(contents)
finally:
smbconf.close()
return smbconf
def test_no_client_ip(self):
out, err = self.run_netcmd(cmd_testparm, ["--client-name=foo"],
retcode=-1)
@@ -56,6 +86,14 @@ class TestParmTests(NetCmdTestCase):
"ERROR: Both a DNS name and an IP address are "
"required for the host access check\n", err)
def test_section(self):
# We don't get an opportunity to verify the output, as the parameters
# are dumped directly to stdout, so just check the return code.
self.run_netcmd(cmd_testparm,
["--configfile=%s" % self.smbconf.name,
"--section-name=tmp"],
retcode=None)
class CommandTests(NetCmdTestCase):