1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
3 # Copyright (C) John Mulligan <phlogistonjohn@asynchrono.us> 2022
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/>.
20 Tests for samba.smbconf module
23 from samba
.samba3
import param
as s3param
27 class SMBConfTests(samba
.tests
.TestCase
):
33 """Property to access module under test without
34 importing it at test module load-time.
36 if self
._smbconf
is not None:
41 self
._smbconf
= samba
.smbconf
46 if self
._s
3smbconf
is not None:
47 return self
._s
3smbconf
49 import samba
.samba3
.smbconf
51 self
._s
3smbconf
= samba
.samba3
.smbconf
52 return self
._s
3smbconf
55 def example_conf_default(self
):
56 return "./testdata/samba3/smb.conf"
60 # fetch the configuration in the same style as other test suites
61 self
.lp_ctx
= samba
.tests
.env_loadparm()
62 # apply the configuration to the samba3 configuration
63 # (because there are two... and they're independent!)
64 # this is needed to make use of the registry
65 s3_lp
= s3param
.get_context()
66 s3_lp
.load(self
.lp_ctx
.configfile
)
68 def test_uninitalized_smbconf(self
):
69 sconf
= self
.smbconf
.SMBConf()
70 self
.assertRaises(RuntimeError, sconf
.requires_messaging
)
71 self
.assertRaises(RuntimeError, sconf
.is_writeable
)
72 self
.assertRaises(RuntimeError, sconf
.share_names
)
73 self
.assertRaises(RuntimeError, sconf
.get_share
, "foo")
75 def test_txt_backend_properties(self
):
76 sconf
= self
.smbconf
.init_txt(self
.example_conf_default
)
77 self
.assertFalse(sconf
.requires_messaging())
78 self
.assertFalse(sconf
.is_writeable())
80 def test_share_names(self
):
81 sconf
= self
.smbconf
.init_txt(self
.example_conf_default
)
82 names
= sconf
.share_names()
83 self
.assertEqual(names
, ["global", "cd1", "cd2", "media", "tmp"])
85 def test_get_share_cd1(self
):
86 sconf
= self
.smbconf
.init_txt(self
.example_conf_default
)
87 s1
= sconf
.get_share("cd1")
88 self
.assertEqual(s1
, ("cd1", [("path", "/mnt/cd1"), ("public", "yes")]))
90 def test_get_share_cd2(self
):
91 sconf
= self
.smbconf
.init_txt(self
.example_conf_default
)
92 s1
= sconf
.get_share("cd2")
93 self
.assertEqual(s1
, ("cd2", [("path", "/mnt/cd2"), ("public", "yes")]))
95 def test_get_config(self
):
96 sconf
= self
.smbconf
.init_txt(self
.example_conf_default
)
97 services
= sconf
.get_config()
98 self
.assertEqual(len(services
), 5)
104 ("workgroup", "SAMBA"),
105 ("security", "user"),
108 "smbpasswd:../testdata/samba3/smbpasswd "
109 "tdbsam:../testdata/samba3/passdb.tdb ldapsam:tdb://samba3.ldb",
111 ("debug level", "5"),
112 ("netbios name", "BEDWYR"),
117 services
[1], ("cd1", [("path", "/mnt/cd1"), ("public", "yes")])
120 def test_init_reg(self
):
121 sconf
= self
.s3smbconf
.init_reg(None)
122 self
.assertTrue(sconf
.is_writeable())
124 def test_init_str_reg(self
):
125 sconf
= self
.s3smbconf
.init("registry:")
126 self
.assertTrue(sconf
.is_writeable())
128 def test_init_str_file(self
):
129 sconf
= self
.s3smbconf
.init(f
"file:{self.example_conf_default}")
130 self
.assertFalse(sconf
.is_writeable())
132 def test_create_share(self
):
133 sconf
= self
.s3smbconf
.init_reg(None)
135 sconf
.create_share("alice")
136 sconf
.create_share("bob")
137 names
= sconf
.share_names()
138 self
.assertEqual(names
, ["alice", "bob"])
140 self
.smbconf
.SMBConfError
, sconf
.create_share
, "alice"
143 def test_create_share(self
):
144 sconf
= self
.s3smbconf
.init_reg(None)
146 sconf
.create_share("alice")
148 names
= sconf
.share_names()
149 self
.assertEqual(names
, [])
151 def test_set_parameter(self
):
152 sconf
= self
.s3smbconf
.init_reg(None)
154 sconf
.create_share("foobar")
155 sconf
.set_parameter("foobar", "path", "/mnt/foobar")
156 sconf
.set_parameter("foobar", "browseable", "no")
158 s1
= sconf
.get_share("foobar")
160 s1
, ("foobar", [("path", "/mnt/foobar"), ("browseable", "no")])
164 if __name__
== "__main__":