plugins/python/regress: load/unload module for each testcase

so they can start from clean state. (My problem was optional argument
tests has destroyed the callbacks.)
This commit is contained in:
Robert Manner
2020-02-05 17:19:37 +01:00
committed by Todd C. Miller
parent 36694fce86
commit 0f3631cc08

View File

@@ -25,6 +25,7 @@
#include "sudo_dso.h" #include "sudo_dso.h"
static const char *python_plugin_so_path = NULL;
static void *python_plugin_handle = NULL; static void *python_plugin_handle = NULL;
static struct io_plugin *python_io; static struct io_plugin *python_io;
static struct policy_plugin *python_policy = NULL; static struct policy_plugin *python_policy = NULL;
@@ -32,6 +33,9 @@ static struct sudoers_group_plugin *group_plugin = NULL;
static struct passwd example_pwd; static struct passwd example_pwd;
static int _load_symbols(void);
static int _unload_symbols(void);
void void
create_io_plugin_options(const char *log_path) create_io_plugin_options(const char *log_path)
{ {
@@ -131,6 +135,7 @@ init(void)
data.plugin_argv = create_str_array(1, NULL); data.plugin_argv = create_str_array(1, NULL);
data.user_env = create_str_array(1, NULL); data.user_env = create_str_array(1, NULL);
VERIFY_TRUE(_load_symbols());
return true; return true;
} }
@@ -158,6 +163,8 @@ cleanup(int success)
str_array_free(&data.plugin_options); str_array_free(&data.plugin_options);
VERIFY_FALSE(Py_IsInitialized()); VERIFY_FALSE(Py_IsInitialized());
VERIFY_TRUE(_unload_symbols());
return true; return true;
} }
@@ -865,11 +872,10 @@ check_python_plugins_do_not_affect_each_other(void)
return true; return true;
} }
int static int
check_python_plugin_can_be_loaded(const char *python_plugin_path) _load_symbols(void)
{ {
printf("Loading python plugin from '%s'\n", python_plugin_path); python_plugin_handle = sudo_dso_load(python_plugin_so_path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
python_plugin_handle = sudo_dso_load(python_plugin_path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
VERIFY_PTR_NE(python_plugin_handle, NULL); VERIFY_PTR_NE(python_plugin_handle, NULL);
python_io = sudo_dso_findsym(python_plugin_handle, "python_io"); python_io = sudo_dso_findsym(python_plugin_handle, "python_io");
@@ -883,6 +889,17 @@ check_python_plugin_can_be_loaded(const char *python_plugin_path)
return true; return true;
} }
static int
_unload_symbols(void)
{
python_io = NULL;
group_plugin = NULL;
python_policy = NULL;
VERIFY_INT(sudo_dso_unload(python_plugin_handle), 0);
return true;
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@@ -890,9 +907,8 @@ main(int argc, char *argv[])
printf("Please specify the python_plugin.so as argument!\n"); printf("Please specify the python_plugin.so as argument!\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
const char *python_plugin_so_path = argv[1]; python_plugin_so_path = argv[1];
RUN_TEST(check_python_plugin_can_be_loaded(python_plugin_so_path));
RUN_TEST(check_example_io_plugin_version_display(true)); RUN_TEST(check_example_io_plugin_version_display(true));
RUN_TEST(check_example_io_plugin_version_display(false)); RUN_TEST(check_example_io_plugin_version_display(false));
RUN_TEST(check_example_io_plugin_command_log()); RUN_TEST(check_example_io_plugin_command_log());