Merge branch 'v4-0-test' of git://git.id10ts.net/samba into 4-0-local
[ira/wip.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 auth import system_session
20 from credentials import Credentials
21 import os
22 from samba.provision import setup_samdb
23 from samba.samdb import SamDB
24 from samba.tests import get_loadparm, TestCaseInTempDir
25 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 = uuid.random()
33         domaindn = "DC=COM,DC=EXAMPLE"
34         self.domaindn = domaindn
35         configdn = "CN=Configuration," + domaindn
36         schemadn = "CN=Schema," + configdn
37         domainguid = uuid.random()
38         policyguid = uuid.random()
39         setup_path = lambda x: os.path.join("setup", x)
40         creds = Credentials()
41         creds.set_anonymous()
42         domainsid = security.random_sid()
43         hostguid = uuid.random()
44         path = os.path.join(self.tempdir, "samdb.ldb")
45         self.samdb = setup_samdb(path, setup_path, system_session(), creds, 
46                                  get_loadparm(), schemadn, configdn, 
47                                  self.domaindn, "example.com", "EXAMPLE.COM", 
48                                  "FOO", lambda x: None, "foo", domaindn, 
49                                  False, domainsid, "# no aci", domainguid, 
50                                  policyguid, "EXAMPLE", True, "secret", 
51                                  "secret", "secret", hostguid, invocationid, 
52                                  "secret", "domain controller")
53
54     def test_add_foreign(self):
55         self.samdb.add_foreign(self.domaindn, "S-1-5-7", "Somedescription")
56