Add docstring.
[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     """Some simple tests for individual functions in the provisioning code.
37     """
38     def test_setup_secretsdb(self):
39         path = os.path.join(self.tempdir, "secrets.ldb")
40         ldb = setup_secretsdb(path, setup_path, None, None, lp=lp)
41         try:
42             self.assertEquals("LSA Secrets",
43                  ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
44         finally:
45             del ldb
46             os.unlink(path)
47             
48     def test_become_dc(self):
49         path = os.path.join(self.tempdir, "secrets.ldb")
50         secrets_ldb = setup_secretsdb(path, setup_path, None, None, lp=lp)
51         try:
52             secretsdb_become_dc(secrets_ldb, setup_path, domain="EXAMPLE", 
53                    realm="example", netbiosname="myhost", 
54                    domainsid="S-5-22", keytab_path="keytab.path", 
55                    samdb_url="ldap://url/", 
56                    dns_keytab_path="dns.keytab", dnspass="bla", 
57                            machinepass="machinepass", dnsdomain="example.com")
58             self.assertEquals(1, 
59                     len(secrets_ldb.search("samAccountName=krbtgt,flatname=EXAMPLE,CN=Principals")))
60             self.assertEquals("keytab.path",
61                     secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains", 
62                                           expression="(privateKeytab=*)", 
63                                           attribute="privateKeytab"))
64             self.assertEquals("S-5-22",
65                     secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains",
66                                           expression="objectSid=*", attribute="objectSid"))
67
68         finally:
69             del secrets_ldb
70             os.unlink(path)
71
72
73 class FindNssTests(unittest.TestCase):
74     """Test findnss() function."""
75     def test_nothing(self):
76         def x(y):
77             raise KeyError
78         self.assertRaises(KeyError, findnss, x, [])
79
80     def test_first(self):
81         self.assertEquals("bla", findnss(lambda x: "bla", ["bla"]))
82
83     def test_skip_first(self):
84         def x(y):
85             if y != "bla":
86                 raise KeyError
87             return "ha"
88         self.assertEquals("ha", findnss(x, ["bloe", "bla"]))
89
90
91 class Disabled:
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     def test_erase_partitions(self):
123         raise NotImplementedError(self.test_erase_partitions)
124
125