aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-09-16 11:12:45 +0200
committerJakub Jelen <jjelen@redhat.com>2019-09-18 15:18:33 +0200
commit61b1e0e7e99ee7a0dc8b909368e2d618e58b8548 (patch)
treec2065652b16ab6a58eb5c5db7884ffc7a1e580d4 /tests/unittests
parent6500134259c40c95d0b342278c42304b1067b85b (diff)
downloadlibssh-61b1e0e7e99ee7a0dc8b909368e2d618e58b8548.tar.gz
libssh-61b1e0e7e99ee7a0dc8b909368e2d618e58b8548.tar.xz
libssh-61b1e0e7e99ee7a0dc8b909368e2d618e58b8548.zip
tests: Verify the localuser match works
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/torture_config.c19
-rw-r--r--tests/unittests/torture_options.c12
2 files changed, 26 insertions, 5 deletions
diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c
index 29680801..55ea210c 100644
--- a/tests/unittests/torture_config.c
+++ b/tests/unittests/torture_config.c
@@ -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"
diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c
index 6ae99e7b..396772d8 100644
--- a/tests/unittests/torture_options.c
+++ b/tests/unittests/torture_options.c
@@ -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;