Skip to content

Commit

Permalink
add test for too many written properties (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
danewalton authored Apr 17, 2021
1 parent 0b0bf0b commit a838872
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug Fixes

- [[#1640]](https://github.com/Azure/azure-sdk-for-c/pull/1640) Update precondition on `az_iot_provisioning_client_parse_received_topic_and_payload()` to require topic and payload minimum size of 1 instead of 0.
- [[#1699]](https://github.com/Azure/azure-sdk-for-c/pull/1699) Update precondition on `az_iot_message_properties_init()` to not allow `written_length` larger than the passed span.

## 1.1.0 (2021-03-09)

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/azure/iot/az_iot_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AZ_NODISCARD az_result az_iot_message_properties_init(
{
_az_PRECONDITION_NOT_NULL(properties);
_az_PRECONDITION_VALID_SPAN(buffer, 0, true);
_az_PRECONDITION(written_length >= 0);
_az_PRECONDITION_RANGE(0, written_length, az_span_size(buffer));

properties->_internal.properties_buffer = buffer;
properties->_internal.properties_written = written_length;
Expand Down
23 changes: 23 additions & 0 deletions sdk/tests/iot/common/test_az_iot_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ static void test_az_iot_message_properties_init_NULL_props_fails(void** state)
ASSERT_PRECONDITION_CHECKED(az_iot_message_properties_init(NULL, test_span, 0));
}

static void test_az_iot_message_properties_init_user_set_params_too_many_written_fail(void** state)
{
(void)state;

az_span test_span = az_span_create_from_str(TEST_KEY_VALUE_ONE);
az_iot_message_properties props;

ASSERT_PRECONDITION_CHECKED(
az_iot_message_properties_init(&props, test_span, az_span_size(test_span) + 1));
}

static void test_az_iot_message_properties_init_user_set_params_negative_written_fail(void** state)
{
(void)state;

az_span test_span = az_span_create_from_str(TEST_KEY_VALUE_ONE);
az_iot_message_properties props;

ASSERT_PRECONDITION_CHECKED(az_iot_message_properties_init(&props, test_span, -1));
}

static void test_az_iot_message_properties_append_get_NULL_props_fails(void** state)
{
(void)state;
Expand Down Expand Up @@ -757,6 +778,8 @@ int test_az_iot_common()
const struct CMUnitTest tests[] = {
#ifndef AZ_NO_PRECONDITION_CHECKING
cmocka_unit_test(test_az_iot_message_properties_init_NULL_props_fails),
cmocka_unit_test(test_az_iot_message_properties_init_user_set_params_too_many_written_fail),
cmocka_unit_test(test_az_iot_message_properties_init_user_set_params_negative_written_fail),
cmocka_unit_test(test_az_iot_message_properties_append_get_NULL_props_fails),
cmocka_unit_test(test_az_iot_message_properties_append_NULL_name_span_fails),
cmocka_unit_test(test_az_iot_message_properties_append_NULL_value_span_fails),
Expand Down

0 comments on commit a838872

Please sign in to comment.