]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool:testparm: Test that --section-name works without --parameter-name
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Thu, 29 Apr 2021 08:17:09 +0000 (20:17 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 17 May 2021 21:39:38 +0000 (21:39 +0000)
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>
python/samba/tests/netcmd.py
selftest/knownfail.d/bug-14143 [new file with mode: 0644]

index 08d5bda8dda2f8733ecd88d498c5429c175aa998..68838759fa4b27a4398205494c90ad8b49883f89 100644 (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):
 
diff --git a/selftest/knownfail.d/bug-14143 b/selftest/knownfail.d/bug-14143
new file mode 100644 (file)
index 0000000..f4f9bc0
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.netcmd.samba.tests.netcmd.TestParmTests.test_section