a022d7bb514eefb655dbed9e76beee9eee5e6c8d
[kai/samba-autobuild/.git] / source4 / scripting / python / samba / tests / samdb.py
1 #!/usr/bin/python
2
3 # Unix SMB/CIFS implementation. Tests for SamDB
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 from samba.auth import system_session
20 from samba.credentials import Credentials
21 import os
22 from samba.provision import setup_samdb, guess_names
23 from samba.samdb import SamDB
24 from samba.tests import cmdline_loadparm, TestCaseInTempDir
25 from samba import security
26 from unittest import TestCase
27 import uuid
28
29 class SamDBTestCase(TestCaseInTempDir):
30     def setUp(self):
31         super(SamDBTestCase, self).setUp()
32         invocationid = str(uuid.uuid4())
33         domaindn = "DC=COM,DC=EXAMPLE"
34         self.domaindn = domaindn
35         configdn = "CN=Configuration," + domaindn
36         schemadn = "CN=Schema," + configdn
37         domainguid = str(uuid.uuid4())
38         policyguid = str(uuid.uuid4())
39         setup_path = lambda x: os.path.join("setup", x)
40         creds = Credentials()
41         creds.set_anonymous()
42         domainsid = security.random_sid()
43         hostguid = str(uuid.uuid4())
44         path = os.path.join(self.tempdir, "samdb.ldb")
45         names = guess_names(lp=cmdline_loadparm, hostname="foo", 
46                             domain="EXAMPLE.COM", dnsdomain="example.com", 
47                             serverrole="domain controller", 
48                             domaindn=self.domaindn, configdn=configdn, 
49                             schemadn=schemadn)
50         self.samdb = setup_samdb(path, setup_path, system_session(), creds, 
51                                  cmdline_loadparm, names, 
52                                  lambda x: None, domainsid, 
53                                  "# no aci", domainguid, 
54                                  policyguid, False, "secret", 
55                                  "secret", "secret", invocationid, 
56                                  "secret", "domain controller")
57     def tearDown(self):
58         for f in ['templates.ldb', 'schema.ldb', 'configuration.ldb', 
59                   'users.ldb', 'samdb.ldb']:
60             os.remove(os.path.join(self.tempdir, f))
61         super(SamDBTestCase, self).tearDown()
62
63     def test_add_foreign(self):
64         self.samdb.add_foreign(self.domaindn, "S-1-5-7", "Somedescription")
65