Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for too many written properties #1699

Merged
merged 5 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
danewalton marked this conversation as resolved.
Show resolved Hide resolved
danewalton marked this conversation as resolved.
Show resolved Hide resolved
_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));
danewalton marked this conversation as resolved.
Show resolved Hide resolved
}

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