Make most python tests pass with Python 3.4

Dictionary order is not stable in Python < 3.6 so we need to sort
by key to have consistent results.
The LogHandler output is also different on older Python versions.
Also, don't stop running python tests after the first error.
This commit is contained in:
Todd C. Miller
2020-04-07 14:03:58 -06:00
parent fa5025a569
commit cd74b83c21
13 changed files with 72 additions and 44 deletions

View File

@@ -1511,6 +1511,8 @@ _unlink_symbols(void)
int
main(int argc, char *argv[])
{
int errors = 0;
if (argc != 2) {
printf("Please specify the python_plugin.so as argument!\n");
return EXIT_FAILURE;
@@ -1546,6 +1548,7 @@ main(int argc, char *argv[])
RUN_TEST(check_example_policy_plugin_version_display(true));
RUN_TEST(check_example_policy_plugin_version_display(false));
// FIXME - sudo.options_from_dict fails for these two on python 3.4
RUN_TEST(check_example_policy_plugin_accepted_execution());
RUN_TEST(check_example_policy_plugin_failed_execution());
RUN_TEST(check_example_policy_plugin_denied_execution());
@@ -1593,5 +1596,5 @@ main(int argc, char *argv[])
RUN_TEST(check_example_debugging("plugin@err"));
RUN_TEST(check_plugin_unload());
return EXIT_SUCCESS;
return errors;
}

View File

@@ -82,7 +82,7 @@ freadall(const char *file_path, char *output, size_t max_len)
}
if (!feof(file)) {
printf("File '%s' was bigger than allocated buffer %lu", file_path, max_len);
printf("File '%s' was bigger than allocated buffer %zu", file_path, max_len);
goto cleanup;
}

View File

@@ -8,7 +8,7 @@ class ApprovalTestPlugin(sudo.Plugin):
super().__init__(plugin_options=plugin_options, **kwargs)
self._id = "(APPROVAL {})".format(id)
sudo.log_info("{} Constructed:".format(self._id))
sudo.log_info(json.dumps(self.__dict__, indent=4))
sudo.log_info(json.dumps(self.__dict__, indent=4, sort_keys=True))
def __del__(self):
sudo.log_info("{} Destructed successfully".format(self._id))

View File

@@ -1,6 +1,6 @@
sudo.debug was called with arguments: (<DEBUG.ERROR: 2>, 'My demo purpose plugin shows this ERROR level debug message')
sudo.debug was called with arguments: (<DEBUG.INFO: 6>, 'My demo purpose plugin shows this INFO level debug message')
LogHandler.emit was called with arguments: (<sudo.LogHandler <stderr> (NOTSET)>, <LogRecord: root, 40, SRC_DIR/example_debugging.py, 72, "Python log system shows this ERROR level debug message">)
LogHandler.emit was called with arguments: (<sudo.LogHandler <stderr> (NOTSET)>, <LogRecord: root, 20, SRC_DIR/example_debugging.py, 73, "Python log system shows this INFO level debug message">)
LogHandler.emit was called with arguments: (<.*sudo.LogHandler.*
LogHandler.emit was called with arguments: (<.*sudo.LogHandler.*
sudo.options_as_dict was called with arguments: (('ModulePath=SRC_DIR/example_debugging.py', 'ClassName=DebugDemoPlugin'),)
sudo.options_as_dict returned result: {'ModulePath': 'SRC_DIR/example_debugging.py', 'ClassName': 'DebugDemoPlugin'}
sudo.options_as_dict returned result: \[('ClassName', 'DebugDemoPlugin'), ('ModulePath', 'SRC_DIR/example_debugging.py')\]

View File

@@ -3,9 +3,9 @@ sudo.debug was called with arguments: (<DEBUG.ERROR: 2>, 'My demo purpose plugin
__init__ @ SRC_DIR/example_debugging.py:63 calls C function:
sudo.debug was called with arguments: (<DEBUG.INFO: 6>, 'My demo purpose plugin shows this INFO level debug message')
handle @ .*/logging/__init__.py:[0-9]* calls C function:
LogHandler.emit was called with arguments: (<sudo.LogHandler <stderr> (NOTSET)>, <LogRecord: root, 40, SRC_DIR/example_debugging.py, 72, "Python log system shows this ERROR level debug message">)
LogHandler.emit was called with arguments: (<.*sudo.LogHandler.*
handle @ .*/logging/__init__.py:[0-9]* calls C function:
LogHandler.emit was called with arguments: (<sudo.LogHandler <stderr> (NOTSET)>, <LogRecord: root, 20, SRC_DIR/example_debugging.py, 73, "Python log system shows this INFO level debug message">)
LogHandler.emit was called with arguments: (<.*sudo.LogHandler.*
__init__ @ SRC_DIR/example_debugging.py:85 calls C function:
sudo.options_as_dict was called with arguments: (('ModulePath=SRC_DIR/example_debugging.py', 'ClassName=DebugDemoPlugin'),)
sudo.options_as_dict returned result: {'ModulePath': 'SRC_DIR/example_debugging.py', 'ClassName': 'DebugDemoPlugin'}
sudo.options_as_dict returned result: \[('ClassName', 'DebugDemoPlugin'), ('ModulePath', 'SRC_DIR/example_debugging.py')\]

View File

@@ -1,2 +1,2 @@
DebugDemoPlugin.__init__ was called with arguments: () {'version': '1.0', 'settings': ('debug_flags=/tmp/sudo_check_python_exampleXXXXXX/debug.log py_calls@diag', 'plugin_path=python_plugin.so'), 'user_env': (), 'user_info': (), 'plugin_options': ('ModulePath=SRC_DIR/example_debugging.py', 'ClassName=DebugDemoPlugin')}
DebugDemoPlugin.__init__ was called with arguments: () \[('plugin_options', ('ModulePath=SRC_DIR/example_debugging.py', 'ClassName=DebugDemoPlugin')), ('settings', ('debug_flags=/tmp/sudo_check_python_exampleXXXXXX/debug.log py_calls@diag', 'plugin_path=python_plugin.so')), ('user_env', ()), ('user_info', ()), ('version', '1.0')\]
DebugDemoPlugin.__init__ returned result: <example_debugging.DebugDemoPlugin object>

View File

@@ -1,4 +1,4 @@
DebugDemoPlugin.__init__ was called with arguments: () {'version': '1.0', 'settings': ('debug_flags=/tmp/sudo_check_python_exampleXXXXXX/debug.log py_calls@info', 'plugin_path=python_plugin.so'), 'user_env': (), 'user_info': (), 'plugin_options': ('ModulePath=SRC_DIR/example_debugging.py', 'ClassName=DebugDemoPlugin')}
DebugDemoPlugin.__init__ was called with arguments: () \[('plugin_options', ('ModulePath=SRC_DIR/example_debugging.py', 'ClassName=DebugDemoPlugin')), ('settings', ('debug_flags=/tmp/sudo_check_python_exampleXXXXXX/debug.log py_calls@info', 'plugin_path=python_plugin.so')), ('user_env', ()), ('user_info', ()), ('version', '1.0')\]
DebugDemoPlugin.__init__ returned result: <example_debugging.DebugDemoPlugin object>
DebugDemoPlugin function 'log_ttyin' is not implemented
DebugDemoPlugin function 'log_ttyout' is not implemented

View File

@@ -1,4 +1,4 @@
SudoPolicyPlugin.__init__ was called with arguments: () {'version': '1.0', 'settings': (), 'user_env': (), 'user_info': (), 'plugin_options': ('ModulePath=SRC_DIR/example_policy_plugin.py', 'ClassName=SudoPolicyPlugin')}
SudoPolicyPlugin.__init__ was called with arguments: () \[('plugin_options', ('ModulePath=SRC_DIR/example_policy_plugin.py', 'ClassName=SudoPolicyPlugin')), ('settings', ()), ('user_env', ()), ('user_info', ()), ('version', '1.0')\]
SudoPolicyPlugin.__init__ returned result: <example_policy_plugin.SudoPolicyPlugin object>
SudoPolicyPlugin.validate was called with arguments: ()
SudoPolicyPlugin.validate returned result: None

View File

@@ -1,2 +1,2 @@
Failed to find plugin class 'MispelledPluginName'
Failed during loading plugin class: (AttributeError) module 'example_debugging' has no attribute 'MispelledPluginName'
Failed during loading plugin class: (AttributeError) .* has no attribute 'MispelledPluginName'

View File

@@ -1,15 +1,23 @@
(APPROVAL 1) Constructed:
{
"_id": "(APPROVAL 1)",
"plugin_options": \[
"ModulePath=SRC_DIR/regress/plugin_approval_test.py",
"ClassName=ApprovalTestPlugin",
"Id=1"
\],
"version": "1.15",
"settings": \[
"SETTING1=VALUE1",
"setting2=value2"
\],
"submit_argv": \[
"sudo",
"-u",
"user",
"whoami",
"--help"
\],
"submit_optind": 3,
"user_env": \[
"USER_ENV1=VALUE1",
"USER_ENV2=value2"
@@ -18,28 +26,28 @@
"INFO1=VALUE1",
"info2=value2"
\],
"submit_optind": 3,
"submit_argv": \[
"sudo",
"-u",
"user",
"whoami",
"--help"
\],
"_id": "(APPROVAL 1)"
"version": "1.15"
}
(APPROVAL 2) Constructed:
{
"_id": "(APPROVAL 2)",
"plugin_options": \[
"ModulePath=SRC_DIR/regress/plugin_approval_test.py",
"ClassName=ApprovalTestPlugin",
"Id=2"
\],
"version": "1.15",
"settings": \[
"SETTING1=VALUE1",
"setting2=value2"
\],
"submit_argv": \[
"sudo",
"-u",
"user",
"whoami",
"--help"
\],
"submit_optind": 3,
"user_env": \[
"USER_ENV1=VALUE1",
"USER_ENV2=value2"
@@ -48,15 +56,7 @@
"INFO1=VALUE1",
"info2=value2"
\],
"submit_optind": 3,
"submit_argv": \[
"sudo",
"-u",
"user",
"whoami",
"--help"
\],
"_id": "(APPROVAL 2)"
"version": "1.15"
}
(APPROVAL 1) Show version was called with arguments: (0,)
Python approval plugin (API 1.0): ApprovalTestPlugin (loaded from 'SRC_DIR/regress/plugin_approval_test.py')

View File

@@ -61,22 +61,22 @@ char ** create_str_array(size_t count, ...);
#define RUN_TEST(testcase) \
do { \
int success = 1; \
printf("Running test " #testcase " ... \n"); \
int rc = EXIT_SUCCESS; \
if (!init()) { \
printf("FAILED: initialization of testcase %s at %s:%d\n", #testcase, __FILE__, __LINE__); \
rc = EXIT_FAILURE; \
success = 0; \
} else \
if (!testcase) { \
printf("FAILED: testcase %s at %s:%d\n", #testcase, __FILE__, __LINE__); \
rc = EXIT_FAILURE; \
success = 0; \
} \
if (!cleanup(rc == EXIT_SUCCESS)) { \
if (!cleanup(success)) { \
printf("FAILED: deitialization of testcase %s at %s:%d\n", #testcase, __FILE__, __LINE__); \
rc = EXIT_FAILURE; \
success = 0; \
} \
if (rc != EXIT_SUCCESS) \
return rc; \
if (!success) \
errors++; \
} while(false)
#define VERIFY_PRINT_MSG(fmt, actual_str, actual, expected_str, expected, expected_to_be_message) \