From 543f3cba7de2bf86f9c3ff7b1c1ccfbe1d3a2810 Mon Sep 17 00:00:00 2001 From: Norbert Pocs Date: Tue, 2 May 2023 18:09:58 +0200 Subject: [PATCH] torture_options: Add tests for incorrect number parsing options Signed-off-by: Norbert Pocs Reviewed-by: Andreas Schneider --- tests/unittests/torture_options.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c index 8d91e30d..919a46cf 100644 --- a/tests/unittests/torture_options.c +++ b/tests/unittests/torture_options.c @@ -316,6 +316,7 @@ static void torture_options_set_port(void **state) { rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, "five"); assert_true(rc == -1); + assert_int_not_equal(session->opts.port, 0); rc = ssh_options_set(session, SSH_OPTIONS_PORT, NULL); assert_true(rc == -1); @@ -1480,6 +1481,26 @@ static void torture_options_apply (void **state) { ssh_list_free(awaited_list); } +static void torture_options_set_verbosity (void **state) +{ + ssh_session session = *state; + int rc, new_level; + + rc = ssh_options_set(session, + SSH_OPTIONS_LOG_VERBOSITY_STR, + "3"); + assert_int_equal(rc, SSH_OK); + new_level = ssh_get_log_level(); + assert_int_equal(new_level, SSH_LOG_PACKET); + + rc = ssh_options_set(session, + SSH_OPTIONS_LOG_VERBOSITY_STR, + "datsun"); + assert_int_equal(rc, -1); + new_level = ssh_get_log_level(); + assert_int_not_equal(new_level, 0); +} + #ifdef WITH_SERVER const char template[] = "temp_dir_XXXXXX"; @@ -1711,6 +1732,10 @@ static void torture_bind_options_bindport_str(void **state) rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BINDPORT_STR, "23"); assert_int_equal(rc, 0); assert_int_equal(bind->bindport, 23); + + rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BINDPORT_STR, "twentythree"); + assert_int_equal(rc, -1); + assert_int_not_equal(bind->bindport, 0); } static void torture_bind_options_log_verbosity(void **state) @@ -1760,6 +1785,11 @@ static void torture_bind_options_log_verbosity_str(void **state) new_level = ssh_get_log_level(); assert_int_equal(new_level, SSH_LOG_PACKET); + rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "verbosity"); + assert_int_equal(rc, -1); + new_level = ssh_get_log_level(); + assert_int_not_equal(new_level, 0); + rc = ssh_set_log_level(previous_level); assert_int_equal(rc, SSH_OK); } @@ -2236,6 +2266,7 @@ int torture_run_tests(void) { cmocka_unit_test_setup_teardown(torture_options_caret_sign, setup, teardown), cmocka_unit_test_setup_teardown(torture_options_apply, setup, teardown), + cmocka_unit_test_setup_teardown(torture_options_set_verbosity, setup, teardown), }; #ifdef WITH_SERVER