Skip to content

Commit

Permalink
add extra check
Browse files Browse the repository at this point in the history
  • Loading branch information
danewalton committed Sep 13, 2022
1 parent 6cd298b commit 87c3028
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions sdk/tests/iot/adu/test_az_iot_adu.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,52 @@ static uint8_t adu_request_payload_with_null_file_url_value[]
"\"f2f4a804ca17afbae\":\"http://contoso-adu-instance--contoso-adu.b.nlu.dl.adu.microsoft.com/"
"westus2/contoso-adu-instance--contoso-adu/67c8d2ef5148403391bed74f51a28597/"
"iot-middleware-sample-adu-v1.1\",\"f06bfc80808396ed5\":null}}}";
static uint8_t adu_request_payload_multiple_file_url_value[]
= "{\"service\":{\"workflow\":{\"action\":3,\"id\":\"51552a54-765e-419f-892a-c822549b6f38\"},"
"\"updateManifest\":\"{\\\"manifestVersion\\\":\\\"4\\\",\\\"updateId\\\":{\\\"provider\\\":"
"\\\"Contoso\\\",\\\"name\\\":\\\"Foobar\\\",\\\"version\\\":\\\"1.1\\\"},"
"\\\"compatibility\\\":[{\\\"deviceManufacturer\\\":\\\"Contoso\\\",\\\"deviceModel\\\":"
"\\\"Foobar\\\"}],\\\"instructions\\\":{\\\"steps\\\":[{\\\"handler\\\":\\\"microsoft/"
"swupdate:1\\\",\\\"files\\\":[\\\"f2f4a804ca17afbae\\\"],\\\"handlerProperties\\\":{"
"\\\"installedCriteria\\\":\\\"1.0\\\"}}]},\\\"files\\\":{\\\"f2f4a804ca17afbae\\\":{"
"\\\"fileName\\\":\\\"iot-middleware-sample-adu-v1.1\\\",\\\"sizeInBytes\\\":844976,"
"\\\"hashes\\\":{\\\"sha256\\\":\\\"xsoCnYAMkZZ7m9RL9Vyg9jKfFehCNxyuPFaJVM/"
"WBi0=\\\"}}},\\\"createdDateTime\\\":\\\"2022-07-07T03:02:48.8449038Z\\\"}\","
"\"updateManifestSignature\":"
"\"eyJhbGciOiJSUzI1NiIsInNqd2siOiJle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wm-"
"G9RYHjZcoSgmQ58vWyaC2l8K8ZqnlQWmuLur0CZFQlanUVxDocJUtu1MnB2ER6emMRD_"
"4Azup2K4apq9E1EfYBbXxOZ0N5jaSr-2xg8NVSow5NqNSaYYY43wy_NIUefRlbSYu5zOrSWtuIwRdsO-"
"43Eo8b9vuJj1Qty9ee6xz1gdUNHnUdnM6dHEplZK0GZznsxRviFXt7yv8bVLd32Z7QDtFh3s17xlKulBZxWP-"
"q96r92RoUTov2M3ynPZSDmc6Mz7-r8ioO5VHO5pAPCH-tF5zsqzipPJKmBMaf5gYk8wR\",\"fileUrls\":{"
"\"f2f4a804ca17afbae\":\"http://contoso-adu-instance--contoso-adu.b.nlu.dl.adu.microsoft.com/"
"westus2/contoso-adu-instance--contoso-adu/67c8d2ef5148403391bed74f51a28597/"
"iot-middleware-sample-adu-v1.1\",\"f06bfc80808396ed5\":null,"
"\"f9fec76f10aede60e\":\"http://contoso-adu-instance--contoso-adu.b.nlu.dl.adu.microsoft.com/"
"westus2/contoso-adu-instance--contoso-adu/9f9bdc01a5cd49c09e79e35505a913c5/"
"contoso-v1.1.bin\"}}}";
static uint8_t adu_request_payload_reverse_order[]
= "{\"service\":{\"updateManifest\":\"{\\\"manifestVersion\\\":\\\"4\\\",\\\"updateId\\\":{"
"\\\"provider\\\":\\\"Contoso\\\",\\\"name\\\":\\\"Foobar\\\",\\\"version\\\":\\\"1.1\\\"},"
Expand Down Expand Up @@ -226,6 +272,7 @@ static uint8_t instructions_steps_file[] = "f2f4a804ca17afbae";
static uint8_t instructions_steps_handler_properties_install_criteria[] = "1.0";
static uint8_t files_id[] = "f2f4a804ca17afbae";
static uint8_t files_filename[] = "iot-middleware-sample-adu-v1.1";
static uint8_t files_id_contoso[] = "f9fec76f10aede60e";
static uint32_t files_size_in_bytes = 844976;
static uint8_t files_hash_id[] = "sha256";
static uint8_t files_hashes_sha[] = "xsoCnYAMkZZ7m9RL9Vyg9jKfFehCNxyuPFaJVM/WBi0=";
Expand Down Expand Up @@ -262,6 +309,10 @@ static uint8_t valid_signature[]
static uint8_t file_url[] = "http://contoso-adu-instance--contoso-adu.b.nlu.dl.adu.microsoft.com/"
"westus2/contoso-adu-instance--contoso-adu/"
"67c8d2ef5148403391bed74f51a28597/iot-middleware-sample-adu-v1.1";
static uint8_t file_url_contoso[]
= "http://contoso-adu-instance--contoso-adu.b.nlu.dl.adu.microsoft.com/"
"westus2/contoso-adu-instance--contoso-adu/9f9bdc01a5cd49c09e79e35505a913c5/"
"contoso-v1.1.bin";

#ifndef AZ_NO_PRECONDITION_CHECKING
ENABLE_PRECONDITION_CHECK_TESTS()
Expand Down Expand Up @@ -668,6 +719,68 @@ static void test_az_iot_adu_client_parse_service_properties_with_null_file_url_v
assert_int_equal(request.file_urls_count, 1);
}

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

az_iot_adu_client adu_client;
az_json_reader reader;
az_iot_adu_client_update_request request;
az_span remainder;

assert_int_equal(az_iot_adu_client_init(&adu_client, NULL), AZ_OK);

assert_int_equal(
az_json_reader_init(
&reader,
az_span_create(
adu_request_payload_multiple_file_url_value,
sizeof(adu_request_payload_multiple_file_url_value) - 1),
NULL),
AZ_OK);

// parse_service_properties requires that the reader be placed on the "service" prop name
assert_int_equal(az_json_reader_next_token(&reader), AZ_OK);
assert_int_equal(az_json_reader_next_token(&reader), AZ_OK);

assert_int_equal(
az_iot_adu_client_parse_service_properties(
&adu_client,
&reader,
az_span_create(scratch_buffer, sizeof(scratch_buffer)),
&request,
&remainder),
AZ_OK);

// Workflow
assert_int_equal(request.workflow.action, workflow_action);
assert_memory_equal(az_span_ptr(request.workflow.id), workflow_id, sizeof(workflow_id) - 1);

// Update Manifest
assert_memory_equal(
az_span_ptr(request.update_manifest), adu_request_manifest, sizeof(adu_request_manifest) - 1);
assert_int_equal(az_span_size(request.update_manifest), sizeof(adu_request_manifest) - 1);

// Signature
assert_memory_equal(
az_span_ptr(request.update_manifest_signature), valid_signature, sizeof(valid_signature) - 1);
assert_int_equal(az_span_size(request.update_manifest_signature), sizeof(valid_signature) - 1);

// File URLs
assert_memory_equal(az_span_ptr(request.file_urls[0].id), files_id, sizeof(files_id) - 1);
assert_int_equal(az_span_size(request.file_urls[0].id), sizeof(files_id) - 1);
assert_memory_equal(az_span_ptr(request.file_urls[0].url), file_url, sizeof(file_url) - 1);
assert_int_equal(az_span_size(request.file_urls[0].url), sizeof(file_url) - 1);
assert_memory_equal(
az_span_ptr(request.file_urls[1].id), files_id_contoso, sizeof(files_id_contoso) - 1);
assert_int_equal(az_span_size(request.file_urls[1].id), sizeof(files_id_contoso) - 1);
assert_memory_equal(
az_span_ptr(request.file_urls[1].url), file_url_contoso, sizeof(file_url_contoso) - 1);
assert_int_equal(az_span_size(request.file_urls[1].url), sizeof(file_url_contoso) - 1);
assert_int_equal(request.file_urls_count, 2);
}

static void test_az_iot_adu_client_parse_service_properties_payload_reverse_order_succeed(
void** state)
{
Expand Down Expand Up @@ -1035,6 +1148,8 @@ int test_az_iot_adu()
cmocka_unit_test(test_az_iot_adu_client_parse_service_properties_succeed),
cmocka_unit_test(
test_az_iot_adu_client_parse_service_properties_with_null_file_url_value_succeed),
cmocka_unit_test(
test_az_iot_adu_client_parse_service_properties_multiple_file_url_values_succeed),
cmocka_unit_test(test_az_iot_adu_client_parse_service_properties_payload_reverse_order_succeed),
cmocka_unit_test(
test_az_iot_adu_client_parse_service_properties_payload_no_deployment_null_manifest),
Expand Down

0 comments on commit 87c3028

Please sign in to comment.