1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2012
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 """Tests for samba.provision."""
21 from samba
.provision
import (
25 determine_netbios_name
,
31 from samba
.tests
import env_loadparm
, TestCase
33 def create_dummy_secretsdb(path
, lp
=None):
34 """Create a dummy secrets database for use in tests.
36 :param path: Path to store the secrets db
37 :param lp: Optional loadparm context. A simple one will
38 be generated if not specified.
42 paths
= ProvisionPaths()
44 paths
.private_dir
= os
.path
.dirname(path
)
45 paths
.keytab
= "no.keytab"
46 paths
.dns_keytab
= "no.dns.keytab"
47 secrets_ldb
= setup_secretsdb(paths
, None, None, lp
=lp
)
48 secrets_ldb
.transaction_commit()
52 class ProvisionTestCase(samba
.tests
.TestCaseInTempDir
):
53 """Some simple tests for individual functions in the provisioning code.
56 def test_setup_secretsdb(self
):
57 path
= os
.path
.join(self
.tempdir
, "secrets.ldb")
58 paths
= ProvisionPaths()
59 secrets_tdb_path
= os
.path
.join(self
.tempdir
, "secrets.tdb")
60 secrets_ntdb_path
= os
.path
.join(self
.tempdir
, "secrets.ntdb")
62 paths
.private_dir
= os
.path
.dirname(path
)
63 paths
.keytab
= "no.keytab"
64 paths
.dns_keytab
= "no.dns.keytab"
65 ldb
= setup_secretsdb(paths
, None, None, lp
=env_loadparm())
67 self
.assertEquals("LSA Secrets",
68 ldb
.searchone(basedn
="CN=LSA Secrets", attribute
="CN"))
72 if os
.path
.exists(secrets_tdb_path
):
73 os
.unlink(secrets_tdb_path
)
74 if os
.path
.exists(secrets_ntdb_path
):
75 os
.unlink(secrets_ntdb_path
)
77 class FindNssTests(TestCase
):
78 """Test findnss() function."""
80 def test_nothing(self
):
83 self
.assertRaises(KeyError, findnss
, x
, [])
86 self
.assertEquals("bla", findnss(lambda x
: "bla", ["bla"]))
88 def test_skip_first(self
):
93 self
.assertEquals("ha", findnss(x
, ["bloe", "bla"]))
96 class Disabled(object):
98 def test_setup_templatesdb(self
):
99 raise NotImplementedError(self
.test_setup_templatesdb
)
101 def test_setup_registry(self
):
102 raise NotImplementedError(self
.test_setup_registry
)
104 def test_setup_samdb_rootdse(self
):
105 raise NotImplementedError(self
.test_setup_samdb_rootdse
)
107 def test_setup_samdb_partitions(self
):
108 raise NotImplementedError(self
.test_setup_samdb_partitions
)
110 def test_provision_dns(self
):
111 raise NotImplementedError(self
.test_provision_dns
)
113 def test_provision_ldapbase(self
):
114 raise NotImplementedError(self
.test_provision_ldapbase
)
116 def test_provision_guess(self
):
117 raise NotImplementedError(self
.test_provision_guess
)
119 def test_join_domain(self
):
120 raise NotImplementedError(self
.test_join_domain
)
122 def test_vampire(self
):
123 raise NotImplementedError(self
.test_vampire
)
126 class SanitizeServerRoleTests(TestCase
):
129 self
.assertEquals("standalone server",
130 sanitize_server_role("standalone server"))
131 self
.assertEquals("member server",
132 sanitize_server_role("member server"))
134 def test_invalid(self
):
135 self
.assertRaises(ValueError, sanitize_server_role
, "foo")
137 def test_valid(self
):
140 sanitize_server_role("ROLE_STANDALONE"))
143 sanitize_server_role("standalone"))
145 "active directory domain controller",
146 sanitize_server_role("domain controller"))
149 class DummyLogger(object):
154 def info(self
, text
, *args
):
155 self
.entries
.append(("INFO", text
% args
))
158 class ProvisionResultTests(TestCase
):
160 def report_logger(self
, result
):
161 logger
= DummyLogger()
162 result
.report_logger(logger
)
163 return logger
.entries
165 def base_result(self
):
166 result
= ProvisionResult()
167 result
.server_role
= "domain controller"
168 result
.names
= ProvisionNames()
169 result
.names
.hostname
= "hostnaam"
170 result
.names
.domain
= "DOMEIN"
171 result
.names
.dnsdomain
= "dnsdomein"
172 result
.domainsid
= "S1-1-1"
173 result
.paths
= ProvisionPaths()
176 def test_basic_report_logger(self
):
177 result
= self
.base_result()
178 entries
= self
.report_logger(result
)
179 self
.assertEquals(entries
, [
180 ('INFO', 'Once the above files are installed, your Samba4 server '
181 'will be ready to use'),
182 ('INFO', 'Server Role: domain controller'),
183 ('INFO', 'Hostname: hostnaam'),
184 ('INFO', 'NetBIOS Domain: DOMEIN'),
185 ('INFO', 'DNS Domain: dnsdomein'),
186 ('INFO', 'DOMAIN SID: S1-1-1')])
188 def test_report_logger_adminpass(self
):
189 result
= self
.base_result()
190 result
.adminpass_generated
= True
191 result
.adminpass
= "geheim"
192 entries
= self
.report_logger(result
)
193 self
.assertEquals(entries
[1],
194 ("INFO", 'Admin password: geheim'))
197 class DetermineNetbiosNameTests(TestCase
):
199 def test_limits_to_15(self
):
200 self
.assertEquals("A" * 15, determine_netbios_name("a" * 30))
202 def test_strips_invalid(self
):
203 self
.assertEquals("BLABLA", determine_netbios_name("bla/bla"))