summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-09-16 15:03:05 +0200
committerJakub Jelen <jjelen@redhat.com>2019-10-01 10:24:01 +0200
commit46c3563da9a43e35cb8ed77edf8a59156d1945c4 (patch)
tree5d9d42543de84b42b61c0675c9e8cad34a557d4f
parentc983c994a2dee1af5d6abb5f9843be57ddc3d505 (diff)
downloadlibssh-46c3563da9a43e35cb8ed77edf8a59156d1945c4.tar.gz
libssh-46c3563da9a43e35cb8ed77edf8a59156d1945c4.tar.xz
libssh-46c3563da9a43e35cb8ed77edf8a59156d1945c4.zip
tests: Verify match exec keyword works on itself
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
-rw-r--r--tests/unittests/torture_config.c44
-rw-r--r--tests/unittests/torture_options.c21
2 files changed, 61 insertions, 4 deletions
diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c
index beb1ce79..7efa32db 100644
--- a/tests/unittests/torture_config.c
+++ b/tests/unittests/torture_config.c
@@ -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"
diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c
index 396772d8..f33ada20 100644
--- a/tests/unittests/torture_options.c
+++ b/tests/unittests/torture_options.c
@@ -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,15 +701,20 @@ 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;
- /* The Match exec keyword can accept more arguments */
+ /* 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"
+ fputs("Match exec \"/bin/true 1\"\n"
"\tPort 33\n"
"Match all\n"
"\tPort 34\n",
@@ -718,7 +723,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);
+#else
+ assert_int_equal(session->opts.port, 33);
+#endif
session->opts.port = 0;
@@ -735,7 +745,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);
+#else
+ assert_int_equal(session->opts.port, 33);
+#endif
session->opts.port = 0;