mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 20:30:38 +09:00
Assorted changes to make the torture_forward test pass
Cherry-picked from the following commit:
be25b58380
This commit is contained in:
committed by
Andreas Schneider
parent
3d70d4f08d
commit
f8007d7147
@@ -4,7 +4,6 @@ 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})
|
||||
add_cmocka_test(torture_forward torture_forward.c ${TORTURE_LIBRARY})
|
||||
if (WITH_SFTP)
|
||||
add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
|
||||
add_cmocka_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY})
|
||||
@@ -14,7 +13,8 @@ endif (WITH_SFTP)
|
||||
set(LIBSSH_CLIENT_TESTS
|
||||
torture_algorithms
|
||||
torture_knownhosts
|
||||
torture_request_env)
|
||||
torture_request_env
|
||||
torture_forward)
|
||||
|
||||
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
|
||||
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user