Commit Graph

31 Commits

Author SHA1 Message Date
Todd C. Miller
02a117f336 Avoid using typing annotations so tests run with Python 3.4. 2020-04-07 14:03:58 -06:00
Todd C. Miller
a23048bbb2 Avoid using sprintf(), vsprintf(), strcat(), and strncat().
It is less error-prone to use functions with a return value that
indicates when truncation ocurred.
2020-03-11 19:46:07 -06:00
Todd C. Miller
ec78f06890 Don't hard-code path to logging/__init__.py or line numbers.
Allows python plugin tests to success on versions other than 3.7.
2020-03-11 17:18:10 -06:00
Robert Manner
6c9515496d plugins/python/regress: add a test and example of using the python logger 2020-02-28 05:46:54 -07:00
Robert Manner
34b4bb72d6 plugins/python: autodetect ClassName field
If "ClassName" is not specified, load the one and only sudo.Plugin from
the module (if so), otherwise display which plugins are available from
which the system admin can choose.
2020-02-28 05:46:54 -07:00
Robert Manner
9cc46f115d plugins/python/regress: update tests for show_version changes
- plugin->show_version is not marked NULL any more.
- if verbose, it also displays which python class was loaded from which file
2020-02-26 13:15:52 -07:00
Robert Manner
27de7dd24d plugins/python: only deinit interpreters when sudo unlinks the plugin
This only happens when sudo unloads the last python plugin.
The reason doing so is because there are some python modules which
does not support importing them again after destroying the interpreter
which has imported them previously.

Another solution would be to just leak the interpreters (let the kernel
free up), but then there might be some python resources like open files
would not get cleaned up correctly if the plugin is badly written.

Tests are meant to test the scenario sudo does, so I have modified them
to generally do not unlink but only a few times (~per plugin type) so it
does not use 48 interpreters (one gets started on every plugin->open) and
it is visible at least which type of plugin fails deinit if there is an
error.
2020-02-19 11:48:16 -07:00
Robert Manner
8395a20a20 plugins/python/regress/testhelpers.c: replace fromisoformat
fromisoformat is only supported from python >=3.7
2020-02-14 09:25:37 -07:00
Robert Manner
43e256e34f plugins/python/regress: add tests for approval plugin 2020-02-12 11:16:00 -07:00
Robert Manner
33e7fdcae0 plugins/python/regress: strengthen errstr verification
Tests did not catch the issue where errstr was not set correctly, but
its pointer contained the expected data, because the memory allocator
reused the same space for storing the string.

Now it is either verified to be NULL, or reset to NULL.
2020-02-12 11:16:00 -07:00
Robert Manner
9fa6500d6a plugins/python/regress: simplify plugin option creation 2020-02-12 11:16:00 -07:00
Robert Manner
d1f94c857c plugins/python/regress: still some memleak fix 2020-02-12 11:16:00 -07:00
Robert Manner
1a1cb54975 plugins/python/regress/check_python_examples: add audit_plugin tests 2020-02-10 05:24:16 -07:00
Robert Manner
bbbcb39334 plugins/python/example_*.py: document returning error string 2020-02-10 05:24:16 -07:00
Robert Manner
9c4f076f85 plugins/python/regress: add test for callback error msg return 2020-02-10 05:24:16 -07:00
Robert Manner
45d2638571 plugins/python/example*.py: pep8 fixes (mainly line too long) 2020-02-10 05:24:16 -07:00
Robert Manner
0f3631cc08 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.)
2020-02-10 05:24:16 -07:00
Robert Manner
21c02e1732 plugins/python/sudo_python_module.c: use IntEnums instead of constants
It is a bit more code, but it is more "pythonic" and easier to debug
as the enum values also know their names.

It is also an API break, eg. sudo.RC_OK becomes sudo.RC.OK as sudo.RC will
be the "type" of the enum, but I guess that is acceptable before the
initial release.
2020-02-10 05:24:16 -07:00
Robert Manner
4110800c14 plugins/python/example_io_plugin: close the file at destroy
to avoid warning of debug python build.
2020-02-10 05:24:16 -07:00
Robert Manner
a3a7630ff4 plugins/python: memleak fixes in test
The main problem was that string array objects were constructed
differently:
- if constructed by the test, then the elements were constant
- if constructed by the plugin, then the elements were allocated

Modified it so that now each array contains allocated strings so
they can be handled similarly. For freeing, I have used the
str_array_free function from the plugin, so I have linked its object
into the test runner.

Happy path is now free of "definitely lost" memleaks, so the test
can be used for valgrind.
2020-02-10 05:24:16 -07:00
Todd C. Miller
a88a05c1eb Adapt python plugin to new plugin API changes 2020-01-30 13:25:38 -07:00
Todd C. Miller
4e87e1a97b Fix typo in a test: python_policy->close not python_io->close 2020-01-28 13:00:33 -07:00
Robert Manner
99f8394182 plugins/python/regress: add a failing textcase about python plugins affect each other
Since python plugins are run inside the same interpreter, they affect
each other's state, which would be better to avoid.
2020-01-24 12:25:15 -07:00
Robert Manner
d67c64bb37 plugins/python/pyhelpers: have a default sudo_printf function
Adapted the default sudo_printf from sudoers plugin to be able to print
errors before plugin open() gets called. (This is used by the multiple io
plugin loading to display error for too much plugin load.)

Since this makes us always have a sudo_log, I have removed the logic about
whether it is available or not.
2020-01-23 12:46:14 -07:00
Robert Manner
2eeda38f95 plugins/python/regress: add a testcase for multiple io plugin loading
to verify 2 python plugins can work next to each other.
2020-01-23 12:46:14 -07:00
Robert Manner
8cacaabe9b plugins/python/regress: add missing license texts 2020-01-20 06:30:20 -07:00
Robert Manner
b66ecf6e13 plugins/python: various portability improvements 2020-01-20 06:30:20 -07:00
Robert Manner
f3b7f3c0d4 plugins/python/example_{io,conversation}: avoid printing signal number
They are platform dependant, so their test would fail on some platforms.
While we could create separate plugin for the tests, I like the idea that
the examples are ensured to be working.

I believe this is a good compromise for being able to auto update the
test cases.
2020-01-20 06:30:20 -07:00
Robert Manner
40f2189586 plugins/python/regress: load the python plugin dynamically
instead of linking with it.
2020-01-20 06:30:20 -07:00
Robert Manner
383ca80333 plugins/python/regress/testdata: generated data for the pyplugin tests 2020-01-20 06:30:20 -07:00
Robert Manner
5da7bd562c plugins/python/regress: adds tests for python plugin feature and examples 2020-01-20 06:30:20 -07:00