1 # Blackbox tests for "samba-tool drs" command
2 # Copyright (C) Kamen Mazdrashki <kamenim@samba.org> 2011
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.
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.
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/>.
18 """Blackbox tests for samba-tool drs."""
24 class SambaToolDrsTests(samba.tests.BlackboxTestCase):
25 """Blackbox test case for samba-tool drs."""
28 super(SambaToolDrsTests, self).setUp()
30 self.dc1 = samba.tests.env_get_var_value("DC1")
31 self.dc2 = samba.tests.env_get_var_value("DC2")
33 creds = self.get_credentials()
34 self.cmdline_creds = "-U%s/%s%%%s" % (creds.get_domain(),
35 creds.get_username(), creds.get_password())
37 def _get_rootDSE(self, dc, ldap_only=True):
38 samdb = samba.tests.connect_samdb(dc, lp=self.get_loadparm(),
39 credentials=self.get_credentials(),
41 return samdb.search(base="", scope=samba.tests.ldb.SCOPE_BASE)[0]
43 def test_samba_tool_bind(self):
44 """Tests 'samba-tool drs bind' command."""
46 # Output should be like:
47 # Extensions supported:
48 # <list-of-supported-extensions>
51 out = self.check_output("samba-tool drs bind %s %s" % (self.dc1,
53 self.assertTrue("Site GUID:" in out)
54 self.assertTrue("Repl epoch:" in out)
56 def test_samba_tool_kcc(self):
57 """Tests 'samba-tool drs kcc' command."""
59 # Output should be like 'Consistency check on <DC> successful.'
60 out = self.check_output("samba-tool drs kcc %s %s" % (self.dc1,
62 self.assertTrue("Consistency check on" in out)
63 self.assertTrue("successful" in out)
65 def test_samba_tool_showrepl(self):
66 """Tests 'samba-tool drs showrepl' command.
68 # Output should be like:
69 # <site-name>/<domain-name>
70 # DSA Options: <hex-options>
71 # DSA object GUID: <DSA-object-GUID>
72 # DSA invocationId: <DSA-invocationId>
73 # <Inbound-connections-list>
74 # <Outbound-connections-list>
77 # TODO: Perhaps we should check at least for
78 # DSA's objectGUDI and invocationId
79 out = self.check_output("samba-tool drs showrepl %s %s" % (self.dc1,
81 self.assertTrue("DSA Options:" in out)
82 self.assertTrue("DSA object GUID:" in out)
83 self.assertTrue("DSA invocationId:" in out)
85 def test_samba_tool_options(self):
86 """Tests 'samba-tool drs options' command
88 # Output should be like 'Current DSA options: IS_GC <OTHER_FLAGS>'
89 out = self.check_output("samba-tool drs options %s %s" % (self.dc1,
91 self.assertTrue("Current DSA options:" in out)
93 def test_samba_tool_replicate(self):
94 """Tests 'samba-tool drs replicate' command."""
96 # Output should be like 'Replicate from <DC-SRC> to <DC-DEST> was successful.'
97 nc_name = self._get_rootDSE(self.dc1)["defaultNamingContext"]
98 out = self.check_output("samba-tool drs replicate %s %s %s %s" % (self.dc1,
102 self.assertTrue("Replicate from" in out)
103 self.assertTrue("was successful" in out)
105 def test_samba_tool_drs_clone_dc(self):
106 """Tests 'samba-tool drs clone-dc-database' command."""
107 server_rootdse = self._get_rootDSE(self.dc1)
108 server_nc_name = server_rootdse["defaultNamingContext"]
109 server_ds_name = server_rootdse["dsServiceName"]
110 server_ldap_service_name = str(server_rootdse["ldapServiceName"][0])
111 server_realm = server_ldap_service_name.split(":")[0]
112 creds = self.get_credentials()
113 out = self.check_output("samba-tool drs clone-dc-database %s --server=%s %s --targetdir=%s"
118 ldb_rootdse = self._get_rootDSE("tdb://" + os.path.join(self.tempdir, "private", "sam.ldb"), ldap_only=False)
119 nc_name = ldb_rootdse["defaultNamingContext"]
120 ds_name = ldb_rootdse["dsServiceName"]
121 ldap_service_name = str(server_rootdse["ldapServiceName"][0])
122 self.assertEqual(nc_name, server_nc_name)
123 # The clone should pretend to be the source server
124 self.assertEqual(ds_name, server_ds_name)
125 self.assertEqual(ldap_service_name, server_ldap_service_name)
126 shutil.rmtree(os.path.join(self.tempdir, "private"))
127 shutil.rmtree(os.path.join(self.tempdir, "etc"))
128 shutil.rmtree(os.path.join(self.tempdir, "msg.lock"))
129 os.remove(os.path.join(self.tempdir, "names.tdb"))
130 shutil.rmtree(os.path.join(self.tempdir, "state"))