diff --git a/CMakeLists.txt b/CMakeLists.txt
index b2bd9b29..0caf444b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,7 @@ option(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON)
option(WITH_TLS "Include SSL/TLS support?" ON)
option(WITH_TLS_PSK "Include TLS-PSK support (requires WITH_TLS)?" ON)
option(WITH_EC "Include Elliptic Curve support (requires WITH_TLS)?" ON)
+option(WITH_TESTS "Enable tests" ON)
if (WITH_TLS)
find_package(OpenSSL REQUIRED)
add_definitions("-DWITH_TLS")
@@ -104,6 +105,21 @@ option(WITH_APPS "Build apps?" ON)
option(WITH_PLUGINS "Build plugins?" ON)
option(DOCUMENTATION "Build documentation?" ON)
+add_library(config-header INTERFACE)
+target_sources(config-header INTERFACE config.h)
+target_include_directories(config-header
+ INTERFACE
+ ${mosquitto_SOURCE_DIR}
+)
+
+if(WITH_TLS)
+ target_include_directories(config-header
+ INTERFACE
+ "${OPENSSL_INCLUDE_DIR}"
+ )
+endif()
+
+
add_subdirectory(lib)
if(WITH_CLIENTS)
add_subdirectory(client)
@@ -145,4 +161,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquittopp.pc" DESTINATION "${CMA
# ========================================
# Testing
# ========================================
-enable_testing()
+if(WITH_TESTS)
+ enable_testing()
+ add_subdirectory(test)
+endif()
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 19d5ffff..fb090ad7 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -57,6 +57,8 @@ Broker:
to trust default CA certificates. Closes #2473.
- Add `--test-config` option which can be used to test a configuration file
before trying to use it in a live broker. Closes #2521.
+- Print messages in mosquitto_passwd when adding/updating passwords.
+ Closes #2544.
Plugins / plugin interface:
- Add persist-sqlite plugin.
@@ -84,6 +86,8 @@ Plugins / plugin interface:
- The dynamic security plugin now supports `%c` and `%u` patterns for
substituting client id and username respectively, in all ACLs except for
subscribeLiteral and unsubscribeLiteral.
+- The dynamic security plugin now supports multiple ways to initialise the
+ first configuration file.
- Add `mosquitto_sub_matches_acl()`, which can match one topic filter (a
subscription) against another topic filter (an ACL).
- Registration of the MOSQ_EVT_CONTROL plugin event is now handled globally
diff --git a/apps/mosquitto_ctrl/CMakeLists.txt b/apps/mosquitto_ctrl/CMakeLists.txt
index 201d07ac..fef60f26 100644
--- a/apps/mosquitto_ctrl/CMakeLists.txt
+++ b/apps/mosquitto_ctrl/CMakeLists.txt
@@ -17,7 +17,6 @@ if(WITH_TLS AND CJSON_FOUND)
)
target_include_directories(mosquitto_ctrl PRIVATE
- "${OPENSSL_INCLUDE_DIR}"
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
"${mosquitto_SOURCE_DIR}"
@@ -57,7 +56,7 @@ if(WITH_TLS AND CJSON_FOUND)
target_link_libraries(mosquitto_ctrl
PRIVATE
- ${OPENSSL_LIBRARIES}
+ OpenSSL::SSL
cJSON
)
diff --git a/apps/mosquitto_passwd/CMakeLists.txt b/apps/mosquitto_passwd/CMakeLists.txt
index 75120186..3d853d64 100644
--- a/apps/mosquitto_passwd/CMakeLists.txt
+++ b/apps/mosquitto_passwd/CMakeLists.txt
@@ -10,7 +10,6 @@ if(WITH_TLS)
)
target_include_directories(mosquitto_passwd PRIVATE
- "${OPENSSL_INCLUDE_DIR}"
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
"${mosquitto_SOURCE_DIR}"
@@ -22,7 +21,7 @@ if(WITH_TLS)
target_link_libraries(mosquitto_passwd
PRIVATE
- ${OPENSSL_LIBRARIES}
+ OpenSSL::SSL
)
install(TARGETS mosquitto_passwd
diff --git a/apps/mosquitto_passwd/mosquitto_passwd.c b/apps/mosquitto_passwd/mosquitto_passwd.c
index 15ca90c4..7edeae03 100644
--- a/apps/mosquitto_passwd/mosquitto_passwd.c
+++ b/apps/mosquitto_passwd/mosquitto_passwd.c
@@ -336,8 +336,10 @@ static int update_pwuser(FILE *fptr, FILE *ftmp, const char *username, const cha
rc = pwfile_iterate(fptr, ftmp, update_pwuser_cb, &helper);
if(helper.found){
+ printf("Updating password for user %s\n", username);
return rc;
}else{
+ printf("Adding password for user %s\n", username);
return output_new_password(ftmp, username, password, iterations);
}
}
@@ -606,6 +608,7 @@ int main(int argc, char *argv[])
return 1;
}
free(password_file);
+ printf("Adding password for user %s\n", username);
rc = output_new_password(fptr, username, password_cmd, iterations);
fclose(fptr);
return rc;
diff --git a/client/sub_client_output.c b/client/sub_client_output.c
index a749caaf..eb3313e5 100644
--- a/client/sub_client_output.c
+++ b/client/sub_client_output.c
@@ -426,7 +426,8 @@ static void formatted_print_blank(char pad, int field_width)
static int formatted_print_float(const unsigned char *payload, int payloadlen, char format, char align, char pad, int field_width, int precision)
{
float float_value;
- double value;
+ double value = 0.0;
+
if (format == 'f'){
if (sizeof(float_value) != payloadlen) {
return -1;
diff --git a/cmake/FindCUnit.cmake b/cmake/FindCUnit.cmake
new file mode 100644
index 00000000..c7a7d8d0
--- /dev/null
+++ b/cmake/FindCUnit.cmake
@@ -0,0 +1,36 @@
+find_package(PkgConfig)
+pkg_check_modules(PC_CUnit QUIET cunit)
+
+find_path(CUnit_INCLUDE_DIR
+ NAMES CUnit/CUnit.h
+ PATHS ${PC_CUnit_INCLUDE_DIRS}
+)
+
+find_library(CUnit_LIBRARY
+ NAMES cunit
+ PATHS ${PC_CUnit_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(CUnit
+ FOUND_VAR CUnit_FOUND
+ REQUIRED_VARS
+ CUnit_LIBRARY
+ CUnit_INCLUDE_DIR
+ VERSION_VAR CUnit_VERSION
+)
+
+if(CUnit_FOUND)
+ set(CUnit_LIBRARIES ${CUnit_LIBRARY})
+ set(CUnit_INCLUDE_DIRS ${CUnit_INCLUDE_DIR})
+ set(CUnit_DEFINITIONS ${PC_CUnit_CFLAGS_OTHER})
+endif()
+
+if(CUnit_FOUND AND NOT TARGET CUnit::CUnit)
+ add_library(CUnit::CUnit UNKNOWN IMPORTED)
+ set_target_properties(CUnit::CUnit PROPERTIES
+ IMPORTED_LOCATION "${CUnit_LIBRARY}"
+ INTERFACE_COMPILE_OPTIONS "${PC_CUnit_CFLAGS_OTHER}"
+ INTERFACE_INCLUDE_DIRECTORIES "${CUnit_INCLUDE_DIR}"
+ )
+endif()
diff --git a/config.h b/config.h
index 83d4adb0..280b78d7 100644
--- a/config.h
+++ b/config.h
@@ -88,7 +88,7 @@
#endif
#define WS_IS_LWS 1
-#define WS_IS_WSLAY 2
+#define WS_IS_BUILTIN 2
#ifdef WITH_BROKER
# ifdef __GNUC__
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 606a18a0..9ec540ce 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -58,7 +58,9 @@ if (WITH_THREADING AND WIN32)
list(APPEND C_SRC "../common/winthread_mosq.c" "../common/winthread_mosq.h")
endif()
-set (LIBRARIES ${OPENSSL_LIBRARIES})
+if(WITH_TLS)
+ set (LIBRARIES OpenSSL::SSL)
+endif()
if(UNIX AND NOT APPLE AND NOT ANDROID)
find_library(LIBRT rt)
@@ -104,7 +106,6 @@ endif()
target_include_directories(libmosquitto
PUBLIC
"${mosquitto_SOURCE_DIR}/include"
- "${OPENSSL_INCLUDE_DIR}"
PRIVATE
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
@@ -152,7 +153,6 @@ if(WITH_STATIC_LIBRARIES)
target_link_libraries(libmosquitto_static PRIVATE ${LIBRARIES})
target_include_directories(libmosquitto_static PRIVATE
- "${OPENSSL_INCLUDE_DIR}"
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
"${mosquitto_SOURCE_DIR}"
@@ -171,5 +171,5 @@ if(WITH_STATIC_LIBRARIES)
)
endif()
-install(FILES ../include/mosquitto.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
-install(FILES ../include/mqtt_protocol.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+install(FILES ${mosquitto_SOURCE_DIR}/include/mosquitto.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+install(FILES ${mosquitto_SOURCE_DIR}/include/mqtt_protocol.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
index c7fe00c4..d249cc57 100644
--- a/lib/cpp/CMakeLists.txt
+++ b/lib/cpp/CMakeLists.txt
@@ -69,4 +69,4 @@ if(WITH_STATIC_LIBRARIES)
)
endif()
-install(FILES mosquittopp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+install(FILES ${mosquitto_SOURCE_DIR}/include/mosquittopp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
diff --git a/lib/http_client.c b/lib/http_client.c
index 5b74dcdf..c4a32a58 100644
--- a/lib/http_client.c
+++ b/lib/http_client.c
@@ -26,6 +26,7 @@ Contributors:
#include "mosquitto_internal.h"
#include "base64_mosq.h"
+#include "http_client.h"
#include "memory_mosq.h"
#include "mqtt_protocol.h"
#include "net_mosq.h"
diff --git a/lib/mosquitto.c b/lib/mosquitto.c
index e24a6916..1fecc3c1 100644
--- a/lib/mosquitto.c
+++ b/lib/mosquitto.c
@@ -183,6 +183,7 @@ int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_st
packet__cleanup(&mosq->in_packet);
mosq->out_packet = NULL;
mosq->out_packet_count = 0;
+ mosq->out_packet_bytes = 0;
mosq->last_msg_in = mosquitto_time();
mosq->next_msg_out = mosquitto_time() + mosq->keepalive;
mosq->ping_t = 0;
diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h
index 7f0cdd86..680e879b 100644
--- a/lib/mosquitto_internal.h
+++ b/lib/mosquitto_internal.h
@@ -243,7 +243,7 @@ struct mosquitto_msg_data{
#define WS_PING 0x09
#define WS_PONG 0x0A
-#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == LWS_IS_BUILTIN
+#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
struct ws_data{
struct mosquitto__packet *out_packet;
char *http_path;
@@ -281,7 +281,7 @@ struct mosquitto {
struct gaicb *adns; /* For getaddrinfo_a */
#endif
uint64_t last_cmsg_id;
-#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == LWS_IS_BUILTIN
+#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
struct ws_data wsd;
#endif
enum mosquitto__protocol protocol;
@@ -307,6 +307,7 @@ struct mosquitto {
uint16_t alias_max_l2r;
uint32_t will_delay_interval;
int out_packet_count;
+ int64_t out_packet_bytes;
time_t will_delay_time;
#ifdef WITH_TLS
SSL *ssl;
diff --git a/lib/net_ws.c b/lib/net_ws.c
index c13f9082..e645f722 100644
--- a/lib/net_ws.c
+++ b/lib/net_ws.c
@@ -204,7 +204,7 @@ static ssize_t read_ws_payloadlen_extended(struct mosquitto *mosq)
}
-ssize_t read_ws_mask(struct mosquitto *mosq)
+static ssize_t read_ws_mask(struct mosquitto *mosq)
{
ssize_t len;
diff --git a/lib/options.c b/lib/options.c
index bbf190ff..f6fdd77b 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -504,7 +504,7 @@ int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int val
break;
case MOSQ_OPT_TRANSPORT:
-#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == LWS_IS_BUILTIN
+#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
if(value == mosq_t_tcp || value == mosq_t_ws){
mosq->transport = (uint8_t)value;
}else{
@@ -516,7 +516,7 @@ int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int val
break;
case MOSQ_OPT_HTTP_HEADER_SIZE:
-#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == LWS_IS_BUILTIN
+#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
if(value < 100){ /* arbitrary limit */
return MOSQ_ERR_INVAL;
}else if(mosq->http_request){
diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c
index afbd0a16..d5ef8792 100644
--- a/lib/packet_mosq.c
+++ b/lib/packet_mosq.c
@@ -46,6 +46,10 @@ Contributors:
# define G_BYTES_SENT_INC(A)
# define G_MSGS_SENT_INC(A)
# define G_PUB_MSGS_SENT_INC(A)
+# define G_OUT_PACKET_COUNT_INC(A)
+# define G_OUT_PACKET_COUNT_DEC(A)
+# define G_OUT_PACKET_BYTES_INC(A)
+# define G_OUT_PACKET_BYTES_DEC(A)
#endif
int packet__alloc(struct mosquitto__packet **packet, uint8_t command, uint32_t remaining_length)
@@ -120,7 +124,10 @@ void packet__cleanup_all_no_locks(struct mosquitto *mosq)
mosquitto__FREE(packet);
}
+ G_OUT_PACKET_COUNT_DEC(mosq->out_packet_count);
+ G_OUT_PACKET_BYTES_DEC(mosq->out_packet_bytes);
mosq->out_packet_count = 0;
+ mosq->out_packet_bytes = 0;
mosq->out_packet_last = NULL;
packet__cleanup(&mosq->in_packet);
@@ -134,6 +141,23 @@ void packet__cleanup_all(struct mosquitto *mosq)
}
+static void packet__queue_append(struct mosquitto *mosq, struct mosquitto__packet *packet)
+{
+ pthread_mutex_lock(&mosq->out_packet_mutex);
+ if(mosq->out_packet){
+ mosq->out_packet_last->next = packet;
+ }else{
+ mosq->out_packet = packet;
+ }
+ mosq->out_packet_last = packet;
+ mosq->out_packet_count++;
+ mosq->out_packet_bytes += packet->packet_length;
+ G_OUT_PACKET_COUNT_INC(1);
+ G_OUT_PACKET_BYTES_INC(packet->packet_length);
+ pthread_mutex_unlock(&mosq->out_packet_mutex);
+}
+
+
int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet)
{
#ifndef WITH_BROKER
@@ -148,15 +172,7 @@ int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet)
packet->pos = WS_PACKET_OFFSET;
packet->to_process = packet->packet_length - WS_PACKET_OFFSET;
- pthread_mutex_lock(&mosq->out_packet_mutex);
- if(mosq->out_packet){
- mosq->out_packet_last->next = packet;
- }else{
- mosq->out_packet = packet;
- }
- mosq->out_packet_last = packet;
- mosq->out_packet_count++;
- pthread_mutex_unlock(&mosq->out_packet_mutex);
+ packet__queue_append(mosq, packet);
lws_callback_on_writable(mosq->wsi);
return MOSQ_ERR_SUCCESS;
@@ -173,14 +189,7 @@ int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet)
packet->to_process = packet->packet_length - WS_PACKET_OFFSET;
}
- pthread_mutex_lock(&mosq->out_packet_mutex);
- if(mosq->out_packet){
- mosq->out_packet_last->next = packet;
- }else{
- mosq->out_packet = packet;
- }
- mosq->out_packet_last = packet;
- pthread_mutex_unlock(&mosq->out_packet_mutex);
+ packet__queue_append(mosq, packet);
#ifdef WITH_BROKER
return packet__write(mosq);
@@ -225,11 +234,15 @@ struct mosquitto__packet *packet__get_next_out(struct mosquitto *mosq)
pthread_mutex_lock(&mosq->out_packet_mutex);
if(mosq->out_packet){
+ mosq->out_packet_count--;
+ mosq->out_packet_bytes -= mosq->out_packet->packet_length;
+ G_OUT_PACKET_COUNT_DEC(1);
+ G_OUT_PACKET_BYTES_DEC(mosq->out_packet->packet_length);
+
mosq->out_packet = mosq->out_packet->next;
if(!mosq->out_packet){
mosq->out_packet_last = NULL;
}
- mosq->out_packet_count--;
packet = mosq->out_packet;
}
pthread_mutex_unlock(&mosq->out_packet_mutex);
diff --git a/man/mosquitto.8.xml b/man/mosquitto.8.xml
index 7d358a79..3696c17a 100644
--- a/man/mosquitto.8.xml
+++ b/man/mosquitto.8.xml
@@ -556,6 +556,28 @@
The total number of messages of any type sent since the broker started.
+
+
+
+
+ The current number of packets queued for delivery across
+ all clients. A large and increasing value here may
+ indicate messages are being sent faster than the network
+ can handle.
+
+
+
+
+
+
+
+ The current number of bytes in packets queued for
+ delivery across all clients. A large and increasing
+ value here may indicate messages are being sent faster
+ than the network can handle.
+
+
+
diff --git a/man/mosquitto_passwd.1.xml b/man/mosquitto_passwd.1.xml
index bd90fa51..30cb6bb2 100644
--- a/man/mosquitto_passwd.1.xml
+++ b/man/mosquitto_passwd.1.xml
@@ -191,6 +191,22 @@
mosquitto_passwd -c /etc/mosquitto/passwd ral
+ Add a user to an existing password file:
+
+ mosquitto_passwd /etc/mosquitto/passwd ral
+
+ Add a user to an existing password file, passing the password on the command line:
+
+ mosquitto_passwd -b /etc/mosquitto/passwd ral z2Dr0BsvtZ
+
+ Update the password for a user in an existing password file:
+
+ mosquitto_passwd /etc/mosquitto/passwd ral
+
+ Add a user to an existing password file using the sha512 hash for Mosquitto 1.6 compatibility:
+
+ mosquitto_passwd -H sha512 /etc/mosquitto/passwd ral
+
Delete a user from a password file
mosquitto_passwd -D /etc/mosquitto/passwd ral
diff --git a/plugins/common/plugin_common.c b/plugins/common/plugin_common.c
index 198edc43..f6ad3460 100644
--- a/plugins/common/plugin_common.c
+++ b/plugins/common/plugin_common.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
#include "plugin_common.h"
#include "json_help.h"
#include
diff --git a/plugins/dynamic-security/config.c b/plugins/dynamic-security/config.c
index 64995c44..dd3823a4 100644
--- a/plugins/dynamic-security/config.c
+++ b/plugins/dynamic-security/config.c
@@ -98,7 +98,7 @@ int dynsec__config_from_json(struct dynsec__data *data, const char *json_str)
tree = cJSON_Parse(json_str);
if(tree == NULL){
- mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: File is not valid JSON.\n");
+ mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: File is not valid JSON.");
return 1;
}
@@ -128,9 +128,7 @@ int dynsec__config_load(struct dynsec__data *data)
fptr = fopen(data->config_file, "rb");
if(fptr == NULL){
/* Attempt to initialise a new config file */
- if(dynsec__config_init(data->config_file) == MOSQ_ERR_SUCCESS){
- mosquitto_log_printf(MOSQ_LOG_INFO, "Dynamic security plugin config not found, generating a default config.");
- mosquitto_log_printf(MOSQ_LOG_INFO, " Generated passwords are at %s.pw", data->config_file);
+ if(dynsec__config_init(data) == MOSQ_ERR_SUCCESS){
/* If it works, try to open the file again */
fptr = fopen(data->config_file, "rb");
}
diff --git a/plugins/dynamic-security/config_init.c b/plugins/dynamic-security/config_init.c
index c7248463..9a72b8bd 100644
--- a/plugins/dynamic-security/config_init.c
+++ b/plugins/dynamic-security/config_init.c
@@ -19,6 +19,7 @@ Contributors:
#include "config.h"
#include
+#include
#include
#include
#include
@@ -63,7 +64,56 @@ static int add_default_access(cJSON *j_tree)
}
-static int generate_password(int iterations, char **password, char **password_hash, char **salt)
+static int get_password_from_init_file(struct dynsec__data *data, char **pw)
+{
+ FILE *fptr;
+ char buf[1024];
+ int pos;
+
+ if(data->password_init_file == NULL){
+ *pw = NULL;
+ return MOSQ_ERR_SUCCESS;
+ }
+ fptr = fopen(data->password_init_file, "rt");
+ if(!fptr){
+ mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Unable to get initial password from '%s', file not accessible.", data->password_init_file);
+ return MOSQ_ERR_INVAL;
+ }
+ if(!fgets(buf, sizeof(buf), fptr)){
+ fclose(fptr);
+ mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Unable to get initial password from '%s', file empty.", data->password_init_file);
+ return MOSQ_ERR_INVAL;
+ }
+ fclose(fptr);
+
+ pos = (int)strlen(buf)-1;
+ while(pos >= 0 && isspace(buf[pos])){
+ buf[pos] = '\0';
+ pos--;
+ }
+ if(strlen(buf) == 0){
+ mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Unable to get initial password from '%s', password is empty.", data->password_init_file);
+ return MOSQ_ERR_INVAL;
+ }
+ *pw = strdup(buf);
+ if(!*pw){
+ mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Unable to get initial password from '%s', out of memory.", data->password_init_file);
+ return MOSQ_ERR_NOMEM;
+ }else{
+ return MOSQ_ERR_SUCCESS;
+ }
+}
+
+
+/* Generate a password for the admin user
+ *
+ * Uses passwords from, in order:
+ *
+ * * The password defined in the plugin_opt_password_init_file file
+ * * The contents of the MOSQUITTO_DYNSEC_PASSWORD environment variable
+ * * Randomly generated passwords for "admin", "user", stored in plain text at '.pw'
+ */
+static int generate_password(struct dynsec__data *data, int iterations, char **password, char **password_hash, char **salt)
{
struct mosquitto_pw pw;
int i;
@@ -75,9 +125,13 @@ static int generate_password(int iterations, char **password, char **password_ha
memset(&pw, 0, sizeof(struct mosquitto_pw));
pw.hashtype = pw_sha512_pbkdf2;
- pwenv = getenv("MOSQUITTO_DYNSEC_PASSWORD");
- if(pwenv){
- if(strlen(pwenv) < 12){
+ if(data->init_mode == dpwim_file){
+ if(get_password_from_init_file(data, password)){
+ return MOSQ_ERR_INVAL;
+ }
+ }else if(data->init_mode == dpwim_env){
+ pwenv = getenv("MOSQUITTO_DYNSEC_PASSWORD");
+ if(pwenv == NULL || strlen(pwenv) < 12){
mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Not generating dynsec config, MOSQUITTO_DYNSEC_PASSWORD must be at least 12 characters.");
return MOSQ_ERR_INVAL;
}
@@ -140,14 +194,14 @@ static int client_role_add(cJSON *j_roles, const char *rolename)
}
-static int client_add_admin(FILE *pwfile, cJSON *j_clients)
+static int client_add_admin(struct dynsec__data *data, FILE *pwfile, cJSON *j_clients)
{
cJSON *j_client, *j_roles;
char *password = NULL;
char *password_hash = NULL;
char *salt = NULL;
- if(generate_password(10000, &password, &password_hash, &salt)){
+ if(generate_password(data, 10000, &password, &password_hash, &salt)){
return MOSQ_ERR_UNKNOWN;
}
@@ -181,23 +235,25 @@ static int client_add_admin(FILE *pwfile, cJSON *j_clients)
return MOSQ_ERR_NOMEM;
}
- fprintf(pwfile, "admin %s\n", password);
+ if(data->init_mode == dpwim_random){
+ fprintf(pwfile, "admin %s\n", password);
+ }
free(password);
return MOSQ_ERR_SUCCESS;
}
-static int client_add_user(FILE *pwfile, cJSON *j_clients)
+static int client_add_user(struct dynsec__data *data, FILE *pwfile, cJSON *j_clients)
{
cJSON *j_client, *j_roles;
char *password = NULL;
char *password_hash = NULL;
char *salt = NULL;
- if(getenv("MOSQUITTO_DYNSEC_PASSWORD")){
+ if(data->init_mode != dpwim_random){
return MOSQ_ERR_SUCCESS;
}
- if(generate_password(10000, &password, &password_hash, &salt)){
+ if(generate_password(data, 10000, &password, &password_hash, &salt)){
return MOSQ_ERR_UNKNOWN;
}
@@ -234,40 +290,42 @@ static int client_add_user(FILE *pwfile, cJSON *j_clients)
return MOSQ_ERR_SUCCESS;
}
-static int add_clients(const char *filename, cJSON *j_tree)
+static int add_clients(struct dynsec__data *data, cJSON *j_tree)
{
cJSON *j_clients;
char *pwfile;
size_t len;
- FILE *fptr;
+ FILE *fptr = NULL;
- len = strlen(filename) + 5;
- pwfile = malloc(len);
- if(pwfile == NULL){
- return MOSQ_ERR_NOMEM;
- }
- snprintf(pwfile, len, "%s.pw", filename);
- fptr = mosquitto__fopen(pwfile, "wb", true);
- free(pwfile);
- if(fptr == NULL){
- return MOSQ_ERR_UNKNOWN;
+ if(data->init_mode == dpwim_random){
+ len = strlen(data->config_file) + 5;
+ pwfile = malloc(len);
+ if(pwfile == NULL){
+ return MOSQ_ERR_NOMEM;
+ }
+ snprintf(pwfile, len, "%s.pw", data->config_file);
+ fptr = mosquitto__fopen(pwfile, "wb", true);
+ free(pwfile);
+ if(fptr == NULL){
+ return MOSQ_ERR_UNKNOWN;
+ }
}
j_clients = cJSON_AddArrayToObject(j_tree, "clients");
if(j_clients == NULL){
- fclose(fptr);
+ if(fptr) fclose(fptr);
return MOSQ_ERR_NOMEM;
}
- if(client_add_admin(fptr, j_clients)
- || client_add_user(fptr, j_clients)
+ if(client_add_admin(data, fptr, j_clients)
+ || client_add_user(data, fptr, j_clients)
){
- fclose(fptr);
+ if(fptr) fclose(fptr);
return MOSQ_ERR_NOMEM;
}
- fclose(fptr);
+ if(fptr) fclose(fptr);
return MOSQ_ERR_SUCCESS;
}
@@ -416,7 +474,7 @@ static int role_add_topic_observe(cJSON *j_roles)
if(cJSON_AddStringToObject(j_role, "rolename", "topic-observe") == NULL
|| cJSON_AddStringToObject(j_role, "textdescription",
- "Read/write access to the full application topic hierarchy.") == NULL
+ "Read only access to the full application topic hierarchy.") == NULL
|| (j_acls = cJSON_AddArrayToObject(j_role, "acls")) == NULL
){
@@ -455,19 +513,32 @@ static int add_roles(cJSON *j_tree)
}
-int dynsec__config_init(const char *filename)
+int dynsec__config_init(struct dynsec__data *data)
{
FILE *fptr;
cJSON *j_tree;
char *json_str;
+ mosquitto_log_printf(MOSQ_LOG_INFO, "Dynamic security plugin config not found, generating a default config.");
+
+ if(data->password_init_file){
+ mosquitto_log_printf(MOSQ_LOG_INFO, " Using admin password from file '%s'", data->password_init_file);
+ data->init_mode = dpwim_file;
+ }else if(getenv("MOSQUITTO_DYNSEC_PASSWORD")){
+ mosquitto_log_printf(MOSQ_LOG_INFO, " Using admin password from MOSQUITTO_DYNSEC_PASSWORD environment variable");
+ data->init_mode = dpwim_env;
+ }else{
+ mosquitto_log_printf(MOSQ_LOG_INFO, " Generated passwords are at %s.pw", data->config_file);
+ data->init_mode = dpwim_random;
+ }
+
j_tree = cJSON_CreateObject();
if(j_tree == NULL){
return MOSQ_ERR_NOMEM;
}
if(add_default_access(j_tree) != MOSQ_ERR_SUCCESS
- || add_clients(filename, j_tree) != MOSQ_ERR_SUCCESS
+ || add_clients(data, j_tree) != MOSQ_ERR_SUCCESS
|| add_groups(j_tree) != MOSQ_ERR_SUCCESS
|| add_roles(j_tree) != MOSQ_ERR_SUCCESS
|| cJSON_AddStringToObject(j_tree, "anonymousGroup", "unauthenticated") == NULL
@@ -483,7 +554,7 @@ int dynsec__config_init(const char *filename)
return MOSQ_ERR_NOMEM;
}
- fptr = mosquitto__fopen(filename, "wb", true);
+ fptr = mosquitto__fopen(data->config_file, "wb", true);
if(fptr == NULL){
return MOSQ_ERR_UNKNOWN;
}
diff --git a/plugins/dynamic-security/dynamic_security.h b/plugins/dynamic-security/dynamic_security.h
index 02bcf63f..5ff8bc2b 100644
--- a/plugins/dynamic-security/dynamic_security.h
+++ b/plugins/dynamic-security/dynamic_security.h
@@ -136,14 +136,22 @@ struct dynsec__acl_default_access{
bool unsubscribe;
};
+enum dynsec_pw_init_mode{
+ dpwim_file = 1,
+ dpwim_env = 2,
+ dpwim_random = 3,
+};
+
struct dynsec__data{
char *config_file;
+ char *password_init_file;
struct dynsec__client *clients;
struct dynsec__group *groups;
struct dynsec__role *roles;
struct dynsec__group *anonymous_group;
struct dynsec__kicklist *kicklist;
struct dynsec__acl_default_access default_access;
+ int init_mode;
};
/* ################################################################
@@ -152,7 +160,7 @@ struct dynsec__data{
* #
* ################################################################ */
-int dynsec__config_init(const char *filename);
+int dynsec__config_init(struct dynsec__data *data);
void dynsec__config_save(struct dynsec__data *data);
int dynsec__config_load(struct dynsec__data *data);
char *dynsec__config_to_json(struct dynsec__data *data);
diff --git a/plugins/dynamic-security/plugin.c b/plugins/dynamic-security/plugin.c
index 216ccbb7..788efacd 100644
--- a/plugins/dynamic-security/plugin.c
+++ b/plugins/dynamic-security/plugin.c
@@ -50,7 +50,11 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, s
if(dynsec_data.config_file == NULL){
return MOSQ_ERR_NOMEM;
}
- break;
+ }else if(!strcasecmp(options[i].key, "password_init_file")){
+ dynsec_data.password_init_file = mosquitto_strdup(options[i].value);
+ if(dynsec_data.password_init_file == NULL){
+ return MOSQ_ERR_NOMEM;
+ }
}
}
if(dynsec_data.config_file == NULL){
@@ -82,5 +86,9 @@ int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *options, int
mosquitto_free(dynsec_data.config_file);
dynsec_data.config_file = NULL;
+
+ mosquitto_free(dynsec_data.password_init_file);
+ dynsec_data.password_init_file = NULL;
+
return MOSQ_ERR_SUCCESS;
}
diff --git a/plugins/examples/add-properties/CMakeLists.txt b/plugins/examples/add-properties/CMakeLists.txt
index afc4d4ef..3f6c689b 100644
--- a/plugins/examples/add-properties/CMakeLists.txt
+++ b/plugins/examples/add-properties/CMakeLists.txt
@@ -7,7 +7,6 @@ add_library(${PLUGIN_NAME} MODULE
target_include_directories(${PLUGIN_NAME} PRIVATE
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
- "${mosquitto_SOURCE_DIR}"
"${mosquitto_SOURCE_DIR}/include"
)
diff --git a/plugins/examples/client-lifetime-stats/CMakeLists.txt b/plugins/examples/client-lifetime-stats/CMakeLists.txt
index 6e4fe0fb..bfd43fef 100644
--- a/plugins/examples/client-lifetime-stats/CMakeLists.txt
+++ b/plugins/examples/client-lifetime-stats/CMakeLists.txt
@@ -7,7 +7,6 @@ add_library(${PLUGIN_NAME} MODULE
target_include_directories(${PLUGIN_NAME} PRIVATE
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
- "${mosquitto_SOURCE_DIR}"
"${mosquitto_SOURCE_DIR}/deps"
"${mosquitto_SOURCE_DIR}/include"
)
diff --git a/plugins/examples/message-timestamp/CMakeLists.txt b/plugins/examples/message-timestamp/CMakeLists.txt
index 8a674285..ad74d786 100644
--- a/plugins/examples/message-timestamp/CMakeLists.txt
+++ b/plugins/examples/message-timestamp/CMakeLists.txt
@@ -7,7 +7,6 @@ add_library(${PLUGIN_NAME} MODULE
target_include_directories(${PLUGIN_NAME} PRIVATE
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
- "${mosquitto_SOURCE_DIR}"
"${mosquitto_SOURCE_DIR}/include"
)
diff --git a/plugins/examples/payload-size-stats/CMakeLists.txt b/plugins/examples/payload-size-stats/CMakeLists.txt
index f3c62875..32dd35da 100644
--- a/plugins/examples/payload-size-stats/CMakeLists.txt
+++ b/plugins/examples/payload-size-stats/CMakeLists.txt
@@ -7,7 +7,6 @@ add_library(${PLUGIN_NAME} MODULE
target_include_directories(${PLUGIN_NAME} PRIVATE
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
- "${mosquitto_SOURCE_DIR}"
"${mosquitto_SOURCE_DIR}/include"
)
diff --git a/plugins/examples/plugin-event-stats/CMakeLists.txt b/plugins/examples/plugin-event-stats/CMakeLists.txt
index 972994a3..316fde29 100644
--- a/plugins/examples/plugin-event-stats/CMakeLists.txt
+++ b/plugins/examples/plugin-event-stats/CMakeLists.txt
@@ -7,7 +7,6 @@ add_library(${PLUGIN_NAME} MODULE
target_include_directories(${PLUGIN_NAME} PRIVATE
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
- "${mosquitto_SOURCE_DIR}"
"${mosquitto_SOURCE_DIR}/include"
)
diff --git a/plugins/examples/print-ip-on-publish/CMakeLists.txt b/plugins/examples/print-ip-on-publish/CMakeLists.txt
index 1cf4b30d..2b01eb3e 100644
--- a/plugins/examples/print-ip-on-publish/CMakeLists.txt
+++ b/plugins/examples/print-ip-on-publish/CMakeLists.txt
@@ -7,7 +7,6 @@ add_library(${PLUGIN_NAME} MODULE
target_include_directories(${PLUGIN_NAME} PRIVATE
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
- "${mosquitto_SOURCE_DIR}"
"${mosquitto_SOURCE_DIR}/include"
)
diff --git a/plugins/persist-sqlite/CMakeLists.txt b/plugins/persist-sqlite/CMakeLists.txt
index b20b6388..ea3571a9 100644
--- a/plugins/persist-sqlite/CMakeLists.txt
+++ b/plugins/persist-sqlite/CMakeLists.txt
@@ -2,7 +2,6 @@ if(SQLITE3_FOUND AND CJSON_FOUND)
set(CLIENT_INC
"${STDBOOL_H_PATH}"
"${STDINT_H_PATH}"
- "${mosquitto_SOURCE_DIR}"
"${mosquitto_SOURCE_DIR}/deps"
"${mosquitto_SOURCE_DIR}/include"
"${mosquitto_SOURCE_DIR}/src"
diff --git a/plugins/persist-sqlite/plugin.c b/plugins/persist-sqlite/plugin.c
index 809896ec..eb5eb099 100644
--- a/plugins/persist-sqlite/plugin.c
+++ b/plugins/persist-sqlite/plugin.c
@@ -31,6 +31,8 @@ Contributors:
#include "persist_sqlite.h"
+MOSQUITTO_PLUGIN_DECLARE_VERSION(5);
+
static mosquitto_plugin_id_t *plg_id = NULL;
static struct mosquitto_sqlite plg_data;
@@ -57,16 +59,32 @@ static void set_defaults(void)
plg_data.page_size = 4 * 1024;
}
-int mosquitto_plugin_version(int supported_version_count, const int *supported_versions)
+static int get_db_file(struct mosquitto_opt *options, int option_count)
{
+ const char *persistence_location;
int i;
- for(i=0; iout_packet = NULL;
context->out_packet_last = NULL;
+ G_OUT_PACKET_COUNT_DEC(context->out_packet_count);
+ G_OUT_PACKET_BYTES_DEC(context->out_packet_bytes);
context->out_packet_count = 0;
+ context->out_packet_bytes = 0;
packet__cleanup(&(context->in_packet));
}
diff --git a/src/conf.c b/src/conf.c
index 0aa89be5..9e61e115 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -1365,12 +1365,12 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "bridge_tcp_user_timeout")){
-#if defined(WITH_BRIDGE) && defined(WITH_TCP_USER_TIMEOUT)
+#ifdef WITH_BRIDGE
if(!cur_bridge){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
-
+#ifdef TCP_USER_TIMEOUT
if(conf__parse_int(&token, "bridge_tcp_user_timeout", &tmp_int, &saveptr)) return MOSQ_ERR_INVAL;
if(tmp_int < 0) {
log__printf(NULL, MOSQ_LOG_ERR, "Error: invalid TCP user timeout value.");
@@ -1378,7 +1378,10 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
}
cur_bridge->tcp_user_timeout = tmp_int;
#else
- log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge and/or TCP user timeout support not available.");
+ log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge TCP user timeout support not available.");
+#endif
+#else
+ log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "bridge_tls_use_os_certs")){
#if defined(WITH_BRIDGE) && defined(WITH_TLS)
diff --git a/src/context.c b/src/context.c
index 9d3a07ec..75883a19 100644
--- a/src/context.c
+++ b/src/context.c
@@ -29,6 +29,7 @@ Contributors:
#include "memory_mosq.h"
#include "packet_mosq.h"
#include "property_mosq.h"
+#include "sys_tree.h"
#include "time_mosq.h"
#include "util_mosq.h"
#include "will_mosq.h"
@@ -99,6 +100,7 @@ struct mosquitto *context__init(void)
packet__cleanup(&context->in_packet);
context->out_packet = NULL;
context->out_packet_count = 0;
+ context->out_packet_bytes = 0;
context->address = NULL;
context->bridge = NULL;
@@ -163,7 +165,10 @@ void context__cleanup(struct mosquitto *context, bool force_free)
context->out_packet = context->out_packet->next;
mosquitto__FREE(packet);
}
+ G_OUT_PACKET_COUNT_DEC(context->out_packet_count);
+ G_OUT_PACKET_BYTES_DEC(context->out_packet_bytes);
context->out_packet_count = 0;
+ context->out_packet_bytes = 0;
#if defined(WITH_BROKER) && defined(__GLIBC__) && defined(WITH_ADNS)
if(context->adns){
gai_cancel(context->adns);
@@ -219,7 +224,7 @@ void context__disconnect(struct mosquitto *context)
return;
}
-#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == LWS_IS_BUILTIN
+#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
if(context->transport == mosq_t_ws){
uint8_t buf[4] = {0x88, 0x02, 0x03, context->wsd.disconnect_reason};
/* Send the disconnect reason, but don't care if it fails */
diff --git a/src/handle_connect.c b/src/handle_connect.c
index 676cfff8..18ed4679 100644
--- a/src/handle_connect.c
+++ b/src/handle_connect.c
@@ -460,6 +460,114 @@ static int check_protocol_version(struct mosquitto__listener *listener, int prot
}
+#ifdef WITH_TLS
+static int get_username_from_cert(struct mosquitto *context)
+{
+ int i;
+ X509 *client_cert = NULL;
+ X509_NAME *name;
+ X509_NAME_ENTRY *name_entry;
+ ASN1_STRING *name_asn1 = NULL;
+ BIO *subject_bio;
+ char *data_start;
+ long name_length;
+ char *subject;
+
+ client_cert = SSL_get_peer_certificate(context->ssl);
+ if(!client_cert){
+ if(context->protocol == mosq_p_mqtt5){
+ send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
+ }else{
+ send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
+ }
+ return MOSQ_ERR_AUTH;
+ }
+ name = X509_get_subject_name(client_cert);
+ if(!name){
+ if(context->protocol == mosq_p_mqtt5){
+ send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
+ }else{
+ send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
+ }
+ X509_free(client_cert);
+ return MOSQ_ERR_AUTH;
+ }
+ if(context->listener->use_identity_as_username){ /* use_identity_as_username */
+ i = X509_NAME_get_index_by_NID(name, NID_commonName, -1);
+ if(i == -1){
+ if(context->protocol == mosq_p_mqtt5){
+ send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
+ }else{
+ send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
+ }
+ X509_free(client_cert);
+ return MOSQ_ERR_AUTH;
+ }
+ name_entry = X509_NAME_get_entry(name, i);
+ if(name_entry){
+ name_asn1 = X509_NAME_ENTRY_get_data(name_entry);
+ if (name_asn1 == NULL) {
+ if(context->protocol == mosq_p_mqtt5){
+ send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
+ }else{
+ send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
+ }
+ X509_free(client_cert);
+ return MOSQ_ERR_AUTH;
+ }
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ context->username = mosquitto__strdup((char *) ASN1_STRING_data(name_asn1));
+#else
+ context->username = mosquitto__strdup((char *) ASN1_STRING_get0_data(name_asn1));
+#endif
+ if(!context->username){
+ if(context->protocol == mosq_p_mqtt5){
+ send__connack(context, 0, MQTT_RC_SERVER_UNAVAILABLE, NULL);
+ }else{
+ send__connack(context, 0, CONNACK_REFUSED_SERVER_UNAVAILABLE, NULL);
+ }
+ X509_free(client_cert);
+ return MOSQ_ERR_NOMEM;
+ }
+ /* Make sure there isn't an embedded NUL character in the CN */
+ if ((size_t)ASN1_STRING_length(name_asn1) != strlen(context->username)) {
+ if(context->protocol == mosq_p_mqtt5){
+ send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
+ }else{
+ send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
+ }
+ X509_free(client_cert);
+ return MOSQ_ERR_AUTH;
+ }
+ }
+ } else { /* use_subject_as_username */
+ subject_bio = BIO_new(BIO_s_mem());
+ X509_NAME_print_ex(subject_bio, X509_get_subject_name(client_cert), 0, XN_FLAG_RFC2253);
+ data_start = NULL;
+ name_length = BIO_get_mem_data(subject_bio, &data_start);
+ subject = mosquitto__malloc(sizeof(char)*(size_t)(name_length+1));
+ if(!subject){
+ BIO_free(subject_bio);
+ X509_free(client_cert);
+ return MOSQ_ERR_NOMEM;
+ }
+ memcpy(subject, data_start, (size_t)name_length);
+ subject[name_length] = '\0';
+ BIO_free(subject_bio);
+ context->username = subject;
+ }
+ if(!context->username){
+ X509_free(client_cert);
+ return MOSQ_ERR_AUTH;
+ }
+ X509_free(client_cert);
+ client_cert = NULL;
+
+ return MOSQ_ERR_SUCCESS;
+}
+#endif
+
+
int handle__connect(struct mosquitto *context)
{
char protocol_name[7];
@@ -479,17 +587,6 @@ int handle__connect(struct mosquitto *context)
void *auth_data_out = NULL;
uint16_t auth_data_out_len = 0;
bool allow_zero_length_clientid;
-#ifdef WITH_TLS
- int i;
- X509 *client_cert = NULL;
- X509_NAME *name;
- X509_NAME_ENTRY *name_entry;
- ASN1_STRING *name_asn1 = NULL;
- BIO *subject_bio;
- char *data_start;
- long name_length;
- char *subject;
-#endif
G_CONNECTION_COUNT_INC();
@@ -807,96 +904,8 @@ int handle__connect(struct mosquitto *context)
}
}else{
#endif /* FINAL_WITH_TLS_PSK */
- client_cert = SSL_get_peer_certificate(context->ssl);
- if(!client_cert){
- if(context->protocol == mosq_p_mqtt5){
- send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
- }else{
- send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
- }
- rc = MOSQ_ERR_AUTH;
- goto handle_connect_error;
- }
- name = X509_get_subject_name(client_cert);
- if(!name){
- if(context->protocol == mosq_p_mqtt5){
- send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
- }else{
- send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
- }
- rc = MOSQ_ERR_AUTH;
- goto handle_connect_error;
- }
- if (context->listener->use_identity_as_username) { /* use_identity_as_username */
- i = X509_NAME_get_index_by_NID(name, NID_commonName, -1);
- if(i == -1){
- if(context->protocol == mosq_p_mqtt5){
- send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
- }else{
- send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
- }
- rc = MOSQ_ERR_AUTH;
- goto handle_connect_error;
- }
- name_entry = X509_NAME_get_entry(name, i);
- if(name_entry){
- name_asn1 = X509_NAME_ENTRY_get_data(name_entry);
- if (name_asn1 == NULL) {
- if(context->protocol == mosq_p_mqtt5){
- send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
- }else{
- send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
- }
- rc = MOSQ_ERR_AUTH;
- goto handle_connect_error;
- }
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
- context->username = mosquitto__strdup((char *) ASN1_STRING_data(name_asn1));
-#else
- context->username = mosquitto__strdup((char *) ASN1_STRING_get0_data(name_asn1));
-#endif
- if(!context->username){
- if(context->protocol == mosq_p_mqtt5){
- send__connack(context, 0, MQTT_RC_SERVER_UNAVAILABLE, NULL);
- }else{
- send__connack(context, 0, CONNACK_REFUSED_SERVER_UNAVAILABLE, NULL);
- }
- rc = MOSQ_ERR_NOMEM;
- goto handle_connect_error;
- }
- /* Make sure there isn't an embedded NUL character in the CN */
- if ((size_t)ASN1_STRING_length(name_asn1) != strlen(context->username)) {
- if(context->protocol == mosq_p_mqtt5){
- send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
- }else{
- send__connack(context, 0, CONNACK_REFUSED_BAD_USERNAME_PASSWORD, NULL);
- }
- rc = MOSQ_ERR_AUTH;
- goto handle_connect_error;
- }
- }
- } else { /* use_subject_as_username */
- subject_bio = BIO_new(BIO_s_mem());
- X509_NAME_print_ex(subject_bio, X509_get_subject_name(client_cert), 0, XN_FLAG_RFC2253);
- data_start = NULL;
- name_length = BIO_get_mem_data(subject_bio, &data_start);
- subject = mosquitto__malloc(sizeof(char)*(size_t)(name_length+1));
- if(!subject){
- BIO_free(subject_bio);
- rc = MOSQ_ERR_NOMEM;
- goto handle_connect_error;
- }
- memcpy(subject, data_start, (size_t)name_length);
- subject[name_length] = '\0';
- BIO_free(subject_bio);
- context->username = subject;
- }
- if(!context->username){
- rc = MOSQ_ERR_AUTH;
- goto handle_connect_error;
- }
- X509_free(client_cert);
- client_cert = NULL;
+ rc = get_username_from_cert(context);
+ if(rc) goto handle_connect_error;
#ifdef FINAL_WITH_TLS_PSK
}
#endif /* FINAL_WITH_TLS_PSK */
@@ -1022,9 +1031,6 @@ handle_connect_error:
mosquitto__FREE(will_struct);
}
context->will = NULL;
-#ifdef WITH_TLS
- if(client_cert) X509_free(client_cert);
-#endif
/* We return an error here which means the client is freed later on. */
context->clean_start = true;
context->session_expiry_interval = 0;
diff --git a/src/loop.c b/src/loop.c
index 51f0acc1..a8b9ce0c 100644
--- a/src/loop.c
+++ b/src/loop.c
@@ -57,7 +57,7 @@ Contributors:
extern int g_run;
-#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_WEBSOCKETS && LWS_LIBRARY_VERSION_NUMBER == 3002000
+#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS && LWS_LIBRARY_VERSION_NUMBER == 3002000
void lws__sul_callback(struct lws_sorted_usec_list *l)
{
}
@@ -175,7 +175,7 @@ int mosquitto_main_loop(struct mosquitto__listener_sock *listensock, int listens
int rc;
-#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_WEBSOCKETS && LWS_LIBRARY_VERSION_NUMBER == 3002000
+#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS && LWS_LIBRARY_VERSION_NUMBER == 3002000
memset(&sul, 0, sizeof(struct lws_sorted_usec_list));
#endif
diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h
index f1e0b2c3..fb864c6a 100644
--- a/src/mosquitto_broker_internal.h
+++ b/src/mosquitto_broker_internal.h
@@ -977,7 +977,6 @@ int http__context_init(struct mosquitto *context);
int http__context_cleanup(struct mosquitto *context);
int http__read(struct mosquitto *context);
int http__write(struct mosquitto *context);
-void ws__context_init(struct mosquitto *context);
#endif
void do_disconnect(struct mosquitto *context, int reason);
diff --git a/src/plugin_public.c b/src/plugin_public.c
index 0da33858..1568911b 100644
--- a/src/plugin_public.c
+++ b/src/plugin_public.c
@@ -323,6 +323,7 @@ BROKER_EXPORT int mosquitto_set_clientid(struct mosquitto *client, const char *c
struct mosquitto *found_client;
char *id_dup;
bool in_by_id;
+ int clientid_len;
if(!client || !clientid) return MOSQ_ERR_INVAL;
@@ -343,7 +344,7 @@ BROKER_EXPORT int mosquitto_set_clientid(struct mosquitto *client, const char *c
}
}
- int clientid_len = (int)strlen(clientid);
+ clientid_len = (int)strlen(clientid);
if(mosquitto_validate_utf8(clientid, clientid_len)){
return MOSQ_ERR_INVAL;
}
@@ -601,7 +602,7 @@ BROKER_EXPORT int mosquitto_persist_client_delete(const char *client_id)
}
-struct mosquitto_base_msg *find_store_msg(uint64_t store_id)
+static struct mosquitto_base_msg *find_store_msg(uint64_t store_id)
{
struct mosquitto_base_msg *base_msg;
diff --git a/src/sys_tree.c b/src/sys_tree.c
index bd03787f..599f5f38 100644
--- a/src/sys_tree.c
+++ b/src/sys_tree.c
@@ -37,11 +37,13 @@ uint64_t g_bytes_received = 0;
uint64_t g_bytes_sent = 0;
uint64_t g_pub_bytes_received = 0;
uint64_t g_pub_bytes_sent = 0;
+int64_t g_out_packet_bytes = 0;
unsigned long g_msgs_received = 0;
unsigned long g_msgs_sent = 0;
unsigned long g_pub_msgs_received = 0;
unsigned long g_pub_msgs_sent = 0;
unsigned long g_msgs_dropped = 0;
+long g_out_packet_count = 0;
unsigned int g_clients_expired = 0;
unsigned int g_socket_connections = 0;
unsigned int g_connection_count = 0;
@@ -179,6 +181,8 @@ void sys_tree__update(void)
static int subscription_count = INT_MAX;
static int shared_subscription_count = INT_MAX;
static int retained_count = INT_MAX;
+ static long out_packet_count = LONG_MAX;
+ static long long out_packet_bytes = LLONG_MAX;
static double msgs_received_load1 = 0;
static double msgs_received_load5 = 0;
@@ -391,6 +395,18 @@ void sys_tree__update(void)
db__messages_easy_queue(NULL, "$SYS/broker/publish/bytes/sent", SYS_TREE_QOS, len, buf, 1, 60, NULL);
}
+ if(out_packet_count != g_out_packet_count){
+ out_packet_count = g_out_packet_count;
+ len = (uint32_t)snprintf(buf, BUFLEN, "%lu", out_packet_count);
+ db__messages_easy_queue(NULL, "$SYS/broker/packet/out/count", SYS_TREE_QOS, len, buf, 1, 60, NULL);
+ }
+
+ if(out_packet_bytes != g_out_packet_bytes){
+ out_packet_bytes = g_out_packet_bytes;
+ len = (uint32_t)snprintf(buf, BUFLEN, "%llu", out_packet_bytes);
+ db__messages_easy_queue(NULL, "$SYS/broker/packet/out/bytes", SYS_TREE_QOS, len, buf, 1, 60, NULL);
+ }
+
last_update = db.now_s;
}
}
diff --git a/src/sys_tree.h b/src/sys_tree.h
index d0d91200..ed5e7a21 100644
--- a/src/sys_tree.h
+++ b/src/sys_tree.h
@@ -24,11 +24,13 @@ extern uint64_t g_bytes_received;
extern uint64_t g_bytes_sent;
extern uint64_t g_pub_bytes_received;
extern uint64_t g_pub_bytes_sent;
+extern int64_t g_out_packet_bytes;
extern unsigned long g_msgs_received;
extern unsigned long g_msgs_sent;
extern unsigned long g_pub_msgs_received;
extern unsigned long g_pub_msgs_sent;
extern unsigned long g_msgs_dropped;
+extern long g_out_packet_count;
extern unsigned int g_clients_expired;
extern unsigned int g_socket_connections;
extern unsigned int g_connection_count;
@@ -45,6 +47,10 @@ extern unsigned int g_connection_count;
#define G_CLIENTS_EXPIRED_INC() (g_clients_expired++)
#define G_SOCKET_CONNECTIONS_INC() (g_socket_connections++)
#define G_CONNECTION_COUNT_INC() (g_connection_count++)
+#define G_OUT_PACKET_COUNT_INC(A) (g_out_packet_count+=(A))
+#define G_OUT_PACKET_COUNT_DEC(A) (g_out_packet_count-=(A))
+#define G_OUT_PACKET_BYTES_INC(A) (g_out_packet_bytes+=(A))
+#define G_OUT_PACKET_BYTES_DEC(A) (g_out_packet_bytes-=(A))
#else
@@ -60,6 +66,10 @@ extern unsigned int g_connection_count;
#define G_CLIENTS_EXPIRED_INC()
#define G_SOCKET_CONNECTIONS_INC()
#define G_CONNECTION_COUNT_INC()
+#define G_OUT_PACKET_COUNT_INC(A)
+#define G_OUT_PACKET_COUNT_DEC(A)
+#define G_OUT_PACKET_BYTES_INC(A)
+#define G_OUT_PACKET_BYTES_DEC(A)
#endif
diff --git a/src/xtreport.c b/src/xtreport.c
index a9093b06..67334abf 100644
--- a/src/xtreport.c
+++ b/src/xtreport.c
@@ -43,13 +43,7 @@ static void client_cost(FILE *fptr, struct mosquitto *context, int fn_index)
long tBytes;
pkt_count = 1;
- pkt_bytes = context->in_packet.packet_length;
- pkt_tmp = context->out_packet;
- while(pkt_tmp){
- pkt_count++;
- pkt_bytes += pkt_tmp->packet_length;
- pkt_tmp = pkt_tmp->next;
- }
+ pkt_bytes = context->in_packet.packet_length + context->out_packet_bytes;
cmsg_count = context->msgs_in.inflight_count + context->msgs_in.queued_count;
cmsg_bytes = context->msgs_in.inflight_bytes + context->msgs_in.queued_bytes;
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 00000000..c1282179
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_subdirectory(broker)
+add_subdirectory(client)
+add_subdirectory(lib)
+add_subdirectory(unit)
diff --git a/test/broker/01-connect-global-max-clients.py b/test/broker/01-connect-global-max-clients.py
index 3adc64bc..395aa34a 100755
--- a/test/broker/01-connect-global-max-clients.py
+++ b/test/broker/01-connect-global-max-clients.py
@@ -37,7 +37,7 @@ def do_test():
# Try to open an 11th connection
try:
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
- except ConnectionResetError:
+ except (ConnectionResetError, BrokenPipeError):
# Expected behaviour
pass
@@ -50,7 +50,7 @@ def do_test():
# Try to open an 11th connection
try:
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
- except ConnectionResetError:
+ except (ConnectionResetError, BrokenPipeError):
# Expected behaviour
pass
@@ -68,7 +68,6 @@ def do_test():
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
- exit(rc)
+ return rc
-do_test()
-exit(0)
+sys.exit(do_test())
diff --git a/test/broker/01-connect-global-max-connections.py b/test/broker/01-connect-global-max-connections.py
index b7f5fafa..e612f534 100755
--- a/test/broker/01-connect-global-max-connections.py
+++ b/test/broker/01-connect-global-max-connections.py
@@ -36,7 +36,7 @@ def do_test():
# Try to open an 11th connection
try:
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
- except ConnectionResetError:
+ except (ConnectionResetError, BrokenPipeError):
# Expected behaviour
pass
@@ -53,7 +53,7 @@ def do_test():
# Try to open an 11th connection
try:
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
- except ConnectionResetError:
+ except (ConnectionResetError, BrokenPipeError):
# Expected behaviour
pass
@@ -75,7 +75,6 @@ def do_test():
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
- exit(rc)
+ return rc
-do_test()
-exit(0)
+sys.exit(do_test())
diff --git a/test/broker/01-connect-max-connections.py b/test/broker/01-connect-max-connections.py
index ab410ea9..cfac7fb6 100755
--- a/test/broker/01-connect-max-connections.py
+++ b/test/broker/01-connect-max-connections.py
@@ -36,7 +36,7 @@ def do_test():
# Try to open an 11th connection
try:
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
- except ConnectionResetError:
+ except (ConnectionResetError, BrokenPipeError):
# Expected behaviour
pass
@@ -53,7 +53,7 @@ def do_test():
# Try to open an 11th connection
try:
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
- except ConnectionResetError:
+ except (ConnectionResetError, BrokenPipeError):
# Expected behaviour
pass
@@ -75,7 +75,6 @@ def do_test():
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
- exit(rc)
+ return rc
-do_test()
-exit(0)
+sys.exit(do_test())
diff --git a/test/broker/01-connect-uname-no-password-denied.py b/test/broker/01-connect-uname-no-password-denied.py
index c1cf6fee..fc7210d9 100755
--- a/test/broker/01-connect-uname-no-password-denied.py
+++ b/test/broker/01-connect-uname-no-password-denied.py
@@ -8,7 +8,7 @@ from mosq_test_helper import *
def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
- f.write("password_file %s\n" % (filename.replace('.conf', '.pwfile')))
+ f.write("password_file %s/%s\n" % (Path(__file__).resolve().parent, filename.replace('.conf', '.pwfile')))
f.write("allow_anonymous false\n")
diff --git a/test/broker/01-connect-uname-or-anon.py b/test/broker/01-connect-uname-or-anon.py
index 02f505d5..12eec9cb 100755
--- a/test/broker/01-connect-uname-or-anon.py
+++ b/test/broker/01-connect-uname-or-anon.py
@@ -12,7 +12,7 @@ def write_config(filename, port, allow_anonymous, password_file):
else:
f.write("allow_anonymous false\n")
if password_file:
- f.write("password_file %s\n" % (filename.replace('.conf', '.pwfile')))
+ f.write("password_file %s/%s\n" % (Path(__file__).resolve().parent, filename.replace('.conf', '.pwfile')))
def do_test(allow_anonymous, password_file, username, expect_success):
port = mosq_test.get_port()
diff --git a/test/broker/01-connect-uname-password-denied.py b/test/broker/01-connect-uname-password-denied.py
index f2836c63..2394bfad 100755
--- a/test/broker/01-connect-uname-password-denied.py
+++ b/test/broker/01-connect-uname-password-denied.py
@@ -8,7 +8,7 @@ from mosq_test_helper import *
def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
- f.write("password_file %s\n" % (filename.replace('.conf', '.pwfile')))
+ f.write("password_file %s/%s\n" % (Path(__file__).resolve().parent, filename.replace('.conf', '.pwfile')))
f.write("allow_anonymous false\n")
diff --git a/test/broker/01-connect-uname-password-success-no-tls.py b/test/broker/01-connect-uname-password-success-no-tls.py
index cbfdd68e..1f443789 100755
--- a/test/broker/01-connect-uname-password-success-no-tls.py
+++ b/test/broker/01-connect-uname-password-success-no-tls.py
@@ -8,7 +8,7 @@ from mosq_test_helper import *
def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
- f.write("password_file %s\n" % (filename.replace('.conf', '.pwfile')))
+ f.write("password_file %s/%s\n" % (Path(__file__).resolve().parent, filename.replace('.conf', '.pwfile')))
f.write("allow_anonymous false\n")
diff --git a/test/broker/01-connect-unix-socket.py b/test/broker/01-connect-unix-socket.py
index 013ea95c..b46d8855 100755
--- a/test/broker/01-connect-unix-socket.py
+++ b/test/broker/01-connect-unix-socket.py
@@ -7,7 +7,7 @@ from mosq_test_helper import *
vg_index = 0
def start_broker(filename):
global vg_index
- cmd = ['../../src/mosquitto', '-v', '-c', filename]
+ cmd = [mosq_test.get_build_root() + '/src/mosquitto', '-v', '-c', filename]
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
logfile = os.path.basename(__file__)+'.'+str(vg_index)+'.vglog'
diff --git a/test/broker/02-subpub-qos0-long-topic.py b/test/broker/02-subpub-qos0-long-topic.py
index ae66847c..137013fb 100755
--- a/test/broker/02-subpub-qos0-long-topic.py
+++ b/test/broker/02-subpub-qos0-long-topic.py
@@ -16,25 +16,28 @@ def do_test(start_broker, topic, succeeds):
publish_packet = mosq_test.gen_publish(topic, qos=0, payload="message")
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
- if succeeds == True:
+ if succeeds:
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
mosq_test.do_send_receive(sock, publish_packet, publish_packet, "publish")
else:
- mosq_test.do_send_receive(sock, subscribe_packet, b"", "suback")
+ try:
+ mosq_test.do_send_receive(sock, subscribe_packet, b"", "suback")
+ return 1
+ except BrokenPipeError:
+ pass
rc = 0
sock.close()
- except mosq_test.TestError:
- pass
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -42,26 +45,24 @@ def do_test(start_broker, topic, succeeds):
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, "/"*200, True) # 200 max hierarchy limit
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, "abc/"*199+"d", True) # 200 max hierarchy limit, longer overall string than 200
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, "/"*201, False) # Exceeds 200 max hierarchy limit
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, "abc/"*201+"d", False) # Exceeds 200 max hierarchy limit, longer overall string than 200
if rc:
- return rc;
+ return rc
return 0
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/02-subscribe-invalid-utf8.py b/test/broker/02-subscribe-invalid-utf8.py
index d204207e..1b60bfa5 100755
--- a/test/broker/02-subscribe-invalid-utf8.py
+++ b/test/broker/02-subscribe-invalid-utf8.py
@@ -15,27 +15,26 @@ def do_test(start_broker, proto_ver):
b[13] = 0 # Topic should never have a 0x0000
subscribe_packet = struct.pack("B"*len(b), *b)
- suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)
-
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
if proto_ver == 4:
- mosq_test.do_send_receive(sock, subscribe_packet, b"", "suback")
+ try:
+ mosq_test.do_send_receive(sock, subscribe_packet, b"", "suback")
+ except BrokenPipeError:
+ rc = 0
else:
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code = mqtt5_rc.MQTT_RC_MALFORMED_PACKET)
mosq_test.do_send_receive(sock, subscribe_packet, disconnect_packet, "suback")
-
- rc = 0
+ rc = 0
sock.close()
- except mosq_test.TestError:
- pass
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -44,19 +43,17 @@ def do_test(start_broker, proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, proto_ver=4)
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, proto_ver=5)
if rc:
- return rc;
+ return rc
return 0
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/02-subscribe-long-topic.py b/test/broker/02-subscribe-long-topic.py
index 08b82971..fe5016e0 100755
--- a/test/broker/02-subscribe-long-topic.py
+++ b/test/broker/02-subscribe-long-topic.py
@@ -13,27 +13,27 @@ def do_test(start_broker, proto_ver):
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
subscribe_packet = mosq_test.gen_subscribe(mid, "/"*65535, 0, proto_ver=proto_ver)
- suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
if proto_ver == 4:
- mosq_test.do_send_receive(sock, subscribe_packet, b"", "suback")
+ try:
+ mosq_test.do_send_receive(sock, subscribe_packet, b"", "suback")
+ except BrokenPipeError:
+ rc = 0
else:
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code = mqtt5_rc.MQTT_RC_MALFORMED_PACKET)
mosq_test.do_send_receive(sock, subscribe_packet, disconnect_packet, "suback")
-
- rc = 0
+ rc = 0
sock.close()
- except mosq_test.TestError:
- pass
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -42,19 +42,17 @@ def do_test(start_broker, proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, proto_ver=4)
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, proto_ver=5)
if rc:
- return rc;
+ return rc
return 0
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/03-publish-invalid-utf8.py b/test/broker/03-publish-invalid-utf8.py
index 876972a3..5d77775d 100755
--- a/test/broker/03-publish-invalid-utf8.py
+++ b/test/broker/03-publish-invalid-utf8.py
@@ -15,27 +15,26 @@ def do_test(start_broker, proto_ver):
b[11] = 0 # Topic should never have a 0x0000
publish_packet = struct.pack("B"*len(b), *b)
- puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
-
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
if proto_ver == 4:
- mosq_test.do_send_receive(sock, publish_packet, b"", "puback")
+ try:
+ mosq_test.do_send_receive(sock, publish_packet, b"", "puback")
+ except BrokenPipeError:
+ rc = 0
else:
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code=mqtt5_rc.MQTT_RC_MALFORMED_PACKET)
mosq_test.do_send_receive(sock, publish_packet, disconnect_packet, "puback")
-
- rc = 0
+ rc = 0
sock.close()
- except mosq_test.TestError:
- pass
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -44,19 +43,17 @@ def do_test(start_broker, proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, proto_ver=4)
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, proto_ver=5)
if rc:
- return rc;
+ return rc
return 0
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/03-publish-long-topic.py b/test/broker/03-publish-long-topic.py
index c89ee0da..a14c34ed 100755
--- a/test/broker/03-publish-long-topic.py
+++ b/test/broker/03-publish-long-topic.py
@@ -14,27 +14,27 @@ def do_test(start_broker, proto_ver):
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
publish_packet = mosq_test.gen_publish("/"*65535, qos=1, mid=mid, payload="message", proto_ver=proto_ver)
- puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
if proto_ver == 4:
- mosq_test.do_send_receive(sock, publish_packet, b"", "puback")
+ try:
+ mosq_test.do_send_receive(sock, publish_packet, b"", "puback")
+ except BrokenPipeError:
+ rc = 0
else:
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code=mqtt5_rc.MQTT_RC_MALFORMED_PACKET)
mosq_test.do_send_receive(sock, publish_packet, disconnect_packet, "puback")
-
- rc = 0
+ rc = 0
sock.close()
- except mosq_test.TestError:
- pass
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -43,19 +43,17 @@ def do_test(start_broker, proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, proto_ver=4)
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, proto_ver=5)
if rc:
- return rc;
+ return rc
return 0
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/03-publish-qos2-max-inflight-exceeded.py b/test/broker/03-publish-qos2-max-inflight-exceeded.py
index f2d9746a..aa2bd635 100755
--- a/test/broker/03-publish-qos2-max-inflight-exceeded.py
+++ b/test/broker/03-publish-qos2-max-inflight-exceeded.py
@@ -27,13 +27,14 @@ def do_test(proto_ver):
disconnect_packet = mosq_test.gen_disconnect(reason_code=mqtt5_rc.MQTT_RC_RECEIVE_MAXIMUM_EXCEEDED, proto_ver=proto_ver)
else:
disconnect_packet = b""
- mosq_test.do_send_receive(sock, publish_packet, disconnect_packet, "disconnect")
+ try:
+ mosq_test.do_send_receive(sock, publish_packet, disconnect_packet, "disconnect")
+ except BrokenPipeError:
+ pass
rc = 0
sock.close()
- except mosq_test.TestError:
- pass
finally:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
@@ -43,9 +44,15 @@ def do_test(proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
+ return rc
-do_test(proto_ver=4)
-do_test(proto_ver=5)
-exit(0)
+def all_test():
+ rc = do_test(proto_ver=4)
+ if rc:
+ return rc
+ rc = do_test(proto_ver=5)
+ return rc
+
+if __name__ == "__main__":
+ sys.exit(all_test())
diff --git a/test/broker/06-bridge-b2br-disconnect-qos1.py b/test/broker/06-bridge-b2br-disconnect-qos1.py
index 6efb8984..bf849925 100755
--- a/test/broker/06-bridge-b2br-disconnect-qos1.py
+++ b/test/broker/06-bridge-b2br-disconnect-qos1.py
@@ -83,7 +83,7 @@ def do_test(proto_ver):
(bridge, address) = ssock.accept()
bridge.settimeout(20)
- mosq_test.expect_packet(bridge, "connect", connect_packet)
+ mosq_test.expect_packet(bridge, "2nd connect", connect_packet)
bridge.send(connack_packet)
mosq_test.expect_packet(bridge, "2nd subscribe", subscribe2_packet)
diff --git a/test/broker/06-bridge-clean-session-csF-lcsF.py b/test/broker/06-bridge-clean-session-csF-lcsF.py
index 6db46cfa..97675cc1 100755
--- a/test/broker/06-bridge-clean-session-csF-lcsF.py
+++ b/test/broker/06-bridge-clean-session-csF-lcsF.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
# Test whether a broker handles cleansession and local_cleansession correctly on bridges
-from mosq_test_helper import *
from collections import namedtuple
-(port_a_listen, port_b_listen) = mosq_test.get_port(2)
-subprocess.run(['./06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "False", "False"])
+from mosq_test_helper import *
+(port_a_listen, port_b_listen) = mosq_test.get_port(2)
+subprocess.run([f'{Path(__file__).resolve().parent}/06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "False", "False"])
diff --git a/test/broker/06-bridge-clean-session-csF-lcsN.py b/test/broker/06-bridge-clean-session-csF-lcsN.py
index aab8255c..72ca1a13 100755
--- a/test/broker/06-bridge-clean-session-csF-lcsN.py
+++ b/test/broker/06-bridge-clean-session-csF-lcsN.py
@@ -5,5 +5,5 @@ from mosq_test_helper import *
from collections import namedtuple
(port_a_listen, port_b_listen) = mosq_test.get_port(2)
-subprocess.run(['./06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "False", "None"])
+subprocess.run([f'{Path(__file__).resolve().parent}/06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "False", "None"])
diff --git a/test/broker/06-bridge-clean-session-csF-lcsT.py b/test/broker/06-bridge-clean-session-csF-lcsT.py
index 005434a1..c54f22d4 100755
--- a/test/broker/06-bridge-clean-session-csF-lcsT.py
+++ b/test/broker/06-bridge-clean-session-csF-lcsT.py
@@ -5,5 +5,5 @@ from mosq_test_helper import *
from collections import namedtuple
(port_a_listen, port_b_listen) = mosq_test.get_port(2)
-subprocess.run(['./06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "False", "True"])
+subprocess.run([f'{Path(__file__).resolve().parent}/06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "False", "True"])
diff --git a/test/broker/06-bridge-clean-session-csT-lcsF.py b/test/broker/06-bridge-clean-session-csT-lcsF.py
index fe6a810d..d73a7484 100755
--- a/test/broker/06-bridge-clean-session-csT-lcsF.py
+++ b/test/broker/06-bridge-clean-session-csT-lcsF.py
@@ -5,5 +5,5 @@ from mosq_test_helper import *
from collections import namedtuple
(port_a_listen, port_b_listen) = mosq_test.get_port(2)
-subprocess.run(['./06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "True", "False"])
+subprocess.run([f'{Path(__file__).resolve().parent}/06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "True", "False"])
diff --git a/test/broker/06-bridge-clean-session-csT-lcsN.py b/test/broker/06-bridge-clean-session-csT-lcsN.py
index 8afa8700..7508bd67 100755
--- a/test/broker/06-bridge-clean-session-csT-lcsN.py
+++ b/test/broker/06-bridge-clean-session-csT-lcsN.py
@@ -5,5 +5,5 @@ from mosq_test_helper import *
from collections import namedtuple
(port_a_listen, port_b_listen) = mosq_test.get_port(2)
-subprocess.run(['./06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "True", "None"])
+subprocess.run([f'{Path(__file__).resolve().parent}/06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "True", "None"])
diff --git a/test/broker/06-bridge-clean-session-csT-lcsT.py b/test/broker/06-bridge-clean-session-csT-lcsT.py
index 9e2d8257..516e23f9 100755
--- a/test/broker/06-bridge-clean-session-csT-lcsT.py
+++ b/test/broker/06-bridge-clean-session-csT-lcsT.py
@@ -5,5 +5,5 @@ from mosq_test_helper import *
from collections import namedtuple
(port_a_listen, port_b_listen) = mosq_test.get_port(2)
-subprocess.run(['./06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "True", "True"])
+subprocess.run([f'{Path(__file__).resolve().parent}/06-bridge-clean-session-core.py', str(port_a_listen), str(port_b_listen), "True", "True"])
diff --git a/test/broker/06-bridge-reconnect-local-out.py b/test/broker/06-bridge-reconnect-local-out.py
index 2dc150ad..c40777a8 100755
--- a/test/broker/06-bridge-reconnect-local-out.py
+++ b/test/broker/06-bridge-reconnect-local-out.py
@@ -48,7 +48,7 @@ def do_test(proto_ver):
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port1, use_conf=False)
- local_cmd = ['../../src/mosquitto', '-c', '06-bridge-reconnect-local-out.conf']
+ local_cmd = [mosq_test.get_build_root() + '/src/mosquitto', '-c', '06-bridge-reconnect-local-out.conf']
local_broker = mosq_test.start_broker(cmd=local_cmd, filename=os.path.basename(__file__)+'_local1', use_conf=False, port=port2)
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
time.sleep(5)
diff --git a/test/broker/07-will-delay-invalid-573191.py b/test/broker/07-will-delay-invalid-573191.py
index 16b00fa0..75368f3c 100755
--- a/test/broker/07-will-delay-invalid-573191.py
+++ b/test/broker/07-will-delay-invalid-573191.py
@@ -8,7 +8,6 @@ from mosq_test_helper import *
def do_test():
rc = 1
- mid = 1
props = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_WILL_DELAY_INTERVAL, 3)
connect_packet = mosq_test.gen_connect("will-573191-test", proto_ver=5, will_topic="", will_properties=props)
connack_packet = b""
@@ -19,6 +18,7 @@ def do_test():
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=30, port=port)
sock.close()
+ except BrokenPipeError:
rc = 0
finally:
broker.terminate()
@@ -28,6 +28,6 @@ def do_test():
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
- exit(rc)
+ return rc
-do_test()
+sys.exit(do_test())
diff --git a/test/broker/07-will-invalid-utf8.py b/test/broker/07-will-invalid-utf8.py
index 2455df79..299ac16a 100755
--- a/test/broker/07-will-invalid-utf8.py
+++ b/test/broker/07-will-invalid-utf8.py
@@ -6,7 +6,6 @@ from mosq_test_helper import *
def do_test(start_broker, proto_ver):
rc = 1
- mid = 53
connect_packet = mosq_test.gen_connect("will-invalid-utf8", will_topic="will/invalid/utf8", proto_ver=proto_ver)
b = list(struct.unpack("B"*len(connect_packet), connect_packet))
@@ -14,17 +13,17 @@ def do_test(start_broker, proto_ver):
connect_packet = struct.pack("B"*len(b), *b)
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, b"", timeout=30, port=port)
- rc = 0
sock.close()
- except mosq_test.TestError:
- pass
+ except BrokenPipeError:
+ rc = 0
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -33,19 +32,14 @@ def do_test(start_broker, proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, proto_ver=4)
if rc:
- return rc;
- rc = do_test(start_broker, proto_ver=5)
- if rc:
- return rc;
- return 0
+ return rc
+ return do_test(start_broker, proto_ver=5)
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/07-will-no-flag.py b/test/broker/07-will-no-flag.py
index c7355842..105ebbf6 100755
--- a/test/broker/07-will-no-flag.py
+++ b/test/broker/07-will-no-flag.py
@@ -16,17 +16,17 @@ def do_test(start_broker, proto_ver):
connect_packet = struct.pack("B"*len(bmod), *bmod)
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, b"", port=port)
sock.close()
+ except BrokenPipeError:
rc = 0
- except mosq_test.TestError:
- pass
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -35,19 +35,14 @@ def do_test(start_broker, proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, proto_ver=4)
if rc:
- return rc;
- rc = do_test(start_broker, proto_ver=5)
- if rc:
- return rc;
- return 0
+ return rc
+ return do_test(start_broker, proto_ver=5)
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/07-will-null-topic.py b/test/broker/07-will-null-topic.py
index 439a61cd..a32b1aee 100755
--- a/test/broker/07-will-null-topic.py
+++ b/test/broker/07-will-null-topic.py
@@ -7,24 +7,19 @@ from mosq_test_helper import *
def do_test(start_broker, proto_ver):
rc = 1
connect_packet = mosq_test.gen_connect("will-null-topic", will_topic="", will_payload=struct.pack("!4sB7s", b"will", 0, b"message"), proto_ver=proto_ver)
- connack_packet = mosq_test.gen_connack(rc=2, proto_ver=proto_ver)
port = mosq_test.get_port()
+ broker = None
if start_broker:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.do_client_connect(connect_packet, b"", timeout=30, port=port)
- rc = 0
sock.close()
- except socket.error as e:
- if e.errno == errno.ECONNRESET:
- # Connection has been closed by peer, this is the expected behaviour
- rc = 0
- except mosq_test.TestError:
- pass
+ except BrokenPipeError:
+ rc = 0
finally:
- if start_broker:
+ if broker:
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -33,19 +28,17 @@ def do_test(start_broker, proto_ver):
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
- exit(rc)
- else:
- return rc
+ return rc
def all_tests(start_broker=False):
rc = do_test(start_broker, proto_ver=4)
if rc:
- return rc;
+ return rc
rc = do_test(start_broker, proto_ver=5)
if rc:
- return rc;
+ return rc
return 0
if __name__ == '__main__':
- all_tests(True)
+ sys.exit(all_tests(True))
diff --git a/test/broker/08-ssl-bridge.py b/test/broker/08-ssl-bridge.py
index 47cfdefc..9923a2a8 100755
--- a/test/broker/08-ssl-bridge.py
+++ b/test/broker/08-ssl-bridge.py
@@ -2,6 +2,9 @@
from mosq_test_helper import *
+source_dir = Path(__file__).resolve().parent
+ssl_dir = source_dir.parent / "ssl"
+
def write_config(filename, port1, port2):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port2))
@@ -13,7 +16,7 @@ def write_config(filename, port1, port2):
f.write("notifications false\n")
f.write("restart_timeout 2\n")
f.write("\n")
- f.write("bridge_cafile ../ssl/all-ca.crt\n")
+ f.write(f"bridge_cafile {ssl_dir}/all-ca.crt\n")
f.write("bridge_insecure true\n")
(port1, port2) = mosq_test.get_port(2)
@@ -33,7 +36,13 @@ publish_packet = mosq_test.gen_publish("bridge/ssl/test", qos=0, payload="messag
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-ssock = ssl.wrap_socket(sock, ca_certs="../ssl/all-ca.crt", keyfile="../ssl/server.key", certfile="../ssl/server.crt", server_side=True)
+ssock = ssl.wrap_socket(
+ sock,
+ ca_certs=ssl_dir / "all-ca.crt",
+ keyfile=ssl_dir / "server.key",
+ certfile=ssl_dir / "server.crt",
+ server_side=True
+)
ssock.settimeout(20)
ssock.bind(('', port1))
ssock.listen(5)
@@ -50,7 +59,7 @@ try:
mosq_test.expect_packet(bridge, "subscribe", subscribe_packet)
bridge.send(suback_packet)
- pub = subprocess.Popen(['./08-ssl-bridge-helper.py', str(port2)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ pub = subprocess.Popen([f'{source_dir}/08-ssl-bridge-helper.py', str(port2)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pub_terminated = 0
if mosq_test.wait_for_subprocess(pub):
print("pub not terminated")
@@ -80,4 +89,3 @@ finally:
ssock.close()
exit(rc)
-
diff --git a/test/broker/08-ssl-connect-cert-auth-crl.py b/test/broker/08-ssl-connect-cert-auth-crl.py
index d80ef530..85a89f08 100755
--- a/test/broker/08-ssl-connect-cert-auth-crl.py
+++ b/test/broker/08-ssl-connect-cert-auth-crl.py
@@ -12,11 +12,11 @@ def write_config(filename, port1, port2):
f.write("allow_anonymous true\n")
f.write("listener %d\n" % (port1))
f.write("allow_anonymous true\n")
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("require_certificate true\n")
- f.write("crlfile ../ssl/crl.pem\n")
+ f.write(f"crlfile {ssl_dir}/crl.pem\n")
(port1, port2) = mosq_test.get_port(2)
conf_file = os.path.basename(__file__).replace('.py', '.conf')
@@ -30,7 +30,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", certfile="../ssl/client.crt", keyfile="../ssl/client.key", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", certfile=f"{ssl_dir}/client.crt", keyfile=f"{ssl_dir}/client.key", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-cert-auth-expired-allowed.py b/test/broker/08-ssl-connect-cert-auth-expired-allowed.py
index b49b775e..dc6917be 100755
--- a/test/broker/08-ssl-connect-cert-auth-expired-allowed.py
+++ b/test/broker/08-ssl-connect-cert-auth-expired-allowed.py
@@ -13,9 +13,9 @@ def write_config(filename, port1, port2):
f.write("listener %d\n" % (port2))
f.write("\n")
f.write("listener %d\n" % (port1))
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("require_certificate true\n")
f.write("disable_client_cert_date_checks true\n")
f.write("allow_anonymous true\n")
@@ -32,7 +32,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", certfile="../ssl/client-expired.crt", keyfile="../ssl/client-expired.key", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", certfile=f"{ssl_dir}/client-expired.crt", keyfile=f"{ssl_dir}/client-expired.key", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
ssock.connect(("localhost", port1))
mosq_test.do_send_receive(ssock, connect_packet, connack_packet, "connack")
diff --git a/test/broker/08-ssl-connect-cert-auth-expired.py b/test/broker/08-ssl-connect-cert-auth-expired.py
index 9dcbd030..14e6225e 100755
--- a/test/broker/08-ssl-connect-cert-auth-expired.py
+++ b/test/broker/08-ssl-connect-cert-auth-expired.py
@@ -14,9 +14,9 @@ def write_config(filename, port1, port2):
f.write("listener %d\n" % (port2))
f.write("\n")
f.write("listener %d\n" % (port1))
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("require_certificate true\n")
(port1, port2) = mosq_test.get_port(2)
@@ -30,7 +30,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", certfile="../ssl/client-expired.crt", keyfile="../ssl/client-expired.key", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", certfile=f"{ssl_dir}/client-expired.crt", keyfile=f"{ssl_dir}/client-expired.key", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
try:
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-cert-auth-revoked.py b/test/broker/08-ssl-connect-cert-auth-revoked.py
index eb21c732..f7057c5b 100755
--- a/test/broker/08-ssl-connect-cert-auth-revoked.py
+++ b/test/broker/08-ssl-connect-cert-auth-revoked.py
@@ -12,11 +12,11 @@ def write_config(filename, port1, port2):
f.write("allow_anonymous true\n")
f.write("listener %d\n" % (port1))
f.write("allow_anonymous true\n")
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("require_certificate true\n")
- f.write("crlfile ../ssl/crl.pem\n")
+ f.write(f"crlfile {ssl_dir}/crl.pem\n")
(port1, port2) = mosq_test.get_port(2)
conf_file = os.path.basename(__file__).replace('.py', '.conf')
@@ -29,7 +29,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", certfile="../ssl/client-revoked.crt", keyfile="../ssl/client-revoked.key", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", certfile=f"{ssl_dir}/client-revoked.crt", keyfile=f"{ssl_dir}/client-revoked.key", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
try:
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-cert-auth-without.py b/test/broker/08-ssl-connect-cert-auth-without.py
index 3f30e6cd..7377e1bf 100755
--- a/test/broker/08-ssl-connect-cert-auth-without.py
+++ b/test/broker/08-ssl-connect-cert-auth-without.py
@@ -12,9 +12,9 @@ def write_config(filename, port1, port2):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port2))
f.write("listener %d\n" % (port1))
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("require_certificate true\n")
(port1, port2) = mosq_test.get_port(2)
@@ -27,7 +27,7 @@ connect_packet = mosq_test.gen_connect("connect-cert-test")
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2, use_conf=True)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
+ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
try:
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-cert-auth.py b/test/broker/08-ssl-connect-cert-auth.py
index 29ff471b..bd8c93fb 100755
--- a/test/broker/08-ssl-connect-cert-auth.py
+++ b/test/broker/08-ssl-connect-cert-auth.py
@@ -14,9 +14,9 @@ def write_config(filename, port1, port2):
f.write("allow_anonymous true\n")
f.write("listener %d\n" % (port1))
f.write("allow_anonymous true\n")
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("require_certificate true\n")
(port1, port2) = mosq_test.get_port(2)
@@ -31,7 +31,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", certfile="../ssl/client.crt", keyfile="../ssl/client.key", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", certfile=f"{ssl_dir}/client.crt", keyfile=f"{ssl_dir}/client.key", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-identity.py b/test/broker/08-ssl-connect-identity.py
index f9c5a4c5..bd1e76d2 100755
--- a/test/broker/08-ssl-connect-identity.py
+++ b/test/broker/08-ssl-connect-identity.py
@@ -13,9 +13,9 @@ def write_config(filename, port1, port2):
f.write("listener %d\n" % (port2))
f.write("\n")
f.write("listener %d\n" %(port1))
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("\n")
f.write("use_identity_as_username true\n")
f.write("require_certificate true\n")
@@ -32,7 +32,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", certfile="../ssl/client.crt", keyfile="../ssl/client.key", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", certfile=f"{ssl_dir}/client.crt", keyfile=f"{ssl_dir}/client.key", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-no-auth-wrong-ca.py b/test/broker/08-ssl-connect-no-auth-wrong-ca.py
index 54986993..52a71b80 100755
--- a/test/broker/08-ssl-connect-no-auth-wrong-ca.py
+++ b/test/broker/08-ssl-connect-no-auth-wrong-ca.py
@@ -13,9 +13,9 @@ def write_config(filename, port1, port2):
f.write("listener %d\n" % (port2))
f.write("\n")
f.write("listener %d\n" % (port1))
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
(port1, port2) = mosq_test.get_port(2)
conf_file = os.path.basename(__file__).replace('.py', '.conf')
@@ -28,7 +28,7 @@ connack_packet = mosq_test.gen_connack(rc=0)
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2, use_conf=True)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-alt-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
+ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-alt-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
try:
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-no-auth.py b/test/broker/08-ssl-connect-no-auth.py
index 2ed774b7..c9134132 100755
--- a/test/broker/08-ssl-connect-no-auth.py
+++ b/test/broker/08-ssl-connect-no-auth.py
@@ -15,9 +15,9 @@ def write_config(filename, port1, port2):
f.write("\n")
f.write("listener %d\n" % (port1))
f.write("allow_anonymous true\n")
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
(port1, port2) = mosq_test.get_port(2)
conf_file = os.path.basename(__file__).replace('.py', '.conf')
@@ -31,7 +31,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-connect-no-identity.py b/test/broker/08-ssl-connect-no-identity.py
index cbb028a9..1573c609 100755
--- a/test/broker/08-ssl-connect-no-identity.py
+++ b/test/broker/08-ssl-connect-no-identity.py
@@ -13,9 +13,9 @@ def write_config(filename, port1, port2):
f.write("listener %d\n" % (port2))
f.write("\n")
f.write("listener %d\n" % (port1))
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("\n")
f.write("use_identity_as_username true\n")
@@ -31,7 +31,7 @@ broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2,
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
ssock.connect(("localhost", port1))
diff --git a/test/broker/08-ssl-hup-disconnect.py b/test/broker/08-ssl-hup-disconnect.py
index 314e99e1..8de8c500 100755
--- a/test/broker/08-ssl-hup-disconnect.py
+++ b/test/broker/08-ssl-hup-disconnect.py
@@ -15,9 +15,9 @@ if sys.version < '2.7':
def write_config(filename, pw_file, port, option):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
- f.write("cafile ../ssl/all-ca.crt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"cafile {ssl_dir}/all-ca.crt\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("require_certificate true\n")
f.write("%s true\n" % (option))
f.write("password_file %s\n" % (pw_file))
@@ -42,7 +42,7 @@ def do_test(option):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", certfile="../ssl/client.crt", keyfile="../ssl/client.key", cert_reqs=ssl.CERT_REQUIRED)
+ ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/test-root-ca.crt", certfile=f"{ssl_dir}/client.crt", keyfile=f"{ssl_dir}/client.key", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
ssock.connect(("localhost", port))
mosq_test.do_send_receive(ssock, connect_packet, connack_packet, "connack")
diff --git a/test/broker/08-tls-psk-bridge.py b/test/broker/08-tls-psk-bridge.py
index 22e68bf0..ec7302a8 100755
--- a/test/broker/08-tls-psk-bridge.py
+++ b/test/broker/08-tls-psk-bridge.py
@@ -10,7 +10,7 @@ def write_config1(filename, port1, port2):
with open(filename, 'w') as f:
f.write("allow_anonymous true\n")
f.write("\n")
- f.write("psk_file 08-tls-psk-bridge.psk\n")
+ f.write(f"psk_file {str(source_dir/'08-tls-psk-bridge.psk')}\n")
f.write("\n")
f.write("listener %d\n" % (port1))
f.write("\n")
@@ -35,12 +35,12 @@ write_config1(conf_file1, port1, port2)
write_config2(conf_file2, port2, port3)
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
rc = 1
@@ -53,7 +53,7 @@ suback_packet = mosq_test.gen_suback(mid, 0)
publish_packet = mosq_test.gen_publish(topic="psk/test", payload="message", qos=0)
-bridge_cmd = ['../../src/mosquitto', '-c', '08-tls-psk-bridge.conf2']
+bridge_cmd = [mosq_test.get_build_root() + '/src/mosquitto', '-c', '08-tls-psk-bridge.conf2']
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port1)
bridge = mosq_test.start_broker(filename=os.path.basename(__file__)+'_bridge', cmd=bridge_cmd, port=port3)
diff --git a/test/broker/08-tls-psk-pub.py b/test/broker/08-tls-psk-pub.py
index 1883eade..5d4ebc58 100755
--- a/test/broker/08-tls-psk-pub.py
+++ b/test/broker/08-tls-psk-pub.py
@@ -10,7 +10,7 @@ if sys.version < '2.7':
def write_config(filename, port1, port2):
with open(filename, 'w') as f:
f.write("allow_anonymous true\n")
- f.write("psk_file 08-tls-psk-pub.psk\n")
+ f.write(f"psk_file {str(source_dir/'08-tls-psk-pub.psk')}\n")
f.write("\n")
f.write("listener %d\n" % (port1))
f.write("psk_hint hint\n")
@@ -23,12 +23,12 @@ conf_file = os.path.basename(__file__).replace('.py', '.conf')
write_config(conf_file, port1, port2)
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
rc = 1
diff --git a/test/broker/09-extended-auth-single.py b/test/broker/09-extended-auth-single.py
index bad1c102..7113fe7d 100755
--- a/test/broker/09-extended-auth-single.py
+++ b/test/broker/09-extended-auth-single.py
@@ -54,9 +54,15 @@ connack5_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props)
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
+
try:
- sock = mosq_test.do_client_connect(connect1_packet, b"", timeout=20, port=port)
- sock.close()
+ sock = None
+ try:
+ sock = mosq_test.do_client_connect(connect1_packet, b"", timeout=20, port=port)
+ sock.close()
+ rc = 2
+ except BrokenPipeError:
+ pass
sock = mosq_test.do_client_connect(connect2_packet, connack2_packet, timeout=20, port=port)
sock.close()
@@ -71,8 +77,6 @@ try:
sock.close()
rc = 0
-except mosq_test.TestError:
- pass
finally:
os.remove(conf_file)
broker.terminate()
@@ -84,5 +88,4 @@ finally:
print(stde.decode('utf-8'))
-exit(rc)
-
+sys.exit(rc)
diff --git a/test/broker/09-extended-auth-single2.py b/test/broker/09-extended-auth-single2.py
index a359f3af..0930ad1e 100755
--- a/test/broker/09-extended-auth-single2.py
+++ b/test/broker/09-extended-auth-single2.py
@@ -54,7 +54,7 @@ def do_test(suffix):
connack5_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props)
- broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
+ broker = mosq_test.start_broker(filename=conf_file, use_conf=True, port=port)
try:
sock = mosq_test.do_client_connect(connect1_packet, b"", timeout=20, port=port)
diff --git a/test/broker/11-persistent-subscription-no-local.py b/test/broker/11-persistent-subscription-no-local.py
index d09a50da..bd527065 100755
--- a/test/broker/11-persistent-subscription-no-local.py
+++ b/test/broker/11-persistent-subscription-no-local.py
@@ -52,7 +52,7 @@ if os.path.exists('mosquitto-%d.db' % (port)):
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
-(stdo1, stde1) = ("", "")
+(stdo1, stde1) = (None, None)
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
mosq_test.do_send_receive(sock, subscribe1_packet, suback1_packet, "suback1")
@@ -64,6 +64,9 @@ try:
sock.send(puback2a_packet)
+ # Send a ping and wait for the the response to make sure the puback2a_packet was processed by the broker
+ mosq_test.do_ping(sock)
+
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
@@ -86,6 +89,9 @@ except mosq_test.TestError:
pass
finally:
os.remove(conf_file)
+ if rc and stde1:
+ print(stde1.decode('utf-8'))
+
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
diff --git a/test/broker/14-dynsec-acl.py b/test/broker/14-dynsec-acl.py
index 9adbb80c..6c156e6d 100755
--- a/test/broker/14-dynsec-acl.py
+++ b/test/broker/14-dynsec-acl.py
@@ -10,7 +10,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous false\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -215,8 +215,9 @@ suback_c_pattern_packet_denied_success = mosq_test.gen_suback(mid, mqtt5_rc.MQTT
try:
- os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ if not os.path.exists(str(port)):
+ os.mkdir(str(port))
+ shutil.copyfile(str(Path(__file__).resolve().parent) + "/dynamic-security-init.json", "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
@@ -400,7 +401,7 @@ finally:
os.remove(f"{port}/dynamic-security.json")
except FileNotFoundError:
pass
- os.rmdir(f"{port}")
+ shutil.rmtree(f"{port}")
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
diff --git a/test/broker/14-dynsec-allow-wildcard.py b/test/broker/14-dynsec-allow-wildcard.py
index 10ab47cc..c40db771 100755
--- a/test/broker/14-dynsec-allow-wildcard.py
+++ b/test/broker/14-dynsec-allow-wildcard.py
@@ -10,7 +10,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous false\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -81,7 +81,7 @@ disconnect_kick_packet = mosq_test.gen_disconnect(reason_code=mqtt5_rc.MQTT_RC_A
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
@@ -128,7 +128,7 @@ finally:
os.remove(f"{port}/dynamic-security.json")
except FileNotFoundError:
pass
- os.rmdir(f"{port}")
+ shutil.rmtree(f"{port}")
broker.terminate()
if mosq_test.wait_for_subprocess(broker):
print("broker not terminated")
diff --git a/test/broker/14-dynsec-anon-group.py b/test/broker/14-dynsec-anon-group.py
index 2f32d1d9..5deab69e 100755
--- a/test/broker/14-dynsec-anon-group.py
+++ b/test/broker/14-dynsec-anon-group.py
@@ -9,7 +9,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -95,7 +95,7 @@ disconnect_packet_kick = mosq_test.gen_disconnect(reason_code=mqtt5_rc.MQTT_RC_A
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-auth.py b/test/broker/14-dynsec-auth.py
index 7447544b..eeb3fd70 100755
--- a/test/broker/14-dynsec-auth.py
+++ b/test/broker/14-dynsec-auth.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous false\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -112,7 +112,7 @@ connack_packet_without_un = mosq_test.gen_connack(rc=mqtt5_rc.MQTT_RC_NOT_AUTHOR
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-client-invalid.py b/test/broker/14-dynsec-client-invalid.py
index 935a35f0..b96e54d3 100755
--- a/test/broker/14-dynsec-client-invalid.py
+++ b/test/broker/14-dynsec-client-invalid.py
@@ -10,7 +10,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -357,7 +357,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-client.py b/test/broker/14-dynsec-client.py
index 50503923..3d690b34 100755
--- a/test/broker/14-dynsec-client.py
+++ b/test/broker/14-dynsec-client.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -73,7 +73,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-config-init-env.py b/test/broker/14-dynsec-config-init-env.py
new file mode 100755
index 00000000..a23b8029
--- /dev/null
+++ b/test/broker/14-dynsec-config-init-env.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+from mosq_test_helper import *
+import json
+import shutil
+
+def write_config(filename, port):
+ with open(filename, 'w') as f:
+ f.write("listener %d\n" % (port))
+ f.write("allow_anonymous false\n")
+ f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
+
+
+port = mosq_test.get_port()
+conf_file = os.path.basename(__file__).replace('.py', '.conf')
+write_config(conf_file, port)
+
+try:
+ os.mkdir(str(port))
+except FileExistsError:
+ pass
+
+rc = 1
+connect_packet = mosq_test.gen_connect("ctrl-test", username="admin", password="adminadminadmin")
+connack_packet = mosq_test.gen_connack(rc=0)
+
+env = os.environ
+env["MOSQUITTO_DYNSEC_PASSWORD"] = "adminadminadmin"
+broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port, env=env)
+
+try:
+ sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=5, port=port)
+ rc = 0
+ sock.close()
+except mosq_test.TestError:
+ pass
+finally:
+ os.remove(conf_file)
+ try:
+ os.remove(f"{port}/dynamic-security.json")
+ except FileNotFoundError:
+ pass
+ try:
+ os.remove(f"{port}/dynamic-security.json.pw")
+ except FileNotFoundError:
+ pass
+ os.rmdir(f"{port}")
+ broker.terminate()
+ broker.wait()
+ (stdo, stde) = broker.communicate()
+ if rc:
+ print(stde.decode('utf-8'))
+
+
+exit(rc)
diff --git a/test/broker/14-dynsec-config-init-file.py b/test/broker/14-dynsec-config-init-file.py
new file mode 100755
index 00000000..aca6a084
--- /dev/null
+++ b/test/broker/14-dynsec-config-init-file.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+from mosq_test_helper import *
+import json
+import shutil
+
+def write_config(filename, port):
+ with open(filename, 'w') as f:
+ f.write("listener %d\n" % (port))
+ f.write("allow_anonymous false\n")
+ f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
+ f.write("plugin_opt_password_init_file %d/init\n" % (port))
+
+
+port = mosq_test.get_port()
+conf_file = os.path.basename(__file__).replace('.py', '.conf')
+write_config(conf_file, port)
+
+try:
+ os.mkdir(str(port))
+ with open(f"{port}/init", "w") as f:
+ f.write("adminadminadmin\n")
+except FileExistsError:
+ pass
+
+rc = 1
+connect_packet = mosq_test.gen_connect("ctrl-test", username="admin", password="adminadminadmin")
+connack_packet = mosq_test.gen_connack(rc=0)
+
+broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
+
+try:
+ sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=5, port=port)
+ rc = 0
+ sock.close()
+except mosq_test.TestError:
+ pass
+finally:
+ os.remove(conf_file)
+ try:
+ os.remove(f"{port}/dynamic-security.json")
+ except FileNotFoundError:
+ pass
+ try:
+ os.remove(f"{port}/init")
+ except FileNotFoundError:
+ pass
+ os.rmdir(f"{port}")
+ broker.terminate()
+ broker.wait()
+ (stdo, stde) = broker.communicate()
+ if rc:
+ print(stde.decode('utf-8'))
+
+
+exit(rc)
diff --git a/test/broker/14-dynsec-config-init-random.py b/test/broker/14-dynsec-config-init-random.py
new file mode 100755
index 00000000..20e7116a
--- /dev/null
+++ b/test/broker/14-dynsec-config-init-random.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+
+from mosq_test_helper import *
+import json
+import shutil
+
+def write_config(filename, port):
+ with open(filename, 'w') as f:
+ f.write("listener %d\n" % (port))
+ f.write("allow_anonymous false\n")
+ f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
+
+
+port = mosq_test.get_port()
+conf_file = os.path.basename(__file__).replace('.py', '.conf')
+write_config(conf_file, port)
+
+try:
+ os.mkdir(str(port))
+except FileExistsError:
+ pass
+
+rc = 1
+broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
+
+with open(f"{port}/dynamic-security.json.pw", "r") as f:
+ data = f.readlines()
+
+admin_pw = data[0].split(" ")[1].strip()
+user_pw = data[1].split(" ")[1].strip()
+
+try:
+ # Admin user
+ connect_packet = mosq_test.gen_connect("ctrl-test", username="admin", password=admin_pw)
+ connack_packet = mosq_test.gen_connack(rc=0)
+ sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=5, port=port)
+
+ # Subscribe should be allowed
+ mid = 2
+ subscribe_packet = mosq_test.gen_subscribe(mid, "$CONTROL/dynamic-security/#", 1)
+ suback_packet = mosq_test.gen_suback(mid, 1)
+ mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "admin suback")
+ sock.close()
+
+ # Basic user
+ connect_packet = mosq_test.gen_connect("ctrl-test", username="democlient", password=user_pw)
+ connack_packet = mosq_test.gen_connack(rc=0)
+ sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=5, port=port)
+
+ # Subscribe should not be allowed
+ mid = 2
+ subscribe_packet = mosq_test.gen_subscribe(mid, "$CONTROL/dynamic-security/#", 1)
+ suback_packet = mosq_test.gen_suback(mid, 128)
+ mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "user suback")
+ sock.close()
+
+ rc = 0
+except mosq_test.TestError:
+ pass
+finally:
+ os.remove(conf_file)
+ try:
+ os.remove(f"{port}/dynamic-security.json")
+ except FileNotFoundError:
+ pass
+ try:
+ os.remove(f"{port}/dynamic-security.json.pw")
+ except FileNotFoundError:
+ pass
+ os.rmdir(f"{port}")
+ broker.terminate()
+ broker.wait()
+ (stdo, stde) = broker.communicate()
+ if rc:
+ print(stde.decode('utf-8'))
+
+
+exit(rc)
diff --git a/test/broker/14-dynsec-default-access.py b/test/broker/14-dynsec-default-access.py
index dcbdaa68..9d7cfe89 100755
--- a/test/broker/14-dynsec-default-access.py
+++ b/test/broker/14-dynsec-default-access.py
@@ -10,7 +10,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous false\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -123,7 +123,7 @@ publish_packet_recv = mosq_test.gen_publish(topic="topic", qos=0, payload="messa
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-disable-client.py b/test/broker/14-dynsec-disable-client.py
index d5b688d0..659a32d4 100755
--- a/test/broker/14-dynsec-disable-client.py
+++ b/test/broker/14-dynsec-disable-client.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -64,7 +64,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-group-invalid.py b/test/broker/14-dynsec-group-invalid.py
index ee80ced9..6cdf1b89 100755
--- a/test/broker/14-dynsec-group-invalid.py
+++ b/test/broker/14-dynsec-group-invalid.py
@@ -10,7 +10,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -333,7 +333,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-group.py b/test/broker/14-dynsec-group.py
index 41f54b97..d2a9302e 100755
--- a/test/broker/14-dynsec-group.py
+++ b/test/broker/14-dynsec-group.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -112,7 +112,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-modify-client.py b/test/broker/14-dynsec-modify-client.py
index 69bf2cc3..5ed2620d 100755
--- a/test/broker/14-dynsec-modify-client.py
+++ b/test/broker/14-dynsec-modify-client.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -151,7 +151,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-modify-group.py b/test/broker/14-dynsec-modify-group.py
index c4965e12..0e55f840 100755
--- a/test/broker/14-dynsec-modify-group.py
+++ b/test/broker/14-dynsec-modify-group.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -134,7 +134,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-modify-role.py b/test/broker/14-dynsec-modify-role.py
index c1fda015..029091f2 100755
--- a/test/broker/14-dynsec-modify-role.py
+++ b/test/broker/14-dynsec-modify-role.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response):
@@ -115,7 +115,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-plugin-invalid.py b/test/broker/14-dynsec-plugin-invalid.py
index 11f97f2a..f1b0523b 100755
--- a/test/broker/14-dynsec-plugin-invalid.py
+++ b/test/broker/14-dynsec-plugin-invalid.py
@@ -10,7 +10,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -104,7 +104,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-role-invalid.py b/test/broker/14-dynsec-role-invalid.py
index b25a6d30..e0c7a25c 100755
--- a/test/broker/14-dynsec-role-invalid.py
+++ b/test/broker/14-dynsec-role-invalid.py
@@ -10,7 +10,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -238,7 +238,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/14-dynsec-role.py b/test/broker/14-dynsec-role.py
index f13c94ce..14722e2f 100755
--- a/test/broker/14-dynsec-role.py
+++ b/test/broker/14-dynsec-role.py
@@ -8,7 +8,7 @@ def write_config(filename, port):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")
- f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
+ f.write(f"plugin {mosq_test.get_build_root()}/plugins/dynamic-security/mosquitto_dynamic_security.so\n")
f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
def command_check(sock, command_payload, expected_response, msg=""):
@@ -180,7 +180,7 @@ suback_packet = mosq_test.gen_suback(mid, 1)
try:
os.mkdir(str(port))
- shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
+ shutil.copyfile(str(Path(__file__).resolve().parent / "dynamic-security-init.json"), "%d/dynamic-security.json" % (port))
except FileExistsError:
pass
diff --git a/test/broker/15-persist-client-v5.0.py b/test/broker/15-persist-client-v5-0.py
similarity index 100%
rename from test/broker/15-persist-client-v5.0.py
rename to test/broker/15-persist-client-v5-0.py
diff --git a/test/broker/15-sqlite-retain-clear-v5-0.py b/test/broker/15-sqlite-retain-clear-v5-0.py
index 6ba94d9c..92c3f13b 100755
--- a/test/broker/15-sqlite-retain-clear-v5-0.py
+++ b/test/broker/15-sqlite-retain-clear-v5-0.py
@@ -27,6 +27,7 @@ publish1_packet = mosq_test.gen_publish(topic1, qos=qos, payload=payload1, retai
publish2_packet = mosq_test.gen_publish(topic2, qos=qos, payload=payload2, retain=True, proto_ver=proto_ver)
publish2_clear_packet = mosq_test.gen_publish(topic2, qos=qos, payload="", retain=True, proto_ver=proto_ver)
+publish2_clear_echo = mosq_test.gen_publish(topic2, qos=qos, payload="", retain=False, proto_ver=proto_ver)
mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "#", 0, proto_ver=proto_ver)
@@ -63,8 +64,8 @@ try:
mosq_test.receive_unordered(sock, publish1_packet, publish2_packet, "publish 1 / 2")
mosq_test.do_ping(sock)
- # Clear retained
- sock.send(publish2_clear_packet)
+ # Clear retained (and wait for the publish to avoid race condition)
+ mosq_test.do_send_receive(sock, publish2_clear_packet, publish2_clear_echo, "clear retain flag")
# Kill broker
broker.terminate()
diff --git a/test/broker/16-cmd-args.py b/test/broker/16-cmd-args.py
index fb131415..c309bf82 100755
--- a/test/broker/16-cmd-args.py
+++ b/test/broker/16-cmd-args.py
@@ -8,7 +8,7 @@ vg_index = 0
def start_broker(args):
global vg_index
- cmd = ['../../src/mosquitto'] + args
+ cmd = [mosq_test.get_build_root() + '/src/mosquitto'] + args
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
logfile = os.path.basename(__file__)+'.'+str(vg_index)+'.vglog'
diff --git a/test/broker/16-config-parse-errors.py b/test/broker/16-config-parse-errors.py
index 4163be22..5cda567b 100755
--- a/test/broker/16-config-parse-errors.py
+++ b/test/broker/16-config-parse-errors.py
@@ -8,7 +8,7 @@ vg_index = 0
def start_broker(filename):
global vg_index
- cmd = ['../../src/mosquitto', '-v', '-c', filename]
+ cmd = [mosq_test.get_build_root() + '/src/mosquitto', '-v', '-c', filename]
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
logfile = os.path.basename(__file__)+'.'+str(vg_index)+'.vglog'
@@ -148,18 +148,18 @@ do_test("sys_interval 65536\n", 3) # Invalid value
do_test("listener 1888\ncertfile\n", 3) # empty certfile
do_test("listener 1888\nkeyfile\n", 3) # empty keyfile
-do_test("listener 1888\ncertfile ./16-config-parse-errors.py\nkeyfile ../ssl/server.key\n", 1) # invalid certfile
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ./16-config-parse-errors.py\n", 1) # invalid keyfile
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ../ssl/client.key\n", 1) # mismatched certfile / keyfile
+do_test(f"listener 1888\ncertfile {source_dir}/16-config-parse-errors.py\nkeyfile {ssl_dir}/server.key\n", 1) # invalid certfile
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {source_dir}/16-config-parse-errors.py\n", 1) # invalid keyfile
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {ssl_dir}/client.key\n", 1) # mismatched certfile / keyfile
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ../ssl/server.key\ntls_version invalid\n", 1) # invalid tls_version
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {ssl_dir}/server.key\ntls_version invalid", 1) # invalid tls_version
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ../ssl/server.key\ncrlfile invalid\n", 1) # missing crl file
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ../ssl/server.key\ndhparamfile invalid\n", 1) # missing dh param file
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ../ssl/server.key\ndhparamfile ./16-config-parse-errors.py\n", 1) # invalid dh param file
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {ssl_dir}/server.key\ncrlfile invalid", 1) # missing crl file
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {ssl_dir}/server.key\ndhparamfile invalid", 1) # missing dh param file
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {ssl_dir}/server.key\ndhparamfile {source_dir}/16-config-parse-errors.py", 1) # invalid dh param file
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ../ssl/server.key\nciphers invalid\n", 1) # invalid ciphers
-do_test("listener 1888\ncertfile ../ssl/server.crt\nkeyfile ../ssl/server.key\nciphers_tls1.3 invalid\n", 1) # invalid ciphers_tls1.3
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {ssl_dir}/server.key\nciphers invalid", 1) # invalid ciphers
+do_test(f"listener 1888\ncertfile {ssl_dir}/server.crt\nkeyfile {ssl_dir}/server.key\nciphers_tls1.3 invalid", 1) # invalid ciphers_tls1.3
exit(0)
diff --git a/test/broker/17-control-list-listeners.py b/test/broker/17-control-list-listeners.py
index cffbee38..6084e794 100755
--- a/test/broker/17-control-list-listeners.py
+++ b/test/broker/17-control-list-listeners.py
@@ -16,12 +16,12 @@ def write_config(filename, ports):
f.write("protocol websockets\n")
f.write("listener %d\n" % (ports[2]))
f.write("protocol mqtt\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("listener %d\n" % (ports[3]))
f.write("protocol websockets\n")
- f.write("certfile ../ssl/server.crt\n")
- f.write("keyfile ../ssl/server.key\n")
+ f.write(f"certfile {ssl_dir}/server.crt\n")
+ f.write(f"keyfile {ssl_dir}/server.key\n")
f.write("listener 0 17-list-listeners-mqtt.sock\n")
f.write("protocol mqtt\n")
f.write("listener 0 17-list-listeners-websockets.sock\n")
diff --git a/test/broker/CMakeLists.txt b/test/broker/CMakeLists.txt
new file mode 100644
index 00000000..52ca73b1
--- /dev/null
+++ b/test/broker/CMakeLists.txt
@@ -0,0 +1,41 @@
+add_subdirectory(c)
+
+
+file(GLOB PY_TEST_FILES [0-9][0-9]-*.py)
+
+list(APPEND PY_TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/msg_sequence_test.py")
+
+set(EXCLUDE_LIST
+ 01-connect-uname-password-success-no-tls
+ 03-publish-qos1-queued-bytes
+ 09-extended-auth-single2
+ 15-persist-client-msg-in-v3-1-1
+ 15-persist-client-msg-in-v5-0
+ 15-persist-client-msg-out-queue-v3-1-1
+ 15-persist-client-msg-out-v3-1-1
+ 15-persist-client-msg-out-v5-0
+ 15-persist-client-v3-1-1
+ 15-persist-client-v5-0
+ 15-persist-publish-properties-v5-0
+ 15-persist-retain-v3-1-1
+ 15-persist-retain-v5-0
+ 15-persist-subscription-v3-1-1
+ 15-persist-subscription-v5-0
+ # Not a test
+ 06-bridge-clean-session-core
+ 08-ssl-bridge-helper
+)
+
+foreach(PY_TEST_FILE ${PY_TEST_FILES})
+ get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE)
+ if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST)
+ continue()
+ endif()
+ add_test(NAME broker-${PY_TEST_NAME}
+ COMMAND ${PY_TEST_FILE}
+ )
+ set_tests_properties(broker-${PY_TEST_NAME}
+ PROPERTIES
+ ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}"
+ )
+endforeach()
diff --git a/test/broker/Makefile b/test/broker/Makefile
index c9f3d808..4248c6e2 100644
--- a/test/broker/Makefile
+++ b/test/broker/Makefile
@@ -239,18 +239,21 @@ ifeq ($(WITH_CJSON),yes)
./14-dynsec-allow-wildcard.py
./14-dynsec-anon-group.py
./14-dynsec-auth.py
- ./14-dynsec-client.py
./14-dynsec-client-invalid.py
+ ./14-dynsec-client.py
+ ./14-dynsec-config-init-env.py
+ ./14-dynsec-config-init-file.py
+ ./14-dynsec-config-init-random.py
./14-dynsec-default-access.py
./14-dynsec-disable-client.py
- ./14-dynsec-group.py
./14-dynsec-group-invalid.py
+ ./14-dynsec-group.py
./14-dynsec-modify-client.py
./14-dynsec-modify-group.py
./14-dynsec-modify-role.py
./14-dynsec-plugin-invalid.py
- ./14-dynsec-role.py
./14-dynsec-role-invalid.py
+ ./14-dynsec-role.py
endif
endif
diff --git a/test/broker/c/CMakeLists.txt b/test/broker/c/CMakeLists.txt
new file mode 100644
index 00000000..9fd39b12
--- /dev/null
+++ b/test/broker/c/CMakeLists.txt
@@ -0,0 +1,47 @@
+set(PLUGINS
+ auth_plugin_acl
+ auth_plugin_acl_change
+ auth_plugin_acl_sub_denied
+ auth_plugin_context_params
+ auth_plugin_delayed
+ auth_plugin_extended_multiple
+ auth_plugin_extended_reauth
+ auth_plugin_extended_single
+ auth_plugin_extended_single2
+ auth_plugin_id_change
+ auth_plugin_msg_params
+ auth_plugin_publish
+ auth_plugin_pwd
+ auth_plugin_v2
+ auth_plugin_v3
+ auth_plugin_v4
+ auth_plugin_v5
+ auth_plugin_v5_control
+ auth_plugin_v5_handle_message
+ plugin_control
+)
+
+foreach(PLUGIN ${PLUGINS})
+ add_library(${PLUGIN} MODULE
+ ${PLUGIN}.c
+ )
+ set_property(TARGET ${PLUGIN}
+ PROPERTY PREFIX ""
+ )
+ target_link_libraries(${PLUGIN} PRIVATE mosquitto)
+endforeach()
+
+set(BINARIES
+ 08-tls-psk-pub
+ 08-tls-psk-bridge
+)
+
+foreach(BINARY ${BINARIES})
+ add_executable(${BINARY}
+ ${BINARY}.c
+ )
+ set_property(TARGET ${BINARY}
+ PROPERTY SUFFIX .test
+ )
+ target_link_libraries(${BINARY} PRIVATE libmosquitto)
+endforeach()
diff --git a/test/broker/mosq_test_helper.py b/test/broker/mosq_test_helper.py
index 52c0ed51..ed48a47e 100644
--- a/test/broker/mosq_test_helper.py
+++ b/test/broker/mosq_test_helper.py
@@ -16,3 +16,7 @@ import struct
import subprocess
import time
import errno
+from pathlib import Path
+
+source_dir = Path(__file__).resolve().parent
+ssl_dir = source_dir.parent / "ssl"
diff --git a/test/broker/msg_sequence_test.py b/test/broker/msg_sequence_test.py
index ce294de5..385f92c0 100755
--- a/test/broker/msg_sequence_test.py
+++ b/test/broker/msg_sequence_test.py
@@ -127,9 +127,10 @@ class MsgSequence(object):
def do_test(hostname, port):
+ data_path=Path(__file__).resolve().parent/"data"
rc = 0
sequences = []
- for (_, _, filenames) in walk("data"):
+ for (_, _, filenames) in walk(data_path):
sequences.extend(filenames)
break
@@ -140,7 +141,7 @@ def do_test(hostname, port):
if seq[-5:] != ".json":
continue
- with open("data/"+seq, "r") as f:
+ with open(data_path/seq, "r") as f:
test_file = json.load(f)
for g in test_file:
diff --git a/test/broker/sqlite_help.py b/test/broker/sqlite_help.py
index 809f3e12..d69f7e72 100755
--- a/test/broker/sqlite_help.py
+++ b/test/broker/sqlite_help.py
@@ -1,4 +1,5 @@
import os
+from pathlib import Path
dir_in = 0
dir_out = 1
@@ -40,7 +41,12 @@ def cleanup(port):
try:
os.rmdir(f"{port}")
rc = 0
- except OSError:
+ except OSError as e:
+ print(f"ERROR sqlite3 file not removed after shutdown")
+ if Path(str(port), "mosquitto.sqlite3-wal").stat().st_size == 0:
+ # some versions of sqlite3 do not remove the wal file
+ # thus we make sure that the file is at least empty (no pending db transactions)
+ rc = 0
os.remove(f"{port}/mosquitto.sqlite3-shm")
os.remove(f"{port}/mosquitto.sqlite3-wal")
os.rmdir(f"{port}")
diff --git a/test/broker/test.py b/test/broker/test.py
index 7bdd84ef..d1fe29d8 100755
--- a/test/broker/test.py
+++ b/test/broker/test.py
@@ -201,18 +201,21 @@ tests = [
(1, './14-dynsec-allow-wildcard.py'),
(1, './14-dynsec-anon-group.py'),
(1, './14-dynsec-auth.py'),
- (1, './14-dynsec-client.py'),
(1, './14-dynsec-client-invalid.py'),
+ (1, './14-dynsec-client.py'),
+ (1, './14-dynsec-config-init-env.py'),
+ (1, './14-dynsec-config-init-file.py'),
+ (1, './14-dynsec-config-init-random.py'),
(1, './14-dynsec-default-access.py'),
(1, './14-dynsec-disable-client.py'),
- (1, './14-dynsec-group.py'),
(1, './14-dynsec-group-invalid.py'),
+ (1, './14-dynsec-group.py'),
(1, './14-dynsec-modify-client.py'),
(1, './14-dynsec-modify-group.py'),
(1, './14-dynsec-modify-role.py'),
(1, './14-dynsec-plugin-invalid.py'),
- (1, './14-dynsec-role.py'),
(1, './14-dynsec-role-invalid.py'),
+ (1, './14-dynsec-role.py'),
#(1, './15-persist-client-msg-in-v5-0.py'),
#(1, './15-persist-client-msg-out-queue-v3-1-1.py'),
diff --git a/test/client/02-subscribe-argv-errors.py b/test/client/02-subscribe-argv-errors.py
index e91940ff..92ec1104 100755
--- a/test/client/02-subscribe-argv-errors.py
+++ b/test/client/02-subscribe-argv-errors.py
@@ -10,7 +10,7 @@ def do_test(args, stderr_expected, rc_expected):
port = mosq_test.get_port()
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub'] + args
diff --git a/test/client/02-subscribe-filter-out.py b/test/client/02-subscribe-filter-out.py
index b7d00c83..f8cac07d 100755
--- a/test/client/02-subscribe-filter-out.py
+++ b/test/client/02-subscribe-filter-out.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-format-json-properties.py b/test/client/02-subscribe-format-json-properties.py
index 52b56816..d98aebae 100755
--- a/test/client/02-subscribe-format-json-properties.py
+++ b/test/client/02-subscribe-format-json-properties.py
@@ -18,7 +18,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-format-json-qos0.py b/test/client/02-subscribe-format-json-qos0.py
index 6bb55e8b..186735dc 100755
--- a/test/client/02-subscribe-format-json-qos0.py
+++ b/test/client/02-subscribe-format-json-qos0.py
@@ -18,7 +18,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-format-json-qos1.py b/test/client/02-subscribe-format-json-qos1.py
index c02136d6..081d2886 100755
--- a/test/client/02-subscribe-format-json-qos1.py
+++ b/test/client/02-subscribe-format-json-qos1.py
@@ -18,7 +18,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-format-json-retain.py b/test/client/02-subscribe-format-json-retain.py
index 559219ba..1bbb8ce4 100755
--- a/test/client/02-subscribe-format-json-retain.py
+++ b/test/client/02-subscribe-format-json-retain.py
@@ -18,7 +18,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-format.py b/test/client/02-subscribe-format.py
index 73e76a09..4ddf6ea5 100755
--- a/test/client/02-subscribe-format.py
+++ b/test/client/02-subscribe-format.py
@@ -17,7 +17,7 @@ def do_test(format_str, expected_output, proto_ver=4):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-null.py b/test/client/02-subscribe-null.py
index f7875479..442ce6db 100755
--- a/test/client/02-subscribe-null.py
+++ b/test/client/02-subscribe-null.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-qos1.py b/test/client/02-subscribe-qos1.py
index fd4e98ca..f185819c 100755
--- a/test/client/02-subscribe-qos1.py
+++ b/test/client/02-subscribe-qos1.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/02-subscribe-verbose.py b/test/client/02-subscribe-verbose.py
index 5b61b553..33597f8e 100755
--- a/test/client/02-subscribe-verbose.py
+++ b/test/client/02-subscribe-verbose.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_sub',
diff --git a/test/client/03-publish-argv-errors.py b/test/client/03-publish-argv-errors.py
index 194d4ada..0e900977 100755
--- a/test/client/03-publish-argv-errors.py
+++ b/test/client/03-publish-argv-errors.py
@@ -10,7 +10,7 @@ def do_test(args, stderr_expected, rc_expected):
port = mosq_test.get_port()
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub'] + args
diff --git a/test/client/03-publish-file-empty.py b/test/client/03-publish-file-empty.py
index dbcb3f55..afccd869 100755
--- a/test/client/03-publish-file-empty.py
+++ b/test/client/03-publish-file-empty.py
@@ -23,7 +23,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-file.py b/test/client/03-publish-file.py
index 999ceb82..35d71af5 100755
--- a/test/client/03-publish-file.py
+++ b/test/client/03-publish-file.py
@@ -24,7 +24,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-options-file.py b/test/client/03-publish-options-file.py
index 850bbce0..330efb42 100755
--- a/test/client/03-publish-options-file.py
+++ b/test/client/03-publish-options-file.py
@@ -26,7 +26,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-qos0-empty.py b/test/client/03-publish-qos0-empty.py
index 59f71d50..a52afa30 100755
--- a/test/client/03-publish-qos0-empty.py
+++ b/test/client/03-publish-qos0-empty.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-qos1-properties.py b/test/client/03-publish-qos1-properties.py
index 434063dd..a581f783 100755
--- a/test/client/03-publish-qos1-properties.py
+++ b/test/client/03-publish-qos1-properties.py
@@ -10,7 +10,7 @@ def do_test(proto_ver):
port = mosq_test.get_port()
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
if proto_ver == 5:
diff --git a/test/client/03-publish-qos1.py b/test/client/03-publish-qos1.py
index e8e3fc16..b8abce2c 100755
--- a/test/client/03-publish-qos1.py
+++ b/test/client/03-publish-qos1.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-repeat.py b/test/client/03-publish-repeat.py
index f3ffc44f..2b0ca152 100755
--- a/test/client/03-publish-repeat.py
+++ b/test/client/03-publish-repeat.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-socks.py b/test/client/03-publish-socks.py
index 23853306..83e3971a 100755
--- a/test/client/03-publish-socks.py
+++ b/test/client/03-publish-socks.py
@@ -29,7 +29,7 @@ def do_test(proto_ver, ipver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = [
diff --git a/test/client/03-publish-stdin-file.py b/test/client/03-publish-stdin-file.py
index 571cb7d3..1c01c114 100755
--- a/test/client/03-publish-stdin-file.py
+++ b/test/client/03-publish-stdin-file.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-stdin-line.py b/test/client/03-publish-stdin-line.py
index 97228589..9511a9a0 100755
--- a/test/client/03-publish-stdin-line.py
+++ b/test/client/03-publish-stdin-line.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/03-publish-url.py b/test/client/03-publish-url.py
index 0f714236..89712a74 100755
--- a/test/client/03-publish-url.py
+++ b/test/client/03-publish-url.py
@@ -17,7 +17,7 @@ def do_test(proto_ver):
V = 'mqttv31'
env = {
- 'LD_LIBRARY_PATH':'../../lib',
+ 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
diff --git a/test/client/CMakeLists.txt b/test/client/CMakeLists.txt
new file mode 100644
index 00000000..0fd8f455
--- /dev/null
+++ b/test/client/CMakeLists.txt
@@ -0,0 +1,19 @@
+file(GLOB PY_TEST_FILES [0-9][0-9]-*.py)
+
+set(EXCLUDE_LIST
+ # none
+)
+
+foreach(PY_TEST_FILE ${PY_TEST_FILES})
+ get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE)
+ if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST)
+ continue()
+ endif()
+ add_test(NAME client-${PY_TEST_NAME}
+ COMMAND ${PY_TEST_FILE}
+ )
+ set_tests_properties(client-${PY_TEST_NAME}
+ PROPERTIES
+ ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}"
+ )
+endforeach()
diff --git a/test/lib/01-con-discon-success-v5.py b/test/lib/01-con-discon-success-v5.py
index 2bdc4af1..31585915 100755
--- a/test/lib/01-con-discon-success-v5.py
+++ b/test/lib/01-con-discon-success-v5.py
@@ -29,12 +29,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/01-con-discon-success.py b/test/lib/01-con-discon-success.py
index ba624aec..66b7078c 100755
--- a/test/lib/01-con-discon-success.py
+++ b/test/lib/01-con-discon-success.py
@@ -27,12 +27,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/01-con-discon-will-clear.py b/test/lib/01-con-discon-will-clear.py
index bcdfa4c6..30c10dfa 100755
--- a/test/lib/01-con-discon-will-clear.py
+++ b/test/lib/01-con-discon-will-clear.py
@@ -21,12 +21,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/01-con-discon-will-v5.py b/test/lib/01-con-discon-will-v5.py
index 1ad5cc3e..e55af1a0 100755
--- a/test/lib/01-con-discon-will-v5.py
+++ b/test/lib/01-con-discon-will-v5.py
@@ -22,12 +22,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/01-con-discon-will.py b/test/lib/01-con-discon-will.py
index 1f9cb8a4..ed5ca35f 100755
--- a/test/lib/01-con-discon-will.py
+++ b/test/lib/01-con-discon-will.py
@@ -21,12 +21,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/01-keepalive-pingreq.py b/test/lib/01-keepalive-pingreq.py
index c4dc3ecd..4eadf388 100755
--- a/test/lib/01-keepalive-pingreq.py
+++ b/test/lib/01-keepalive-pingreq.py
@@ -27,12 +27,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/01-no-clean-session.py b/test/lib/01-no-clean-session.py
index 3d98e0f6..cf641e27 100755
--- a/test/lib/01-no-clean-session.py
+++ b/test/lib/01-no-clean-session.py
@@ -21,12 +21,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/01-pre-connect-callback.py b/test/lib/01-pre-connect-callback.py
index 6a895d46..52aeaca8 100755
--- a/test/lib/01-pre-connect-callback.py
+++ b/test/lib/01-pre-connect-callback.py
@@ -21,12 +21,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/01-server-keepalive-pingreq.py b/test/lib/01-server-keepalive-pingreq.py
index 1f1f86dd..a5958dfd 100755
--- a/test/lib/01-server-keepalive-pingreq.py
+++ b/test/lib/01-server-keepalive-pingreq.py
@@ -27,12 +27,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/01-unpwd-set.py b/test/lib/01-unpwd-set.py
index 21964082..d57abe98 100755
--- a/test/lib/01-unpwd-set.py
+++ b/test/lib/01-unpwd-set.py
@@ -21,12 +21,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/01-will-set.py b/test/lib/01-will-set.py
index d581163f..df592c59 100755
--- a/test/lib/01-will-set.py
+++ b/test/lib/01-will-set.py
@@ -23,12 +23,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/01-will-unpwd-set.py b/test/lib/01-will-unpwd-set.py
index 56c58e90..5e58875f 100755
--- a/test/lib/01-will-unpwd-set.py
+++ b/test/lib/01-will-unpwd-set.py
@@ -25,12 +25,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/02-subscribe-qos0.py b/test/lib/02-subscribe-qos0.py
index d83ca402..dda275d9 100755
--- a/test/lib/02-subscribe-qos0.py
+++ b/test/lib/02-subscribe-qos0.py
@@ -35,12 +35,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/02-subscribe-qos1.py b/test/lib/02-subscribe-qos1.py
index 0bb4c73e..6cdb0c5b 100755
--- a/test/lib/02-subscribe-qos1.py
+++ b/test/lib/02-subscribe-qos1.py
@@ -35,12 +35,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/02-subscribe-qos2.py b/test/lib/02-subscribe-qos2.py
index cb276981..5a27b080 100755
--- a/test/lib/02-subscribe-qos2.py
+++ b/test/lib/02-subscribe-qos2.py
@@ -35,12 +35,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/02-unsubscribe-multiple-v5.py b/test/lib/02-unsubscribe-multiple-v5.py
index 76e66af3..d5b2a321 100755
--- a/test/lib/02-unsubscribe-multiple-v5.py
+++ b/test/lib/02-unsubscribe-multiple-v5.py
@@ -29,12 +29,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
rc = 1
diff --git a/test/lib/02-unsubscribe-v5.py b/test/lib/02-unsubscribe-v5.py
index 52721791..897de2ec 100755
--- a/test/lib/02-unsubscribe-v5.py
+++ b/test/lib/02-unsubscribe-v5.py
@@ -24,12 +24,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/02-unsubscribe.py b/test/lib/02-unsubscribe.py
index b27581ea..f989c2d5 100755
--- a/test/lib/02-unsubscribe.py
+++ b/test/lib/02-unsubscribe.py
@@ -25,12 +25,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-b2c-qos1-unexpected-puback.py b/test/lib/03-publish-b2c-qos1-unexpected-puback.py
index a2d68cd5..c29def47 100755
--- a/test/lib/03-publish-b2c-qos1-unexpected-puback.py
+++ b/test/lib/03-publish-b2c-qos1-unexpected-puback.py
@@ -23,12 +23,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-b2c-qos1.py b/test/lib/03-publish-b2c-qos1.py
index 600873eb..efed9023 100755
--- a/test/lib/03-publish-b2c-qos1.py
+++ b/test/lib/03-publish-b2c-qos1.py
@@ -34,12 +34,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-b2c-qos2-len.py b/test/lib/03-publish-b2c-qos2-len.py
index 221ef816..93abd148 100755
--- a/test/lib/03-publish-b2c-qos2-len.py
+++ b/test/lib/03-publish-b2c-qos2-len.py
@@ -29,12 +29,12 @@ def len_test(test, pubrel_packet):
client_args = sys.argv[1:]
env = dict(os.environ)
- env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+ env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
- env['PYTHONPATH'] = '../../lib/python:'+pp
+ env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-b2c-qos2-unexpected-pubcomp.py b/test/lib/03-publish-b2c-qos2-unexpected-pubcomp.py
index 67ff99fc..e9f2dca3 100755
--- a/test/lib/03-publish-b2c-qos2-unexpected-pubcomp.py
+++ b/test/lib/03-publish-b2c-qos2-unexpected-pubcomp.py
@@ -23,12 +23,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-b2c-qos2-unexpected-pubrel.py b/test/lib/03-publish-b2c-qos2-unexpected-pubrel.py
index f79ba78d..4ad70738 100755
--- a/test/lib/03-publish-b2c-qos2-unexpected-pubrel.py
+++ b/test/lib/03-publish-b2c-qos2-unexpected-pubrel.py
@@ -30,12 +30,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-b2c-qos2.py b/test/lib/03-publish-b2c-qos2.py
index a4b223e7..b064b238 100755
--- a/test/lib/03-publish-b2c-qos2.py
+++ b/test/lib/03-publish-b2c-qos2.py
@@ -41,12 +41,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-c2b-qos1-disconnect.py b/test/lib/03-publish-c2b-qos1-disconnect.py
index 3567ed3e..8a659b6f 100755
--- a/test/lib/03-publish-c2b-qos1-disconnect.py
+++ b/test/lib/03-publish-c2b-qos1-disconnect.py
@@ -26,12 +26,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos1-len.py b/test/lib/03-publish-c2b-qos1-len.py
index 47732267..62b90d9e 100755
--- a/test/lib/03-publish-c2b-qos1-len.py
+++ b/test/lib/03-publish-c2b-qos1-len.py
@@ -26,12 +26,12 @@ def len_test(test, puback_packet):
client_args = sys.argv[1:]
env = dict(os.environ)
- env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+ env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
- env['PYTHONPATH'] = '../../lib/python:'+pp
+ env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos1-receive-maximum.py b/test/lib/03-publish-c2b-qos1-receive-maximum.py
index c04b1cde..7a48f532 100755
--- a/test/lib/03-publish-c2b-qos1-receive-maximum.py
+++ b/test/lib/03-publish-c2b-qos1-receive-maximum.py
@@ -50,12 +50,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos1-timeout.py b/test/lib/03-publish-c2b-qos1-timeout.py
index df785812..2be1c211 100755
--- a/test/lib/03-publish-c2b-qos1-timeout.py
+++ b/test/lib/03-publish-c2b-qos1-timeout.py
@@ -40,12 +40,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-c2b-qos2-disconnect.py b/test/lib/03-publish-c2b-qos2-disconnect.py
index 428473a2..c1e4359a 100755
--- a/test/lib/03-publish-c2b-qos2-disconnect.py
+++ b/test/lib/03-publish-c2b-qos2-disconnect.py
@@ -28,12 +28,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-c2b-qos2-len.py b/test/lib/03-publish-c2b-qos2-len.py
index 18dc6e47..d8ace41d 100755
--- a/test/lib/03-publish-c2b-qos2-len.py
+++ b/test/lib/03-publish-c2b-qos2-len.py
@@ -27,12 +27,12 @@ def len_test(test, pubrec_packet, pubcomp_packet):
client_args = sys.argv[1:]
env = dict(os.environ)
- env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+ env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
- env['PYTHONPATH'] = '../../lib/python:'+pp
+ env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos2-maximum-qos-0.py b/test/lib/03-publish-c2b-qos2-maximum-qos-0.py
index cd7bd8a2..f5a75c85 100755
--- a/test/lib/03-publish-c2b-qos2-maximum-qos-0.py
+++ b/test/lib/03-publish-c2b-qos2-maximum-qos-0.py
@@ -28,12 +28,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos2-maximum-qos-1.py b/test/lib/03-publish-c2b-qos2-maximum-qos-1.py
index 04feb358..67e754da 100755
--- a/test/lib/03-publish-c2b-qos2-maximum-qos-1.py
+++ b/test/lib/03-publish-c2b-qos2-maximum-qos-1.py
@@ -32,12 +32,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos2-pubrec-error.py b/test/lib/03-publish-c2b-qos2-pubrec-error.py
index 76ee0fd6..21363e99 100755
--- a/test/lib/03-publish-c2b-qos2-pubrec-error.py
+++ b/test/lib/03-publish-c2b-qos2-pubrec-error.py
@@ -39,12 +39,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos2-receive-maximum-1.py b/test/lib/03-publish-c2b-qos2-receive-maximum-1.py
index e945efcb..6ac73f83 100755
--- a/test/lib/03-publish-c2b-qos2-receive-maximum-1.py
+++ b/test/lib/03-publish-c2b-qos2-receive-maximum-1.py
@@ -56,12 +56,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos2-receive-maximum-2.py b/test/lib/03-publish-c2b-qos2-receive-maximum-2.py
index 243895a8..d2e7c541 100755
--- a/test/lib/03-publish-c2b-qos2-receive-maximum-2.py
+++ b/test/lib/03-publish-c2b-qos2-receive-maximum-2.py
@@ -56,12 +56,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
diff --git a/test/lib/03-publish-c2b-qos2-timeout.py b/test/lib/03-publish-c2b-qos2-timeout.py
index 5c187641..e1ef1a4d 100755
--- a/test/lib/03-publish-c2b-qos2-timeout.py
+++ b/test/lib/03-publish-c2b-qos2-timeout.py
@@ -46,12 +46,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-c2b-qos2.py b/test/lib/03-publish-c2b-qos2.py
index 979f66f9..7553fe16 100755
--- a/test/lib/03-publish-c2b-qos2.py
+++ b/test/lib/03-publish-c2b-qos2.py
@@ -46,12 +46,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-qos0-no-payload.py b/test/lib/03-publish-qos0-no-payload.py
index 40a1e7c5..8e598083 100755
--- a/test/lib/03-publish-qos0-no-payload.py
+++ b/test/lib/03-publish-qos0-no-payload.py
@@ -31,12 +31,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-publish-qos0.py b/test/lib/03-publish-qos0.py
index dcca5b68..64741950 100755
--- a/test/lib/03-publish-qos0.py
+++ b/test/lib/03-publish-qos0.py
@@ -31,12 +31,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/03-request-response-correlation.py b/test/lib/03-request-response-correlation.py
index aeaf95d1..26516b32 100755
--- a/test/lib/03-request-response-correlation.py
+++ b/test/lib/03-request-response-correlation.py
@@ -41,12 +41,12 @@ sock.bind(('', port))
sock.listen(5)
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client1 = mosq_test.start_client(filename="03-request-response-correlation-1.log", cmd=["c/03-request-response-correlation-1.test"], env=env, port=port)
try:
diff --git a/test/lib/03-request-response.py b/test/lib/03-request-response.py
index e38f6802..853361d3 100755
--- a/test/lib/03-request-response.py
+++ b/test/lib/03-request-response.py
@@ -33,12 +33,12 @@ sock.bind(('', port))
sock.listen(5)
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client1 = mosq_test.start_client(filename="03-request-response-1.log", cmd=["c/03-request-response-1.test"], env=env, port=port)
try:
diff --git a/test/lib/04-retain-qos0.py b/test/lib/04-retain-qos0.py
index 3c64b9fa..90c95dd9 100755
--- a/test/lib/04-retain-qos0.py
+++ b/test/lib/04-retain-qos0.py
@@ -22,12 +22,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/08-ssl-bad-cacert.py b/test/lib/08-ssl-bad-cacert.py
index 35313375..70991ef6 100755
--- a/test/lib/08-ssl-bad-cacert.py
+++ b/test/lib/08-ssl-bad-cacert.py
@@ -10,12 +10,12 @@ rc = 1
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env)
if mosq_test.wait_for_subprocess(client):
diff --git a/test/lib/08-ssl-connect-cert-auth-enc.py b/test/lib/08-ssl-connect-cert-auth-enc.py
index a944c112..afc45bd0 100755
--- a/test/lib/08-ssl-connect-cert-auth-enc.py
+++ b/test/lib/08-ssl-connect-cert-auth-enc.py
@@ -26,8 +26,8 @@ disconnect_packet = mosq_test.gen_disconnect()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-ssock = ssl.wrap_socket(sock, ca_certs="../ssl/all-ca.crt",
- keyfile="../ssl/server.key", certfile="../ssl/server.crt",
+ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/all-ca.crt",
+ keyfile=f"{ssl_dir}/server.key", certfile=f"{ssl_dir}/server.crt",
server_side=True, cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(10)
ssock.bind(('', port))
@@ -35,12 +35,12 @@ ssock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
@@ -59,5 +59,8 @@ finally:
print("test client not finished")
rc=1
ssock.close()
+ if rc:
+ (stdo, stde) = client.communicate()
+ print(stde.decode('utf-8'))
exit(rc)
diff --git a/test/lib/08-ssl-connect-cert-auth.py b/test/lib/08-ssl-connect-cert-auth.py
index 6b36340a..5ae510ab 100755
--- a/test/lib/08-ssl-connect-cert-auth.py
+++ b/test/lib/08-ssl-connect-cert-auth.py
@@ -26,8 +26,8 @@ disconnect_packet = mosq_test.gen_disconnect()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-ssock = ssl.wrap_socket(sock, ca_certs="../ssl/all-ca.crt",
- keyfile="../ssl/server.key", certfile="../ssl/server.crt",
+ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/all-ca.crt",
+ keyfile=f"{ssl_dir}/server.key", certfile=f"{ssl_dir}/server.crt",
server_side=True, cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(10)
ssock.bind(('', port))
@@ -35,12 +35,12 @@ ssock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/08-ssl-connect-no-auth.py b/test/lib/08-ssl-connect-no-auth.py
index a6051146..341dc86b 100755
--- a/test/lib/08-ssl-connect-no-auth.py
+++ b/test/lib/08-ssl-connect-no-auth.py
@@ -25,19 +25,19 @@ disconnect_packet = mosq_test.gen_disconnect()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-ssock = ssl.wrap_socket(sock, ca_certs="../ssl/all-ca.crt", keyfile="../ssl/server.key", certfile="../ssl/server.crt", server_side=True)
+ssock = ssl.wrap_socket(sock, ca_certs=f"{ssl_dir}/all-ca.crt", keyfile=f"{ssl_dir}/server.key", certfile=f"{ssl_dir}/server.crt", server_side=True)
ssock.settimeout(10)
ssock.bind(('', port))
ssock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/08-ssl-fake-cacert.py b/test/lib/08-ssl-fake-cacert.py
index fae86d17..3d903704 100755
--- a/test/lib/08-ssl-fake-cacert.py
+++ b/test/lib/08-ssl-fake-cacert.py
@@ -10,21 +10,26 @@ if sys.version < '2.7':
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-ssock = ssl.wrap_socket(sock, ca_certs="../ssl/all-ca.crt",
- keyfile="../ssl/server.key", certfile="../ssl/server.crt",
- server_side=True, cert_reqs=ssl.CERT_REQUIRED)
+ssock = ssl.wrap_socket(
+ sock,
+ ca_certs=f"{ssl_dir}/all-ca.crt",
+ keyfile=f"{ssl_dir}/server.key",
+ certfile=f"{ssl_dir}/server.crt",
+ server_side=True,
+ cert_reqs=ssl.CERT_REQUIRED
+)
ssock.settimeout(10)
ssock.bind(('', port))
ssock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/09-util-topic-tokenise.py b/test/lib/09-util-topic-tokenise.py
index 38e9be2d..825ef879 100755
--- a/test/lib/09-util-topic-tokenise.py
+++ b/test/lib/09-util-topic-tokenise.py
@@ -6,12 +6,12 @@ rc = 1
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env)
if mosq_test.wait_for_subprocess(client):
diff --git a/test/lib/11-prop-oversize-packet.py b/test/lib/11-prop-oversize-packet.py
index 40a34d52..9ee3c1f7 100755
--- a/test/lib/11-prop-oversize-packet.py
+++ b/test/lib/11-prop-oversize-packet.py
@@ -28,12 +28,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/11-prop-recv-qos0.py b/test/lib/11-prop-recv-qos0.py
index 7df053eb..4b154b9a 100755
--- a/test/lib/11-prop-recv-qos0.py
+++ b/test/lib/11-prop-recv-qos0.py
@@ -27,12 +27,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/11-prop-recv-qos1.py b/test/lib/11-prop-recv-qos1.py
index 309a3a9d..0273571f 100755
--- a/test/lib/11-prop-recv-qos1.py
+++ b/test/lib/11-prop-recv-qos1.py
@@ -30,12 +30,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/11-prop-recv-qos2.py b/test/lib/11-prop-recv-qos2.py
index bf4e561e..776b204f 100755
--- a/test/lib/11-prop-recv-qos2.py
+++ b/test/lib/11-prop-recv-qos2.py
@@ -32,12 +32,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/11-prop-send-content-type.py b/test/lib/11-prop-send-content-type.py
index dfc69b21..a89fa656 100755
--- a/test/lib/11-prop-send-content-type.py
+++ b/test/lib/11-prop-send-content-type.py
@@ -22,12 +22,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/11-prop-send-payload-format.py b/test/lib/11-prop-send-payload-format.py
index cb66fa9a..17175018 100755
--- a/test/lib/11-prop-send-payload-format.py
+++ b/test/lib/11-prop-send-payload-format.py
@@ -32,12 +32,12 @@ sock.listen(5)
client_args = sys.argv[1:]
env = dict(os.environ)
-env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
+env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp'
try:
pp = env['PYTHONPATH']
except KeyError:
pp = ''
-env['PYTHONPATH'] = '../../lib/python:'+pp
+env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
try:
diff --git a/test/lib/CMakeLists.txt b/test/lib/CMakeLists.txt
new file mode 100644
index 00000000..60be580f
--- /dev/null
+++ b/test/lib/CMakeLists.txt
@@ -0,0 +1,24 @@
+add_subdirectory(c)
+add_subdirectory(cpp)
+
+
+file(GLOB PY_TEST_FILES [0-9][0-9]-*.py)
+
+set(EXCLUDE_LIST
+ 03-publish-c2b-qos1-timeout
+ 03-publish-c2b-qos2-timeout
+)
+
+foreach(PY_TEST_FILE ${PY_TEST_FILES})
+ get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE)
+ if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST)
+ continue()
+ endif()
+ add_test(NAME lib-${PY_TEST_NAME}
+ COMMAND ${PY_TEST_FILE} c/${PY_TEST_NAME}.test
+ )
+ set_tests_properties(lib-${PY_TEST_NAME}
+ PROPERTIES
+ ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}"
+ )
+endforeach()
diff --git a/test/lib/c/08-ssl-connect-cert-auth-enc.c b/test/lib/c/08-ssl-connect-cert-auth-enc.c
index 2d98b32c..ebd0521e 100644
--- a/test/lib/c/08-ssl-connect-cert-auth-enc.c
+++ b/test/lib/c/08-ssl-connect-cert-auth-enc.c
@@ -5,6 +5,8 @@
#include
#include
+#include "path_helper.h"
+
static int run = -1;
static void on_connect(struct mosquitto *mosq, void *obj, int rc)
@@ -54,7 +56,15 @@ int main(int argc, char *argv[])
if(mosq == NULL){
return 1;
}
- mosquitto_tls_set(mosq, "../ssl/test-root-ca.crt", "../ssl/certs", "../ssl/client-encrypted.crt", "../ssl/client-encrypted.key", password_callback);
+ char cafile[4096];
+ cat_sourcedir_with_relpath(cafile, "/../../ssl/test-root-ca.crt");
+ char capath[4096];
+ cat_sourcedir_with_relpath(capath, "/../../ssl/certs");
+ char certfile[4096];
+ cat_sourcedir_with_relpath(certfile, "/../../ssl/client-encrypted.crt");
+ char keyfile[4096];
+ cat_sourcedir_with_relpath(keyfile, "/../../ssl/client-encrypted.key");
+ mosquitto_tls_set(mosq, cafile, capath, certfile, keyfile, password_callback);
mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_disconnect_callback_set(mosq, on_disconnect);
diff --git a/test/lib/c/08-ssl-connect-cert-auth.c b/test/lib/c/08-ssl-connect-cert-auth.c
index c9582baa..97043f36 100644
--- a/test/lib/c/08-ssl-connect-cert-auth.c
+++ b/test/lib/c/08-ssl-connect-cert-auth.c
@@ -1,3 +1,4 @@
+#include "path_helper.h"
#include
#include
#include
@@ -42,7 +43,15 @@ int main(int argc, char *argv[])
if(mosq == NULL){
return 1;
}
- mosquitto_tls_set(mosq, "../ssl/test-root-ca.crt", "../ssl/certs", "../ssl/client.crt", "../ssl/client.key", NULL);
+ char cafile[4096];
+ cat_sourcedir_with_relpath(cafile, "/../../ssl/test-root-ca.crt");
+ char capath[4096];
+ cat_sourcedir_with_relpath(capath, "/../../ssl/certs");
+ char certfile[4096];
+ cat_sourcedir_with_relpath(certfile, "/../../ssl/client.crt");
+ char keyfile[4096];
+ cat_sourcedir_with_relpath(keyfile, "/../../ssl/client.key");
+ mosquitto_tls_set(mosq, cafile, capath, certfile, keyfile, NULL);
mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_disconnect_callback_set(mosq, on_disconnect);
diff --git a/test/lib/c/08-ssl-connect-no-auth.c b/test/lib/c/08-ssl-connect-no-auth.c
index 3713b4b6..acf4cc13 100644
--- a/test/lib/c/08-ssl-connect-no-auth.c
+++ b/test/lib/c/08-ssl-connect-no-auth.c
@@ -1,3 +1,4 @@
+#include "path_helper.h"
#include
#include
#include
@@ -42,7 +43,9 @@ int main(int argc, char *argv[])
if(mosq == NULL){
return 1;
}
- mosquitto_tls_set(mosq, "../ssl/all-ca.crt", NULL, NULL, NULL, NULL);
+ char cafile[4096];
+ cat_sourcedir_with_relpath(cafile, "/../../ssl/test-root-ca.crt");
+ mosquitto_tls_set(mosq, cafile, NULL, NULL, NULL, NULL);
mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_disconnect_callback_set(mosq, on_disconnect);
diff --git a/test/lib/c/08-ssl-fake-cacert.c b/test/lib/c/08-ssl-fake-cacert.c
index 828a2d15..f8ce340b 100644
--- a/test/lib/c/08-ssl-fake-cacert.c
+++ b/test/lib/c/08-ssl-fake-cacert.c
@@ -4,6 +4,8 @@
#include
#include
+#include "path_helper.h"
+
static void on_connect(struct mosquitto *mosq, void *obj, int rc)
{
(void)mosq;
@@ -30,7 +32,13 @@ int main(int argc, char *argv[])
if(mosq == NULL){
return 1;
}
- mosquitto_tls_set(mosq, "../ssl/test-fake-root-ca.crt", NULL, "../ssl/client.crt", "../ssl/client.key", NULL);
+ char cafile[4096];
+ cat_sourcedir_with_relpath(cafile, "/../../ssl/test-fake-root-ca.crt");
+ char certfile[4096];
+ cat_sourcedir_with_relpath(certfile, "/../../ssl/client.crt");
+ char keyfile[4096];
+ cat_sourcedir_with_relpath(keyfile, "/../../ssl/client.key");
+ mosquitto_tls_set(mosq, cafile, NULL, certfile, keyfile, NULL);
mosquitto_connect_callback_set(mosq, on_connect);
rc = mosquitto_connect(mosq, "localhost", port, 60);
diff --git a/test/lib/c/CMakeLists.txt b/test/lib/c/CMakeLists.txt
new file mode 100644
index 00000000..54f02d03
--- /dev/null
+++ b/test/lib/c/CMakeLists.txt
@@ -0,0 +1,65 @@
+set(BINARIES
+ 01-con-discon-success
+ 01-con-discon-success-v5
+ 01-con-discon-will
+ 01-con-discon-will-v5
+ 01-con-discon-will-clear
+ 01-keepalive-pingreq
+ 01-no-clean-session
+ 01-pre-connect-callback
+ 01-server-keepalive-pingreq
+ 01-unpwd-set
+ 01-will-set
+ 01-will-unpwd-set
+ 02-subscribe-qos0
+ 02-subscribe-qos1-async1
+ 02-subscribe-qos1-async2
+ 02-subscribe-qos1
+ 02-subscribe-qos2
+ 02-unsubscribe-multiple-v5
+ 02-unsubscribe-v5
+ 02-unsubscribe
+ 03-publish-b2c-qos1-unexpected-puback
+ 03-publish-b2c-qos1
+ 03-publish-b2c-qos2-len
+ 03-publish-b2c-qos2-unexpected-pubrel
+ 03-publish-b2c-qos2-unexpected-pubcomp
+ 03-publish-b2c-qos2
+ 03-publish-c2b-qos1-disconnect
+ 03-publish-c2b-qos1-len
+ 03-publish-c2b-qos1-receive-maximum
+ 03-publish-c2b-qos2-disconnect
+ 03-publish-c2b-qos2-len
+ 03-publish-c2b-qos2-maximum-qos-0
+ 03-publish-c2b-qos2-maximum-qos-1
+ 03-publish-c2b-qos2-pubrec-error
+ 03-publish-c2b-qos2-receive-maximum-1
+ 03-publish-c2b-qos2-receive-maximum-2
+ 03-publish-c2b-qos2
+ 03-publish-qos0-no-payload
+ 03-publish-qos0
+ 03-request-response-1
+ 03-request-response-2
+ 03-request-response-correlation-1
+ 04-retain-qos0
+ 08-ssl-bad-cacert
+ 08-ssl-connect-cert-auth-enc
+ 08-ssl-connect-cert-auth
+ 08-ssl-connect-no-auth
+ 08-ssl-fake-cacert
+ 09-util-topic-tokenise
+ 11-prop-oversize-packet
+ 11-prop-recv-qos0
+ 11-prop-recv-qos1
+ 11-prop-recv-qos2
+ 11-prop-send-payload-format
+ 11-prop-send-content-type
+)
+
+foreach(BINARY ${BINARIES})
+ add_executable(${BINARY} ${BINARY}.c)
+ target_compile_definitions(${BINARY} PRIVATE TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
+ target_include_directories(${BINARY} PRIVATE ${CMAKE_SOURCE_DIR}/test)
+ set_property(TARGET ${BINARY} PROPERTY SUFFIX .test)
+ target_link_libraries(${BINARY} PRIVATE libmosquitto)
+endforeach()
diff --git a/test/lib/c/Makefile b/test/lib/c/Makefile
index 0bbf341b..5c9b3d04 100644
--- a/test/lib/c/Makefile
+++ b/test/lib/c/Makefile
@@ -1,7 +1,7 @@
R=../../..
.PHONY: all clean reallyclean
-CFLAGS=-I${R}/include -Werror
+CFLAGS=-I${R}/include -I${R}/test -Werror
LIBS=${R}/lib/libmosquitto.so.1
SRC = \
@@ -65,8 +65,8 @@ TESTS = ${SRC:.c=.test}
all : ${TESTS}
-${TESTS} : %.test: %.c
- $(CC) $< -o $@ $(CFLAGS) $(LIBS)
+${TESTS} : %.test: %.c ${R}/test/path_helper.h
+ $(CC) $< -o $@ -D TEST_SOURCE_DIR='"$(realpath .)"' $(CFLAGS) $(LIBS)
reallyclean : clean
-rm -f *.orig
diff --git a/test/lib/cpp/CMakeLists.txt b/test/lib/cpp/CMakeLists.txt
new file mode 100644
index 00000000..c9b56bce
--- /dev/null
+++ b/test/lib/cpp/CMakeLists.txt
@@ -0,0 +1,37 @@
+set(BINARIES
+ 01-con-discon-success
+ 01-will-set
+ 01-unpwd-set
+ 01-will-unpwd-set
+ 01-no-clean-session
+ 01-keepalive-pingreq
+ 02-subscribe-qos0
+ 02-subscribe-qos1
+ 02-subscribe-qos2
+ 02-unsubscribe
+ 03-publish-qos0
+ 03-publish-qos0-no-payload
+ 03-publish-c2b-qos1-disconnect
+ 03-publish-c2b-qos2
+ 03-publish-c2b-qos2-disconnect
+ 03-publish-b2c-qos1
+ 03-publish-b2c-qos2
+ 04-retain-qos0
+ 08-ssl-connect-no-auth
+ 08-ssl-connect-cert-auth
+ 08-ssl-connect-cert-auth-enc
+ 08-ssl-bad-cacert
+ 08-ssl-fake-cacert
+ 09-util-topic-tokenise
+)
+
+foreach(BINARY ${BINARIES})
+ set(TARGET "${BINARY}-cpp")
+ add_executable(${TARGET}
+ ${BINARY}.cpp
+ )
+ set_property(TARGET ${TARGET}
+ PROPERTY SUFFIX .test
+ )
+ target_link_libraries(${TARGET} PRIVATE mosquittopp)
+endforeach()
diff --git a/test/lib/mosq_test_helper.py b/test/lib/mosq_test_helper.py
index 0e861dba..9b3cf8de 100644
--- a/test/lib/mosq_test_helper.py
+++ b/test/lib/mosq_test_helper.py
@@ -13,3 +13,9 @@ import ssl
import struct
import subprocess
import time
+
+
+from pathlib import Path
+
+source_dir = Path(__file__).resolve().parent
+ssl_dir = source_dir.parent / "ssl"
diff --git a/test/mosq_test.py b/test/mosq_test.py
index b068074d..71ea4836 100644
--- a/test/mosq_test.py
+++ b/test/mosq_test.py
@@ -1,3 +1,4 @@
+import atexit
import errno
import os
import socket
@@ -6,11 +7,13 @@ import struct
import sys
import time
+import traceback
+
import mqtt5_props
import __main__
-import atexit
+from pathlib import Path
vg_index = 1
vg_logfiles = []
@@ -18,23 +21,29 @@ class TestError(Exception):
def __init__(self, message="Mismatched packets"):
self.message = message
-def start_broker(filename, cmd=None, port=0, use_conf=False, expect_fail=False, nolog=False, checkhost="localhost"):
+def get_build_root():
+ result = os.getenv("BUILD_ROOT")
+ if result is None:
+ result = str(Path(__file__).resolve().parents[1])
+ return result
+
+def start_broker(filename, cmd=None, port=0, use_conf=False, expect_fail=False, nolog=False, checkhost="localhost", env=None):
global vg_index
global vg_logfiles
delay = 0.1
- if use_conf == True:
- cmd = ['../../src/mosquitto', '-v', '-c', filename.replace('.py', '.conf')]
+ if use_conf:
+ cmd = [get_build_root() + '/src/mosquitto', '-v', '-c', filename.replace('.py', '.conf')]
if port == 0:
port = 1888
else:
if cmd is None and port != 0:
- cmd = ['../../src/mosquitto', '-v', '-p', str(port)]
+ cmd = [get_build_root() + '/src/mosquitto', '-v', '-p', str(port)]
elif cmd is None and port == 0:
port = 1888
- cmd = ['../../src/mosquitto', '-v', '-c', filename.replace('.py', '.conf')]
+ cmd = [get_build_root() + '/src/mosquitto', '-v', '-c', filename.replace('.py', '.conf')]
elif cmd is not None and port == 0:
port = 1888
@@ -55,9 +64,9 @@ def start_broker(filename, cmd=None, port=0, use_conf=False, expect_fail=False,
#print(port)
#print(cmd)
if nolog == False:
- broker = subprocess.Popen(cmd, stderr=subprocess.PIPE)
+ broker = subprocess.Popen(cmd, stderr=subprocess.PIPE, env=env)
else:
- broker = subprocess.Popen(cmd, stderr=subprocess.DEVNULL)
+ broker = subprocess.Popen(cmd, stderr=subprocess.DEVNULL, env=env)
for i in range(0, 20):
time.sleep(delay)
c = None
@@ -137,7 +146,7 @@ def expect_packet(sock, name, expected):
while len(packet_recvd) < rlen:
data = sock.recv(rlen-len(packet_recvd))
if len(data) == 0:
- break
+ raise BrokenPipeError(f"when reading {name} from {sock.getpeername()}")
packet_recvd += data
except socket.timeout:
pass
@@ -159,6 +168,7 @@ def packet_matches(name, recvd, expected):
print("Expected: "+to_string(expected))
except struct.error:
print("Expected (not decoded, len=%d): %s" % (len(expected), expected))
+ traceback.print_stack(file=sys.stdout)
return False
else:
diff --git a/test/path_helper.h b/test/path_helper.h
new file mode 100644
index 00000000..3af9b8f7
--- /dev/null
+++ b/test/path_helper.h
@@ -0,0 +1,16 @@
+#ifndef PATH_HELPER_H
+#define PATH_HELPER_H
+
+#include
+#include
+#include
+#include
+#include
+
+/* returns / written to */
+void cat_sourcedir_with_relpath(char* dest, const char* relpath) {
+ strcpy(dest,TEST_SOURCE_DIR);
+ strcat(dest, relpath);
+}
+
+#endif
diff --git a/test/random/random_client.py b/test/random/random_client.py
index 3838b37f..917fbe8a 100755
--- a/test/random/random_client.py
+++ b/test/random/random_client.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
+from pathlib import Path
import paho.mqtt.client as paho
import random
import sys
@@ -115,7 +116,9 @@ def main():
mqttc.username_pw_set("bad", "bad")
if use_tls:
- mqttc.tls_set(ca_certs="../ssl/all-ca.crt")
+ source_dir = Path(__file__).resolve().parent
+ ssl_dir = source_dir.parent / "ssl"
+ mqttc.tls_set(ca_certs=f"{ssl_dir}/all-ca.crt")
mqttc.connect("localhost", port)
mqttc.loop_start()
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
new file mode 100644
index 00000000..b8d9ec92
--- /dev/null
+++ b/test/unit/CMakeLists.txt
@@ -0,0 +1,143 @@
+find_package(CUnit REQUIRED)
+
+add_library(common-unit-test-header INTERFACE)
+target_include_directories(common-unit-test-header
+ INTERFACE
+ "${mosquitto_SOURCE_DIR}/include"
+ "${mosquitto_SOURCE_DIR}/common"
+ "${mosquitto_SOURCE_DIR}/deps"
+ "${mosquitto_SOURCE_DIR}/lib"
+ "${mosquitto_SOURCE_DIR}/src"
+ "${mosquitto_SOURCE_DIR}/test"
+)
+target_link_libraries(common-unit-test-header INTERFACE config-header CUnit::CUnit)
+
+# unit-broker
+add_executable(broker-test
+ datatype_read.c
+ datatype_write.c
+ misc_trim_test.c
+ property_add.c
+ property_read.c
+ property_user_read.c
+ property_write.c
+ stubs.c
+ util_topic_test.c
+ utf8.c
+ # main test files
+ test.c
+ ../../lib/packet_datatypes.c
+ ../../lib/packet_mosq.c
+ ../../lib/property_mosq.c
+ ../../lib/memory_mosq.c
+ ../../common/misc_mosq.c
+ ../../lib/util_mosq.c
+ ../../lib/util_topic.c
+ ../../lib/utf8_mosq.c
+)
+
+target_link_libraries(broker-test PRIVATE common-unit-test-header OpenSSL::SSL)
+add_test(NAME unit-broker-test COMMAND broker-test)
+
+# bridge-topic-test
+add_library(bridge-topic-obj OBJECT ../../src/bridge_topic.c)
+target_compile_definitions(bridge-topic-obj PRIVATE WITH_BRIDGE WITH_BROKER)
+target_link_libraries(bridge-topic-obj PUBLIC common-unit-test-header)
+
+add_executable(bridge-topic-test
+ bridge_topic_test.c
+ stubs.c
+ ../../lib/memory_mosq.c
+ ../../src/memory_public.c
+ ../../lib/util_topic.c
+)
+target_link_libraries(bridge-topic-test PRIVATE bridge-topic-obj common-unit-test-header)
+add_test(NAME unit-bridge-topic-test COMMAND bridge-topic-test)
+
+# keepalive-test
+add_executable(keepalive-test
+ keepalive_test.c
+ keepalive_stubs.c
+ ../../lib/memory_mosq.c
+)
+target_link_libraries(keepalive-test PRIVATE common-unit-test-header)
+add_test(NAME unit-keepalive-test COMMAND keepalive-test)
+
+# persist-read-test
+add_library(persistence-read-obj
+ OBJECT
+ ../../src/persist_read_v234.c
+ ../../src/persist_read_v5.c
+ ../../src/persist_read.c
+ ../../src/retain.c
+ ../../src/topic_tok.c
+)
+target_compile_definitions(persistence-read-obj PRIVATE WITH_PERSISTENCE WITH_BROKER)
+target_link_libraries(persistence-read-obj PUBLIC common-unit-test-header OpenSSL::SSL)
+
+add_executable(persist-read-test
+ persist_read_test.c
+ persist_read_stubs.c
+ ../../common/misc_mosq.c
+ ../../lib/memory_mosq.c
+ ../../lib/packet_datatypes.c
+ ../../lib/property_mosq.c
+ ../../lib/utf8_mosq.c
+ ../../lib/util_mosq.c
+ ../../src/memory_public.c
+)
+target_compile_definitions(persist-read-test PRIVATE TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
+target_link_libraries(persist-read-test PRIVATE persistence-read-obj)
+add_test(NAME unit-persist-read-test COMMAND persist-read-test)
+
+# persist-write-test
+add_library(persistence-write-obj
+ OBJECT
+ ../../src/database.c
+ ../../src/persist_read_v234.c
+ ../../src/persist_read_v5.c
+ ../../src/persist_read.c
+ ../../src/persist_write_v5.c
+ ../../src/persist_write.c
+ ../../src/retain.c
+ ../../src/subs.c
+ ../../src/topic_tok.c
+)
+target_compile_definitions(persistence-write-obj PRIVATE WITH_PERSISTENCE WITH_BROKER)
+target_link_libraries(persistence-write-obj PUBLIC common-unit-test-header)
+
+add_executable(persist-write-test
+ persist_write_test.c
+ persist_write_stubs.c
+ ../../common/misc_mosq.c
+ ../../lib/memory_mosq.c
+ ../../lib/packet_datatypes.c
+ ../../lib/property_mosq.c
+ ../../lib/utf8_mosq.c
+ ../../lib/util_mosq.c
+ ../../src/memory_public.c
+ ../../lib/packet_mosq.c
+)
+target_compile_definitions(persist-write-test PRIVATE TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
+target_link_libraries(persist-write-test PRIVATE persistence-write-obj OpenSSL::SSL)
+add_test(NAME unit-persist-write-test COMMAND persist-write-test)
+
+# subs-test
+add_library(persistence-obj
+ OBJECT
+ ../../src/database.c
+ ../../src/subs.c
+ ../../src/topic_tok.c
+)
+target_compile_definitions(persistence-obj PRIVATE WITH_PERSISTENCE WITH_BROKER)
+target_link_libraries(persistence-obj PUBLIC common-unit-test-header)
+
+add_executable(subs-test
+ subs_stubs.c
+ subs_test.c
+ ../../lib/memory_mosq.c
+ ../../src/memory_public.c
+)
+
+target_link_libraries(subs-test PRIVATE common-unit-test-header persistence-obj)
+add_test(NAME unit-subs-test COMMAND subs-test)
diff --git a/test/unit/Makefile b/test/unit/Makefile
index 7367a291..7a9cf05d 100644
--- a/test/unit/Makefile
+++ b/test/unit/Makefile
@@ -3,12 +3,12 @@ include ${R}/config.mk
.PHONY: all check test test-broker test-lib clean coverage
-CPPFLAGS:=$(CPPFLAGS) -I${R} -I${R}/include -I${R}/lib -I${R}/src -I${R}/common
+CPPFLAGS:=$(CPPFLAGS) -I${R} -I${R}/include -I${R}/lib -I${R}/src -I${R}/common -I${R}/test
ifeq ($(WITH_BUNDLED_DEPS),yes)
CPPFLAGS:=$(CPPFLAGS) -I${R}/deps
endif
-CFLAGS:=$(CFLAGS) -coverage -Wall -ggdb
+CFLAGS:=$(CFLAGS) -coverage -Wall -ggdb -D TEST_SOURCE_DIR='"$(realpath .)"'
LDFLAGS:=$(LDFLAGS) -coverage
LDADD:=$(LDADD) -lcunit
diff --git a/test/unit/persist_read_test.c b/test/unit/persist_read_test.c
index 85bf8043..21cf039d 100644
--- a/test/unit/persist_read_test.c
+++ b/test/unit/persist_read_test.c
@@ -5,6 +5,7 @@
#include
#include
+#include "path_helper.h"
#define WITH_BROKER
#define WITH_PERSISTENCE
@@ -44,7 +45,10 @@ static void TEST_empty_file(void)
config.persistence = true;
- config.persistence_filepath = "files/persist_read/empty.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/empty.test-db");
+ config.persistence_filepath = persistence_filepath;
+
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
}
@@ -61,11 +65,14 @@ static void TEST_corrupt_header(void)
config.persistence = true;
- config.persistence_filepath = "files/persist_read/corrupt-header-short.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/corrupt-header-short.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, 1);
- config.persistence_filepath = "files/persist_read/corrupt-header-long.test-db";
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/corrupt-header-long.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, 1);
}
@@ -80,7 +87,9 @@ static void TEST_unsupported_version(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/unsupported-version.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/unsupported-version.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, 1);
@@ -97,7 +106,9 @@ static void TEST_v3_config_ok(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-cfg.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-cfg.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -115,7 +126,9 @@ static void TEST_v4_config_ok(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v4-cfg.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v4-cfg.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -133,7 +146,9 @@ static void TEST_v3_config_truncated(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-cfg-truncated.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-cfg-truncated.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, 1);
@@ -151,7 +166,9 @@ static void TEST_v3_config_bad_dbid(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-cfg-bad-dbid.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-cfg-bad-dbid.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, 1);
@@ -169,7 +186,9 @@ static void TEST_v3_bad_chunk(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-bad-chunk.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-bad-chunk.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -187,7 +206,9 @@ static void TEST_v3_message_store(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-message-store.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-message-store.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -222,7 +243,9 @@ static void TEST_v3_client(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-client.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-client.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -248,7 +271,9 @@ static void TEST_v3_client_message(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-client-message.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-client-message.test-db");
+ config.persistence_filepath = persistence_filepath;
config.max_inflight_messages = 20;
rc = persist__restore();
@@ -299,7 +324,9 @@ static void TEST_v3_retain(void)
retain__init();
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-retain.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-retain.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -349,7 +376,9 @@ static void TEST_v3_sub(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v3-sub.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v3-sub.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -377,7 +406,9 @@ static void TEST_v4_message_store(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v4-message-store.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v4-message-store.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -411,7 +442,9 @@ static void TEST_v6_config_ok(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-cfg.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-cfg.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -429,7 +462,9 @@ static void TEST_v5_config_truncated(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v5-cfg-truncated.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v5-cfg-truncated.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, 1);
@@ -447,7 +482,9 @@ static void TEST_v5_bad_chunk(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v5-bad-chunk.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v5-bad-chunk.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -465,7 +502,9 @@ static void TEST_v6_message_store(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-message-store.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-message-store.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -504,7 +543,9 @@ static void TEST_v6_message_store_props(void)
config.listener_count = 1;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-message-store-props.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-message-store-props.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -542,7 +583,9 @@ static void TEST_v5_client(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v5-client.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v5-client.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -574,7 +617,9 @@ static void TEST_v6_client(void)
config.listeners = &listener;
config.listener_count = 1;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-client.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-client.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -605,7 +650,9 @@ static void TEST_v6_client_message(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-client-message.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-client-message.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -652,7 +699,9 @@ static void TEST_v6_client_message_props(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-client-message-props.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-client-message-props.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -698,7 +747,9 @@ static void TEST_v6_retain(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-retain.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-retain.test-db");
+ config.persistence_filepath = persistence_filepath;
retain__init();
rc = persist__restore();
@@ -746,7 +797,9 @@ static void TEST_v6_sub(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-sub.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-sub.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
diff --git a/test/unit/persist_write_test.c b/test/unit/persist_write_test.c
index 9596b48b..60879f39 100644
--- a/test/unit/persist_write_test.c
+++ b/test/unit/persist_write_test.c
@@ -5,6 +5,7 @@
#include
#include
+#include "path_helper.h"
#define WITH_BROKER
#define WITH_PERSISTENCE
@@ -105,7 +106,9 @@ static void TEST_empty_file(void)
config.persistence_filepath = "empty.db";
rc = persist__backup(false);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_write/empty.test-db", "empty.db"));
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_write/empty.test-db");
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "empty.db"));
unlink("empty.db");
}
@@ -120,7 +123,9 @@ static void TEST_v6_config_ok(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-cfg.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-cfg.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -128,7 +133,7 @@ static void TEST_v6_config_ok(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_read/v6-cfg.test-db", "v6-cfg.db"));
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "v6-cfg.db"));
unlink("v6-cfg.db");
}
@@ -143,7 +148,9 @@ static void TEST_v6_message_store_no_ref(void)
db.config = &config;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-message-store.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-message-store.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -151,7 +158,9 @@ static void TEST_v6_message_store_no_ref(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_write/v6-message-store-no-ref.test-db", "v6-message-store-no-ref.db"));
+ char persistence_filepath_no_ref[4096];
+ cat_sourcedir_with_relpath(persistence_filepath_no_ref, "/files/persist_write/v6-message-store-no-ref.test-db");
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath_no_ref, "v6-message-store-no-ref.db"));
unlink("v6-message-store-no-ref.db");
}
@@ -172,7 +181,9 @@ static void TEST_v6_message_store_props(void)
config.listener_count = 1;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-message-store-props.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-message-store-props.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -180,7 +191,7 @@ static void TEST_v6_message_store_props(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_read/v6-message-store-props.test-db", "v6-message-store-props.db"));
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "v6-message-store-props.db"));
unlink("v6-message-store-props.db");
}
@@ -201,7 +212,9 @@ static void TEST_v6_client(void)
config.listener_count = 1;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-client.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-client.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -209,7 +222,7 @@ static void TEST_v6_client(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_read/v6-client.test-db", "v6-client.db"));
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "v6-client.db"));
unlink("v6-client.db");
}
@@ -230,7 +243,9 @@ static void TEST_v6_client_message(void)
config.listener_count = 1;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-client-message.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-client-message.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -238,7 +253,7 @@ static void TEST_v6_client_message(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_read/v6-client-message.test-db", "v6-client-message.db"));
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "v6-client-message.db"));
unlink("v6-client-message.db");
}
@@ -259,7 +274,9 @@ static void TEST_v6_client_message_props(void)
config.listener_count = 1;
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-client-message-props.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-client-message-props.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -275,7 +292,7 @@ static void TEST_v6_client_message_props(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_read/v6-client-message-props.test-db", "v6-client-message-props.db"));
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "v6-client-message-props.db"));
//unlink("v6-client-message-props.db");
}
@@ -298,7 +315,9 @@ static void TEST_v6_sub(void)
db__open(&config);
config.persistence = true;
- config.persistence_filepath = "files/persist_read/v6-sub.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_read/v6-sub.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -306,7 +325,7 @@ static void TEST_v6_sub(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_read/v6-sub.test-db", "v6-sub.db"));
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "v6-sub.db"));
unlink("v6-sub.db");
}
@@ -325,7 +344,9 @@ static void TEST_v5_full(void)
db__open(&config);
config.persistence = true;
- config.persistence_filepath = "files/persist_write/v5-full.test-db";
+ char persistence_filepath[4096];
+ cat_sourcedir_with_relpath(persistence_filepath, "/files/persist_write/v5-full.test-db");
+ config.persistence_filepath = persistence_filepath;
rc = persist__restore();
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
@@ -333,7 +354,7 @@ static void TEST_v5_full(void)
rc = persist__backup(true);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
- CU_ASSERT_EQUAL(0, file_diff("files/persist_write/v5-full.test-db", "v5-full.db"));
+ CU_ASSERT_EQUAL(0, file_diff(persistence_filepath, "v5-full.db"));
unlink("v5-full.db");
}
#endif
diff --git a/www/pages/documentation/dynamic-security.md b/www/pages/documentation/dynamic-security.md
index 43277963..07f86830 100644
--- a/www/pages/documentation/dynamic-security.md
+++ b/www/pages/documentation/dynamic-security.md
@@ -329,25 +329,60 @@ during normal operation the configuration stays in memory.
### Generating the configuration file - 2.1 onwards
-To generate your initial configuration file there are two choices. In version
+To generate your initial configuration file there are a few choices. In version
2.0.x, you must use the `mosquitto_ctrl` utility as described below. From
version 2.1 onwards, if the configuration file does not exist, the plugin will
-attempt to generate a default configuration file with some sensible defaults,
-including an admin client that can administer the plugin, a democlient client
-that has read/write access to the application topic hierarchy, and a few roles
-for different situations. Random passwords will be generated for the two
-clients and placed in a file with the same name and location as the
-configuration file, with `.pw` appended. For example
-`dynamic-security.json.pw`.
+attempt to generate a default configuration file with some sensible defaults.
The roles created are:
+* `broker-admin` - grants access to administer general broker settings
* `client` - read/write access to the full application topic hierarchy '#'
* `dynsec-admin` - grants access to administer clients/groups/roles
+* `super-admin` - grants access to administer any `$CONTROL` APIs
* `sys-notify` - allow bridges to publish connection state messages
* `sys-observe` - allow read only access to the $SYS/# topic hierarchy
* `topic-observe` - allow read only access to the full application topic hierarchy '#'
+The groups created are:
+
+* `unauthenticated` - automatic group that anonymous/unauthenticated clients
+ are placed in, if anonymous access is allowed.
+
+The initial users can be generated in three different ways, as described below.
+
+#### Initialisation file
+
+Create a text file with a single line. This line will be used as the password
+for the `admin` user, which will have access to administer the dynamic security
+plugin.
+
+Set the configuration option to trigger the use of this file:
+```
+plugin_opt_password_init_file path/to/init-file
+```
+
+Once the initial run of the broker has been done, the init file can be deleted.
+
+This method is well suited to use with e.g. docker secrets inside a container.
+
+#### Environment variable
+
+Set the `MOSQUITTO_DYNSEC_PASSWORD` environment variable to a string text and
+it will be used as the password for the `admin` user, which will have access to
+administer the dynamic security plugin.
+
+#### Default
+
+If neither `plugin_opt_password_init_file` nor `MOSQUITTO_DYNSEC_PASSWORD` are
+set, then the plugin will generate random passwords and store them in *plain
+text* at `.pw`, for example `dynamic-security.json.pw`.
+This file should be deleted once the passwords are known.
+
+Two users will be created, `admin`, which will have access to administer the
+dynamic security plugin, and `democlient`, which will have read/write access to
+the application topic hierarchy `#`.
+
### Generating the configuration file - 2.0 onwards
To generate an initial file using the `mosquitto_ctrl` utility: