summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-09-16 16:38:51 +0200
committerJakub Jelen <jjelen@redhat.com>2019-10-01 10:24:01 +0200
commita22367fbe1932dbf9d0c06917fc688897c6aa96c (patch)
treedc737b427b1f8bbfbaab54f37bfb35890e28ae6b
parent46c3563da9a43e35cb8ed77edf8a59156d1945c4 (diff)
downloadlibssh-a22367fbe1932dbf9d0c06917fc688897c6aa96c.tar.gz
libssh-a22367fbe1932dbf9d0c06917fc688897c6aa96c.tar.xz
libssh-a22367fbe1932dbf9d0c06917fc688897c6aa96c.zip
tests: Verify multiple match conditions can be present on a line
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
-rw-r--r--tests/unittests/torture_options.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c
index f33ada20..e698874f 100644
--- a/tests/unittests/torture_options.c
+++ b/tests/unittests/torture_options.c
@@ -6,6 +6,7 @@
#define _POSIX_PTHREAD_SEMANTICS
# include <pwd.h>
#endif
+#include <sys/stat.h>
#include "torture.h"
#include "torture_key.h"
@@ -732,11 +733,42 @@ static void torture_options_config_match(void **state)
session->opts.port = 0;
- /* Commands containing whitespace characters must be quoted. */
+ unlink("test_config");
+}
+
+static void torture_options_config_match_multi(void **state)
+{
+ ssh_session session = *state;
+ FILE *config = NULL;
+ struct stat sb;
+ int rv;
+
+ /* Required for options_parse_config() */
+ ssh_options_set(session, SSH_OPTIONS_HOST, "testhost1");
+
+ /* Exec is not executed when it can not be matched */
torture_reset_config(session);
config = fopen("test_config", "w");
assert_non_null(config);
- fputs("Match exec \"/bin/true 1\"\n"
+ fputs("Match host wronghost exec \"touch test_config_wrong\"\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);
+ assert_int_equal(stat("test_config_wrong", &sb), -1);
+
+ session->opts.port = 0;
+
+ /* After matching exec, other conditions can be used */
+ torture_reset_config(session);
+ config = fopen("test_config", "w");
+ assert_non_null(config);
+ fputs("Match exec true host testhost1\n"
"\tPort 33\n"
"Match all\n"
"\tPort 34\n",
@@ -752,7 +784,20 @@ static void torture_options_config_match(void **state)
assert_int_equal(session->opts.port, 33);
#endif
- session->opts.port = 0;
+ /* After matching exec, other conditions can be used */
+ torture_reset_config(session);
+ config = fopen("test_config", "w");
+ assert_non_null(config);
+ fputs("Match exec true host otherhost\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);
unlink("test_config");
}
@@ -1652,6 +1697,8 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_options_config_host, setup, teardown),
cmocka_unit_test_setup_teardown(torture_options_config_match,
setup, teardown),
+ cmocka_unit_test_setup_teardown(torture_options_config_match_multi,
+ setup, teardown),
};
#ifdef WITH_SERVER