From c977a970933ad6a563cf6599497f6679dd04779d Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 2 Oct 2018 19:31:23 +0200 Subject: Assorted changes to make the proxycommand test pass Cherry-picked from the following commit: e4653b82bdb63469fd7279cc2b37c48a9d838665 --- tests/client/CMakeLists.txt | 4 ++-- tests/client/torture_proxycommand.c | 42 ++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt index 8d0bda8b..186e0e7b 100644 --- a/tests/client/CMakeLists.txt +++ b/tests/client/CMakeLists.txt @@ -2,7 +2,6 @@ project(clienttests C) add_cmocka_test(torture_auth torture_auth.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_connect torture_connect.c ${TORTURE_LIBRARY}) -add_cmocka_test(torture_proxycommand torture_proxycommand.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_session torture_session.c ${TORTURE_LIBRARY}) if (WITH_SFTP) add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY}) @@ -12,7 +11,8 @@ set(LIBSSH_CLIENT_TESTS torture_algorithms torture_knownhosts torture_request_env - torture_forward) + torture_forward + torture_proxycommand) if (WITH_SFTP) set(LIBSSH_CLIENT_TESTS diff --git a/tests/client/torture_proxycommand.c b/tests/client/torture_proxycommand.c index a1508811..07e80e3b 100644 --- a/tests/client/torture_proxycommand.c +++ b/tests/client/torture_proxycommand.c @@ -4,8 +4,39 @@ #include #include "libssh/priv.h" +#include +#include +#include + +static int sshd_setup(void **state) +{ + torture_setup_sshd_server(state); + + return 0; +} + +static int sshd_teardown(void **state) { + torture_teardown_sshd_server(state); + + return 0; +} + static void setup(void **state) { ssh_session session = ssh_new(); + int verbosity = torture_libssh_verbosity(); + struct passwd *pwd; + int rc; + + pwd = getpwnam("bob"); + assert_non_null(pwd); + + rc = setuid(pwd->pw_uid); + assert_return_code(rc, errno); + + ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); + ssh_options_set(session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER); + + ssh_options_set(session, SSH_OPTIONS_USER, TORTURE_SSH_USER_ALICE); *state = session; } @@ -18,10 +49,7 @@ static void torture_options_set_proxycommand(void **state) { ssh_session session = *state; int rc; - rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost"); - assert_true(rc == 0); - - rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "nc localhost 22"); + rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "nc 127.0.0.10 22"); assert_true(rc == 0); rc = ssh_connect(session); assert_true(rc == SSH_OK); @@ -31,9 +59,6 @@ static void torture_options_set_proxycommand_notexist(void **state) { ssh_session session = *state; int rc; - rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost"); - assert_true(rc == 0); - rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "this_command_does_not_exist"); assert_true(rc == SSH_OK); rc = ssh_connect(session); @@ -42,6 +67,7 @@ static void torture_options_set_proxycommand_notexist(void **state) { int torture_run_tests(void) { int rc; + struct torture_state *s = NULL; UnitTest tests[] = { unit_test_setup_teardown(torture_options_set_proxycommand, setup, teardown), unit_test_setup_teardown(torture_options_set_proxycommand_notexist, setup, teardown), @@ -51,7 +77,9 @@ int torture_run_tests(void) { ssh_init(); torture_filter_tests(tests); + sshd_setup((void **)&s); rc = run_tests(tests); + sshd_teardown((void **)&s); ssh_finalize(); return rc; -- cgit v1.2.3