mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 12:20:42 +09:00
tests: Verify the localuser match works
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
This commit is contained in:
@@ -440,6 +440,8 @@ static void torture_config_unknown(void **state) {
|
||||
static void torture_config_match(void **state)
|
||||
{
|
||||
ssh_session session = *state;
|
||||
char *localuser = NULL;
|
||||
char config[1024];
|
||||
int ret = 0;
|
||||
|
||||
/* Without any settings we should get all-matched.com hostname */
|
||||
@@ -531,6 +533,19 @@ static void torture_config_match(void **state)
|
||||
assert_ssh_return_code(session, ret);
|
||||
assert_string_equal(session->opts.host, "canonical.com");
|
||||
|
||||
localuser = ssh_get_local_username();
|
||||
assert_non_null(localuser);
|
||||
snprintf(config, sizeof(config),
|
||||
"Match localuser %s\n"
|
||||
"\tHostName otherhost\n"
|
||||
"", localuser);
|
||||
free(localuser);
|
||||
torture_write_file(LIBSSH_TESTCONFIG10, config);
|
||||
torture_reset_config(session);
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
assert_ssh_return_code(session, ret);
|
||||
assert_string_equal(session->opts.host, "otherhost");
|
||||
|
||||
/* Try to create some invalid configurations */
|
||||
/* Missing argument to Match*/
|
||||
torture_write_file(LIBSSH_TESTCONFIG10,
|
||||
@@ -550,7 +565,7 @@ static void torture_config_match(void **state)
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
assert_ssh_return_code_equal(session, ret, SSH_ERROR);
|
||||
|
||||
/* Missing argument to unsupported option localuser */
|
||||
/* Missing argument to option localuser */
|
||||
torture_write_file(LIBSSH_TESTCONFIG10,
|
||||
"Match localuser\n"
|
||||
"\tUser localuser2\n"
|
||||
@@ -559,7 +574,7 @@ static void torture_config_match(void **state)
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
assert_ssh_return_code_equal(session, ret, SSH_ERROR);
|
||||
|
||||
/* Missing argument to option user*/
|
||||
/* Missing argument to option user */
|
||||
torture_write_file(LIBSSH_TESTCONFIG10,
|
||||
"Match user\n"
|
||||
"\tUser user2\n"
|
||||
|
||||
@@ -571,6 +571,7 @@ static void torture_options_config_host(void **state) {
|
||||
static void torture_options_config_match(void **state)
|
||||
{
|
||||
ssh_session session = *state;
|
||||
char *localuser = NULL;
|
||||
FILE *config = NULL;
|
||||
int rv;
|
||||
|
||||
@@ -665,11 +666,16 @@ static void torture_options_config_match(void **state)
|
||||
|
||||
session->opts.port = 0;
|
||||
|
||||
/* The Match localuser keyword is ignored */
|
||||
/* The Match localuser keyword */
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match originalhost origin\n"
|
||||
fputs("Match localuser ", config);
|
||||
localuser = ssh_get_local_username();
|
||||
assert_non_null(localuser);
|
||||
fputs(localuser, config);
|
||||
free(localuser);
|
||||
fputs("\n"
|
||||
"\tPort 33\n"
|
||||
"Match all\n"
|
||||
"\tPort 34\n",
|
||||
@@ -678,7 +684,7 @@ static void torture_options_config_match(void **state)
|
||||
|
||||
rv = ssh_options_parse_config(session, "test_config");
|
||||
assert_ssh_return_code(session, rv);
|
||||
assert_int_equal(session->opts.port, 34);
|
||||
assert_int_equal(session->opts.port, 33);
|
||||
|
||||
session->opts.port = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user