aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-10-23 15:49:07 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-10-23 15:54:12 +0200
commit87549f7bb6a570481f377e628001a04175f7d3a5 (patch)
tree80abbdfe077bc0f469a242bd8d79d201eb2ef7a9
parentd7ab3d7b3ddf1c25d8286819b7d86ff0683ae444 (diff)
downloadlibssh-87549f7bb6a570481f377e628001a04175f7d3a5.tar.gz
libssh-87549f7bb6a570481f377e628001a04175f7d3a5.tar.xz
libssh-87549f7bb6a570481f377e628001a04175f7d3a5.zip
tests: Add a sftp_read blocking test.
-rw-r--r--tests/client/CMakeLists.txt1
-rw-r--r--tests/client/torture_sftp_read.c82
2 files changed, 83 insertions, 0 deletions
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt
index cfce09ea..3626a9d9 100644
--- a/tests/client/CMakeLists.txt
+++ b/tests/client/CMakeLists.txt
@@ -8,4 +8,5 @@ add_cmockery_test(torture_proxycommand torture_proxycommand.c ${TORTURE_LIBRARY}
if (WITH_SFTP)
add_cmockery_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
add_cmockery_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY})
+ add_cmockery_test(torture_sftp_read torture_sftp_read.c ${TORTURE_LIBRARY})
endif (WITH_SFTP)
diff --git a/tests/client/torture_sftp_read.c b/tests/client/torture_sftp_read.c
new file mode 100644
index 00000000..0f71013e
--- /dev/null
+++ b/tests/client/torture_sftp_read.c
@@ -0,0 +1,82 @@
+#define LIBSSH_STATIC
+
+#include "torture.h"
+#include "sftp.c"
+
+#define MAX_XFER_BUF_SIZE 16384
+
+static void 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";
+ }
+
+ user = getenv("TORTURE_USER");
+ password = getenv("TORTURE_PASSWORD");
+
+ session = torture_ssh_session(host, user, password);
+ assert_false(session == NULL);
+ t = torture_sftp_session(session);
+ assert_false(t == NULL);
+
+ *state = t;
+}
+
+static void teardown(void **state) {
+ struct torture_sftp *t = *state;
+
+ assert_false(t == NULL);
+
+ torture_rmdirs(t->testdir);
+ torture_sftp_close(t);
+}
+
+static void torture_sftp_read_blocking(void **state) {
+ struct torture_sftp *t = *state;
+ char libssh_tmp_file[] = "/tmp/libssh_sftp_test_XXXXXX";
+ char buf[MAX_XFER_BUF_SIZE];
+ ssize_t bytesread;
+ ssize_t byteswritten;
+ int fd;
+ sftp_file file;
+
+
+ file = sftp_open(t->sftp, "/usr/bin/ssh", O_RDONLY, 0);
+
+ fd = mkstemp(libssh_tmp_file);
+ unlink(libssh_tmp_file);
+
+ for (;;) {
+ bytesread = sftp_read(file, buf, MAX_XFER_BUF_SIZE);
+ if (bytesread == 0) {
+ break; /* EOF */
+ }
+ assert_false(bytesread < 0);
+
+ byteswritten = write(fd, buf, bytesread);
+ assert_int_equal(byteswritten, bytesread);
+ }
+
+ close(fd);
+ sftp_close(file);
+}
+
+int torture_run_tests(void) {
+ int rc;
+ const UnitTest tests[] = {
+ unit_test_setup_teardown(torture_sftp_read_blocking, setup, teardown)
+ };
+
+ ssh_init();
+
+ rc = run_tests(tests);
+ ssh_finalize();
+
+ return rc;
+}