Add tests for findnss(), add some docstrings.
[ira/wip.git] / source / scripting / python / samba / tests / provision.py
1 #!/usr/bin/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 import os
21 from samba.provision import setup_secretsdb, secretsdb_become_dc, findnss
22 import samba.tests
23 from ldb import Dn
24 import param
25 import unittest
26
27 lp = param.LoadParm()
28 lp.load("st/dc/etc/smb.conf")
29
30 setup_dir = "setup"
31 def setup_path(file):
32     return os.path.join(setup_dir, file)
33
34
35 class ProvisionTestCase(samba.tests.TestCaseInTempDir):
36     def test_setup_secretsdb(self):
37         path = os.path.join(self.tempdir, "secrets.ldb")
38         ldb = setup_secretsdb(path, setup_path, None, None, lp=lp)
39         try:
40             self.assertEquals("LSA Secrets",
41                  ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
42         finally:
43             del ldb
44             os.unlink(path)
45             
46     def test_become_dc(self):
47         path = os.path.join(self.tempdir, "secrets.ldb")
48         secrets_ldb = setup_secretsdb(path, setup_path, None, None, lp=lp)
49         try:
50             secretsdb_become_dc(secrets_ldb, setup_path, domain="EXAMPLE", 
51                    realm="example", netbiosname="myhost", 
52                    domainsid="S-5-22", keytab_path="keytab.path", 
53                    samdb_url="ldap://url/", 
54                    dns_keytab_path="dns.keytab", dnspass="bla", 
55                            machinepass="machinepass", dnsdomain="example.com")
56             self.assertEquals(1, 
57                     len(secrets_ldb.search("samAccountName=krbtgt,flatname=EXAMPLE,CN=Principals")))
58             self.assertEquals("keytab.path",
59                     secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains", 
60                                           expression="(privateKeytab=*)", 
61                                           attribute="privateKeytab"))
62             self.assertEquals("S-5-22",
63                     secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains",
64                                           expression="objectSid=*", attribute="objectSid"))
65
66         finally:
67             del secrets_ldb
68             os.unlink(path)
69
70
71 class FindNssTests(unittest.TestCase):
72     """Test findnss() function."""
73     def test_nothing(self):
74         def x(y):
75             raise KeyError
76         self.assertRaises(KeyError, findnss, x, [])
77
78     def test_first(self):
79         self.assertEquals("bla", findnss(lambda x: "bla", ["bla"]))
80
81     def test_skip_first(self):
82         def x(y):
83             if y != "bla":
84                 raise KeyError
85             return "ha"
86         self.assertEquals("ha", findnss(x, ["bloe", "bla"]))
87
88
89 class Disabled:
90     def test_setup_templatesdb(self):
91         raise NotImplementedError(self.test_setup_templatesdb)
92
93     def test_setup_registry(self):
94         raise NotImplementedError(self.test_setup_registry)
95
96     def test_setup_samdb_rootdse(self):
97         raise NotImplementedError(self.test_setup_samdb_rootdse)
98
99     def test_setup_samdb_partitions(self):
100         raise NotImplementedError(self.test_setup_samdb_partitions)
101
102     def test_create_phpldapadmin_config(self):
103         raise NotImplementedError(self.test_create_phpldapadmin_config)
104
105     def test_provision_dns(self):
106         raise NotImplementedError(self.test_provision_dns)
107
108     def test_provision_ldapbase(self):
109         raise NotImplementedError(self.test_provision_ldapbase)
110
111     def test_provision_guess(self):
112         raise NotImplementedError(self.test_provision_guess)
113
114     def test_join_domain(self):
115         raise NotImplementedError(self.test_join_domain)
116
117     def test_vampire(self):
118         raise NotImplementedError(self.test_vampire)
119
120     def test_erase_partitions(self):
121         raise NotImplementedError(self.test_erase_partitions)
122
123