3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
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 setup_secretsdb, findnss, ProvisionPaths, find_setup_dir
25 from samba.tests import env_loadparm, TestCase
27 setup_dir = find_setup_dir()
29 return os.path.join(setup_dir, file)
32 def create_dummy_secretsdb(path, lp=None):
33 """Create a dummy secrets database for use in tests.
35 :param path: Path to store the secrets db
36 :param lp: Optional loadparm context. A simple one will
37 be generated if not specified.
41 paths = ProvisionPaths()
43 paths.private_dir = os.path.dirname(path)
44 paths.keytab = "no.keytab"
45 paths.dns_keytab = "no.dns.keytab"
46 secrets_ldb = setup_secretsdb(paths, setup_path, None, None, lp=lp)
47 secrets_ldb.transaction_commit()
51 class ProvisionTestCase(samba.tests.TestCaseInTempDir):
52 """Some simple tests for individual functions in the provisioning code.
55 def test_setup_secretsdb(self):
56 path = os.path.join(self.tempdir, "secrets.ldb")
57 paths = ProvisionPaths()
59 paths.private_dir = os.path.dirname(path)
60 paths.keytab = "no.keytab"
61 paths.dns_keytab = "no.dns.keytab"
62 ldb = setup_secretsdb(paths, setup_path, None, None, lp=env_loadparm())
64 self.assertEquals("LSA Secrets",
65 ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
71 class FindNssTests(TestCase):
72 """Test findnss() function."""
74 def test_nothing(self):
77 self.assertRaises(KeyError, findnss, x, [])
80 self.assertEquals("bla", findnss(lambda x: "bla", ["bla"]))
82 def test_skip_first(self):
87 self.assertEquals("ha", findnss(x, ["bloe", "bla"]))
90 class Disabled(object):
92 def test_setup_templatesdb(self):
93 raise NotImplementedError(self.test_setup_templatesdb)
95 def test_setup_registry(self):
96 raise NotImplementedError(self.test_setup_registry)
98 def test_setup_samdb_rootdse(self):
99 raise NotImplementedError(self.test_setup_samdb_rootdse)
101 def test_setup_samdb_partitions(self):
102 raise NotImplementedError(self.test_setup_samdb_partitions)
104 def test_create_phpldapadmin_config(self):
105 raise NotImplementedError(self.test_create_phpldapadmin_config)
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)