From 8a6bb872fe1b2a878ada7ac97841320b027950cf Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 28 Nov 2022 14:36:43 +0000 Subject: [PATCH] Invalid/unsupported plugin tests. --- test/broker/01-connect-unix-socket.py | 20 +--- test/broker/09-plugin-bad.py | 45 +++++++++ test/broker/09-plugin-unsupported.py | 35 +++++++ test/broker/16-config-missing.py | 19 +--- test/broker/16-config-parse-errors-tls-psk.py | 19 +--- test/broker/16-config-parse-errors-tls.py | 19 +--- .../16-config-parse-errors-without-tls.py | 19 +--- test/broker/Makefile | 2 + test/broker/c/CMakeLists.txt | 23 +++++ test/broker/c/Makefile | 22 +++++ test/broker/c/bad_v1.c | 8 ++ test/broker/c/bad_v2_1.c | 96 +++++++++++++++++++ test/broker/c/bad_v2_2.c | 81 ++++++++++++++++ test/broker/c/bad_v2_3.c | 57 +++++++++++ test/broker/c/bad_v2_4.c | 47 +++++++++ test/broker/c/bad_v2_5.c | 37 +++++++ test/broker/c/bad_v2_6.c | 28 ++++++ test/broker/c/bad_v2_7.c | 19 ++++ test/broker/c/bad_v3_1.c | 88 +++++++++++++++++ test/broker/c/bad_v3_2.c | 72 ++++++++++++++ test/broker/c/bad_v3_3.c | 48 ++++++++++ test/broker/c/bad_v3_4.c | 38 ++++++++ test/broker/c/bad_v3_5.c | 28 ++++++ test/broker/c/bad_v3_6.c | 19 ++++ test/broker/c/bad_v3_7.c | 10 ++ test/broker/c/bad_v4_1.c | 38 ++++++++ test/broker/c/bad_v4_2.c | 28 ++++++ test/broker/c/bad_v4_3.c | 19 ++++ test/broker/c/bad_v4_4.c | 10 ++ test/broker/c/bad_v5_1.c | 8 ++ test/broker/c/bad_v6.c | 8 ++ test/broker/c/bad_vnone_1.c | 4 + test/broker/test.py | 2 + test/mosq_test.py | 6 +- 34 files changed, 931 insertions(+), 91 deletions(-) create mode 100755 test/broker/09-plugin-bad.py create mode 100755 test/broker/09-plugin-unsupported.py create mode 100644 test/broker/c/bad_v1.c create mode 100644 test/broker/c/bad_v2_1.c create mode 100644 test/broker/c/bad_v2_2.c create mode 100644 test/broker/c/bad_v2_3.c create mode 100644 test/broker/c/bad_v2_4.c create mode 100644 test/broker/c/bad_v2_5.c create mode 100644 test/broker/c/bad_v2_6.c create mode 100644 test/broker/c/bad_v2_7.c create mode 100644 test/broker/c/bad_v3_1.c create mode 100644 test/broker/c/bad_v3_2.c create mode 100644 test/broker/c/bad_v3_3.c create mode 100644 test/broker/c/bad_v3_4.c create mode 100644 test/broker/c/bad_v3_5.c create mode 100644 test/broker/c/bad_v3_6.c create mode 100644 test/broker/c/bad_v3_7.c create mode 100644 test/broker/c/bad_v4_1.c create mode 100644 test/broker/c/bad_v4_2.c create mode 100644 test/broker/c/bad_v4_3.c create mode 100644 test/broker/c/bad_v4_4.c create mode 100644 test/broker/c/bad_v5_1.c create mode 100644 test/broker/c/bad_v6.c create mode 100644 test/broker/c/bad_vnone_1.c diff --git a/test/broker/01-connect-unix-socket.py b/test/broker/01-connect-unix-socket.py index b46d8855..66d732a8 100755 --- a/test/broker/01-connect-unix-socket.py +++ b/test/broker/01-connect-unix-socket.py @@ -4,24 +4,6 @@ from mosq_test_helper import * -vg_index = 0 -def start_broker(filename): - global vg_index - 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' - if os.environ.get('MOSQ_USE_VALGRIND') == 'callgrind': - cmd = ['valgrind', '-q', '--tool=callgrind', '--log-file='+logfile] + cmd - elif os.environ.get('MOSQ_USE_VALGRIND') == 'massif': - cmd = ['valgrind', '-q', '--tool=massif', '--log-file='+logfile] + cmd - else: - cmd = ['valgrind', '-q', '--trace-children=yes', '--leak-check=full', '--show-leak-kinds=all', '--log-file='+logfile] + cmd - - vg_index += 1 - return subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) - - def write_config(filename, port): with open(filename, 'w') as f: f.write("listener 0 %d.sock\n" % (port)) @@ -36,7 +18,7 @@ def do_test(): port = mosq_test.get_port() conf_file = os.path.basename(__file__).replace('.py', '.conf') write_config(conf_file, port) - broker = start_broker(filename=conf_file) + broker = mosq_test.start_broker(filename=conf_file, check_port=False) try: if os.environ.get('MOSQ_USE_VALGRIND') is None: diff --git a/test/broker/09-plugin-bad.py b/test/broker/09-plugin-bad.py new file mode 100755 index 00000000..939801aa --- /dev/null +++ b/test/broker/09-plugin-bad.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +from mosq_test_helper import * + +# Check whether incomplete plugins are handled ok + +def write_config(filename, port, plugver, num): + with open(filename, 'w') as f: + f.write(f"listener {port}\n") + f.write(f"auth_plugin c/bad_v{plugver}_{num}.so\n") + f.write("allow_anonymous false\n") + +def do_test(plugver, num): + port = mosq_test.get_port() + conf_file = os.path.basename(__file__).replace('.py', '.conf') + write_config(conf_file, port, plugver, num) + + try: + rc = 1 + broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port, check_port=False) + broker.wait(1) + broker.terminate() + if broker.returncode == 13: + rc = 0 + except mosq_test.TestError: + pass + finally: + os.remove(conf_file) + (stdo, stde) = broker.communicate() + if rc: + print(stde.decode('utf-8')) + exit(rc) + +do_test("none", 1) + +for i in range(1,8): + do_test(2, i) + +for i in range(1,8): + do_test(3, i) + +for i in range(1,5): + do_test(4, i) + +do_test(5, 1) diff --git a/test/broker/09-plugin-unsupported.py b/test/broker/09-plugin-unsupported.py new file mode 100755 index 00000000..0f2a4cc3 --- /dev/null +++ b/test/broker/09-plugin-unsupported.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +from mosq_test_helper import * + +# Check whether unsupported plugin versions are handled ok + +def write_config(filename, port, plugver): + with open(filename, 'w') as f: + f.write(f"listener {port}\n") + f.write(f"auth_plugin c/bad_v{plugver}.so\n") + f.write("allow_anonymous false\n") + +def do_test(plugver): + port = mosq_test.get_port() + conf_file = os.path.basename(__file__).replace('.py', '.conf') + write_config(conf_file, port, plugver) + + try: + rc = 1 + broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port, check_port=False) + broker.wait(1) + broker.terminate() + if broker.returncode == 13: + rc = 0 + except mosq_test.TestError: + pass + finally: + os.remove(conf_file) + (stdo, stde) = broker.communicate() + if rc: + print(stde.decode('utf-8')) + exit(rc) + +do_test(1) +do_test(6) diff --git a/test/broker/16-config-missing.py b/test/broker/16-config-missing.py index 27852da6..1ff14eee 100755 --- a/test/broker/16-config-missing.py +++ b/test/broker/16-config-missing.py @@ -4,24 +4,9 @@ from mosq_test_helper import * -def start_broker(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__)+'.vglog' - if os.environ.get('MOSQ_USE_VALGRIND') == 'callgrind': - cmd = ['valgrind', '-q', '--tool=callgrind', '--log-file='+logfile] + cmd - elif os.environ.get('MOSQ_USE_VALGRIND') == 'massif': - cmd = ['valgrind', '-q', '--tool=massif', '--log-file='+logfile] + cmd - else: - cmd = ['valgrind', '-q', '--trace-children=yes', '--leak-check=full', '--show-leak-kinds=all', '--log-file='+logfile] + cmd - - return subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) - - conf_file = os.path.basename(__file__).replace('.py', '.conf') -broker = start_broker(conf_file) +broker = mosq_test.start_broker(conf_file, check_port=False) mosq_test.wait_for_subprocess(broker) @@ -31,5 +16,5 @@ error_message = stde.decode('utf-8') if not error_message.endswith(f"Error: Unable to open config file {conf_file}.\n"): print(f"Got wrong error message: '{error_message}'") exit(1) - + exit(0) diff --git a/test/broker/16-config-parse-errors-tls-psk.py b/test/broker/16-config-parse-errors-tls-psk.py index fce7a00f..98e00351 100755 --- a/test/broker/16-config-parse-errors-tls-psk.py +++ b/test/broker/16-config-parse-errors-tls-psk.py @@ -6,23 +6,6 @@ from mosq_test_helper import * vg_index = 0 -def start_broker(filename): - global vg_index - cmd = ['../../src/mosquitto', '-v', '-c', filename] - - if os.environ.get('MOSQ_USE_VALGRIND') is not None: - logfile = os.path.basename(__file__)+'.'+str(vg_index)+'.vglog' - if os.environ.get('MOSQ_USE_VALGRIND') == 'callgrind': - cmd = ['valgrind', '-q', '--tool=callgrind', '--log-file='+logfile] + cmd - elif os.environ.get('MOSQ_USE_VALGRIND') == 'massif': - cmd = ['valgrind', '-q', '--tool=massif', '--log-file='+logfile] + cmd - else: - cmd = ['valgrind', '-q', '--trace-children=yes', '--leak-check=full', '--show-leak-kinds=all', '--log-file='+logfile] + cmd - - vg_index += 1 - return subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) - - def write_config(filename, port, config_str): with open(filename, 'w') as f: f.write(f"{config_str}") @@ -36,7 +19,7 @@ def do_test(config_str, rc_expected): write_config(conf_file, port, config_str) try: - broker = start_broker(conf_file) + broker = mosq_test.start_broker(conf_file, check_port=False) broker.wait(timeout=1) if broker.returncode == rc_expected: diff --git a/test/broker/16-config-parse-errors-tls.py b/test/broker/16-config-parse-errors-tls.py index d989fe5d..60fa9349 100755 --- a/test/broker/16-config-parse-errors-tls.py +++ b/test/broker/16-config-parse-errors-tls.py @@ -6,23 +6,6 @@ from mosq_test_helper import * vg_index = 0 -def start_broker(filename): - global vg_index - cmd = ['../../src/mosquitto', '-v', '-c', filename] - - if os.environ.get('MOSQ_USE_VALGRIND') is not None: - logfile = os.path.basename(__file__)+'.'+str(vg_index)+'.vglog' - if os.environ.get('MOSQ_USE_VALGRIND') == 'callgrind': - cmd = ['valgrind', '-q', '--tool=callgrind', '--log-file='+logfile] + cmd - elif os.environ.get('MOSQ_USE_VALGRIND') == 'massif': - cmd = ['valgrind', '-q', '--tool=massif', '--log-file='+logfile] + cmd - else: - cmd = ['valgrind', '-q', '--trace-children=yes', '--leak-check=full', '--show-leak-kinds=all', '--log-file='+logfile] + cmd - - vg_index += 1 - return subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) - - def write_config(filename, port, config_str): with open(filename, 'w') as f: f.write(f"{config_str}") @@ -36,7 +19,7 @@ def do_test(config_str, rc_expected): write_config(conf_file, port, config_str) try: - broker = start_broker(conf_file) + broker = mosq_test.start_broker(conf_file, check_port=False) broker.wait(timeout=1) if broker.returncode == rc_expected: diff --git a/test/broker/16-config-parse-errors-without-tls.py b/test/broker/16-config-parse-errors-without-tls.py index b41f6029..da0d788a 100755 --- a/test/broker/16-config-parse-errors-without-tls.py +++ b/test/broker/16-config-parse-errors-without-tls.py @@ -6,23 +6,6 @@ from mosq_test_helper import * vg_index = 0 -def start_broker(filename): - global vg_index - 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' - if os.environ.get('MOSQ_USE_VALGRIND') == 'callgrind': - cmd = ['valgrind', '-q', '--tool=callgrind', '--log-file='+logfile] + cmd - elif os.environ.get('MOSQ_USE_VALGRIND') == 'massif': - cmd = ['valgrind', '-q', '--tool=massif', '--log-file='+logfile] + cmd - else: - cmd = ['valgrind', '-q', '--trace-children=yes', '--leak-check=full', '--show-leak-kinds=all', '--log-file='+logfile] + cmd - - vg_index += 1 - return subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) - - def write_config(filename, port, config_str): with open(filename, 'w') as f: f.write(f"{config_str}") @@ -36,7 +19,7 @@ def do_test(config_str, rc_expected, error_log_entry): write_config(conf_file, port, config_str) try: - broker = start_broker(conf_file) + broker = mosq_test.start_broker(conf_file, check_port=False) mosq_test.wait_for_subprocess(broker,timeout=1) if broker.returncode != rc_expected: diff --git a/test/broker/Makefile b/test/broker/Makefile index 4db49586..a554e500 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -200,11 +200,13 @@ endif ./09-plugin-auth-v4-unpwd-success.py ./09-plugin-auth-v5-unpwd-fail.py ./09-plugin-auth-v5-unpwd-success.py + ./09-plugin-bad.py ./09-plugin-change-id.py ./09-plugin-delayed-auth.py ./09-plugin-evt-psk-key.py ./09-plugin-publish.py ./09-plugin-tick.py + ./09-plugin-unsupported.py ./09-pwfile-parse-invalid.py 10 : diff --git a/test/broker/c/CMakeLists.txt b/test/broker/c/CMakeLists.txt index e338d507..86285b00 100644 --- a/test/broker/c/CMakeLists.txt +++ b/test/broker/c/CMakeLists.txt @@ -19,7 +19,30 @@ set(PLUGINS auth_plugin_v5_control auth_plugin_v5_handle_message auth_plugin_v5_handle_tick + bad_vnone_1 + bad_v1 + bad_v2_1 + bad_v2_2 + bad_v2_3 + bad_v2_4 + bad_v2_5 + bad_v2_6 + bad_v2_7 + bad_v3_1 + bad_v3_2 + bad_v3_3 + bad_v3_4 + bad_v3_5 + bad_v3_6 + bad_v3_7 + bad_v4_1 + bad_v4_2 + bad_v4_3 + bad_v4_4 + bad_v5_1 + bad_v6 plugin_control + plugin_evt_psk_key ) foreach(PLUGIN ${PLUGINS}) diff --git a/test/broker/c/Makefile b/test/broker/c/Makefile index 1e098408..f0389ee4 100644 --- a/test/broker/c/Makefile +++ b/test/broker/c/Makefile @@ -24,6 +24,28 @@ PLUGIN_SRC = \ auth_plugin_v5_control.c \ auth_plugin_v5_handle_message.c \ auth_plugin_v5_handle_tick.c \ + bad_vnone_1.c \ + bad_v1.c \ + bad_v2_1.c \ + bad_v2_2.c \ + bad_v2_3.c \ + bad_v2_4.c \ + bad_v2_5.c \ + bad_v2_6.c \ + bad_v2_7.c \ + bad_v3_1.c \ + bad_v3_2.c \ + bad_v3_3.c \ + bad_v3_4.c \ + bad_v3_5.c \ + bad_v3_6.c \ + bad_v3_7.c \ + bad_v4_1.c \ + bad_v4_2.c \ + bad_v4_3.c \ + bad_v4_4.c \ + bad_v5_1.c \ + bad_v6.c \ plugin_control.c \ plugin_evt_psk_key.c diff --git a/test/broker/c/bad_v1.c b/test/broker/c/bad_v1.c new file mode 100644 index 00000000..9469c2dd --- /dev/null +++ b/test/broker/c/bad_v1.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include +#include +#include + +MOSQUITTO_PLUGIN_DECLARE_VERSION(1); diff --git a/test/broker/c/bad_v2_1.c b/test/broker/c/bad_v2_1.c new file mode 100644 index 00000000..693d7e3d --- /dev/null +++ b/test/broker/c/bad_v2_1.c @@ -0,0 +1,96 @@ +#include +#include +#include "mosquitto_plugin_v2.h" + +/* + * Following constant come from mosquitto.h + * + * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2 + */ +enum mosq_err_t { + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12 +}; + +int mosquitto_auth_plugin_version(void) +{ + return 2; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_acl_check(void *user_data, const char *clientid, const char *username, const char *topic, int access) +{ + (void)user_data; + (void)clientid; + (void)topic; + + if(access != MOSQ_ACL_READ && access != MOSQ_ACL_WRITE){ + return MOSQ_ERR_ACL_DENIED; + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ + return MOSQ_ERR_SUCCESS; + }else if(username && !strcmp(username, "readwrite")){ + if((!strcmp(topic, "readonly") && access == MOSQ_ACL_READ) + || !strcmp(topic, "writeable")){ + + return MOSQ_ERR_SUCCESS; + }else{ + return MOSQ_ERR_ACL_DENIED; + } + + }else{ + return MOSQ_ERR_ACL_DENIED; + } +} + +int mosquitto_auth_unpwd_check(void *user_data, const char *username, const char *password) +{ + (void)user_data; + + if(!strcmp(username, "test-username") && password && !strcmp(password, "cnwTICONIURW")){ + return MOSQ_ERR_SUCCESS; + }else if(!strcmp(username, "readonly") || !strcmp(username, "readwrite")){ + return MOSQ_ERR_SUCCESS; + }else if(!strcmp(username, "test-username@v2")){ + return MOSQ_ERR_SUCCESS; + }else{ + return MOSQ_ERR_AUTH; + } +} diff --git a/test/broker/c/bad_v2_2.c b/test/broker/c/bad_v2_2.c new file mode 100644 index 00000000..a6e98b0b --- /dev/null +++ b/test/broker/c/bad_v2_2.c @@ -0,0 +1,81 @@ +#include +#include +#include "mosquitto_plugin_v2.h" + +/* + * Following constant come from mosquitto.h + * + * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2 + */ +enum mosq_err_t { + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12 +}; + +int mosquitto_auth_plugin_version(void) +{ + return 2; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_acl_check(void *user_data, const char *clientid, const char *username, const char *topic, int access) +{ + (void)user_data; + (void)clientid; + (void)topic; + + if(access != MOSQ_ACL_READ && access != MOSQ_ACL_WRITE){ + return MOSQ_ERR_ACL_DENIED; + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ + return MOSQ_ERR_SUCCESS; + }else if(username && !strcmp(username, "readwrite")){ + if((!strcmp(topic, "readonly") && access == MOSQ_ACL_READ) + || !strcmp(topic, "writeable")){ + + return MOSQ_ERR_SUCCESS; + }else{ + return MOSQ_ERR_ACL_DENIED; + } + + }else{ + return MOSQ_ERR_ACL_DENIED; + } +} diff --git a/test/broker/c/bad_v2_3.c b/test/broker/c/bad_v2_3.c new file mode 100644 index 00000000..70a1bf58 --- /dev/null +++ b/test/broker/c/bad_v2_3.c @@ -0,0 +1,57 @@ +#include +#include +#include "mosquitto_plugin_v2.h" + +/* + * Following constant come from mosquitto.h + * + * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2 + */ +enum mosq_err_t { + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12 +}; + +int mosquitto_auth_plugin_version(void) +{ + return 2; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v2_4.c b/test/broker/c/bad_v2_4.c new file mode 100644 index 00000000..bcee0868 --- /dev/null +++ b/test/broker/c/bad_v2_4.c @@ -0,0 +1,47 @@ +#include +#include +#include "mosquitto_plugin_v2.h" + +/* + * Following constant come from mosquitto.h + * + * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2 + */ +enum mosq_err_t { + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12 +}; + +int mosquitto_auth_plugin_version(void) +{ + return 2; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v2_5.c b/test/broker/c/bad_v2_5.c new file mode 100644 index 00000000..4a9cd5b9 --- /dev/null +++ b/test/broker/c/bad_v2_5.c @@ -0,0 +1,37 @@ +#include +#include +#include "mosquitto_plugin_v2.h" + +/* + * Following constant come from mosquitto.h + * + * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2 + */ +enum mosq_err_t { + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12 +}; + +int mosquitto_auth_plugin_version(void) +{ + return 2; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v2_6.c b/test/broker/c/bad_v2_6.c new file mode 100644 index 00000000..c8e0cb2b --- /dev/null +++ b/test/broker/c/bad_v2_6.c @@ -0,0 +1,28 @@ +#include +#include +#include "mosquitto_plugin_v2.h" + +/* + * Following constant come from mosquitto.h + * + * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2 + */ +enum mosq_err_t { + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12 +}; + +int mosquitto_auth_plugin_version(void) +{ + return 2; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v2_7.c b/test/broker/c/bad_v2_7.c new file mode 100644 index 00000000..d3e74ccf --- /dev/null +++ b/test/broker/c/bad_v2_7.c @@ -0,0 +1,19 @@ +#include +#include +#include "mosquitto_plugin_v2.h" + +/* + * Following constant come from mosquitto.h + * + * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2 + */ +enum mosq_err_t { + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12 +}; + +int mosquitto_auth_plugin_version(void) +{ + return 2; +} diff --git a/test/broker/c/bad_v3_1.c b/test/broker/c/bad_v3_1.c new file mode 100644 index 00000000..d67f8732 --- /dev/null +++ b/test/broker/c/bad_v3_1.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 3; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg) +{ + const char *username = mosquitto_client_username(client); + + (void)user_data; + + if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ + return MOSQ_ERR_SUCCESS; + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) { + return MOSQ_ERR_SUCCESS; + }else if(username && !strcmp(username, "readwrite")){ + if((!strcmp(msg->topic, "readonly") && access == MOSQ_ACL_READ) + || !strcmp(msg->topic, "writeable")){ + + return MOSQ_ERR_SUCCESS; + }else{ + return MOSQ_ERR_ACL_DENIED; + } + + }else{ + return MOSQ_ERR_ACL_DENIED; + } +} + +int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password) +{ + (void)user_data; + (void)client; + + if(!strcmp(username, "test-username") && password && !strcmp(password, "cnwTICONIURW")){ + return MOSQ_ERR_SUCCESS; + }else if(!strcmp(username, "readonly") || !strcmp(username, "readwrite")){ + return MOSQ_ERR_SUCCESS; + }else if(!strcmp(username, "test-username@v2")){ + return MOSQ_ERR_PLUGIN_DEFER; + }else{ + return MOSQ_ERR_AUTH; + } +} diff --git a/test/broker/c/bad_v3_2.c b/test/broker/c/bad_v3_2.c new file mode 100644 index 00000000..26aea6a5 --- /dev/null +++ b/test/broker/c/bad_v3_2.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 3; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg) +{ + const char *username = mosquitto_client_username(client); + + (void)user_data; + + if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ + return MOSQ_ERR_SUCCESS; + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) { + return MOSQ_ERR_SUCCESS; + }else if(username && !strcmp(username, "readwrite")){ + if((!strcmp(msg->topic, "readonly") && access == MOSQ_ACL_READ) + || !strcmp(msg->topic, "writeable")){ + + return MOSQ_ERR_SUCCESS; + }else{ + return MOSQ_ERR_ACL_DENIED; + } + + }else{ + return MOSQ_ERR_ACL_DENIED; + } +} diff --git a/test/broker/c/bad_v3_3.c b/test/broker/c/bad_v3_3.c new file mode 100644 index 00000000..4a9bb481 --- /dev/null +++ b/test/broker/c/bad_v3_3.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 3; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v3_4.c b/test/broker/c/bad_v3_4.c new file mode 100644 index 00000000..526bb75b --- /dev/null +++ b/test/broker/c/bad_v3_4.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 3; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v3_5.c b/test/broker/c/bad_v3_5.c new file mode 100644 index 00000000..be503814 --- /dev/null +++ b/test/broker/c/bad_v3_5.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 3; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v3_6.c b/test/broker/c/bad_v3_6.c new file mode 100644 index 00000000..c2e968e6 --- /dev/null +++ b/test/broker/c/bad_v3_6.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 3; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v3_7.c b/test/broker/c/bad_v3_7.c new file mode 100644 index 00000000..4ae0c058 --- /dev/null +++ b/test/broker/c/bad_v3_7.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 3; +} diff --git a/test/broker/c/bad_v4_1.c b/test/broker/c/bad_v4_1.c new file mode 100644 index 00000000..55064a70 --- /dev/null +++ b/test/broker/c/bad_v4_1.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 4; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + (void)reload; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v4_2.c b/test/broker/c/bad_v4_2.c new file mode 100644 index 00000000..02752caa --- /dev/null +++ b/test/broker/c/bad_v4_2.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 4; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} + +int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v4_3.c b/test/broker/c/bad_v4_3.c new file mode 100644 index 00000000..274f4a92 --- /dev/null +++ b/test/broker/c/bad_v4_3.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 4; +} + +int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) +{ + (void)user_data; + (void)auth_opts; + (void)auth_opt_count; + + return MOSQ_ERR_SUCCESS; +} diff --git a/test/broker/c/bad_v4_4.c b/test/broker/c/bad_v4_4.c new file mode 100644 index 00000000..8933a6b0 --- /dev/null +++ b/test/broker/c/bad_v4_4.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include +#include + +int mosquitto_auth_plugin_version(void) +{ + return 4; +} diff --git a/test/broker/c/bad_v5_1.c b/test/broker/c/bad_v5_1.c new file mode 100644 index 00000000..8305f98d --- /dev/null +++ b/test/broker/c/bad_v5_1.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include +#include +#include + +MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/broker/c/bad_v6.c b/test/broker/c/bad_v6.c new file mode 100644 index 00000000..613a26f0 --- /dev/null +++ b/test/broker/c/bad_v6.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include +#include +#include + +MOSQUITTO_PLUGIN_DECLARE_VERSION(6); diff --git a/test/broker/c/bad_vnone_1.c b/test/broker/c/bad_vnone_1.c new file mode 100644 index 00000000..84b6f610 --- /dev/null +++ b/test/broker/c/bad_vnone_1.c @@ -0,0 +1,4 @@ +int dummy(void) +{ + return 4; +} diff --git a/test/broker/test.py b/test/broker/test.py index 95e72a82..d7e6c7d8 100755 --- a/test/broker/test.py +++ b/test/broker/test.py @@ -169,11 +169,13 @@ tests = [ (1, './09-plugin-auth-v4-unpwd-success.py'), (1, './09-plugin-auth-v5-unpwd-fail.py'), (1, './09-plugin-auth-v5-unpwd-success.py'), + (1, './09-plugin-bad.py'), (1, './09-plugin-change-id.py'), (1, './09-plugin-evt-psk-key.py'), (1, './09-plugin-delayed-auth.py'), (1, './09-plugin-publish.py'), (1, './09-plugin-tick.py'), + (1, './09-plugin-unsupported.py'), (1, './09-pwfile-parse-invalid.py'), (2, './10-listener-mount-point.py'), diff --git a/test/mosq_test.py b/test/mosq_test.py index f326b018..14ba87c9 100644 --- a/test/mosq_test.py +++ b/test/mosq_test.py @@ -27,7 +27,7 @@ def get_build_root(): 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): +def start_broker(filename, cmd=None, port=0, use_conf=False, expect_fail=False, nolog=False, checkhost="localhost", env=None, check_port=True): global vg_index global vg_logfiles @@ -67,6 +67,10 @@ def start_broker(filename, cmd=None, port=0, use_conf=False, expect_fail=False, broker = subprocess.Popen(cmd, stderr=subprocess.PIPE, env=env) else: broker = subprocess.Popen(cmd, stderr=subprocess.DEVNULL, env=env) + + if check_port == False: + return broker + for i in range(0, 20): time.sleep(delay) c = None