diff options
Diffstat (limited to 'tests/client/torture_forward.c')
-rw-r--r-- | tests/client/torture_forward.c | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/tests/client/torture_forward.c b/tests/client/torture_forward.c index 876ed74b..94eea72d 100644 --- a/tests/client/torture_forward.c +++ b/tests/client/torture_forward.c @@ -24,24 +24,42 @@ #include "torture.h" #include <libssh/libssh.h> +#include <errno.h> +#include <sys/types.h> +#include <pwd.h> + +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; - const char *host; - const char *user; - const char *password; + struct passwd *pwd; + int rc; - host = getenv("TORTURE_HOST"); - if (host == NULL) { - host = "localhost"; - } + pwd = getpwnam("bob"); + assert_non_null(pwd); - user = getenv("TORTURE_USER"); - password = getenv("TORTURE_PASSWORD"); + rc = setuid(pwd->pw_uid); + assert_return_code(rc, errno); - session = torture_ssh_session(host, NULL, user, password); + session = torture_ssh_session(TORTURE_SSH_SERVER, + NULL, + TORTURE_SSH_USER_ALICE, + NULL); assert_non_null(session); + *state = session; } @@ -60,26 +78,25 @@ static void teardown(void **state) static void torture_ssh_forward(void **state) { ssh_session session = (ssh_session) *state; -#if 0 ssh_channel c; -#endif + int dport; int bound_port; int rc; - rc = ssh_channel_listen_forward(session, "127.0.0.1", 8080, &bound_port); + rc = ssh_channel_listen_forward(session, "127.0.0.21", 8080, &bound_port); assert_int_equal(rc, SSH_OK); -#if 0 - c = ssh_forward_accept(session, 60000); - assert_non_null(c); + c = ssh_channel_accept_forward(session, 10, &dport); + /* We do not get a listener and run into the timeout here */ + assert_null(c); ssh_channel_send_eof(c); ssh_channel_close(c); -#endif } int torture_run_tests(void) { int rc; + struct torture_state *s = NULL; UnitTest tests[] = { unit_test_setup_teardown(torture_ssh_forward, setup, teardown), @@ -88,7 +105,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; |