mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(esp_tls): extends esp-tls test apps
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_REQUIRES test_utils esp-tls unity
|
||||
WHOLE_ARCHIVE)
|
||||
|
||||
# Expose esp-tls private headers for internal component tests
|
||||
idf_component_get_property(esp_tls_dir esp-tls COMPONENT_DIR)
|
||||
target_include_directories(${COMPONENT_LIB} PRIVATE "${esp_tls_dir}/private_include")
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "memory_checks.h"
|
||||
#include "esp_tls.h"
|
||||
#include "esp_tls_custom_stack.h"
|
||||
#include "esp_tls_private.h"
|
||||
#include "unity.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
@@ -60,6 +61,46 @@ const char *test_key_pem = "-----BEGIN PRIVATE KEY-----\n"\
|
||||
"Aogx44Fozd1t2hYcozPuZD4s\n"\
|
||||
"-----END PRIVATE KEY-----\n";
|
||||
|
||||
static ssize_t dummy_read(esp_tls_t *tls, char *data, size_t datalen) { return (ssize_t)datalen; }
|
||||
|
||||
TEST_CASE("esp_tls_conn_write/read reject NULL tls", "[esp-tls]")
|
||||
{
|
||||
char buf[16] = {0};
|
||||
TEST_ASSERT_EQUAL(-1, esp_tls_conn_write(NULL, buf, sizeof(buf)));
|
||||
TEST_ASSERT_EQUAL(-1, esp_tls_conn_read(NULL, buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
TEST_CASE("esp_tls_conn_write reject NULL data buffer", "[esp-tls]")
|
||||
{
|
||||
esp_tls_t *tls = esp_tls_init();
|
||||
TEST_ASSERT_NOT_NULL(tls);
|
||||
TEST_ASSERT_EQUAL(-1, esp_tls_conn_write(tls, NULL, 16));
|
||||
esp_tls_conn_destroy(tls);
|
||||
}
|
||||
|
||||
TEST_CASE("esp_tls_conn_read accepts zero datalen", "[esp-tls]")
|
||||
{
|
||||
esp_tls_t *tls = esp_tls_init();
|
||||
TEST_ASSERT_NOT_NULL(tls);
|
||||
tls->is_tls = true;
|
||||
tls->read = dummy_read;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_tls_set_conn_state(tls, ESP_TLS_DONE));
|
||||
/* datalen=0 on read is used in some projects, to get the data in the SSL buffers */
|
||||
TEST_ASSERT_EQUAL(0, esp_tls_conn_read(tls, NULL, 0));
|
||||
esp_tls_conn_destroy(tls);
|
||||
}
|
||||
|
||||
TEST_CASE("esp_tls_conn_write/read reject unconnected tls", "[esp-tls]")
|
||||
{
|
||||
esp_tls_t *tls = esp_tls_init();
|
||||
TEST_ASSERT_NOT_NULL(tls);
|
||||
/* read/write function pointers are NULL right after init */
|
||||
char buf[16] = {0};
|
||||
TEST_ASSERT_EQUAL(-1, esp_tls_conn_write(tls, buf, sizeof(buf)));
|
||||
TEST_ASSERT_EQUAL(-1, esp_tls_conn_read(tls, buf, sizeof(buf)));
|
||||
esp_tls_conn_destroy(tls);
|
||||
}
|
||||
|
||||
#if CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
TEST_CASE("esp-tls init deinit", "[esp-tls]")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user