From fb956bb7398ed053d10753e530bad4fd37768149 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 18 Sep 2019 17:04:47 -0700 Subject: [PATCH] Porting PR #52933 to 2019.2.1 --- salt/beacons/inotify.py | 4 ++++ tests/unit/beacons/test_inotify.py | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/salt/beacons/inotify.py b/salt/beacons/inotify.py index da68b6ab5743..e3bfe4eb8947 100644 --- a/salt/beacons/inotify.py +++ b/salt/beacons/inotify.py @@ -117,6 +117,10 @@ def validate(config): if 'files' not in _config: return False, 'Configuration for inotify beacon must include files.' else: + if not isinstance(_config['files'], dict): + return False, ('Configuration for inotify beacon invalid, ' + 'files must be a dict.') + for path in _config.get('files'): if not isinstance(_config['files'][path], dict): diff --git a/tests/unit/beacons/test_inotify.py b/tests/unit/beacons/test_inotify.py index 5c0dc8c89868..41b6f8475764 100644 --- a/tests/unit/beacons/test_inotify.py +++ b/tests/unit/beacons/test_inotify.py @@ -39,10 +39,33 @@ def setUp(self): def tearDown(self): shutil.rmtree(self.tmpdir, ignore_errors=True) + def test_non_list_config(self): + config = {} + + ret = inotify.validate(config) + + self.assertEqual(ret, (False, 'Configuration for inotify beacon must' + ' be a list.')) + def test_empty_config(self): config = [{}] - ret = inotify.beacon(config) - self.assertEqual(ret, []) + ret = inotify.validate(config) + _expected = (False, 'Configuration for inotify beacon must include files.') + self.assertEqual(ret, _expected) + + def test_files_none_config(self): + config = [{'files': None}] + ret = inotify.validate(config) + _expected = (False, 'Configuration for inotify beacon invalid, ' + 'files must be a dict.') + self.assertEqual(ret, _expected) + + def test_files_list_config(self): + config = [{'files': [{u'/importantfile': {u'mask': [u'modify']}}]}] + ret = inotify.validate(config) + _expected = (False, 'Configuration for inotify beacon invalid, ' + 'files must be a dict.') + self.assertEqual(ret, _expected) def test_file_open(self): path = os.path.realpath(__file__)