1 # Unix SMB/CIFS implementation. Tests for smb manipulation
2 # Copyright (C) David Mulder <dmulder@suse.com> 2018
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 from samba import gpo, tests
19 from samba.param import LoadParm
21 poldir = r'\\addom.samba.example.com\sysvol\addom.samba.example.com\Policies'
22 dspath = 'CN=Policies,CN=System,DC=addom,DC=samba,DC=example,DC=com'
23 gpt_data = '[General]\nVersion=%d'
25 class GPOTests(tests.TestCase):
27 super(GPOTests, self).setUp()
28 self.server = os.environ["SERVER"]
30 self.lp.load_default()
31 self.creds = self.insta_creds(template=self.get_credentials())
34 super(GPOTests, self).tearDown()
36 def test_gpo_list(self):
38 ads = gpo.ADS_STRUCT(self.server, self.lp, self.creds)
40 gpos = ads.get_gpo_list(self.creds.get_username())
41 guid = '{31B2F340-016D-11D2-945F-00C04FB984F9}'
42 names = ['Local Policy', guid]
43 file_sys_paths = [None, '%s\\%s' % (poldir, guid)]
44 ds_paths = [None, 'CN=%s,%s' % (guid, dspath)]
45 for i in range(0, len(gpos)):
46 assert gpos[i].name == names[i], \
47 'The gpo name did not match expected name %s' % gpos[i].name
48 assert gpos[i].file_sys_path == file_sys_paths[i], \
49 'file_sys_path did not match expected %s' % gpos[i].file_sys_path
50 assert gpos[i].ds_path == ds_paths[i], \
51 'ds_path did not match expected %s' % gpos[i].ds_path
53 def test_gpt_version(self):
55 local_path = self.lp.get("path", "sysvol")
56 policies = 'addom.samba.example.com/Policies'
57 guid = '{31B2F340-016D-11D2-945F-00C04FB984F9}'
58 gpo_path = os.path.join(local_path, policies, guid)
59 old_vers = gpo.gpo_get_sysvol_gpt_version(gpo_path)[1]
61 with open(os.path.join(gpo_path, 'GPT.INI'), 'w') as gpt:
62 gpt.write(gpt_data % 42)
63 assert gpo.gpo_get_sysvol_gpt_version(gpo_path)[1] == 42, \
64 'gpo_get_sysvol_gpt_version() did not return the expected version'
66 with open(os.path.join(gpo_path, 'GPT.INI'), 'w') as gpt:
67 gpt.write(gpt_data % old_vers)
68 assert gpo.gpo_get_sysvol_gpt_version(gpo_path)[1] == old_vers, \
69 'gpo_get_sysvol_gpt_version() did not return the expected version'