s3:ntlm_auth: make logs more consistent with length check
[Samba.git] / python / samba / tests / param.py
blob7c45d91c1e6a36e9f567c899bcee0736d27eae98
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.param."""
20 from samba import param
21 import samba.tests
22 import os
25 class LoadParmTestCase(samba.tests.TestCaseInTempDir):
27 def setUp(self):
28 super().setUp()
29 self.tempf = os.path.join(self.tempdir, "test")
30 open(self.tempf, 'w').write("empty")
32 def tearDown(self):
33 os.unlink(self.tempf)
34 super().tearDown()
36 def test_init(self):
37 file = param.LoadParm()
38 self.assertTrue(file is not None)
40 def test_length(self):
41 file = param.LoadParm()
42 self.assertEqual(0, len(file))
44 def test_set_workgroup(self):
45 file = param.LoadParm()
46 file.set("workgroup", "bla")
47 self.assertEqual("BLA", file.get("workgroup"))
49 def test_is_mydomain(self):
50 file = param.LoadParm()
51 file.set("workgroup", "bla")
52 self.assertTrue(file.is_mydomain("BLA"))
53 self.assertFalse(file.is_mydomain("FOOBAR"))
55 def test_is_myname(self):
56 file = param.LoadParm()
57 file.set("netbios name", "bla")
58 self.assertTrue(file.is_myname("BLA"))
59 self.assertFalse(file.is_myname("FOOBAR"))
61 def test_load_default(self):
62 file = param.LoadParm()
63 file.load_default()
65 def test_section_nonexistent(self):
66 samba_lp = param.LoadParm()
67 samba_lp.load_default()
68 self.assertRaises(KeyError, samba_lp.__getitem__, "nonexistent")
70 def test_log_level(self):
71 samba_lp = param.LoadParm()
72 samba_lp.set("log level", "5 auth:4")
73 self.assertEqual(5, samba_lp.log_level())
75 def test_dump(self):
76 samba_lp = param.LoadParm()
77 # Just test successful method execution (outputs to stdout)
78 self.assertEqual(None, samba_lp.dump())
80 def test_dump_to_file(self):
81 samba_lp = param.LoadParm()
82 self.assertEqual(None, samba_lp.dump(False, self.tempf))
83 content = open(self.tempf, 'r').read()
84 self.assertIn('[global]', content)
85 self.assertIn('interfaces', content)
87 def test_dump_a_parameter(self):
88 samba_lp = param.LoadParm()
89 samba_lp.load_default()
90 # Just test successful method execution
91 self.assertEqual(None, samba_lp.dump_a_parameter('interfaces'))
93 def test_dump_a_parameter_to_file(self):
94 samba_lp = param.LoadParm()
95 samba_lp.load_default()
96 self.assertEqual(None,
97 samba_lp.dump_a_parameter('interfaces',
98 'global',
99 self.tempf))
100 content = open(self.tempf, 'r').read()
101 self.assertIn('10.53.57.', content)
103 def test_samdb_url(self):
104 samba_lp = param.LoadParm()
105 samdb_url = samba_lp.samdb_url()
106 self.assertTrue(samdb_url.startswith('tdb://'))
107 self.assertTrue(samdb_url.endswith('/sam.ldb'))