1
1

tests: Verify match exec keyword works on itself

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Этот коммит содержится в:
Jakub Jelen 2019-09-16 15:03:05 +02:00
родитель c983c994a2
Коммит 46c3563da9
2 изменённых файлов: 76 добавлений и 19 удалений

Просмотреть файл

@ -547,6 +547,48 @@ static void torture_config_match(void **state)
assert_ssh_return_code(session, ret);
assert_string_equal(session->opts.host, "otherhost");
torture_write_file(LIBSSH_TESTCONFIG10,
"Match exec /bin/true\n"
"\tHostName execed-true.com\n"
"");
torture_reset_config(session);
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
assert_ssh_return_code(session, ret);
#ifdef _WIN32
/* The match exec is not supported on windows at this moment */
assert_string_equal(session->opts.host, "otherhost");
#else
assert_string_equal(session->opts.host, "execed-true.com");
#endif
torture_write_file(LIBSSH_TESTCONFIG10,
"Match !exec /bin/false\n"
"\tHostName execed-false.com\n"
"");
torture_reset_config(session);
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
assert_ssh_return_code(session, ret);
#ifdef _WIN32
/* The match exec is not supported on windows at this moment */
assert_string_equal(session->opts.host, "otherhost");
#else
assert_string_equal(session->opts.host, "execed-false.com");
#endif
torture_write_file(LIBSSH_TESTCONFIG10,
"Match exec \"test -f /bin/true\"\n"
"\tHostName execed-arguments.com\n"
"");
torture_reset_config(session);
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
assert_ssh_return_code(session, ret);
#ifdef _WIN32
/* The match exec is not supported on windows at this moment */
assert_string_equal(session->opts.host, "otherhost");
#else
assert_string_equal(session->opts.host, "execed-arguments.com");
#endif
/* Try to create some invalid configurations */
/* Missing argument to Match*/
torture_write_file(LIBSSH_TESTCONFIG10,
@ -593,7 +635,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 exec */
/* Missing argument to option exec */
torture_write_file(LIBSSH_TESTCONFIG10,
"Match exec\n"
"\tUser exec\n"

Просмотреть файл

@ -688,7 +688,7 @@ static void torture_options_config_match(void **state)
session->opts.port = 0;
/* The Match exec keyword is ignored */
/* The Match exec keyword */
torture_reset_config(session);
config = fopen("test_config", "w");
assert_non_null(config);
@ -701,24 +701,12 @@ static void torture_options_config_match(void **state)
rv = ssh_options_parse_config(session, "test_config");
assert_ssh_return_code(session, rv);
#ifdef _WIN32
/* The match exec is not supported on windows at this moment */
assert_int_equal(session->opts.port, 34);
session->opts.port = 0;
/* The Match exec keyword can accept more arguments */
torture_reset_config(session);
config = fopen("test_config", "w");
assert_non_null(config);
fputs("Match exec /bin/true 1 \n"
"\tPort 33\n"
"Match all\n"
"\tPort 34\n",
config);
fclose(config);
rv = ssh_options_parse_config(session, "test_config");
assert_ssh_return_code(session, rv);
assert_int_equal(session->opts.port, 34);
#else
assert_int_equal(session->opts.port, 33);
#endif
session->opts.port = 0;
@ -735,7 +723,34 @@ static void torture_options_config_match(void **state)
rv = ssh_options_parse_config(session, "test_config");
assert_ssh_return_code(session, rv);
#ifdef _WIN32
/* The match exec is not supported on windows at this moment */
assert_int_equal(session->opts.port, 34);
#else
assert_int_equal(session->opts.port, 33);
#endif
session->opts.port = 0;
/* Commands containing whitespace characters must be quoted. */
torture_reset_config(session);
config = fopen("test_config", "w");
assert_non_null(config);
fputs("Match exec \"/bin/true 1\"\n"
"\tPort 33\n"
"Match all\n"
"\tPort 34\n",
config);
fclose(config);
rv = ssh_options_parse_config(session, "test_config");
assert_ssh_return_code(session, rv);
#ifdef _WIN32
/* The match exec is not supported on windows at this moment */
assert_int_equal(session->opts.port, 34);
#else
assert_int_equal(session->opts.port, 33);
#endif
session->opts.port = 0;