1f2194671e9932282cb4c9da66c1b0270a40a8ec
[samba.git] / python / samba / tests / samba_tool / forest.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) William Brown <william@blackhats.net.au> 2018
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 import os
19 import ldb
20 from samba.tests.samba_tool.base import SambaToolCmdTest
21
22 class ForestCmdTestCase(SambaToolCmdTest):
23     """Tests for samba-tool dsacl subcommands"""
24     samdb = None
25
26     def setUp(self):
27         super(ForestCmdTestCase, self).setUp()
28         self.samdb = self.getSamDB("-H", "ldap://%s" % os.environ["DC_SERVER"],
29                                    "-U%s%%%s" % (os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"]))
30         self.domain_dn = self.samdb.domain_dn()
31
32     def tearDown(self):
33         super(ForestCmdTestCase, self).tearDown()
34         # Reset the values we might have changed.
35         ds_dn = "CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration"
36         m = ldb.Message()
37         m.dn = ldb.Dn(self.samdb, "%s,%s" % (ds_dn, self.domain_dn))
38         m['dsheuristics'] = ldb.MessageElement(
39             '0000000', ldb.FLAG_MOD_REPLACE, 'dsheuristics')
40
41         self.samdb.modify(m)
42
43     def test_display(self):
44         """Tests that we can display forest settings"""
45         (result, out, err) = self.runsublevelcmd("forest", ("directory_service",
46                                                             "show"),
47                                                  "-H", "ldap://%s" % os.environ["DC_SERVER"],
48                                                  "-U%s%%%s" % (os.environ["DC_USERNAME"],
49                                                                os.environ["DC_PASSWORD"]))
50
51         self.assertCmdSuccess(result, out, err)
52         self.assertEquals(err,"","Shouldn't be any error messages")
53         self.assertIn("dsheuristics: <NO VALUE>", out)
54
55     def test_modify_dsheuristics(self):
56         """Test that we can modify the dsheuristics setting"""
57
58         (result, out, err) = self.runsublevelcmd("forest", ("directory_service",
59                                                             "dsheuristics"), "0000002",
60                                                  "-H", "ldap://%s" % os.environ["DC_SERVER"],
61                                                  "-U%s%%%s" % (os.environ["DC_USERNAME"],
62                                                                os.environ["DC_PASSWORD"]))
63
64         self.assertCmdSuccess(result, out, err)
65         self.assertEquals(err,"","Shouldn't be any error messages")
66         self.assertIn("set dsheuristics: 0000002", out)