tests: Migrate torture_proxycommand to new cwrap test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
b65dcb3a35
Коммит
e4653b82bd
@ -2,7 +2,6 @@ project(clienttests C)
|
|||||||
|
|
||||||
find_package(socket_wrapper)
|
find_package(socket_wrapper)
|
||||||
|
|
||||||
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_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)
|
||||||
@ -16,7 +15,8 @@ set(LIBSSH_CLIENT_TESTS
|
|||||||
torture_connect
|
torture_connect
|
||||||
torture_auth
|
torture_auth
|
||||||
torture_forward
|
torture_forward
|
||||||
torture_knownhosts)
|
torture_knownhosts
|
||||||
|
torture_proxycommand)
|
||||||
|
|
||||||
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})
|
||||||
|
@ -4,58 +4,91 @@
|
|||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
#include "libssh/priv.h"
|
#include "libssh/priv.h"
|
||||||
|
|
||||||
static int setup(void **state) {
|
#include <sys/types.h>
|
||||||
ssh_session session = ssh_new();
|
#include <pwd.h>
|
||||||
|
|
||||||
*state = session;
|
static int sshd_setup(void **state)
|
||||||
|
{
|
||||||
|
torture_setup_sshd_server(state);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int teardown(void **state) {
|
static int sshd_teardown(void **state) {
|
||||||
ssh_free(*state);
|
torture_teardown_sshd_server(state);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int session_setup(void **state)
|
||||||
|
{
|
||||||
|
struct torture_state *s = *state;
|
||||||
|
int verbosity = torture_libssh_verbosity();
|
||||||
|
struct passwd *pwd;
|
||||||
|
|
||||||
|
pwd = getpwnam("bob");
|
||||||
|
assert_non_null(pwd);
|
||||||
|
setuid(pwd->pw_uid);
|
||||||
|
|
||||||
|
s->ssh.session = ssh_new();
|
||||||
|
assert_non_null(s->ssh.session);
|
||||||
|
|
||||||
|
ssh_options_set(s->ssh.session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||||
|
ssh_options_set(s->ssh.session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER);
|
||||||
|
|
||||||
|
ssh_options_set(s->ssh.session, SSH_OPTIONS_USER, TORTURE_SSH_USER_ALICE);
|
||||||
|
|
||||||
|
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_options_set_proxycommand(void **state) {
|
static void torture_options_set_proxycommand(void **state) {
|
||||||
ssh_session session = *state;
|
struct torture_state *s = *state;
|
||||||
|
ssh_session session = s->ssh.session;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
|
rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "nc 127.0.0.10 22");
|
||||||
assert_true(rc == 0);
|
assert_int_equal(rc, 0);
|
||||||
|
|
||||||
rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "nc localhost 22");
|
|
||||||
assert_true(rc == 0);
|
|
||||||
rc = ssh_connect(session);
|
rc = ssh_connect(session);
|
||||||
assert_true(rc == SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void torture_options_set_proxycommand_notexist(void **state) {
|
static void torture_options_set_proxycommand_notexist(void **state) {
|
||||||
ssh_session session = *state;
|
struct torture_state *s = *state;
|
||||||
|
ssh_session session = s->ssh.session;
|
||||||
int rc;
|
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");
|
rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "this_command_does_not_exist");
|
||||||
assert_true(rc == SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
rc = ssh_connect(session);
|
rc = ssh_connect(session);
|
||||||
assert_true(rc == SSH_ERROR);
|
assert_int_equal(rc, SSH_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_options_set_proxycommand, setup, teardown),
|
cmocka_unit_test_setup_teardown(torture_options_set_proxycommand,
|
||||||
cmocka_unit_test_setup_teardown(torture_options_set_proxycommand_notexist, setup, teardown),
|
session_setup,
|
||||||
|
session_teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_options_set_proxycommand_notexist,
|
||||||
|
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;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user