mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-06-02 03:41:34 +03:00
tests: Migrate torture_sftp_dir to cwrap test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
parent
bd4a0aa705
commit
af3de262b6
@ -4,7 +4,6 @@ find_package(socket_wrapper)
|
|||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@ -18,6 +17,12 @@ set(LIBSSH_CLIENT_TESTS
|
|||||||
torture_session
|
torture_session
|
||||||
torture_request_env)
|
torture_request_env)
|
||||||
|
|
||||||
|
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})
|
||||||
|
|
||||||
|
@ -3,44 +3,59 @@
|
|||||||
#include "torture.h"
|
#include "torture.h"
|
||||||
#include "sftp.c"
|
#include "sftp.c"
|
||||||
|
|
||||||
static int setup(void **state) {
|
#include <sys/types.h>
|
||||||
ssh_session session;
|
#include <pwd.h>
|
||||||
struct torture_sftp *t;
|
|
||||||
const char *host;
|
|
||||||
const char *user;
|
|
||||||
const char *password;
|
|
||||||
|
|
||||||
host = getenv("TORTURE_HOST");
|
static int sshd_setup(void **state)
|
||||||
if (host == NULL) {
|
{
|
||||||
host = "localhost";
|
torture_setup_sshd_server(state);
|
||||||
}
|
|
||||||
|
|
||||||
user = getenv("TORTURE_USER");
|
|
||||||
password = getenv("TORTURE_PASSWORD");
|
|
||||||
|
|
||||||
session = torture_ssh_session(host, NULL, user, password);
|
|
||||||
assert_false(session == NULL);
|
|
||||||
t = torture_sftp_session(session);
|
|
||||||
assert_false(t == NULL);
|
|
||||||
|
|
||||||
*state = t;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int teardown(void **state) {
|
static int sshd_teardown(void **state) {
|
||||||
struct torture_sftp *t = *state;
|
torture_teardown_sshd_server(state);
|
||||||
|
|
||||||
assert_false(t == NULL);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
torture_rmdirs(t->testdir);
|
static int session_setup(void **state)
|
||||||
torture_sftp_close(t);
|
{
|
||||||
|
struct torture_state *s = *state;
|
||||||
|
struct passwd *pwd;
|
||||||
|
|
||||||
|
pwd = getpwnam("bob");
|
||||||
|
assert_non_null(pwd);
|
||||||
|
setuid(pwd->pw_uid);
|
||||||
|
|
||||||
|
s->ssh.session = torture_ssh_session(TORTURE_SSH_SERVER,
|
||||||
|
NULL,
|
||||||
|
TORTURE_SSH_USER_ALICE,
|
||||||
|
NULL);
|
||||||
|
assert_non_null(s->ssh.session);
|
||||||
|
|
||||||
|
s->ssh.tsftp = torture_sftp_session(s->ssh.session);
|
||||||
|
assert_non_null(s->ssh.tsftp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int session_teardown(void **state)
|
||||||
|
{
|
||||||
|
struct torture_state *s = *state;
|
||||||
|
|
||||||
|
torture_rmdirs(s->ssh.tsftp->testdir);
|
||||||
|
torture_sftp_close(s->ssh.tsftp);
|
||||||
|
ssh_disconnect(s->ssh.session);
|
||||||
|
ssh_free(s->ssh.session);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void torture_sftp_mkdir(void **state) {
|
static void torture_sftp_mkdir(void **state) {
|
||||||
struct torture_sftp *t = *state;
|
struct torture_state *s = *state;
|
||||||
|
|
||||||
|
struct torture_sftp *t = s->ssh.tsftp;
|
||||||
char tmpdir[128] = {0};
|
char tmpdir[128] = {0};
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -66,13 +81,16 @@ static void torture_sftp_mkdir(void **state) {
|
|||||||
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_sftp_mkdir, setup, teardown)
|
cmocka_unit_test_setup_teardown(torture_sftp_mkdir,
|
||||||
|
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user