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 samba.tests import TestCase
|
---|
25 |
|
---|
26 | from selftest.target.samba import (
|
---|
27 | bindir_path,
|
---|
28 | get_interface,
|
---|
29 | mk_realms_stanza,
|
---|
30 | write_krb5_conf,
|
---|
31 | )
|
---|
32 |
|
---|
33 |
|
---|
34 | class BinDirPathTests(TestCase):
|
---|
35 |
|
---|
36 | def test_mapping(self):
|
---|
37 | self.assertEquals("exe",
|
---|
38 | bindir_path("/some/path", "exe"))
|
---|
39 | self.assertEquals("/bin/exe",
|
---|
40 | bindir_path("/bin", "/bin/exe"))
|
---|
41 |
|
---|
42 | def test_no_mapping(self):
|
---|
43 | self.assertEqual("exe", bindir_path("/some/path", "exe"))
|
---|
44 | self.assertEqual("/bin/ls",
|
---|
45 | bindir_path("/bin", "ls"))
|
---|
46 |
|
---|
47 |
|
---|
48 | class MkRealmsStanzaTests(TestCase):
|
---|
49 |
|
---|
50 | def test_basic(self):
|
---|
51 | self.assertEqual(
|
---|
52 | mk_realms_stanza("rijk", "dnsnaam", "domein", "ipv4_kdc"),
|
---|
53 | '''\
|
---|
54 | rijk = {
|
---|
55 | kdc = ipv4_kdc:88
|
---|
56 | admin_server = ipv4_kdc:88
|
---|
57 | default_domain = dnsnaam
|
---|
58 | }
|
---|
59 | dnsnaam = {
|
---|
60 | kdc = ipv4_kdc:88
|
---|
61 | admin_server = ipv4_kdc:88
|
---|
62 | default_domain = dnsnaam
|
---|
63 | }
|
---|
64 | domein = {
|
---|
65 | kdc = ipv4_kdc:88
|
---|
66 | admin_server = ipv4_kdc:88
|
---|
67 | default_domain = dnsnaam
|
---|
68 | }
|
---|
69 |
|
---|
70 | ''')
|
---|
71 |
|
---|
72 |
|
---|
73 | class WriteKrb5ConfTests(TestCase):
|
---|
74 |
|
---|
75 | def test_simple(self):
|
---|
76 | f = StringIO()
|
---|
77 | write_krb5_conf(f, "rijk", "dnsnaam", "domein", "kdc_ipv4")
|
---|
78 | self.assertEquals('''\
|
---|
79 | #Generated krb5.conf for rijk
|
---|
80 |
|
---|
81 | [libdefaults]
|
---|
82 | \tdefault_realm = rijk
|
---|
83 | \tdns_lookup_realm = false
|
---|
84 | \tdns_lookup_kdc = false
|
---|
85 | \tticket_lifetime = 24h
|
---|
86 | \tforwardable = yes
|
---|
87 | \tallow_weak_crypto = yes
|
---|
88 |
|
---|
89 | [realms]
|
---|
90 | rijk = {
|
---|
91 | kdc = kdc_ipv4:88
|
---|
92 | admin_server = kdc_ipv4:88
|
---|
93 | default_domain = dnsnaam
|
---|
94 | }
|
---|
95 | dnsnaam = {
|
---|
96 | kdc = kdc_ipv4:88
|
---|
97 | admin_server = kdc_ipv4:88
|
---|
98 | default_domain = dnsnaam
|
---|
99 | }
|
---|
100 | domein = {
|
---|
101 | kdc = kdc_ipv4:88
|
---|
102 | admin_server = kdc_ipv4:88
|
---|
103 | default_domain = dnsnaam
|
---|
104 | }
|
---|
105 |
|
---|
106 | ''', f.getvalue())
|
---|
107 |
|
---|
108 |
|
---|
109 | class GetInterfaceTests(TestCase):
|
---|
110 |
|
---|
111 | def test_get_interface(self):
|
---|
112 | self.assertEquals(21, get_interface("localdc"))
|
---|
113 | self.assertEquals(4, get_interface("localshare4"))
|
---|
114 |
|
---|
115 | def test_unknown(self):
|
---|
116 | self.assertRaises(KeyError, get_interface, "unknown")
|
---|