fix(api): fixed a bug when splitting the argument string (#45)

* fix(api): fixed a bug when splitting the argument string

* fix(api): added the shlex module for splitting

* fix(api): added the shlex module for splitting

* fix(api): moved shlex.split to self method split_params

* Fix indentation.

* Implement custom splitting algorithm.

* Raise AssertionError in case of internal error.

* Update plugins/modules/api.py

this is correct thanks !

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Nikolay Dachev <nikolay@dachev.info>
This commit is contained in:
Akim Lindberg 2021-09-29 16:02:28 +03:00 committed by GitHub
parent f432b1fa07
commit 5042905471
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 135 additions and 6 deletions

View file

@ -288,3 +288,33 @@ 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