1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2026-01-06 14:21:55 +03:00

tests: Reproducer for usage of NULL sshdir

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
This commit is contained in:
Jakub Jelen
2022-02-15 11:42:52 +01:00
parent 2edb4b50ac
commit 70d3760daa

View File

@@ -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),
};