mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-06 18:29:50 +09:00
Assorted changes to make the sftp_dir test working
Cherry-picked from the following commit:
af3de262b6
This commit is contained in:
committed by
Andreas Schneider
parent
f8007d7147
commit
0f9e6598ef
@@ -6,7 +6,6 @@ add_cmocka_test(torture_proxycommand torture_proxycommand.c ${TORTURE_LIBRARY})
|
||||
add_cmocka_test(torture_session torture_session.c ${TORTURE_LIBRARY})
|
||||
if (WITH_SFTP)
|
||||
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})
|
||||
endif (WITH_SFTP)
|
||||
|
||||
@@ -16,6 +15,12 @@ set(LIBSSH_CLIENT_TESTS
|
||||
torture_request_env
|
||||
torture_forward)
|
||||
|
||||
if (WITH_SFTP)
|
||||
set(LIBSSH_CLIENT_TESTS
|
||||
${LIBSSH_CLIENT_TESTS}
|
||||
torture_sftp_dir)
|
||||
endif (WITH_SFTP)
|
||||
|
||||
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
|
||||
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
|
||||
|
||||
|
||||
@@ -3,22 +3,36 @@
|
||||
#include "torture.h"
|
||||
#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) {
|
||||
ssh_session session;
|
||||
struct torture_sftp *t;
|
||||
const char *host;
|
||||
const char *user;
|
||||
const char *password;
|
||||
struct passwd *pwd;
|
||||
|
||||
host = getenv("TORTURE_HOST");
|
||||
if (host == NULL) {
|
||||
host = "localhost";
|
||||
}
|
||||
pwd = getpwnam("bob");
|
||||
assert_non_null(pwd);
|
||||
setuid(pwd->pw_uid);
|
||||
|
||||
user = getenv("TORTURE_USER");
|
||||
password = getenv("TORTURE_PASSWORD");
|
||||
|
||||
session = torture_ssh_session(host, NULL, user, password);
|
||||
session = torture_ssh_session(TORTURE_SSH_SERVER,
|
||||
NULL,
|
||||
TORTURE_SSH_USER_ALICE,
|
||||
NULL);
|
||||
assert_false(session == NULL);
|
||||
t = torture_sftp_session(session);
|
||||
assert_false(t == NULL);
|
||||
@@ -61,6 +75,7 @@ static void torture_sftp_mkdir(void **state) {
|
||||
|
||||
int torture_run_tests(void) {
|
||||
int rc;
|
||||
struct torture_state *s = NULL;
|
||||
UnitTest tests[] = {
|
||||
unit_test_setup_teardown(torture_sftp_mkdir, setup, teardown)
|
||||
};
|
||||
@@ -68,7 +83,9 @@ int torture_run_tests(void) {
|
||||
ssh_init();
|
||||
|
||||
torture_filter_tests(tests);
|
||||
sshd_setup((void **)&s);
|
||||
rc = run_tests(tests);
|
||||
sshd_teardown((void **)&s);
|
||||
ssh_finalize();
|
||||
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user