~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source4/scripting/python/samba/tests/samdb.py

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, setup_templatesdb, make_smbconf, find_setup_dir
 
23
from samba.samdb import SamDB
 
24
from samba.tests import TestCaseInTempDir
 
25
from samba.dcerpc import security
 
26
from unittest import TestCase
 
27
import uuid
 
28
from samba import param
 
29
 
 
30
 
 
31
class SamDBTestCase(TestCaseInTempDir):
 
32
    """Base-class for tests with a Sam Database.
 
33
    
 
34
    This is used by the Samba SamDB-tests, but e.g. also by the OpenChange
 
35
    provisioning tests (which need a Sam).
 
36
    """
 
37
 
 
38
    def setup_path(self, relpath):
 
39
        return os.path.join(find_setup_dir(), relpath)
 
40
 
 
41
    def setUp(self):
 
42
        super(SamDBTestCase, self).setUp()
 
43
        invocationid = str(uuid.uuid4())
 
44
        domaindn = "DC=COM,DC=EXAMPLE"
 
45
        self.domaindn = domaindn
 
46
        configdn = "CN=Configuration," + domaindn
 
47
        schemadn = "CN=Schema," + configdn
 
48
        domainguid = str(uuid.uuid4())
 
49
        policyguid = str(uuid.uuid4())
 
50
        creds = Credentials()
 
51
        creds.set_anonymous()
 
52
        domainsid = security.random_sid()
 
53
        hostguid = str(uuid.uuid4())
 
54
        path = os.path.join(self.tempdir, "samdb.ldb")
 
55
        session_info = system_session()
 
56
        
 
57
        hostname="foo"
 
58
        domain="EXAMPLE"
 
59
        dnsdomain="example.com" 
 
60
        serverrole="domain controller"
 
61
 
 
62
        smbconf = os.path.join(self.tempdir, "smb.conf")
 
63
        make_smbconf(smbconf, self.setup_path, hostname, domain, dnsdomain, 
 
64
                     serverrole, self.tempdir)
 
65
 
 
66
        self.lp = param.LoadParm()
 
67
        self.lp.load(smbconf)
 
68
 
 
69
        names = guess_names(lp=self.lp, hostname=hostname, 
 
70
                            domain=domain, dnsdomain=dnsdomain, 
 
71
                            serverrole=serverrole, 
 
72
                            domaindn=self.domaindn, configdn=configdn, 
 
73
                            schemadn=schemadn)
 
74
        setup_templatesdb(os.path.join(self.tempdir, "templates.ldb"), 
 
75
                          self.setup_path, session_info=session_info, 
 
76
                          credentials=creds, lp=self.lp)
 
77
        self.samdb = setup_samdb(path, self.setup_path, session_info, creds, 
 
78
                                 self.lp, names, 
 
79
                                 lambda x: None, domainsid, 
 
80
                                 "# no aci", domainguid, 
 
81
                                 policyguid, False, "secret", 
 
82
                                 "secret", "secret", invocationid, 
 
83
                                 "secret", "domain controller")
 
84
 
 
85
    def tearDown(self):
 
86
        for f in ['templates.ldb', 'schema.ldb', 'configuration.ldb', 
 
87
                  'users.ldb', 'samdb.ldb', 'smb.conf']:
 
88
            os.remove(os.path.join(self.tempdir, f))
 
89
        super(SamDBTestCase, self).tearDown()
 
90
 
 
91
 
 
92
class SamDBTests(SamDBTestCase):
 
93
    """Tests for the SamDB implementation."""
 
94
 
 
95
    def test_add_foreign(self):
 
96
        self.samdb.add_foreign(self.domaindn, "S-1-5-7", "Somedescription")
 
97