Cancel transactions when exceptions are raised.
[Samba.git] / source4 / scripting / python / samba / tests / samdb.py
blob161f9f4f652bac47af97059edac8700a565088f0
1 #!/usr/bin/python
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.
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
21 import os
22 from samba.provision import setup_samdb, guess_names, setup_templatesdb, make_smbconf
23 from samba.samdb import SamDB
24 from samba.tests import cmdline_loadparm, TestCaseInTempDir
25 from samba.dcerpc import security
26 from unittest import TestCase
27 import uuid
28 from samba import param
30 class SamDBTestCase(TestCaseInTempDir):
32 def setUp(self):
33 super(SamDBTestCase, self).setUp()
34 invocationid = str(uuid.uuid4())
35 domaindn = "DC=COM,DC=EXAMPLE"
36 self.domaindn = domaindn
37 configdn = "CN=Configuration," + domaindn
38 schemadn = "CN=Schema," + configdn
39 domainguid = str(uuid.uuid4())
40 policyguid = str(uuid.uuid4())
41 setup_path = lambda x: os.path.join("setup", x)
42 creds = Credentials()
43 creds.set_anonymous()
44 domainsid = security.random_sid()
45 hostguid = str(uuid.uuid4())
46 path = os.path.join(self.tempdir, "samdb.ldb")
47 session_info = system_session()
49 hostname="foo"
50 domain="EXAMPLE"
51 dnsdomain="example.com"
52 serverrole="domain controller"
54 smbconf = os.path.join(self.tempdir, "smb.conf")
55 make_smbconf(smbconf, setup_path, hostname, domain, dnsdomain, serverrole,
56 self.tempdir)
58 lp = param.LoadParm()
59 lp.load(smbconf)
61 names = guess_names(lp=lp, hostname=hostname,
62 domain=domain, dnsdomain=dnsdomain,
63 serverrole=serverrole,
64 domaindn=self.domaindn, configdn=configdn,
65 schemadn=schemadn)
66 setup_templatesdb(os.path.join(self.tempdir, "templates.ldb"),
67 setup_path, session_info=session_info,
68 credentials=creds, lp=cmdline_loadparm)
69 self.samdb = setup_samdb(path, setup_path, session_info, creds,
70 cmdline_loadparm, names,
71 lambda x: None, domainsid,
72 "# no aci", domainguid,
73 policyguid, False, "secret",
74 "secret", "secret", invocationid,
75 "secret", "domain controller")
77 def tearDown(self):
78 for f in ['templates.ldb', 'schema.ldb', 'configuration.ldb',
79 'users.ldb', 'samdb.ldb', 'smb.conf']:
80 os.remove(os.path.join(self.tempdir, f))
81 super(SamDBTestCase, self).tearDown()
83 def test_add_foreign(self):
84 self.samdb.add_foreign(self.domaindn, "S-1-5-7", "Somedescription")