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 secrets_tdb_path
= os
.path
.join(self
.tempdir
, "secrets.tdb")
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"))
71 os
.unlink(secrets_tdb_path
)
74 class FindNssTests(TestCase
):
75 """Test findnss() function."""
77 def test_nothing(self
):
80 self
.assertRaises(KeyError, findnss
, x
, [])
83 self
.assertEquals("bla", findnss(lambda x
: "bla", ["bla"]))
85 def test_skip_first(self
):
90 self
.assertEquals("ha", findnss(x
, ["bloe", "bla"]))
93 class Disabled(object):
95 def test_setup_templatesdb(self
):
96 raise NotImplementedError(self
.test_setup_templatesdb
)
98 def test_setup_registry(self
):
99 raise NotImplementedError(self
.test_setup_registry
)
101 def test_setup_samdb_rootdse(self
):
102 raise NotImplementedError(self
.test_setup_samdb_rootdse
)
104 def test_setup_samdb_partitions(self
):
105 raise NotImplementedError(self
.test_setup_samdb_partitions
)
107 def test_provision_dns(self
):
108 raise NotImplementedError(self
.test_provision_dns
)
110 def test_provision_ldapbase(self
):
111 raise NotImplementedError(self
.test_provision_ldapbase
)
113 def test_provision_guess(self
):
114 raise NotImplementedError(self
.test_provision_guess
)
116 def test_join_domain(self
):
117 raise NotImplementedError(self
.test_join_domain
)
119 def test_vampire(self
):
120 raise NotImplementedError(self
.test_vampire
)
123 class SanitizeServerRoleTests(TestCase
):
126 self
.assertEquals("standalone server",
127 sanitize_server_role("standalone server"))
128 self
.assertEquals("member server",
129 sanitize_server_role("member server"))
131 def test_invalid(self
):
132 self
.assertRaises(ValueError, sanitize_server_role
, "foo")
134 def test_valid(self
):
137 sanitize_server_role("ROLE_STANDALONE"))
140 sanitize_server_role("standalone"))
142 "active directory domain controller",
143 sanitize_server_role("domain controller"))
146 class DummyLogger(object):
151 def info(self
, text
, *args
):
152 self
.entries
.append(("INFO", text
% args
))
155 class ProvisionResultTests(TestCase
):
157 def report_logger(self
, result
):
158 logger
= DummyLogger()
159 result
.report_logger(logger
)
160 return logger
.entries
162 def base_result(self
):
163 result
= ProvisionResult()
164 result
.server_role
= "domain controller"
165 result
.names
= ProvisionNames()
166 result
.names
.hostname
= "hostnaam"
167 result
.names
.domain
= "DOMEIN"
168 result
.names
.dnsdomain
= "dnsdomein"
169 result
.domainsid
= "S1-1-1"
170 result
.paths
= ProvisionPaths()
173 def test_basic_report_logger(self
):
174 result
= self
.base_result()
175 entries
= self
.report_logger(result
)
176 self
.assertEquals(entries
, [
177 ('INFO', 'Once the above files are installed, your Samba4 server '
178 'will be ready to use'),
179 ('INFO', 'Server Role: domain controller'),
180 ('INFO', 'Hostname: hostnaam'),
181 ('INFO', 'NetBIOS Domain: DOMEIN'),
182 ('INFO', 'DNS Domain: dnsdomein'),
183 ('INFO', 'DOMAIN SID: S1-1-1')])
185 def test_report_logger_adminpass(self
):
186 result
= self
.base_result()
187 result
.adminpass_generated
= True
188 result
.adminpass
= "geheim"
189 entries
= self
.report_logger(result
)
190 self
.assertEquals(entries
[1],
191 ("INFO", 'Admin password: geheim'))
194 class DetermineNetbiosNameTests(TestCase
):
196 def test_limits_to_15(self
):
197 self
.assertEquals("A" * 15, determine_netbios_name("a" * 30))
199 def test_strips_invalid(self
):
200 self
.assertEquals("BLABLA", determine_netbios_name("bla/bla"))