From 70d3760daa2a29e94da736c721932da5b9424307 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 15 Feb 2022 11:42:52 +0100 Subject: [PATCH] tests: Reproducer for usage of NULL sshdir Signed-off-by: Jakub Jelen Reviewed-by: Anderson Toshiyuki Sasaki --- tests/unittests/torture_config.c | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c index 8afbe143..ab51e8f0 100644 --- a/tests/unittests/torture_config.c +++ b/tests/unittests/torture_config.c @@ -327,6 +327,21 @@ static int setup(void **state) return 0; } +static int setup_no_sshdir(void **state) +{ + ssh_session session = NULL; + int verbosity; + + session = ssh_new(); + + verbosity = torture_libssh_verbosity(); + ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); + + *state = session; + + return 0; +} + static int teardown(void **state) { ssh_free(*state); @@ -1666,7 +1681,7 @@ static void torture_config_identity(void **state) /* Make absolute path for config include */ -static void torture_config_make_absolute(void **state) +static void torture_config_make_absolute_int(void **state, bool no_sshdir_fails) { ssh_session session = *state; char *result = NULL; @@ -1687,6 +1702,16 @@ static void torture_config_make_absolute(void **state) assert_string_equal(result, "/etc/ssh/./ssh_config.d/test.conf"); free(result); + /* User config is relative to sshdir -- here faked to /tmp/ssh/ */ + result = ssh_config_make_absolute(session, "my_config", 0); + if (no_sshdir_fails) { + assert_null(result); + } else { + /* The path depends on the PWD so lets skip checking the actual path here */ + assert_non_null(result); + } + free(result); + /* User config is relative to sshdir -- here faked to /tmp/ssh/ */ ssh_options_set(session, SSH_OPTIONS_SSH_DIR, "/tmp/ssh"); result = ssh_config_make_absolute(session, "my_config", 0); @@ -1694,6 +1719,15 @@ static void torture_config_make_absolute(void **state) free(result); } +static void torture_config_make_absolute(void **state) +{ + torture_config_make_absolute_int(state, 0); +} + +static void torture_config_make_absolute_no_sshdir(void **state) +{ + torture_config_make_absolute_int(state, 1); +} int torture_run_tests(void) { @@ -1761,6 +1795,8 @@ int torture_run_tests(void) setup, teardown), cmocka_unit_test_setup_teardown(torture_config_make_absolute, setup, teardown), + cmocka_unit_test_setup_teardown(torture_config_make_absolute_no_sshdir, + setup_no_sshdir, teardown), };