diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2015-09-16 08:41:19 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2016-01-14 08:04:49 +0100 |
commit | 571f547556ad9e2aee38ce894057cca042e8f154 (patch) | |
tree | c6d0d551a1c2afa2d79dc6615fff5979b0b7f42e /tests/client | |
parent | af3de262b69f44ba84009b9aba644b5f1cf3b1a7 (diff) | |
download | libssh-571f547556ad9e2aee38ce894057cca042e8f154.tar.gz libssh-571f547556ad9e2aee38ce894057cca042e8f154.tar.xz libssh-571f547556ad9e2aee38ce894057cca042e8f154.zip |
tests: Migrate torture_sftp_read to a cwrap test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/client')
-rw-r--r-- | tests/client/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/client/torture_sftp_read.c | 69 |
2 files changed, 44 insertions, 29 deletions
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt index 3598b430..c49b231e 100644 --- a/tests/client/CMakeLists.txt +++ b/tests/client/CMakeLists.txt @@ -4,7 +4,6 @@ find_package(socket_wrapper) if (WITH_SFTP) add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY}) - add_cmocka_test(torture_sftp_read torture_sftp_read.c ${TORTURE_LIBRARY}) endif (WITH_SFTP) set(LIBSSH_CLIENT_TESTS @@ -20,7 +19,8 @@ set(LIBSSH_CLIENT_TESTS if (WITH_SFTP) set(LIBSSH_CLIENT_TESTS ${LIBSSH_CLIENT_TESTS} - torture_sftp_dir) + torture_sftp_dir + torture_sftp_read) endif (WITH_SFTP) foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS}) diff --git a/tests/client/torture_sftp_read.c b/tests/client/torture_sftp_read.c index 35bb7e43..51578773 100644 --- a/tests/client/torture_sftp_read.c +++ b/tests/client/torture_sftp_read.c @@ -3,48 +3,61 @@ #include "torture.h" #include "sftp.c" +#include <sys/types.h> +#include <pwd.h> + #define MAX_XFER_BUF_SIZE 16384 -static int setup(void **state) +static int sshd_setup(void **state) { - ssh_session session; - struct torture_sftp *t; - const char *host; - const char *user; - const char *password; - - host = getenv("TORTURE_HOST"); - 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); + return 0; +} - *state = t; +static int sshd_teardown(void **state) { + torture_teardown_sshd_server(state); return 0; } -static int teardown(void **state) +static int session_setup(void **state) { - struct torture_sftp *t = (struct torture_sftp*) *state; + struct torture_state *s = *state; + struct passwd *pwd; + + pwd = getpwnam("bob"); + assert_non_null(pwd); + setuid(pwd->pw_uid); - assert_false(t == NULL); + s->ssh.session = torture_ssh_session(TORTURE_SSH_SERVER, + NULL, + TORTURE_SSH_USER_ALICE, + NULL); + assert_non_null(s->ssh.session); - torture_rmdirs(t->testdir); - torture_sftp_close(t); + 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; } static void torture_sftp_read_blocking(void **state) { - struct torture_sftp *t = (struct torture_sftp*) *state; + struct torture_state *s = *state; + struct torture_sftp *t = s->ssh.tsftp; + char libssh_tmp_file[] = "/tmp/libssh_sftp_test_XXXXXX"; char buf[MAX_XFER_BUF_SIZE]; ssize_t bytesread; @@ -79,13 +92,15 @@ static void torture_sftp_read_blocking(void **state) { int torture_run_tests(void) { int rc; struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(torture_sftp_read_blocking, setup, teardown) + cmocka_unit_test_setup_teardown(torture_sftp_read_blocking, + session_setup, + session_teardown) }; ssh_init(); torture_filter_tests(tests); - rc = cmocka_run_group_tests(tests, NULL, NULL); + rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown); ssh_finalize(); return rc; |