Add module_utils and filters for quoting and unquoting (#53)

* Move splitting code to own file.

* Move list to dictionary code to quoting as well.

* Add quoting functionality.

* Add quoting filters.

* Add integration tests to CI.

* Fix bugs, increase coverage.

* Make parsing more strict.

* Extract function parse_argument_value from split_routeros_command to make proper parsing of WHERE possible.

* Adjust expected error message in integration tests.

* Simplify code and improve coverage.

* Add changelog fragment for WHERE strictness in api module.

* Add documenation.

* Fix typo.

* Add documentation references.

* Add example to api module which uses quote_argument_value.

* Fix bug, and add tests which prevent this in the future.

* Add more escape sequence tests.

* Make sure all control characters are quoted.
This commit is contained in:
Felix Fontein 2021-10-11 23:44:40 +02:00 committed by GitHub
parent f9d246cd7a
commit d73eb1c144
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 803 additions and 145 deletions

View file

@ -288,33 +288,3 @@ class TestRouterosApiModule(ModuleTestCase):
result = exc.exception.args[0]
self.assertEqual(result['changed'], False)
TEST_SPLIT_ROUTEROS = [
('', []),
(' ', []),
(r'a b c', ['a', 'b', 'c']),
(r'a=b c d=e', ['a=b', 'c', 'd=e']),
(r'a="b f" c d=e', ['a=b f', 'c', 'd=e']),
(r'a="b\"f" c\FF d=\"e', ['a=b"f', '\xff', 'c', 'd="e']),
]
@pytest.mark.parametrize("command, result", TEST_SPLIT_ROUTEROS)
def test_split_routeros(command, result):
result_ = api.split_routeros(command)
print(result_, result)
assert result_ == result
TEST_SPLIT_ROUTEROS_ERRORS = [
(r'a="b\"f" c\FF d="e', 'Unexpected end of string during escaped parameter'),
]
@pytest.mark.parametrize("command, message", TEST_SPLIT_ROUTEROS_ERRORS)
def test_split_routeros_errors(command, message):
with pytest.raises(api.ParseError) as exc:
api.split_routeros(command)
print(exc.value.args[0], message)
assert exc.value.args[0] == message