tests: Reproducer for missing value to LogLevel

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 163373c9d9)
This commit is contained in:
Jakub Jelen
2025-12-15 11:07:08 +01:00
parent 77ce02d809
commit e668b03dd7

View File

@@ -53,6 +53,7 @@ extern LIBSSH_THREAD int ssh_log_level;
#define LIBSSH_TEST_NONEWLINEONELINE "libssh_test_NoNewLineOneline.tmp" #define LIBSSH_TEST_NONEWLINEONELINE "libssh_test_NoNewLineOneline.tmp"
#define LIBSSH_TEST_RECURSIVE_INCLUDE "libssh_test_recursive_include.tmp" #define LIBSSH_TEST_RECURSIVE_INCLUDE "libssh_test_recursive_include.tmp"
#define LIBSSH_TESTCONFIG_MATCH_COMPLEX "libssh_test_match_complex.tmp" #define LIBSSH_TESTCONFIG_MATCH_COMPLEX "libssh_test_match_complex.tmp"
#define LIBSSH_TESTCONFIG_LOGLEVEL_MISSING "libssh_test_loglevel_missing.tmp"
#define LIBSSH_TESTCONFIG_STRING1 \ #define LIBSSH_TESTCONFIG_STRING1 \
"User "USERNAME"\nInclude "LIBSSH_TESTCONFIG2"\n\n" "User "USERNAME"\nInclude "LIBSSH_TESTCONFIG2"\n\n"
@@ -243,6 +244,8 @@ extern LIBSSH_THREAD int ssh_log_level;
"\tForwardAgent yes\n" \ "\tForwardAgent yes\n" \
"\tHostName complex-match\n" "\tHostName complex-match\n"
#define LIBSSH_TESTCONFIG_LOGLEVEL_MISSING_STRING "LogLevel\n"
/** /**
* @brief helper function loading configuration from either file or string * @brief helper function loading configuration from either file or string
*/ */
@@ -293,6 +296,7 @@ static int setup_config_files(void **state)
unlink(LIBSSH_TEST_NONEWLINEEND); unlink(LIBSSH_TEST_NONEWLINEEND);
unlink(LIBSSH_TEST_NONEWLINEONELINE); unlink(LIBSSH_TEST_NONEWLINEONELINE);
unlink(LIBSSH_TESTCONFIG_MATCH_COMPLEX); unlink(LIBSSH_TESTCONFIG_MATCH_COMPLEX);
unlink(LIBSSH_TESTCONFIG_LOGLEVEL_MISSING);
torture_write_file(LIBSSH_TESTCONFIG1, torture_write_file(LIBSSH_TESTCONFIG1,
LIBSSH_TESTCONFIG_STRING1); LIBSSH_TESTCONFIG_STRING1);
@@ -361,6 +365,8 @@ static int setup_config_files(void **state)
/* Match complex combinations */ /* Match complex combinations */
torture_write_file(LIBSSH_TESTCONFIG_MATCH_COMPLEX, torture_write_file(LIBSSH_TESTCONFIG_MATCH_COMPLEX,
LIBSSH_TESTCONFIG_MATCH_COMPLEX_STRING); LIBSSH_TESTCONFIG_MATCH_COMPLEX_STRING);
torture_write_file(LIBSSH_TESTCONFIG_LOGLEVEL_MISSING,
LIBSSH_TESTCONFIG_LOGLEVEL_MISSING_STRING);
return 0; return 0;
} }
@@ -390,6 +396,7 @@ static int teardown_config_files(void **state)
unlink(LIBSSH_TEST_NONEWLINEEND); unlink(LIBSSH_TEST_NONEWLINEEND);
unlink(LIBSSH_TEST_NONEWLINEONELINE); unlink(LIBSSH_TEST_NONEWLINEONELINE);
unlink(LIBSSH_TESTCONFIG_MATCH_COMPLEX); unlink(LIBSSH_TESTCONFIG_MATCH_COMPLEX);
unlink(LIBSSH_TESTCONFIG_LOGLEVEL_MISSING);
return 0; return 0;
} }
@@ -2617,6 +2624,17 @@ static void torture_config_match_complex(void **state)
ssh_string_free_char(v); ssh_string_free_char(v);
} }
/* Missing value to LogLevel configuration option
*/
static void torture_config_loglevel_missing_value(void **state)
{
ssh_session session = *state;
ssh_options_set(session, SSH_OPTIONS_HOST, "Bar");
_parse_config(session, LIBSSH_TESTCONFIG_LOGLEVEL_MISSING, NULL, SSH_OK);
}
int torture_run_tests(void) int torture_run_tests(void)
{ {
int rc; int rc;
@@ -2713,6 +2731,9 @@ int torture_run_tests(void)
setup, teardown), setup, teardown),
cmocka_unit_test_setup_teardown(torture_config_match_complex, cmocka_unit_test_setup_teardown(torture_config_match_complex,
setup, teardown), setup, teardown),
cmocka_unit_test_setup_teardown(torture_config_loglevel_missing_value,
setup,
teardown),
}; };