mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-12 03:00:26 +09:00
tests: Migrate torture_forward to a cwrap test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -5,7 +5,6 @@ find_package(socket_wrapper)
|
|||||||
add_cmocka_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY})
|
add_cmocka_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY})
|
||||||
add_cmocka_test(torture_proxycommand torture_proxycommand.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_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})
|
add_cmocka_test(torture_request_env torture_request_env.c ${TORTURE_LIBRARY})
|
||||||
if (WITH_SFTP)
|
if (WITH_SFTP)
|
||||||
add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
|
add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
|
||||||
@@ -16,7 +15,8 @@ endif (WITH_SFTP)
|
|||||||
set(LIBSSH_CLIENT_TESTS
|
set(LIBSSH_CLIENT_TESTS
|
||||||
torture_algorithms
|
torture_algorithms
|
||||||
torture_connect
|
torture_connect
|
||||||
torture_auth)
|
torture_auth
|
||||||
|
torture_forward)
|
||||||
|
|
||||||
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
|
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
|
||||||
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
|
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
|
||||||
|
|||||||
@@ -24,75 +24,75 @@
|
|||||||
#include "torture.h"
|
#include "torture.h"
|
||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
|
|
||||||
static int setup(void **state)
|
static int sshd_setup(void **state)
|
||||||
{
|
{
|
||||||
ssh_session session;
|
torture_setup_sshd_server(state);
|
||||||
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;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int teardown(void **state)
|
static int sshd_teardown(void **state) {
|
||||||
{
|
torture_teardown_sshd_server(state);
|
||||||
ssh_session session = (ssh_session) *state;
|
|
||||||
|
|
||||||
assert_non_null(session);
|
return 0;
|
||||||
|
|
||||||
if (ssh_is_connected(session)) {
|
|
||||||
ssh_disconnect(session);
|
|
||||||
}
|
}
|
||||||
ssh_free(session);
|
|
||||||
|
static int session_setup(void **state)
|
||||||
|
{
|
||||||
|
struct torture_state *s = *state;
|
||||||
|
|
||||||
|
s->ssh.session = torture_ssh_session(TORTURE_SSH_SERVER,
|
||||||
|
NULL,
|
||||||
|
TORTURE_SSH_USER_ALICE,
|
||||||
|
NULL);
|
||||||
|
assert_non_null(s->ssh.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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void torture_ssh_forward(void **state)
|
static void torture_ssh_forward(void **state)
|
||||||
{
|
{
|
||||||
ssh_session session = (ssh_session) *state;
|
struct torture_state *s = *state;
|
||||||
#if 0
|
ssh_session session = s->ssh.session;
|
||||||
ssh_channel c;
|
ssh_channel c;
|
||||||
#endif
|
int dport;
|
||||||
int bound_port;
|
int bound_port;
|
||||||
int rc;
|
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);
|
assert_int_equal(rc, SSH_OK);
|
||||||
|
|
||||||
#if 0
|
c = ssh_channel_accept_forward(session, 10, &dport);
|
||||||
c = ssh_forward_accept(session, 60000);
|
/* We do not get a listener and run into the timeout here */
|
||||||
assert_non_null(c);
|
assert_null(c);
|
||||||
|
|
||||||
ssh_channel_send_eof(c);
|
ssh_channel_send_eof(c);
|
||||||
ssh_channel_close(c);
|
ssh_channel_close(c);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int torture_run_tests(void) {
|
int torture_run_tests(void) {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
struct CMUnitTest tests[] = {
|
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();
|
ssh_init();
|
||||||
|
|
||||||
torture_filter_tests(tests);
|
torture_filter_tests(tests);
|
||||||
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown);
|
||||||
|
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
Reference in New Issue
Block a user