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
from samba . auth import system_session
2017-12-06 04:31:54 +03:00
from samba . provision import provision
2009-02-12 17:58:11 +03:00
from samba . tests import TestCaseInTempDir
2017-12-06 04:31:54 +03:00
from samba . dsdb import DS_DOMAIN_FUNCTION_2008_R2
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 ) :
2023-11-28 06:38:22 +03:00
super ( ) . setUp ( )
2017-12-06 04:31:54 +03:00
self . session = system_session ( )
logger = logging . getLogger ( " selftest " )
2020-11-10 03:46:28 +03:00
self . domain = " dsdb "
self . realm = " dsdb.samba.example.com "
2017-12-06 04:31:54 +03:00
host_name = " test "
server_role = " active directory domain controller "
self . result = provision ( logger ,
self . session , targetdir = self . tempdir ,
2020-11-10 03:46:28 +03:00
realm = self . realm , domain = self . domain ,
2017-12-06 04:31:54 +03:00
hostname = host_name ,
use_ntvfs = True ,
serverrole = server_role ,
dns_backend = " SAMBA_INTERNAL " ,
dom_for_fun_level = DS_DOMAIN_FUNCTION_2008_R2 )
self . samdb = self . result . samdb
self . lp = self . result . lp
2008-05-30 08:26:47 +04:00
2008-05-29 19:31:16 +04:00
def tearDown ( self ) :
2022-06-15 04:22:24 +03:00
self . rm_files ( ' names.tdb ' )
self . rm_dirs ( ' etc ' , ' msg.lock ' , ' private ' , ' state ' , ' bind-dns ' )
2017-12-06 04:31:54 +03:00
2023-11-28 06:38:22 +03:00
super ( ) . tearDown ( )
2020-11-10 03:46:28 +03:00
class SamDBTests ( SamDBTestCase ) :
def test_get_domain ( self ) :
self . assertEqual ( self . samdb . domain_dns_name ( ) , self . realm . lower ( ) )
self . assertEqual ( self . samdb . domain_netbios_name ( ) , self . domain . upper ( ) )