diff --git a/CODEOWNERS b/CODEOWNERS index a17f9cc..fd28d26 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -9,4 +9,4 @@ # AZURE FUNCTIONS TEAM # For all file changes, github would automatically # include the following people in the PRs. -* @vrdmr @gavin-aguiar @hallvictoria @EvanR-Dev +* @vrdmr @gavin-aguiar @hallvictoria diff --git a/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py b/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py index c240e6a..8dc8fba 100644 --- a/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py +++ b/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py @@ -8,6 +8,7 @@ _X_OPT_LOCK_TOKEN = b"x-opt-lock-token" +LOCK_TOKEN_LENGTH = 16 # AMQP format codes (subset) FMT_NULL = 0x40 @@ -30,17 +31,17 @@ def get_lock_token(message: bytes, index: int) -> str: # Convert the lock token to a UUID using the first 16 bytes # Use little-endian to match SDK - lock_token_uuid = uuid.UUID(bytes_le=lock_token_encoded[:16]) + lock_token_uuid = uuid.UUID(bytes_le=lock_token_encoded[:LOCK_TOKEN_LENGTH]) return lock_token_uuid -def get_amqp_message(message: bytes, index: int): +def get_amqp_message(message: bytes): """ Get the amqp message from the model_binding_data content and create the message. """ - amqp_message = message[index + len(_X_OPT_LOCK_TOKEN):] + amqp_message = message[LOCK_TOKEN_LENGTH:] decoded_message = uamqp.Message().decode_from_bytes(amqp_message) return decoded_message @@ -62,7 +63,7 @@ def get_decoded_message(content: bytes): lock_token = get_lock_token(content, index) delivery_anno_dict = {_X_OPT_LOCK_TOKEN: lock_token} - decoded_message = get_amqp_message(content, index) + decoded_message = get_amqp_message(content) decoded_message.delivery_annotations = delivery_anno_dict return decoded_message except Exception as e: diff --git a/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py b/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py index 51eb114..dee131c 100644 --- a/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py +++ b/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py @@ -149,3 +149,30 @@ def test_input_get_decoded_message_ex(self): _ = get_decoded_message("Invalid message") self.assertIn("Failed to decode ServiceBus content", e.exception.args[0]) + + def test_populated_properties(self): + sample_mbd = MockMBD( + version="1.0", + source="AzureServiceBusReceivedMessage", + content_type="application/octet-stream", + content=SERVICEBUS_SAMPLE_CONTENT + ) + + datum: Datum = Datum(value=sample_mbd, type="model_binding_data") + result: ServiceBusReceivedMessage = ServiceBusConverter.decode( + data=datum, trigger_metadata=None, pytype=ServiceBusReceivedMessage + ) + + self.assertIsNotNone(result) + self.assertIsInstance(result, ServiceBusSDK) + + self.assertIsNotNone(result.body) + self.assertIsNotNone(result.delivery_count) + self.assertIsNotNone(result.enqueued_time_utc) + self.assertIsNotNone(result.expires_at_utc) + self.assertIsNotNone(result.lock_token) + self.assertIsNotNone(result.locked_until_utc) + self.assertIsNotNone(result.message_id) + self.assertIsNotNone(result.sequence_number) + self.assertIsNotNone(result.state) + self.assertIsNotNone(result.time_to_live)