Assorted changes to make the sftp_dir test working

Cherry-picked from the following commit:
af3de262b6
This commit is contained in:
Jakub Jelen
2018-10-02 19:13:09 +02:00
committed by Andreas Schneider
parent f8007d7147
commit 0f9e6598ef
2 changed files with 34 additions and 12 deletions

View File

@@ -6,7 +6,6 @@ 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})
add_cmocka_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_sftp_read torture_sftp_read.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_sftp_read torture_sftp_read.c ${TORTURE_LIBRARY})
endif (WITH_SFTP) endif (WITH_SFTP)
@@ -16,6 +15,12 @@ set(LIBSSH_CLIENT_TESTS
torture_request_env torture_request_env
torture_forward) torture_forward)
if (WITH_SFTP)
set(LIBSSH_CLIENT_TESTS
${LIBSSH_CLIENT_TESTS}
torture_sftp_dir)
endif (WITH_SFTP)
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})

View File

@@ -3,22 +3,36 @@
#include "torture.h" #include "torture.h"
#include "sftp.c" #include "sftp.c"
#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_session session;
struct torture_sftp *t; struct torture_sftp *t;
const char *host; struct passwd *pwd;
const char *user;
const char *password;
host = getenv("TORTURE_HOST"); pwd = getpwnam("bob");
if (host == NULL) { assert_non_null(pwd);
host = "localhost"; setuid(pwd->pw_uid);
}
user = getenv("TORTURE_USER"); session = torture_ssh_session(TORTURE_SSH_SERVER,
password = getenv("TORTURE_PASSWORD"); NULL,
TORTURE_SSH_USER_ALICE,
session = torture_ssh_session(host, NULL, user, password); NULL);
assert_false(session == NULL); assert_false(session == NULL);
t = torture_sftp_session(session); t = torture_sftp_session(session);
assert_false(t == NULL); assert_false(t == NULL);
@@ -61,6 +75,7 @@ static void torture_sftp_mkdir(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_sftp_mkdir, setup, teardown) unit_test_setup_teardown(torture_sftp_mkdir, setup, teardown)
}; };
@@ -68,7 +83,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;