docs-xml: "cluster addresses" dns registration
[Samba.git] / python / samba / tests / dckeytab.py
blobcdb8c5151e7327ebbf590275c646edd0a4d9fa53
1 # Tests for source4/libnet/py_net_dckeytab.c
3 # Copyright (C) David Mulder <dmulder@suse.com> 2018
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import os
20 import sys
21 import string
22 from samba.net import Net
23 import samba.dckeytab
24 from samba import tests
25 from samba.param import LoadParm
28 def open_bytes(filename):
29 if sys.version_info[0] == 3:
30 return open(filename, errors='ignore')
31 else:
32 return open(filename, 'rb')
35 class DCKeytabTests(tests.TestCase):
36 def setUp(self):
37 super(DCKeytabTests, self).setUp()
38 self.lp = LoadParm()
39 self.lp.load_default()
40 self.creds = self.insta_creds(template=self.get_credentials())
41 self.ktfile = os.path.join(self.lp.get('private dir'), 'test.keytab')
42 self.principal = self.creds.get_principal()
44 def tearDown(self):
45 super(DCKeytabTests, self).tearDown()
46 os.remove(self.ktfile)
48 def test_export_keytab(self):
49 net = Net(None, self.lp)
50 net.export_keytab(keytab=self.ktfile, principal=self.principal)
51 assert os.path.exists(self.ktfile), 'keytab was not created'
52 with open_bytes(self.ktfile) as bytes_kt:
53 result = ''
54 for c in bytes_kt.read():
55 if c in string.printable:
56 result += c
57 principal_parts = self.principal.split('@')
58 assert principal_parts[0] in result and \
59 principal_parts[1] in result, \
60 'Principal not found in generated keytab'