3 # Unix SMB/CIFS implementation. Tests for SamDB
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
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.
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.
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/>.
19 from samba.auth import system_session
20 from samba.credentials import Credentials
22 from samba.provision import setup_samdb, guess_names, setup_templatesdb
23 from samba.samdb import SamDB
24 from samba.tests import cmdline_loadparm, TestCaseInTempDir
25 from samba import security
26 from unittest import TestCase
29 class SamDBTestCase(TestCaseInTempDir):
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)
42 domainsid = security.random_sid()
43 hostguid = str(uuid.uuid4())
44 path = os.path.join(self.tempdir, "samdb.ldb")
45 session_info = system_session()
46 names = guess_names(lp=cmdline_loadparm, hostname="foo",
47 domain="EXAMPLE.COM", dnsdomain="example.com",
48 serverrole="domain controller",
49 domaindn=self.domaindn, configdn=configdn,
51 setup_templatesdb(os.path.join(self.tempdir, "templates.ldb"),
52 setup_path, session_info=session_info,
53 credentials=creds, lp=cmdline_loadparm)
54 self.samdb = setup_samdb(path, setup_path, session_info, creds,
55 cmdline_loadparm, names,
56 lambda x: None, domainsid,
57 "# no aci", domainguid,
58 policyguid, False, "secret",
59 "secret", "secret", invocationid,
60 "secret", "domain controller")
62 for f in ['templates.ldb', 'schema.ldb', 'configuration.ldb',
63 'users.ldb', 'samdb.ldb']:
64 os.remove(os.path.join(self.tempdir, f))
65 super(SamDBTestCase, self).tearDown()
67 def test_add_foreign(self):
68 self.samdb.add_foreign(self.domaindn, "S-1-5-7", "Somedescription")