diff options
author | David Mulder <dmulder@suse.com> | 2020-06-16 15:29:40 -0600 |
---|---|---|
committer | David Mulder <dmulder@samba.org> | 2020-06-23 16:32:30 +0000 |
commit | 97a8f999461f8ca9c24824734131700745310605 (patch) | |
tree | fefdff3bce0fa9e7ae31cf5c2ec7bbdaad3a2dda /python | |
parent | a9d1ccc5699a4e8c66012f769cec8fba6ce84a59 (diff) | |
download | samba-97a8f999461f8ca9c24824734131700745310605.tar.gz |
gpo: Test gpo scripts apply
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/tests/gpo.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/python/samba/tests/gpo.py b/python/samba/tests/gpo.py index dce00bd8f86..02ff6d97121 100644 --- a/python/samba/tests/gpo.py +++ b/python/samba/tests/gpo.py @@ -23,11 +23,14 @@ from samba.param import LoadParm from samba.gpclass import check_refresh_gpo_list, check_safe_path, \ check_guid, parse_gpext_conf, atomic_write_conf, get_deleted_gpos_list from subprocess import Popen, PIPE -from tempfile import NamedTemporaryFile +from tempfile import NamedTemporaryFile, TemporaryDirectory from samba.gp_sec_ext import gp_sec_ext +from samba.gp_scripts_ext import gp_scripts_ext import logging from samba.credentials import Credentials from samba.compat import get_bytes +from samba.dcerpc import preg +from samba.ndr import ndr_pack realm = os.environ.get('REALM') policies = realm + '/POLICIES' @@ -316,3 +319,46 @@ class GPOTests(tests.TestCase): for guid in guids: gpttmpl = gpofile % (local_path, guid) unstage_file(gpttmpl) + + def test_gp_daily_scripts(self): + local_path = self.lp.cache_path('gpo_cache') + guid = '{31B2F340-016D-11D2-945F-00C04FB984F9}' + reg_pol = os.path.join(local_path, policies, guid, + 'MACHINE/REGISTRY.POL') + logger = logging.getLogger('gpo_tests') + cache_dir = self.lp.get('cache directory') + store = GPOStorage(os.path.join(cache_dir, 'gpo.tdb')) + + machine_creds = Credentials() + machine_creds.guess(self.lp) + machine_creds.set_machine_account() + + # Initialize the group policy extension + ext = gp_scripts_ext(logger, self.lp, machine_creds, store) + + ads = gpo.ADS_STRUCT(self.server, self.lp, machine_creds) + if ads.connect(): + gpos = ads.get_gpo_list(machine_creds.get_username()) + + # Stage the Registry.pol file with test data + stage = preg.file() + e = preg.entry() + e.keyname = b'Software\\Policies\\Samba\\Unix Settings\\Daily Scripts' + e.valuename = b'Software\\Policies\\Samba\\Unix Settings' + e.type = 1 + e.data = b'echo hello world' + stage.num_entries = 1 + stage.entries = [e] + ret = stage_file(reg_pol, ndr_pack(stage)) + self.assertTrue(ret, 'Could not create the target %s' % reg_pol) + + # Process all gpos, with temp output directory + with TemporaryDirectory() as dname: + ext.process_group_policy([], gpos, dname) + scripts = os.listdir(dname) + self.assertEquals(len(scripts), 1, 'The daily script was not created') + out, _ = Popen([os.path.join(dname, scripts[0])], stdout=PIPE).communicate() + self.assertIn(b'hello world', out, 'Daily script execution failed') + + # Unstage the Registry.pol file + unstage_file(reg_pol) |