From 6d67418c415f65870adbd6d3ecfa4e48163f46e1 Mon Sep 17 00:00:00 2001 From: Mike Grima Date: Mon, 11 Mar 2019 13:25:36 -0700 Subject: [PATCH] Fixed validation bugs in put_configuration_recorder --- moto/config/models.py | 14 ++++++++------ tests/test_config/test_config.py | 6 +++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/moto/config/models.py b/moto/config/models.py index 5e43c6b12..cd6e07afa 100644 --- a/moto/config/models.py +++ b/moto/config/models.py @@ -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: diff --git a/tests/test_config/test_config.py b/tests/test_config/test_config.py index a61d2a29c..96c62455c 100644 --- a/tests/test_config/test_config.py +++ b/tests/test_config/test_config.py @@ -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: