From b96cde5656c904ccd5a2051d9c294ad521fe5c9f Mon Sep 17 00:00:00 2001 From: XavierChanth Date: Tue, 10 Dec 2024 17:03:33 -0500 Subject: [PATCH 1/2] chore: cleanup some tests --- packages/atclient/tests/CMakeLists.txt | 16 ++++++++-------- .../{atclient => atcommons}/tests/test_cjson.c | 2 +- .../tests/test_atclient_notify.c | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) rename packages/{atclient => atcommons}/tests/test_cjson.c (96%) diff --git a/packages/atclient/tests/CMakeLists.txt b/packages/atclient/tests/CMakeLists.txt index 6bfc370c..d335d259 100644 --- a/packages/atclient/tests/CMakeLists.txt +++ b/packages/atclient/tests/CMakeLists.txt @@ -1,11 +1,11 @@ - file(GLOB_RECURSE files ${CMAKE_CURRENT_LIST_DIR}/test_*.c) foreach(file ${files}) - # ${filename} - without `.c` - get_filename_component(filename ${file} NAME) - string(REPLACE ".c" "" filename ${filename}) + # ${filename} - without `.c` + get_filename_component(filename ${file} NAME) + string(REPLACE ".c" "" filename ${filename}) + + add_executable(${filename} ${file}) + target_link_libraries(${filename} PRIVATE atclient) + add_test(NAME ${filename} COMMAND $) +endforeach() - add_executable(${filename} ${file}) - target_link_libraries(${filename} PRIVATE atclient) - add_test(NAME ${filename} COMMAND $) -endforeach() \ No newline at end of file diff --git a/packages/atclient/tests/test_cjson.c b/packages/atcommons/tests/test_cjson.c similarity index 96% rename from packages/atclient/tests/test_cjson.c rename to packages/atcommons/tests/test_cjson.c index c5a73c8f..8bc1ac83 100644 --- a/packages/atclient/tests/test_cjson.c +++ b/packages/atcommons/tests/test_cjson.c @@ -1,4 +1,4 @@ -#include +#include #include // IWYU pragma: keep #include diff --git a/tests/functional_tests/tests/test_atclient_notify.c b/tests/functional_tests/tests/test_atclient_notify.c index 5c931c1d..525ad1c9 100644 --- a/tests/functional_tests/tests/test_atclient_notify.c +++ b/tests/functional_tests/tests/test_atclient_notify.c @@ -219,22 +219,22 @@ static int test_2_notify_long_text(atclient *atclient, char *notification_id) { goto exit; } - if((ret = atclient_notify_params_set_operation(¶ms, ATCLIENT_NOTIFY_OPERATION_UPDATE)) != 0) { + if ((ret = atclient_notify_params_set_operation(¶ms, ATCLIENT_NOTIFY_OPERATION_UPDATE)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set operation: %d\n", ret); goto exit; } - if((ret = atclient_notify_params_set_atkey(¶ms, &atkey)) != 0) { + if ((ret = atclient_notify_params_set_atkey(¶ms, &atkey)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set atkey: %d\n", ret); goto exit; } - if((ret = atclient_notify_params_set_value(¶ms, VERY_LONG_TEXT)) != 0) { + if ((ret = atclient_notify_params_set_value(¶ms, VERY_LONG_TEXT)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set value: %d\n", ret); goto exit; } - if((ret = atclient_notify_params_set_should_encrypt(¶ms, true)) != 0) { + if ((ret = atclient_notify_params_set_should_encrypt(¶ms, true)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set should_encrypt: %d\n", ret); goto exit; } @@ -251,4 +251,4 @@ exit: { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "test_2_notify_long_text End (%d)\n", ret); return ret; } -} \ No newline at end of file +} From 6feea2eb50e0b1b7f45de24b275968a49eaef579 Mon Sep 17 00:00:00 2001 From: XavierChanth Date: Wed, 11 Dec 2024 10:00:10 -0500 Subject: [PATCH 2/2] feat: use atchops pers in uuid, make it overridable --- packages/atchops/include/atchops/constants.h | 8 ++++++++ packages/atchops/src/uuid.c | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/atchops/include/atchops/constants.h b/packages/atchops/include/atchops/constants.h index 4cfe6590..bb64e87f 100644 --- a/packages/atchops/include/atchops/constants.h +++ b/packages/atchops/include/atchops/constants.h @@ -5,7 +5,15 @@ extern "C" { #endif #include // IWYU pragma: keep + +// Only define this if it isn't defined +// Consumers of the SDK should be able to override it so their personalization +// isn't open source +// TODO: later provide more intentional ways of forcing consumers of the SDK +// to override this +#ifndef ATCHOPS_RNG_PERSONALIZATION #define ATCHOPS_RNG_PERSONALIZATION "@atchops12345" +#endif #ifdef __cplusplus } diff --git a/packages/atchops/src/uuid.c b/packages/atchops/src/uuid.c index eb7dfd7f..73fdea04 100644 --- a/packages/atchops/src/uuid.c +++ b/packages/atchops/src/uuid.c @@ -1,4 +1,5 @@ #include "atchops/uuid.h" +#include "atchops/constants.h" #include #include #include @@ -105,16 +106,14 @@ static int uuid4_init(void) { mbedtls_ctr_drbg_context ctr_drbg; mbedtls_entropy_context entropy; - // TODO replace this string - const unsigned char pers[13] = {"Arduino_Seed"}; - size_t off = sizeof(uint64_t) / sizeof(unsigned char); size_t n = off * 2; unsigned char pointer[n]; // create char pointer to long number mbedtls_ctr_drbg_init(&ctr_drbg); mbedtls_entropy_init(&entropy); - ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pers, sizeof(pers)); + ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (unsigned char *)ATCHOPS_RNG_PERSONALIZATION, + sizeof(ATCHOPS_RNG_PERSONALIZATION)); if (ret != 0) { mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_entropy_free(&entropy);