From 3353677c72067f2b8ec5b00f53f0053263ebc0ad Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sat, 6 Nov 2021 12:21:40 -0100 Subject: [PATCH] Events - match full list against pattern (#4534) --- moto/events/models.py | 3 ++- tests/test_events/test_event_pattern.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/moto/events/models.py b/moto/events/models.py index f749e0758..ce219238b 100644 --- a/moto/events/models.py +++ b/moto/events/models.py @@ -838,12 +838,13 @@ class EventPattern: def _does_item_match_filters(self, item, filters): allowed_values = [value for value in filters if isinstance(value, str)] allowed_values_match = item in allowed_values if allowed_values else True + full_match = isinstance(item, list) and item == allowed_values named_filter_matches = [ self._does_item_match_named_filter(item, pattern) for pattern in filters if isinstance(pattern, dict) ] - return allowed_values_match and all(named_filter_matches) + return (full_match or allowed_values_match) and all(named_filter_matches) @staticmethod def _does_item_match_named_filter(item, pattern): diff --git a/tests/test_events/test_event_pattern.py b/tests/test_events/test_event_pattern.py index ceb303351..bb384de54 100644 --- a/tests/test_events/test_event_pattern.py +++ b/tests/test_events/test_event_pattern.py @@ -16,6 +16,8 @@ def test_event_pattern_with_nested_event_filter(): pattern = EventPattern.load(json.dumps({"detail": {"foo": ["bar"]}})) assert pattern.matches_event({"detail": {"foo": "bar"}}) assert not pattern.matches_event({"detail": {"foo": "baz"}}) + # The full list should match as well + assert pattern.matches_event({"detail": {"foo": ["bar"]}}) def test_event_pattern_with_exists_event_filter():