3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2012
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Tests for samba.provision."""
23 from samba.provision import (
32 from samba.tests import env_loadparm, TestCase
34 def create_dummy_secretsdb(path, lp=None):
35 """Create a dummy secrets database for use in tests.
37 :param path: Path to store the secrets db
38 :param lp: Optional loadparm context. A simple one will
39 be generated if not specified.
43 paths = ProvisionPaths()
45 paths.private_dir = os.path.dirname(path)
46 paths.keytab = "no.keytab"
47 paths.dns_keytab = "no.dns.keytab"
48 secrets_ldb = setup_secretsdb(paths, None, None, lp=lp)
49 secrets_ldb.transaction_commit()
53 class ProvisionTestCase(samba.tests.TestCaseInTempDir):
54 """Some simple tests for individual functions in the provisioning code.
57 def test_setup_secretsdb(self):
58 path = os.path.join(self.tempdir, "secrets.ldb")
59 paths = ProvisionPaths()
61 paths.private_dir = os.path.dirname(path)
62 paths.keytab = "no.keytab"
63 paths.dns_keytab = "no.dns.keytab"
64 ldb = setup_secretsdb(paths, None, None, lp=env_loadparm())
66 self.assertEquals("LSA Secrets",
67 ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
73 class FindNssTests(TestCase):
74 """Test findnss() function."""
76 def test_nothing(self):
79 self.assertRaises(KeyError, findnss, x, [])
82 self.assertEquals("bla", findnss(lambda x: "bla", ["bla"]))
84 def test_skip_first(self):
89 self.assertEquals("ha", findnss(x, ["bloe", "bla"]))
92 class Disabled(object):
94 def test_setup_templatesdb(self):
95 raise NotImplementedError(self.test_setup_templatesdb)
97 def test_setup_registry(self):
98 raise NotImplementedError(self.test_setup_registry)
100 def test_setup_samdb_rootdse(self):
101 raise NotImplementedError(self.test_setup_samdb_rootdse)
103 def test_setup_samdb_partitions(self):
104 raise NotImplementedError(self.test_setup_samdb_partitions)
106 def test_create_phpldapadmin_config(self):
107 raise NotImplementedError(self.test_create_phpldapadmin_config)
109 def test_provision_dns(self):
110 raise NotImplementedError(self.test_provision_dns)
112 def test_provision_ldapbase(self):
113 raise NotImplementedError(self.test_provision_ldapbase)
115 def test_provision_guess(self):
116 raise NotImplementedError(self.test_provision_guess)
118 def test_join_domain(self):
119 raise NotImplementedError(self.test_join_domain)
121 def test_vampire(self):
122 raise NotImplementedError(self.test_vampire)
125 class SanitizeServerRoleTests(TestCase):
128 self.assertEquals("standalone", sanitize_server_role("standalone"))
129 self.assertEquals("member server",
130 sanitize_server_role("member server"))
132 def test_invalid(self):
133 self.assertRaises(ValueError, sanitize_server_role, "foo")
135 def test_valid(self):
136 self.assertEquals("standalone", sanitize_server_role("ROLE_STANDALONE"))
139 class DummyLogger(object):
144 def info(self, text):
145 self.entries.append(("INFO", text))
148 class ProvisionResultTests(TestCase):
150 def test_report_logger(self):
151 logger = DummyLogger()
152 result = ProvisionResult()
153 result.server_role = "domain controller"
154 result.names = ProvisionNames()
155 result.names.hostname = "hostnaam"
156 result.names.domain = "DOMEIN"
157 result.names.dnsdomain = "dnsdomein"
158 result.domainsid = "S1-1-1"
159 result.report_logger(logger)
160 self.assertEquals(logger.entries, [
161 ('INFO', 'Server Role: domain controller'),
162 ('INFO', 'Hostname: hostnaam'),
163 ('INFO', 'NetBIOS Domain: DOMEIN'),
164 ('INFO', 'DNS Domain: dnsdomein'),
165 ('INFO', 'DOMAIN SID: S1-1-1')])