2008-02-13 04:18:45 +03:00
# Unix SMB/CIFS implementation. Tests for SamDB
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
2010-11-28 06:02:28 +03:00
#
2008-02-13 04:18:45 +03:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
2010-11-28 06:02:28 +03:00
#
2008-02-13 04:18:45 +03:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2010-11-28 06:02:28 +03:00
#
2008-02-13 04:18:45 +03:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2010-12-05 18:56:27 +03:00
""" Tests for samba.samdb. """
2010-06-13 17:05:50 +04:00
import logging
2008-02-13 04:18:45 +03:00
import os
2010-06-14 04:15:32 +04:00
import uuid
from samba . auth import system_session
2010-11-28 06:02:28 +03:00
from samba . provision import ( setup_samdb , guess_names , make_smbconf ,
2011-02-05 02:34:51 +03:00
provision_paths_from_lp )
2010-06-25 15:26:06 +04:00
from samba . provision import DEFAULT_POLICY_GUID , DEFAULT_DC_POLICY_GUID
2010-11-28 06:02:28 +03:00
from samba . provision . backend import ProvisionBackend
2009-02-12 17:58:11 +03:00
from samba . tests import TestCaseInTempDir
2008-12-23 13:44:10 +03:00
from samba . dcerpc import security
2010-06-14 04:15:32 +04:00
from samba . schema import Schema
2008-05-30 16:15:40 +04:00
from samba import param
2008-02-13 04:18:45 +03:00
2009-02-12 18:00:11 +03:00
2008-02-13 04:18:45 +03:00
class SamDBTestCase ( TestCaseInTempDir ) :
2009-02-12 18:00:11 +03:00
""" Base-class for tests with a Sam Database.
2010-11-28 06:02:28 +03:00
2009-02-12 18:00:11 +03:00
This is used by the Samba SamDB - tests , but e . g . also by the OpenChange
provisioning tests ( which need a Sam ) .
"""
2009-02-11 19:54:58 +03:00
2008-02-13 04:18:45 +03:00
def setUp ( self ) :
super ( SamDBTestCase , self ) . setUp ( )
2008-05-11 06:36:37 +04:00
invocationid = str ( uuid . uuid4 ( ) )
2008-02-13 04:18:45 +03:00
domaindn = " DC=COM,DC=EXAMPLE "
self . domaindn = domaindn
configdn = " CN=Configuration, " + domaindn
schemadn = " CN=Schema, " + configdn
2008-05-11 06:36:37 +04:00
domainguid = str ( uuid . uuid4 ( ) )
2010-06-25 15:26:06 +04:00
policyguid = DEFAULT_POLICY_GUID
2008-02-13 04:18:45 +03:00
domainsid = security . random_sid ( )
path = os . path . join ( self . tempdir , " samdb.ldb " )
2008-05-29 19:38:12 +04:00
session_info = system_session ( )
2012-02-27 01:23:27 +04:00
2008-05-30 08:26:47 +04:00
hostname = " foo "
domain = " EXAMPLE "
2012-09-27 20:30:47 +04:00
dnsdomain = " example.com "
2008-05-30 08:26:47 +04:00
serverrole = " domain controller "
2010-06-25 15:26:06 +04:00
policyguid_dc = DEFAULT_DC_POLICY_GUID
2008-05-30 08:26:47 +04:00
smbconf = os . path . join ( self . tempdir , " smb.conf " )
2011-02-05 02:34:51 +03:00
make_smbconf ( smbconf , hostname , domain , dnsdomain ,
2012-02-27 01:23:27 +04:00
self . tempdir , serverrole = serverrole )
2008-05-30 08:26:47 +04:00
2009-02-11 20:17:00 +03:00
self . lp = param . LoadParm ( )
self . lp . load ( smbconf )
2008-05-30 08:26:47 +04:00
2012-09-27 20:30:47 +04:00
names = guess_names ( lp = self . lp , hostname = hostname ,
domain = domain , dnsdomain = dnsdomain ,
serverrole = serverrole ,
domaindn = self . domaindn , configdn = configdn ,
2008-05-29 19:31:16 +04:00
schemadn = schemadn )
2009-10-30 06:51:57 +03:00
paths = provision_paths_from_lp ( self . lp , names . dnsdomain )
2010-06-14 04:15:32 +04:00
logger = logging . getLogger ( " provision " )
provision_backend = ProvisionBackend ( " ldb " , paths = paths ,
2011-02-05 02:34:51 +03:00
lp = self . lp , credentials = None ,
2010-06-14 04:15:32 +04:00
names = names , logger = logger )
2011-02-05 02:34:51 +03:00
schema = Schema ( domainsid , invocationid = invocationid ,
2010-06-14 04:15:32 +04:00
schemadn = names . schemadn , serverdn = names . serverdn ,
am_rodc = False )
2011-02-05 02:34:51 +03:00
self . samdb = setup_samdb ( path , session_info ,
2010-06-14 04:15:32 +04:00
provision_backend , self . lp , names , logger ,
domainsid , domainguid , policyguid , policyguid_dc , False ,
" secret " , " secret " , " secret " , invocationid , " secret " ,
None , " domain controller " , schema = schema )
2008-05-30 08:26:47 +04:00
2008-05-29 19:31:16 +04:00
def tearDown ( self ) :
2009-09-26 20:37:56 +04:00
for f in [ ' schema.ldb ' , ' configuration.ldb ' ,
2008-05-30 08:26:47 +04:00
' users.ldb ' , ' samdb.ldb ' , ' smb.conf ' ] :
2008-05-29 19:31:16 +04:00
os . remove ( os . path . join ( self . tempdir , f ) )
super ( SamDBTestCase , self ) . tearDown ( )