expand tabs in python file, consistent with the rest of the file.
[amitay/samba.git] / source4 / 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 from samba import param
25 import unittest
26
27 lp = samba.tests.cmdline_loadparm
28
29 setup_dir = "setup"
30 def setup_path(file):
31     return os.path.join(setup_dir, file)
32
33
34 class ProvisionTestCase(samba.tests.TestCaseInTempDir):
35     """Some simple tests for individual functions in the provisioning code.
36     """
37     def test_setup_secretsdb(self):
38         path = os.path.join(self.tempdir, "secrets.ldb")
39         ldb = setup_secretsdb(path, setup_path, None, None, lp=lp)
40         try:
41             self.assertEquals("LSA Secrets",
42                  ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
43         finally:
44             del ldb
45             os.unlink(path)
46             
47     def test_become_dc(self):
48         path = os.path.join(self.tempdir, "secrets.ldb")
49         secrets_ldb = setup_secretsdb(path, setup_path, None, None, lp=lp)
50         try:
51             secretsdb_become_dc(secrets_ldb, setup_path, domain="EXAMPLE", 
52                    realm="example", netbiosname="myhost", 
53                    domainsid="S-5-22", keytab_path="keytab.path", 
54                    samdb_url="ldap://url/", 
55                    dns_keytab_path="dns.keytab", dnspass="bla", 
56                            machinepass="machinepass", dnsdomain="example.com")
57             self.assertEquals(1, 
58                     len(secrets_ldb.search("samAccountName=krbtgt,flatname=EXAMPLE,CN=Principals")))
59             self.assertEquals("keytab.path",
60                     secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains", 
61                                           expression="(privateKeytab=*)", 
62                                           attribute="privateKeytab"))
63             self.assertEquals("S-5-22",
64                     secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains",
65                                           expression="objectSid=*", attribute="objectSid"))
66
67         finally:
68             del secrets_ldb
69             os.unlink(path)
70
71
72 class FindNssTests(unittest.TestCase):
73     """Test findnss() function."""
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     def test_setup_templatesdb(self):
92         raise NotImplementedError(self.test_setup_templatesdb)
93
94     def test_setup_registry(self):
95         raise NotImplementedError(self.test_setup_registry)
96
97     def test_setup_samdb_rootdse(self):
98         raise NotImplementedError(self.test_setup_samdb_rootdse)
99
100     def test_setup_samdb_partitions(self):
101         raise NotImplementedError(self.test_setup_samdb_partitions)
102
103     def test_create_phpldapadmin_config(self):
104         raise NotImplementedError(self.test_create_phpldapadmin_config)
105
106     def test_provision_dns(self):
107         raise NotImplementedError(self.test_provision_dns)
108
109     def test_provision_ldapbase(self):
110         raise NotImplementedError(self.test_provision_ldapbase)
111
112     def test_provision_guess(self):
113         raise NotImplementedError(self.test_provision_guess)
114
115     def test_join_domain(self):
116         raise NotImplementedError(self.test_join_domain)
117
118     def test_vampire(self):
119         raise NotImplementedError(self.test_vampire)
120
121     def test_erase_partitions(self):
122         raise NotImplementedError(self.test_erase_partitions)
123
124