Invalid/unsupported plugin tests.

pull/2345/merge
Roger A. Light 3 years ago
parent 677aa2cc8d
commit 8a6bb872fe

@ -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:

@ -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)

@ -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)

@ -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)

@ -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:

@ -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:

@ -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:

@ -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 :

@ -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})

@ -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

@ -0,0 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
MOSQUITTO_PLUGIN_DECLARE_VERSION(1);

@ -0,0 +1,96 @@
#include <string.h>
#include <stdbool.h>
#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;
}
}

@ -0,0 +1,81 @@
#include <string.h>
#include <stdbool.h>
#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;
}
}

@ -0,0 +1,57 @@
#include <string.h>
#include <stdbool.h>
#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;
}

@ -0,0 +1,47 @@
#include <string.h>
#include <stdbool.h>
#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;
}

@ -0,0 +1,37 @@
#include <string.h>
#include <stdbool.h>
#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;
}

@ -0,0 +1,28 @@
#include <string.h>
#include <stdbool.h>
#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;
}

@ -0,0 +1,19 @@
#include <string.h>
#include <stdbool.h>
#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;
}

@ -0,0 +1,88 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}
}

@ -0,0 +1,72 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}
}

@ -0,0 +1,48 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}

@ -0,0 +1,38 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}

@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}

@ -0,0 +1,19 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}

@ -0,0 +1,10 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
int mosquitto_auth_plugin_version(void)
{
return 3;
}

@ -0,0 +1,38 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}

@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}

@ -0,0 +1,19 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
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;
}

@ -0,0 +1,10 @@
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
int mosquitto_auth_plugin_version(void)
{
return 4;
}

@ -0,0 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
MOSQUITTO_PLUGIN_DECLARE_VERSION(5);

@ -0,0 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_plugin.h>
MOSQUITTO_PLUGIN_DECLARE_VERSION(6);

@ -0,0 +1,4 @@
int dummy(void)
{
return 4;
}

@ -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'),

@ -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

Loading…
Cancel
Save