Merge branch 'fix/esp_tls_check_tls_conn_before_read_write_v6.0' into 'release/v6.0'

Fix/esp tls check tls conn before read write (v6.0)

See merge request espressif/esp-idf!47523
This commit is contained in:
Jiang Jiang Jian
2026-05-12 17:59:41 +08:00
9 changed files with 95 additions and 6 deletions
@@ -0,0 +1,6 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
components/esp-tls/test_apps:
disable:
- if: IDF_TARGET not in ["esp32c3"]
reason: Testing on one target is enough
+2 -2
View File
@@ -1,2 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32-C3 |
| ----------------- | -------- |
@@ -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]")
{
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import pytest
from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
@pytest.mark.generic
@idf_parametrize('config', ['default'], indirect=['config'])
@idf_parametrize('target', ['esp32c3'], indirect=['target'])
def test_esp_tls(dut: Dut) -> None:
dut.run_all_single_board_cases()