tests: Verify the recursive includes do not crash
neither client nor server configuration parser Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
227f416183
Коммит
d76d5c633f
@ -95,6 +95,7 @@ extern LIBSSH_THREAD int ssh_log_level;
|
||||
#define LIBSSH_TEST_BIND_CONFIG_FULL "libssh_test_bind_config_full"
|
||||
#define LIBSSH_TEST_BIND_CONFIG_INCLUDE "libssh_test_bind_config_include"
|
||||
#define LIBSSH_TEST_BIND_CONFIG_INCLUDE_RECURSIVE "libssh_test_bind_config_include_recursive"
|
||||
#define LIBSSH_TEST_BIND_CONFIG_INCLUDE_RECURSIVE_LOOP "libssh_test_bind_config_include_recursive_loop"
|
||||
#define LIBSSH_TEST_BIND_CONFIG_CORNER_CASES "libssh_test_bind_config_corner_cases"
|
||||
|
||||
#define LIBSSH_TEST_BIND_CONFIG_MATCH_ALL "libssh_test_bind_config_match_all"
|
||||
@ -265,6 +266,9 @@ static int setup_config_files(void **state)
|
||||
torture_write_file(LIBSSH_TEST_BIND_CONFIG_INCLUDE_RECURSIVE,
|
||||
"Include "LIBSSH_TEST_BIND_CONFIG_INCLUDE"\n");
|
||||
|
||||
torture_write_file(LIBSSH_TEST_BIND_CONFIG_INCLUDE_RECURSIVE_LOOP,
|
||||
"Include "LIBSSH_TEST_BIND_CONFIG_INCLUDE_RECURSIVE_LOOP"\n");
|
||||
|
||||
/* Unsupported options and corner cases */
|
||||
torture_write_file(LIBSSH_TEST_BIND_CONFIG_CORNER_CASES,
|
||||
"\n" /* empty line */
|
||||
@ -1076,6 +1080,23 @@ static void torture_bind_config_include_recursive(void **state)
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
}
|
||||
|
||||
static void torture_bind_config_include_recursive_loop(void **state)
|
||||
{
|
||||
struct bind_st *test_state;
|
||||
ssh_bind bind;
|
||||
int rc;
|
||||
|
||||
assert_non_null(state);
|
||||
test_state = *((struct bind_st **)state);
|
||||
assert_non_null(test_state);
|
||||
assert_non_null(test_state->bind);
|
||||
bind = test_state->bind;
|
||||
|
||||
rc = ssh_bind_config_parse_file(bind,
|
||||
LIBSSH_TEST_BIND_CONFIG_INCLUDE_RECURSIVE_LOOP);
|
||||
assert_int_equal(rc, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Verify the configuration parser does not choke on unknown
|
||||
* or unsupported configuration options
|
||||
@ -1287,6 +1308,8 @@ int torture_run_tests(void)
|
||||
sshbind_setup, sshbind_teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_bind_config_include_recursive,
|
||||
sshbind_setup, sshbind_teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_bind_config_include_recursive_loop,
|
||||
sshbind_setup, sshbind_teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_bind_config_corner_cases,
|
||||
sshbind_setup, sshbind_teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_bind_config_match_all,
|
||||
|
@ -38,6 +38,7 @@ extern LIBSSH_THREAD int ssh_log_level;
|
||||
#define LIBSSH_TEST_PUBKEYTYPES "libssh_test_PubkeyAcceptedKeyTypes.tmp"
|
||||
#define LIBSSH_TEST_NONEWLINEEND "libssh_test_NoNewLineEnd.tmp"
|
||||
#define LIBSSH_TEST_NONEWLINEONELINE "libssh_test_NoNewLineOneline.tmp"
|
||||
#define LIBSSH_TEST_RECURSIVE_INCLUDE "libssh_test_recursive_include.tmp"
|
||||
|
||||
#define LIBSSH_TESTCONFIG_STRING1 \
|
||||
"User "USERNAME"\nInclude "LIBSSH_TESTCONFIG2"\n\n"
|
||||
@ -183,6 +184,9 @@ extern LIBSSH_THREAD int ssh_log_level;
|
||||
#define LIBSSH_TEST_NONEWLINEONELINE_STRING \
|
||||
"ConnectTimeout 30"
|
||||
|
||||
#define LIBSSH_TEST_RECURSIVE_INCLUDE_STRING \
|
||||
"Include " LIBSSH_TEST_RECURSIVE_INCLUDE
|
||||
|
||||
/**
|
||||
* @brief helper function loading configuration from either file or string
|
||||
*/
|
||||
@ -417,6 +421,22 @@ static void torture_config_include_string(void **state)
|
||||
torture_config_include(state, NULL, LIBSSH_TESTCONFIG_STRING1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tests ssh_config_parse_file with recursive Include directives from file
|
||||
*/
|
||||
static void torture_config_include_recursive_file(void **state)
|
||||
{
|
||||
_parse_config(*state, LIBSSH_TEST_RECURSIVE_INCLUDE, NULL, SSH_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tests ssh_config_parse_string with Include directives from string
|
||||
*/
|
||||
static void torture_config_include_recursive_string(void **state)
|
||||
{
|
||||
_parse_config(*state, NULL, LIBSSH_TEST_RECURSIVE_INCLUDE_STRING, SSH_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tests ssh_config_parse_file with multiple Port settings.
|
||||
*/
|
||||
@ -1646,6 +1666,10 @@ int torture_run_tests(void)
|
||||
setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_config_include_string,
|
||||
setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_config_include_recursive_file,
|
||||
setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_config_include_recursive_string,
|
||||
setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_config_double_ports_file,
|
||||
setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_config_double_ports_string,
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user