samba-tool visualize: use correct DC in graph label
[samba.git] / python / samba / tests / samba_tool / gpo.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Andrew Bartlett 2012
3 #
4 # based on time.py:
5 # Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 import os
22 from samba.tests.samba_tool.base import SambaToolCmdTest
23 import shutil
24
25 class GpoCmdTestCase(SambaToolCmdTest):
26     """Tests for samba-tool time subcommands"""
27
28     gpo_name = "testgpo"
29
30     def test_gpo_list(self):
31         """Run gpo list against the server and make sure it looks accurate"""
32         (result, out, err) = self.runsubcmd("gpo", "listall", "-H", "ldap://%s" % os.environ["SERVER"])
33         self.assertCmdSuccess(result, out, err, "Ensuring gpo listall ran successfully")
34
35     def test_fetchfail(self):
36         """Run against a non-existent GPO, and make sure it fails (this hard-coded UUID is very unlikely to exist"""
37         (result, out, err) = self.runsubcmd("gpo", "fetch", "c25cac17-a02a-4151-835d-fae17446ee43", "-H", "ldap://%s" % os.environ["SERVER"])
38         self.assertCmdFail(result, "check for result code")
39
40     def test_fetch(self):
41         """Run against a real GPO, and make sure it passes"""
42         (result, out, err) = self.runsubcmd("gpo", "fetch", self.gpo_guid, "-H", "ldap://%s" % os.environ["SERVER"], "--tmpdir", self.tempdir)
43         self.assertCmdSuccess(result, out, err, "Ensuring gpo fetched successfully")
44         shutil.rmtree(os.path.join(self.tempdir, "policy"))
45
46     def test_show(self):
47         """Show a real GPO, and make sure it passes"""
48         (result, out, err) = self.runsubcmd("gpo", "show", self.gpo_guid, "-H", "ldap://%s" % os.environ["SERVER"])
49         self.assertCmdSuccess(result, out, err, "Ensuring gpo fetched successfully")
50
51     def test_show_as_admin(self):
52         """Show a real GPO, and make sure it passes"""
53         (result, out, err) = self.runsubcmd("gpo", "show", self.gpo_guid, "-H", "ldap://%s" % os.environ["SERVER"], "-U%s%%%s" % (os.environ["USERNAME"], os.environ["PASSWORD"]))
54         self.assertCmdSuccess(result, out, err, "Ensuring gpo fetched successfully")
55
56     def test_aclcheck(self):
57         """Check all the GPOs on the remote server have correct ACLs"""
58         (result, out, err) = self.runsubcmd("gpo", "aclcheck", "-H", "ldap://%s" % os.environ["SERVER"], "-U%s%%%s" % (os.environ["USERNAME"], os.environ["PASSWORD"]))
59         self.assertCmdSuccess(result, out, err, "Ensuring gpo checked successfully")
60
61     def setUp(self):
62         """set up a temporary GPO to work with"""
63         super(GpoCmdTestCase, self).setUp()
64         (result, out, err) = self.runsubcmd("gpo", "create", self.gpo_name,
65                                             "-H", "ldap://%s" % os.environ["SERVER"],
66                                             "-U%s%%%s" % (os.environ["USERNAME"], os.environ["PASSWORD"]),
67                                             "--tmpdir", self.tempdir)
68         shutil.rmtree(os.path.join(self.tempdir, "policy"))
69         self.assertCmdSuccess(result, out, err, "Ensuring gpo created successfully")
70         try:
71             self.gpo_guid = "{%s}" % out.split("{")[1].split("}")[0]
72         except IndexError:
73             self.fail("Failed to find GUID in output: %s" % out)
74
75     def tearDown(self):
76         """remove the temporary GPO to work with"""
77         (result, out, err) = self.runsubcmd("gpo", "del", self.gpo_guid, "-H", "ldap://%s" % os.environ["SERVER"], "-U%s%%%s" % (os.environ["USERNAME"], os.environ["PASSWORD"]))
78         self.assertCmdSuccess(result, out, err, "Ensuring gpo deleted successfully")
79         super(GpoCmdTestCase, self).tearDown()