aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Dunn <amdunn@gmail.com>2014-04-16 23:29:52 -0500
committerAndreas Schneider <asn@cryptomilk.org>2015-01-20 19:50:52 +0100
commit4bde48bb2e32774533ac0d45485fa6109f3cb891 (patch)
tree6dd8a35e13cea12ac3a8552c986c107764bfa437
parentf4154c503b4f16e318853a4ef028295558798655 (diff)
downloadlibssh-4bde48bb2e32774533ac0d45485fa6109f3cb891.tar.gz
libssh-4bde48bb2e32774533ac0d45485fa6109f3cb891.tar.xz
libssh-4bde48bb2e32774533ac0d45485fa6109f3cb891.zip
tests: Add ssh server setup functionality
Add the ability to generate a keypair (RSA, but tests that focus on what occurs over a connection may well not care) and an ssh_bind easily. Signed-off-by: Alan Dunn <amdunn@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/torture.c44
-rw-r--r--tests/torture.h5
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/torture.c b/tests/torture.c
index 74640031..726db214 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -393,6 +393,50 @@ failed:
return NULL;
}
+#ifdef WITH_SERVER
+
+ssh_bind torture_ssh_bind(const char *addr,
+ const unsigned int port,
+ const char *private_key_file) {
+ int rc;
+ ssh_bind sshbind = NULL;
+
+ sshbind = ssh_bind_new();
+ if (sshbind == NULL) {
+ goto out;
+ }
+
+ rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, addr);
+ if (rc != 0) {
+ goto out_free;
+ }
+
+ rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port);
+ if (rc != 0) {
+ goto out_free;
+ }
+
+ rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY,
+ private_key_file);
+ if (rc != 0) {
+ goto out_free;
+ }
+
+ rc = ssh_bind_listen(sshbind);
+ if (rc != SSH_OK) {
+ goto out_free;
+ }
+
+ goto out;
+ out_free:
+ ssh_bind_free(sshbind);
+ sshbind = NULL;
+ out:
+ return sshbind;
+}
+
+#endif
+
#ifdef WITH_SFTP
struct torture_sftp *torture_sftp_session(ssh_session session) {
diff --git a/tests/torture.h b/tests/torture.h
index bfad2c97..b4eab587 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -35,6 +35,7 @@
#include <setjmp.h>
#include "libssh/priv.h"
+#include "libssh/server.h"
#include "libssh/sftp.h"
#include <cmocka.h>
@@ -66,6 +67,10 @@ ssh_session torture_ssh_session(const char *host,
const char *user,
const char *password);
+ssh_bind torture_ssh_bind(const char *addr,
+ const unsigned int port,
+ const char *private_key_file);
+
struct torture_sftp *torture_sftp_session(ssh_session session);
void torture_sftp_close(struct torture_sftp *t);