1 # Unix SMB/CIFS implementation. Tests for samba.kcc core.
2 # Copyright (C) Andrew Bartlett 2015
4 # Written by Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
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/>.
20 """Tests for samba.kcc"""
25 from tempfile import mkdtemp
30 from samba.dcerpc import misc
33 from samba.param import LoadParm
34 from samba.credentials import Credentials
35 from samba.samdb import SamDB
37 unix_now = int(time.time())
38 unix_once_upon_a_time = 1000000000 # 2001-09-09
41 'ad_dc_ntvfs': ['CN=LOCALDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com'],
42 'fl2000dc': ['CN=DC5,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba2000,DC=example,DC=com'],
43 'fl2003dc': ['CN=DC6,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba2003,DC=example,DC=com'],
44 'fl2008r2dc': ['CN=DC7,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba2008r2,DC=example,DC=com'],
45 'promoted_dc': ['CN=PROMOTEDVDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com',
46 'CN=LOCALDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com'],
47 'vampire_dc': ['CN=LOCALDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com',
48 'CN=LOCALVAMPIREDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com'],
51 class KCCTests(samba.tests.TestCase):
53 super(KCCTests, self).setUp()
55 self.creds = Credentials()
56 self.creds.guess(self.lp)
57 self.creds.set_username(os.environ["USERNAME"])
58 self.creds.set_password(os.environ["PASSWORD"])
61 def test_list_dsas(self):
62 my_kcc = kcc.KCC(unix_now, False, False, False, False)
63 my_kcc.load_samdb("ldap://%s" % os.environ["SERVER"],
65 dsas = my_kcc.list_dsas()
66 env = os.environ['TEST_ENV']
67 for expected_dsa in ENV_DSAS[env]:
68 self.assertIn(expected_dsa, dsas)
70 def test_verify(self):
71 """check that the KCC generates graphs that pass its own verify
72 option. This is not a spectacular achievement when there are
73 only a couple of nodes to connect, but it shows something.
75 my_kcc = kcc.KCC(unix_now, readonly=True, verify=True,
76 debug=False, dot_file_dir=None)
78 my_kcc.run("ldap://%s" % os.environ["SERVER"],
80 attempt_live_connections=False)