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
.binddns_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()
60 secrets_tdb_path
= os
.path
.join(self
.tempdir
, "secrets.tdb")
62 paths
.private_dir
= os
.path
.dirname(path
)
63 paths
.binddns_dir
= os
.path
.dirname(path
)
64 paths
.keytab
= "no.keytab"
65 paths
.dns_keytab
= "no.dns.keytab"
66 ldb
= setup_secretsdb(paths
, None, None, lp
=env_loadparm())
68 self
.assertEquals("LSA Secrets",
69 ldb
.searchone(basedn
="CN=LSA Secrets", attribute
="CN"))
73 if os
.path
.exists(secrets_tdb_path
):
74 os
.unlink(secrets_tdb_path
)
76 class FindNssTests(TestCase
):
77 """Test findnss() function."""
79 def test_nothing(self
):
82 self
.assertRaises(KeyError, findnss
, x
, [])
85 self
.assertEquals("bla", findnss(lambda x
: "bla", ["bla"]))
87 def test_skip_first(self
):
92 self
.assertEquals("ha", findnss(x
, ["bloe", "bla"]))
95 class Disabled(object):
97 def test_setup_templatesdb(self
):
98 raise NotImplementedError(self
.test_setup_templatesdb
)
100 def test_setup_registry(self
):
101 raise NotImplementedError(self
.test_setup_registry
)
103 def test_setup_samdb_rootdse(self
):
104 raise NotImplementedError(self
.test_setup_samdb_rootdse
)
106 def test_setup_samdb_partitions(self
):
107 raise NotImplementedError(self
.test_setup_samdb_partitions
)
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
)
122 class SanitizeServerRoleTests(TestCase
):
125 self
.assertEquals("standalone server",
126 sanitize_server_role("standalone server"))
127 self
.assertEquals("member server",
128 sanitize_server_role("member server"))
130 def test_invalid(self
):
131 self
.assertRaises(ValueError, sanitize_server_role
, "foo")
133 def test_valid(self
):
136 sanitize_server_role("ROLE_STANDALONE"))
139 sanitize_server_role("standalone"))
141 "active directory domain controller",
142 sanitize_server_role("domain controller"))
145 class DummyLogger(object):
150 def info(self
, text
, *args
):
151 self
.entries
.append(("INFO", text
% args
))
154 class ProvisionResultTests(TestCase
):
156 def report_logger(self
, result
):
157 logger
= DummyLogger()
158 result
.report_logger(logger
)
159 return logger
.entries
161 def base_result(self
):
162 result
= ProvisionResult()
163 result
.server_role
= "domain controller"
164 result
.names
= ProvisionNames()
165 result
.names
.hostname
= "hostnaam"
166 result
.names
.domain
= "DOMEIN"
167 result
.names
.dnsdomain
= "dnsdomein"
168 result
.domainsid
= "S1-1-1"
169 result
.paths
= ProvisionPaths()
172 def test_basic_report_logger(self
):
173 result
= self
.base_result()
174 entries
= self
.report_logger(result
)
175 self
.assertEquals(entries
, [
176 ('INFO', 'Once the above files are installed, your Samba AD server '
177 'will be ready to use'),
178 ('INFO', 'Server Role: domain controller'),
179 ('INFO', 'Hostname: hostnaam'),
180 ('INFO', 'NetBIOS Domain: DOMEIN'),
181 ('INFO', 'DNS Domain: dnsdomein'),
182 ('INFO', 'DOMAIN SID: S1-1-1')])
184 def test_report_logger_adminpass(self
):
185 result
= self
.base_result()
186 result
.adminpass_generated
= True
187 result
.adminpass
= "geheim"
188 entries
= self
.report_logger(result
)
189 self
.assertEquals(entries
[1],
190 ("INFO", 'Admin password: geheim'))
193 class DetermineNetbiosNameTests(TestCase
):
195 def test_limits_to_15(self
):
196 self
.assertEquals("A" * 15, determine_netbios_name("a" * 30))
198 def test_strips_invalid(self
):
199 self
.assertEquals("BLABLA", determine_netbios_name("bla/bla"))