diff --git a/ccx_messaging/consumers/idp_kafka_consumer.py b/ccx_messaging/consumers/idp_kafka_consumer.py index 751d049..6fc0387 100644 --- a/ccx_messaging/consumers/idp_kafka_consumer.py +++ b/ccx_messaging/consumers/idp_kafka_consumer.py @@ -15,7 +15,7 @@ # to extract named groups for the different meaningful components S3_ARCHIVE_PATTERN = re.compile( r"(?P[0-9]+)\/" # extract named group for organization id - r"(?P[0-9,a-z,-]{36})\/" # extract named group for the cluster_id + r"(?P[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\/" # extract named group for the cluster_id # noqa: E501 r"(?P" # extract named group for the archive name, including the following 3 lines r"(?P" # extract the timestamp named group, including the following line # Next line extract year, month, day and time named groups from the timestamp diff --git a/test/consumers/idp_kafka_consumer_test.py b/test/consumers/idp_kafka_consumer_test.py index beae2d5..23d97cf 100644 --- a/test/consumers/idp_kafka_consumer_test.py +++ b/test/consumers/idp_kafka_consumer_test.py @@ -242,3 +242,35 @@ def test_create_broker_bad_path(): sut = IDPConsumer(None, None, None, incoming_topic=None) with pytest.raises(CCXMessagingError): sut.create_broker(input_msg) + + +@patch("ccx_messaging.consumers.kafka_consumer.ConfluentConsumer", lambda *a, **k: MagicMock()) +def test_create_broker_bad_cluster_id_format(): + """Test that `create_broker` generates a broker with the expected values.""" + path = ( + "00000000/aaaaaaaa-bbbb-xxxx-ffff-badbadbadbad/" + "66666666666666-77777777777777777777777777777777" + ) + input_msg = { + "path": path, + } + + sut = IDPConsumer(None, None, None, incoming_topic=None) + with pytest.raises(CCXMessagingError): + sut.create_broker(input_msg) + + +@patch("ccx_messaging.consumers.kafka_consumer.ConfluentConsumer", lambda *a, **k: MagicMock()) +def test_create_broker_bad_cluster_id_short(): + """Test that `create_broker` generates a broker with the expected values.""" + path = ( + "00000000/aa-bbbb-cc-ffff-badbadbadbad/" + "66666666666666-77777777777777777777777777777777" + ) + input_msg = { + "path": path, + } + + sut = IDPConsumer(None, None, None, incoming_topic=None) + with pytest.raises(CCXMessagingError): + sut.create_broker(input_msg)