tests: Migrate torture_forward to a cwrap test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
66f51df9df
Коммит
be25b58380
@ -5,7 +5,6 @@ find_package(socket_wrapper)
|
||||
add_cmocka_test(torture_knownhosts torture_knownhosts.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})
|
||||
add_cmocka_test(torture_request_env torture_request_env.c ${TORTURE_LIBRARY})
|
||||
if (WITH_SFTP)
|
||||
add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
|
||||
@ -16,7 +15,8 @@ endif (WITH_SFTP)
|
||||
set(LIBSSH_CLIENT_TESTS
|
||||
torture_algorithms
|
||||
torture_connect
|
||||
torture_auth)
|
||||
torture_auth
|
||||
torture_forward)
|
||||
|
||||
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
|
||||
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
|
||||
|
@ -24,75 +24,75 @@
|
||||
#include "torture.h"
|
||||
#include <libssh/libssh.h>
|
||||
|
||||
static int setup(void **state)
|
||||
static int sshd_setup(void **state)
|
||||
{
|
||||
ssh_session session;
|
||||
const char *host;
|
||||
const char *user;
|
||||
const char *password;
|
||||
|
||||
host = getenv("TORTURE_HOST");
|
||||
if (host == NULL) {
|
||||
host = "localhost";
|
||||
}
|
||||
|
||||
user = getenv("TORTURE_USER");
|
||||
password = getenv("TORTURE_PASSWORD");
|
||||
|
||||
session = torture_ssh_session(host, NULL, user, password);
|
||||
|
||||
assert_non_null(session);
|
||||
*state = session;
|
||||
torture_setup_sshd_server(state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int teardown(void **state)
|
||||
static int sshd_teardown(void **state) {
|
||||
torture_teardown_sshd_server(state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int session_setup(void **state)
|
||||
{
|
||||
ssh_session session = (ssh_session) *state;
|
||||
struct torture_state *s = *state;
|
||||
|
||||
assert_non_null(session);
|
||||
s->ssh.session = torture_ssh_session(TORTURE_SSH_SERVER,
|
||||
NULL,
|
||||
TORTURE_SSH_USER_ALICE,
|
||||
NULL);
|
||||
assert_non_null(s->ssh.session);
|
||||
|
||||
if (ssh_is_connected(session)) {
|
||||
ssh_disconnect(session);
|
||||
}
|
||||
ssh_free(session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int session_teardown(void **state)
|
||||
{
|
||||
struct torture_state *s = *state;
|
||||
|
||||
ssh_disconnect(s->ssh.session);
|
||||
ssh_free(s->ssh.session);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void torture_ssh_forward(void **state)
|
||||
{
|
||||
ssh_session session = (ssh_session) *state;
|
||||
#if 0
|
||||
struct torture_state *s = *state;
|
||||
ssh_session session = s->ssh.session;
|
||||
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 CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(torture_ssh_forward, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_ssh_forward,
|
||||
session_setup,
|
||||
session_teardown),
|
||||
};
|
||||
|
||||
ssh_init();
|
||||
|
||||
torture_filter_tests(tests);
|
||||
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
||||
rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown);
|
||||
|
||||
ssh_finalize();
|
||||
return rc;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user