Merge pull request #2103 from mikegrima/config

Fixed validation bugs in put_configuration_recorder
This commit is contained in:
Mike Grima 2019-03-11 13:58:54 -07:00 committed by GitHub
commit 53b94606de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -166,21 +166,23 @@ class ConfigBackend(BaseBackend):
recorder_status = self.recorders[config_recorder['name']].status
# Validate the Recording Group:
if not config_recorder.get('recordingGroup'):
if config_recorder.get('recordingGroup') is None:
recording_group = RecordingGroup()
else:
rg = config_recorder['recordingGroup']
# If an empty dict is passed in, then bad:
if not rg:
raise InvalidRecordingGroupException()
# Can't have both the resource types specified and the other flags as True.
if rg.get('resourceTypes') and (
rg.get('allSupported', True) or
rg.get('allSupported', False) or
rg.get('includeGlobalResourceTypes', False)):
raise InvalidRecordingGroupException()
# If an empty dict is provided, then bad:
if not rg.get('resourceTypes', False) \
and not rg.get('resourceTypes') \
and not rg.get('includeGlobalResourceTypes', False):
# Must supply resourceTypes if 'allSupported' is not supplied:
if not rg.get('allSupported') and not rg.get('resourceTypes'):
raise InvalidRecordingGroupException()
# Validate that the list provided is correct:

View File

@ -28,7 +28,11 @@ def test_put_configuration_recorder():
{'allSupported': True, 'includeGlobalResourceTypes': True, 'resourceTypes': ['item']},
{'allSupported': False, 'includeGlobalResourceTypes': True, 'resourceTypes': ['item']},
{'allSupported': True, 'includeGlobalResourceTypes': False, 'resourceTypes': ['item']},
{'allSupported': False, 'includeGlobalResourceTypes': False, 'resourceTypes': []}
{'allSupported': False, 'includeGlobalResourceTypes': False, 'resourceTypes': []},
{'includeGlobalResourceTypes': False, 'resourceTypes': []},
{'includeGlobalResourceTypes': True},
{'resourceTypes': []},
{}
]
for bg in bad_groups: