mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
Assorted changes to make the proxycommand test pass
Cherry-picked from the following commit:
e4653b82bd
This commit is contained in:
committed by
Andreas Schneider
parent
743a34ad9f
commit
c977a97093
@@ -2,7 +2,6 @@ project(clienttests C)
|
|||||||
|
|
||||||
add_cmocka_test(torture_auth torture_auth.c ${TORTURE_LIBRARY})
|
add_cmocka_test(torture_auth torture_auth.c ${TORTURE_LIBRARY})
|
||||||
add_cmocka_test(torture_connect torture_connect.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_session torture_session.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})
|
||||||
@@ -12,7 +11,8 @@ set(LIBSSH_CLIENT_TESTS
|
|||||||
torture_algorithms
|
torture_algorithms
|
||||||
torture_knownhosts
|
torture_knownhosts
|
||||||
torture_request_env
|
torture_request_env
|
||||||
torture_forward)
|
torture_forward
|
||||||
|
torture_proxycommand)
|
||||||
|
|
||||||
if (WITH_SFTP)
|
if (WITH_SFTP)
|
||||||
set(LIBSSH_CLIENT_TESTS
|
set(LIBSSH_CLIENT_TESTS
|
||||||
|
@@ -4,8 +4,39 @@
|
|||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
#include "libssh/priv.h"
|
#include "libssh/priv.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) {
|
static void setup(void **state) {
|
||||||
ssh_session session = ssh_new();
|
ssh_session session = ssh_new();
|
||||||
|
int verbosity = torture_libssh_verbosity();
|
||||||
|
struct passwd *pwd;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
pwd = getpwnam("bob");
|
||||||
|
assert_non_null(pwd);
|
||||||
|
|
||||||
|
rc = setuid(pwd->pw_uid);
|
||||||
|
assert_return_code(rc, errno);
|
||||||
|
|
||||||
|
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||||
|
ssh_options_set(session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER);
|
||||||
|
|
||||||
|
ssh_options_set(session, SSH_OPTIONS_USER, TORTURE_SSH_USER_ALICE);
|
||||||
|
|
||||||
*state = session;
|
*state = session;
|
||||||
}
|
}
|
||||||
@@ -18,10 +49,7 @@ static void torture_options_set_proxycommand(void **state) {
|
|||||||
ssh_session session = *state;
|
ssh_session session = *state;
|
||||||
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);
|
|
||||||
|
|
||||||
rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "nc localhost 22");
|
|
||||||
assert_true(rc == 0);
|
assert_true(rc == 0);
|
||||||
rc = ssh_connect(session);
|
rc = ssh_connect(session);
|
||||||
assert_true(rc == SSH_OK);
|
assert_true(rc == SSH_OK);
|
||||||
@@ -31,9 +59,6 @@ static void torture_options_set_proxycommand_notexist(void **state) {
|
|||||||
ssh_session session = *state;
|
ssh_session session = *state;
|
||||||
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_true(rc == SSH_OK);
|
||||||
rc = ssh_connect(session);
|
rc = ssh_connect(session);
|
||||||
@@ -42,6 +67,7 @@ static void torture_options_set_proxycommand_notexist(void **state) {
|
|||||||
|
|
||||||
int torture_run_tests(void) {
|
int torture_run_tests(void) {
|
||||||
int rc;
|
int rc;
|
||||||
|
struct torture_state *s = NULL;
|
||||||
UnitTest tests[] = {
|
UnitTest tests[] = {
|
||||||
unit_test_setup_teardown(torture_options_set_proxycommand, setup, teardown),
|
unit_test_setup_teardown(torture_options_set_proxycommand, setup, teardown),
|
||||||
unit_test_setup_teardown(torture_options_set_proxycommand_notexist, setup, teardown),
|
unit_test_setup_teardown(torture_options_set_proxycommand_notexist, setup, teardown),
|
||||||
@@ -51,7 +77,9 @@ int torture_run_tests(void) {
|
|||||||
ssh_init();
|
ssh_init();
|
||||||
|
|
||||||
torture_filter_tests(tests);
|
torture_filter_tests(tests);
|
||||||
|
sshd_setup((void **)&s);
|
||||||
rc = run_tests(tests);
|
rc = run_tests(tests);
|
||||||
|
sshd_teardown((void **)&s);
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
Reference in New Issue
Block a user