]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: Test gpo manage motd list command
authorDavid Mulder <dmulder@suse.com>
Wed, 17 Feb 2021 21:58:51 +0000 (14:58 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 8 Mar 2021 19:45:30 +0000 (19:45 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
python/samba/netcmd/gpo.py
python/samba/tests/samba_tool/gpo.py
selftest/knownfail.d/gpo [new file with mode: 0644]

index 818c46ddb1adee6a481e4e8f594fbd1a1b57f6ba..d2bede247d3047509e476c3a4bc229b175f94e95 100644 (file)
@@ -3323,6 +3323,39 @@ class cmd_scripts(SuperCommand):
     subcommands = {}
     subcommands["startup"] = cmd_startup()
 
+class cmd_list_motd(Command):
+    """List VGP MOTD Group Policy from the sysvol
+
+This command lists the Message of the Day from the sysvol that will be applied
+to winbind clients.
+
+Example:
+samba-tool gpo manage motd list {31B2F340-016D-11D2-945F-00C04FB984F9}
+    """
+
+    synopsis = "%prog <gpo> [options]"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "versionopts": options.VersionOptions,
+        "credopts": options.CredentialsOptions,
+    }
+
+    takes_options = [
+        Option("-H", "--URL", help="LDB URL for database or target server", type=str,
+                metavar="URL", dest="H"),
+    ]
+
+    takes_args = ["gpo"]
+
+    def run(self, gpo, H=None, sambaopts=None, credopts=None, versionopts=None):
+        pass
+
+class cmd_motd(SuperCommand):
+    """Manage Message of the Day Group Policy Objects"""
+    subcommands = {}
+    subcommands["list"] = cmd_list_motd()
+
 class cmd_manage(SuperCommand):
     """Manage Group Policy Objects"""
     subcommands = {}
@@ -3333,6 +3366,7 @@ class cmd_manage(SuperCommand):
     subcommands["files"] = cmd_files()
     subcommands["openssh"] = cmd_openssh()
     subcommands["scripts"] = cmd_scripts()
+    subcommands["motd"] = cmd_motd()
 
 class cmd_gpo(SuperCommand):
     """Group Policy Object (GPO) management."""
index 13734f3b1635686e66fa15319493478f297f7394..860254b74f0423aa0d38619161e4fba7b7612a20 100644 (file)
@@ -1223,6 +1223,45 @@ class GpoCmdTestCase(SambaToolCmdTest):
         # Unstage the manifest.xml file
         unstage_file(vgp_xml)
 
+    def test_vgp_motd(self):
+        lp = LoadParm()
+        lp.load(os.environ['SERVERCONFFILE'])
+        local_path = lp.get('path', 'sysvol')
+        vgp_xml = os.path.join(local_path, lp.get('realm').lower(), 'Policies',
+                               self.gpo_guid, 'Machine/VGP/VTLA/Unix',
+                               'MOTD/manifest.xml')
+
+        stage = etree.Element('vgppolicy')
+        policysetting = etree.SubElement(stage, 'policysetting')
+        pv = etree.SubElement(policysetting, 'version')
+        pv.text = '1'
+        name = etree.SubElement(policysetting, 'name')
+        name.text = 'Text File'
+        description = etree.SubElement(policysetting, 'description')
+        description.text = 'Represents a Generic Text File'
+        apply_mode = etree.SubElement(policysetting, 'apply_mode')
+        apply_mode.text = 'replace'
+        data = etree.SubElement(policysetting, 'data')
+        filename = etree.SubElement(data, 'filename')
+        filename.text = 'motd'
+        text = etree.SubElement(data, 'text')
+        text.text = 'This is a message of the day'
+        ret = stage_file(vgp_xml, etree.tostring(stage, 'utf-8'))
+        self.assertTrue(ret, 'Could not create the target %s' % vgp_xml)
+
+        (result, out, err) = self.runsublevelcmd("gpo", ("manage",
+                                                 "motd", "list"),
+                                                 self.gpo_guid, "-H",
+                                                 "ldap://%s" %
+                                                 os.environ["SERVER"],
+                                                 "-U%s%%%s" %
+                                                 (os.environ["USERNAME"],
+                                                 os.environ["PASSWORD"]))
+        self.assertIn(text.text, out, 'The test entry was not found!')
+
+        # Unstage the manifest.xml file
+        unstage_file(vgp_xml)
+
     def setUp(self):
         """set up a temporary GPO to work with"""
         super(GpoCmdTestCase, self).setUp()
diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo
new file mode 100644 (file)
index 0000000..41587fc
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_vgp_motd