Skip to content

Commit

Permalink
lib: azure_iot_hub: Fix invalid message ID
Browse files Browse the repository at this point in the history
Set valid nonzero message ID on response messages.

Signed-off-by: Jorgen Kvalvaag <[email protected]>
  • Loading branch information
jorgenmk committed Dec 11, 2024
1 parent 05b212b commit ffa08e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions subsys/net/lib/azure_iot_hub/src/azure_iot_hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ int azure_iot_hub_method_respond(struct azure_iot_hub_result *result)
}

struct mqtt_publish_param param = {
.message_id = mqtt_helper_msg_id_get(),
.message.payload.data = result->payload.ptr,
.message.payload.len = result->payload.size,
.message.topic.topic.utf8 = topic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,15 @@ void test_azure_iot_hub_method_respond(void)
iot_hub_state = STATE_CONNECTED;

__cmock_mqtt_helper_publish_Stub(mqtt_helper_publish_method_respond_stub);
__cmock_mqtt_helper_msg_id_get_ExpectAndReturn(1);

TEST_ASSERT_EQUAL(0, azure_iot_hub_method_respond(&result));
}

void test_azure_iot_hub_method_respond_not_connected(void)
{
struct azure_iot_hub_result result_dummy;
__cmock_mqtt_helper_msg_id_get_ExpectAndReturn(1);

TEST_ASSERT_EQUAL(-ENOTCONN, azure_iot_hub_method_respond(&result_dummy));
}
Expand All @@ -626,6 +628,7 @@ void test_azure_iot_hub_method_respond_too_long_request_id(void)
};

iot_hub_state = STATE_CONNECTED;
__cmock_mqtt_helper_msg_id_get_ExpectAndReturn(1);

TEST_ASSERT_EQUAL(-EFAULT, azure_iot_hub_method_respond(&result));
}
Expand All @@ -652,6 +655,7 @@ void test_azure_iot_hub_method_respond_mqtt_fail(void)
iot_hub_state = STATE_CONNECTED;

__cmock_mqtt_helper_publish_Stub(mqtt_helper_publish_fail_stub);
__cmock_mqtt_helper_msg_id_get_ExpectAndReturn(1);

TEST_ASSERT_EQUAL(-ENXIO, azure_iot_hub_method_respond(&result));
}
Expand Down

0 comments on commit ffa08e9

Please sign in to comment.