f6a5571840d013c590f5dcb0099917ad8c65119c
[samba.git] / source4 / scripting / python / samba / tests / provision.py
1 #!/usr/bin/env python
2
3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
5 #   
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.
10 #   
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.
15 #   
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/>.
18 #
19
20 """Tests for samba.provision."""
21
22 import os
23 from samba.provision import setup_secretsdb, findnss, ProvisionPaths, find_setup_dir
24 import samba.tests
25 from samba.tests import env_loadparm, TestCase
26
27 setup_dir = find_setup_dir()
28 def setup_path(file):
29     return os.path.join(setup_dir, file)
30
31
32 def create_dummy_secretsdb(path, lp=None):
33     """Create a dummy secrets database for use in tests.
34
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.
38     """
39     if lp is None:
40         lp = env_loadparm()
41     paths = ProvisionPaths()
42     paths.secrets = path
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()
48     return secrets_ldb
49
50
51 class ProvisionTestCase(samba.tests.TestCaseInTempDir):
52     """Some simple tests for individual functions in the provisioning code.
53     """
54
55     def test_setup_secretsdb(self):
56         path = os.path.join(self.tempdir, "secrets.ldb")
57         paths = ProvisionPaths()
58         paths.secrets = path
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())
63         try:
64             self.assertEquals("LSA Secrets",
65                  ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
66         finally:
67             del ldb
68             os.unlink(path)
69             
70
71 class FindNssTests(TestCase):
72     """Test findnss() function."""
73
74     def test_nothing(self):
75         def x(y):
76             raise KeyError
77         self.assertRaises(KeyError, findnss, x, [])
78
79     def test_first(self):
80         self.assertEquals("bla", findnss(lambda x: "bla", ["bla"]))
81
82     def test_skip_first(self):
83         def x(y):
84             if y != "bla":
85                 raise KeyError
86             return "ha"
87         self.assertEquals("ha", findnss(x, ["bloe", "bla"]))
88
89
90 class Disabled(object):
91
92     def test_setup_templatesdb(self):
93         raise NotImplementedError(self.test_setup_templatesdb)
94
95     def test_setup_registry(self):
96         raise NotImplementedError(self.test_setup_registry)
97
98     def test_setup_samdb_rootdse(self):
99         raise NotImplementedError(self.test_setup_samdb_rootdse)
100
101     def test_setup_samdb_partitions(self):
102         raise NotImplementedError(self.test_setup_samdb_partitions)
103
104     def test_create_phpldapadmin_config(self):
105         raise NotImplementedError(self.test_create_phpldapadmin_config)
106
107     def test_provision_dns(self):
108         raise NotImplementedError(self.test_provision_dns)
109
110     def test_provision_ldapbase(self):
111         raise NotImplementedError(self.test_provision_ldapbase)
112
113     def test_provision_guess(self):
114         raise NotImplementedError(self.test_provision_guess)
115
116     def test_join_domain(self):
117         raise NotImplementedError(self.test_join_domain)
118
119     def test_vampire(self):
120         raise NotImplementedError(self.test_vampire)
121
122