From a0c8195ad37292ab800a6c777fc28383995b4b64 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 22 Oct 2019 18:38:01 +0200 Subject: vty: Return error if cmd returns CMD_WARNING while reading cfg file Otherwise bad configurations can easily sneak in and produce unexpected behavior. Change-Id: Ic9c1b566ec4a459f03e6319cf369691903cf9d00 --- tests/Makefile.am | 1 + tests/vty/fail_cmd_ret_warning.cfg | 3 +++ tests/vty/vty_test.c | 20 ++++++++++++++++++++ tests/vty/vty_test.ok | 4 ++++ 4 files changed, 28 insertions(+) create mode 100644 tests/vty/fail_cmd_ret_warning.cfg (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index e0993b16..60213ed3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -293,6 +293,7 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \ vty/fail_not_de-indented.cfg \ vty/fail_tabs_and_spaces.cfg \ vty/fail_too_much_indent.cfg \ + vty/fail_cmd_ret_warning.cfg \ vty/ok.cfg \ vty/ok_empty_parent.cfg \ vty/ok_ignore_blank.cfg \ diff --git a/tests/vty/fail_cmd_ret_warning.cfg b/tests/vty/fail_cmd_ret_warning.cfg new file mode 100644 index 00000000..b03f02ae --- /dev/null +++ b/tests/vty/fail_cmd_ret_warning.cfg @@ -0,0 +1,3 @@ +return-success +return-warning +return-success diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c index 30efb9af..0d68a6c0 100644 --- a/tests/vty/vty_test.c +++ b/tests/vty/vty_test.c @@ -421,8 +421,27 @@ DEFUN(cfg_ambiguous_str_2, cfg_ambiguous_str_2_cmd, return CMD_SUCCESS; } +DEFUN(cfg_ret_success, cfg_ret_success_cmd, + "return-success", + "testing return success\n") +{ + printf("Called: 'return-success'\n"); + return CMD_SUCCESS; +} + +DEFUN(cfg_ret_warning, cfg_ret_warning_cmd, + "return-warning", + "testing return warning\n") +{ + printf("Called: 'return-warning'\n"); + return CMD_WARNING; +} + void test_vty_add_cmds() { + install_element(CONFIG_NODE, &cfg_ret_warning_cmd); + install_element(CONFIG_NODE, &cfg_ret_success_cmd); + install_element(CONFIG_NODE, &cfg_level1_cmd); install_node(&level1_node, NULL); install_element(LEVEL1_NODE, &cfg_level1_child_cmd); @@ -524,6 +543,7 @@ int main(int argc, char **argv) test_exit_by_indent("fail_tabs_and_spaces.cfg", -EINVAL); test_exit_by_indent("ok_indented_root.cfg", 0); test_exit_by_indent("ok_empty_parent.cfg", 0); + test_exit_by_indent("fail_cmd_ret_warning.cfg", -EINVAL); test_is_cmd_ambiguous(); diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok index 2f76ff91..0b5ac9c0 100644 --- a/tests/vty/vty_test.ok +++ b/tests/vty/vty_test.ok @@ -286,6 +286,10 @@ called level2 node k called level3 node k called level1 child cmd k got rc=0 +reading file fail_cmd_ret_warning.cfg, expecting rc=-22 +Called: 'return-success' +Called: 'return-warning' +got rc=-22 Going to test is_cmd_ambiguous() Going to execute 'ambiguous_nr' Called: 'ambiguous_nr [<0-23>]' (argc=0) -- cgit v1.2.3