aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-02-06 14:58:28 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-02-06 16:27:43 +0100
commit38d6d38c1fcc9d323a062c413a5c0b6b8ef6590c (patch)
tree44f340d5f50f0f02b7ad247383e5309df77c1f59
parent215c41710e842a892da23724d64c0f5414165496 (diff)
downloadlibssh-38d6d38c1fcc9d323a062c413a5c0b6b8ef6590c.tar.gz
libssh-38d6d38c1fcc9d323a062c413a5c0b6b8ef6590c.tar.xz
libssh-38d6d38c1fcc9d323a062c413a5c0b6b8ef6590c.zip
torture: Added a function to setup a sftp session.
-rw-r--r--tests/torture.c60
-rw-r--r--tests/torture.h9
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/torture.c b/tests/torture.c
index 983f1c38..92d9c97a 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -198,6 +198,66 @@ failed:
return NULL;
}
+struct torture_sftp *torture_sftp_session(ssh_session session) {
+ struct torture_sftp *t;
+ char template[] = "/tmp/ssh_torture_XXXXXX";
+ char *p;
+
+ if (session == NULL) {
+ return NULL;
+ }
+
+ t = malloc(sizeof(struct torture_sftp *));
+ if (t == NULL) {
+ return NULL;
+ }
+
+ t->ssh = session;
+ t->sftp = sftp_new(session);
+ if (t->sftp == NULL) {
+ goto failed;
+ }
+
+
+ p = mkdtemp(template);
+ if (p == NULL) {
+ goto failed;
+ }
+ t->testdir = strdup(p);
+ if (t->testdir == NULL) {
+ goto failed;
+ }
+
+ return t;
+failed:
+ if (t->sftp != NULL) {
+ sftp_free(t->sftp);
+ }
+ ssh_disconnect(t->ssh);
+ ssh_free(t->ssh);
+
+ return NULL;
+}
+
+void torture_sftp_close(struct torture_sftp *t) {
+ if (t == NULL) {
+ return;
+ }
+
+ if (t->sftp != NULL) {
+ sftp_free(t->sftp);
+ }
+
+ if (t->ssh != NULL) {
+ if (ssh_is_connected(t->ssh)) {
+ ssh_disconnect(t->ssh);
+ }
+ }
+
+ free(t->testdir);
+ free(t);
+}
+
int main(int argc, char **argv) {
struct argument_s arguments;
diff --git a/tests/torture.h b/tests/torture.h
index e80d0e76..b4fce84a 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -44,6 +44,12 @@ struct argument_s {
int verbose;
};
+struct torture_sftp {
+ ssh_session ssh;
+ sftp_session sftp;
+ char *testdir;
+};
+
void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments);
int torture_rmdirs(const char *path);
@@ -58,6 +64,9 @@ ssh_session torture_ssh_session(const char *host,
const char *user,
const char *password);
+struct torture_sftp *torture_sftp_session(ssh_session session);
+void torture_sftp_close(struct torture_sftp *t);
+
/*
* This function must be defined in every unit test file.
*/