6fe1efefaff4acd1e6c61a3ea6dc79f301c2a4ec
[nivanova/samba-autobuild/.git] / selftest / tests / test_samba.py
1 # test_run.py -- Tests for selftest.target.samba
2 # Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; version 3
7 # of the License or (at your option) any later version of
8 # the License.
9 #
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.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # MA  02110-1301, USA.
19
20 """Tests for selftest.target.samba."""
21
22 from cStringIO import StringIO
23
24 from selftest.tests import TestCase
25
26 from selftest.target.samba import (
27     bindir_path,
28     mk_realms_stanza,
29     write_krb5_conf,
30     )
31
32
33 class BinDirPathTests(TestCase):
34
35     def test_mapping(self):
36         self.assertEquals("exe4",
37             bindir_path({"exe": "exe4"}, "/some/path", "exe"))
38         self.assertEquals("/bin/ls",
39             bindir_path({"exe": "ls"}, "/bin", "exe"))
40
41     def test_no_mapping(self):
42         self.assertEqual("exe", bindir_path({}, "/some/path", "exe"))
43         self.assertEqual("/bin/ls",
44             bindir_path({}, "/bin", "ls"))
45
46
47 class MkRealmsStanzaTests(TestCase):
48
49     def test_basic(self):
50         self.assertEqual(
51            mk_realms_stanza("rijk", "dnsnaam", "domein", "ipv4_kdc"),
52           '''\
53  rijk = {
54   kdc = ipv4_kdc:88
55   admin_server = ipv4_kdc:88
56   default_domain = dnsnaam
57  }
58  dnsnaam = {
59   kdc = ipv4_kdc:88
60   admin_server = ipv4_kdc:88
61   default_domain = dnsnaam
62  }
63  domein = {
64   kdc = ipv4_kdc:88
65   admin_server = ipv4_kdc:88
66   default_domain = dnsnaam
67  }
68
69 ''')
70
71
72 class WriteKrb5ConfTests(TestCase):
73
74     def test_simple(self):
75         f = StringIO()
76         write_krb5_conf(f, "rijk", "dnsnaam", "domein", "kdc_ipv4")
77         self.assertEquals('''\
78 #Generated krb5.conf for rijk
79
80 [libdefaults]
81 \tdefault_realm = rijk
82 \tdns_lookup_realm = false
83 \tdns_lookup_kdc = false
84 \tticket_lifetime = 24h
85 \tforwardable = yes
86 \tallow_weak_crypto = yes
87
88 [realms]
89  rijk = {
90   kdc = kdc_ipv4:88
91   admin_server = kdc_ipv4:88
92   default_domain = dnsnaam
93  }
94  dnsnaam = {
95   kdc = kdc_ipv4:88
96   admin_server = kdc_ipv4:88
97   default_domain = dnsnaam
98  }
99  domein = {
100   kdc = kdc_ipv4:88
101   admin_server = kdc_ipv4:88
102   default_domain = dnsnaam
103  }
104
105 ''', f.getvalue())