mirror of
https://github.com/espressif/esp-mqtt.git
synced 2026-09-16 22:20:05 +00:00
feat: Add support for percent-encoding in password and it's corresponding test
Add support of percent-encoded characters when passing the username and password in URI Closes https://github.com/espressif/esp-mqtt/issues/294
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../../cmake/CPM.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../../cmake/RapidCheck.cmake)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
idf_build_set_property(MINIMAL_BUILD ON)
|
||||
list(APPEND EXTRA_COMPONENT_DIRS
|
||||
|
||||
@@ -4,7 +4,7 @@ idf_component_register(SRCS "test_mqtt_client.cpp" "test_log_intercept.cpp" "te
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -fsanitize=address -Wno-missing-field-initializers)
|
||||
target_link_options(${COMPONENT_LIB} PUBLIC -fsanitize=address)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC Catch2::Catch2WithMain)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC Catch2::Catch2WithMain rapidcheck rapidcheck_catch)
|
||||
|
||||
idf_component_get_property(mqtt mqtt COMPONENT_LIB)
|
||||
target_compile_definitions(${mqtt} PRIVATE SOC_WIFI_SUPPORTED=1)
|
||||
|
||||
@@ -4,14 +4,17 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <net/if.h>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include "esp_transport.h"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
#include <rapidcheck.h>
|
||||
|
||||
#include "mqtt_client.h"
|
||||
#include "test_log_intercept.hpp"
|
||||
@@ -31,7 +34,6 @@ extern "C" {
|
||||
#include "Mockidf_additions.h"
|
||||
#endif
|
||||
#include "Mockesp_timer.h"
|
||||
|
||||
/*
|
||||
* The following functions are not directly called but the generation of them
|
||||
* from cmock is broken, so we need to define them here.
|
||||
@@ -99,6 +101,40 @@ SCENARIO("MQTT Client Operation")
|
||||
REQUIRE(res == ESP_FAIL);
|
||||
}
|
||||
}
|
||||
SECTION("Any well-formed URI is accepted") {
|
||||
static constexpr std::array<const char *, 4> schemes = {
|
||||
"mqtt", "mqtts", "ws", "wss"
|
||||
};
|
||||
auto host_char = rc::gen::element('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
|
||||
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
|
||||
's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
|
||||
rc::check("esp_mqtt_client_set_uri accepts well-formed URIs",
|
||||
[&] {
|
||||
auto scheme = *rc::gen::elementOf(schemes);
|
||||
auto host = *rc::gen::container<std::string>(
|
||||
*rc::gen::inRange<int>(1, 33), host_char).as("host");
|
||||
auto path = *rc::gen::container<std::string>(
|
||||
*rc::gen::inRange<int>(0, 17), host_char).as("path");
|
||||
auto port = *rc::gen::maybe(rc::gen::inRange<uint16_t>(1, 65535)).as("port");
|
||||
std::string uri = scheme;
|
||||
uri += "://";
|
||||
uri += host;
|
||||
|
||||
if (port) {
|
||||
uri += ":";
|
||||
uri += std::to_string(*port);
|
||||
}
|
||||
|
||||
if (!path.empty())
|
||||
{
|
||||
uri += "/";
|
||||
uri += path;
|
||||
}
|
||||
|
||||
RC_ASSERT(esp_mqtt_client_set_uri(client.get(), uri.c_str()) == ESP_OK);
|
||||
});
|
||||
}
|
||||
SECTION("User set interface to use") {
|
||||
struct ifreq if_name = {};
|
||||
strncpy(if_name.ifr_name, "custom", IFNAMSIZ - 1);
|
||||
|
||||
Reference in New Issue
Block a user