b251802280569f821926147912310a3568ed6fc5
[nivanova/samba-autobuild/.git] / python / samba / tests / kcc / __init__.py
1 # Unix SMB/CIFS implementation. Tests for samba.kcc core.
2 # Copyright (C) Andrew Bartlett 2015
3 #
4 # Written by Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
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
20 """Tests for samba.kcc"""
21
22 import samba
23 import os
24 import time
25 from tempfile import mkdtemp
26
27 import samba.tests
28 from samba import kcc
29 from samba import ldb
30 from samba.dcerpc import misc
31
32
33 from samba.param import LoadParm
34 from samba.credentials import Credentials
35 from samba.samdb import SamDB
36
37 unix_now = int(time.time())
38 unix_once_upon_a_time = 1000000000  # 2001-09-09
39
40 ENV_DSAS = {
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'],
49 }
50
51 class KCCTests(samba.tests.TestCase):
52     def setUp(self):
53         super(KCCTests, self).setUp()
54         self.lp = LoadParm()
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"])
59
60
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"],
64                           self.lp, self.creds)
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)
69
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.
74         """
75         my_kcc = kcc.KCC(unix_now, readonly=True, verify=True,
76                          debug=False, dot_file_dir=None)
77
78         my_kcc.run("ldap://%s" % os.environ["SERVER"],
79                    self.lp, self.creds,
80                    attempt_live_connections=False)