aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2015-05-30 22:43:11 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2015-06-05 18:51:38 +0200
commitcd09d52db4201be016107afa064116487b4cfcdb (patch)
tree5a5f9f324ce49211a12107c56f0b815daebd70e2
parent111dca9c08a435edf75d12dbc306121c0430a5b1 (diff)
downloadlibssh-cd09d52db4201be016107afa064116487b4cfcdb.tar.gz
libssh-cd09d52db4201be016107afa064116487b4cfcdb.tar.xz
libssh-cd09d52db4201be016107afa064116487b4cfcdb.zip
tests: use the same host and port number in all tests
-rw-r--r--tests/client/torture_algorithms.c25
-rw-r--r--tests/client/torture_auth.c31
-rw-r--r--tests/client/torture_connect.c11
-rw-r--r--tests/client/torture_forward.c14
-rw-r--r--tests/client/torture_knownhosts.c52
-rw-r--r--tests/client/torture_proxycommand.c8
-rw-r--r--tests/client/torture_request_env.c16
-rw-r--r--tests/client/torture_session.c5
-rw-r--r--tests/client/torture_sftp_dir.c15
-rw-r--r--tests/client/torture_sftp_read.c15
-rw-r--r--tests/torture.c46
-rw-r--r--tests/torture.h8
-rw-r--r--tests/unittests/torture_server_x11.c6
13 files changed, 148 insertions, 104 deletions
diff --git a/tests/client/torture_algorithms.c b/tests/client/torture_algorithms.c
index cd00bc48..8ef8b35d 100644
--- a/tests/client/torture_algorithms.c
+++ b/tests/client/torture_algorithms.c
@@ -40,7 +40,10 @@ static void teardown(void **state) {
static void test_algorithm(ssh_session session, const char *algo, const char *hmac) {
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, algo);
@@ -173,7 +176,10 @@ static void torture_algorithms_zlib(void **state) {
ssh_session session = *state;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
+ rc = ssh_options_set(session,SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib");
@@ -213,7 +219,10 @@ static void torture_algorithms_zlib_openssh(void **state) {
ssh_session session = *state;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
+ rc = ssh_options_set(session,SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib@openssh.com");
@@ -255,7 +264,10 @@ static void torture_algorithms_ecdh_sha2_nistp256(void **state) {
ssh_session session = *state;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
+ rc = ssh_options_set(session,SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "ecdh-sha2-nistp256");
@@ -277,7 +289,10 @@ static void torture_algorithms_dh_group1(void **state) {
ssh_session session = *state;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
+ rc = ssh_options_set(session,SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "diffie-hellman-group1-sha1");
diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c
index 7f5167e8..37014c8a 100644
--- a/tests/client/torture_auth.c
+++ b/tests/client/torture_auth.c
@@ -31,7 +31,8 @@ static void setup(void **state) {
int verbosity = torture_libssh_verbosity();
ssh_session session = ssh_new();
- ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
*state = session;
@@ -44,7 +45,7 @@ static void teardown(void **state) {
static void torture_auth_autopubkey(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
+ const char *user = torture_libssh_user();
int rc;
if (user == NULL) {
@@ -73,7 +74,7 @@ static void torture_auth_autopubkey(void **state) {
static void torture_auth_autopubkey_nonblocking(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
+ const char *user = torture_libssh_user();
int rc;
if (user == NULL) {
@@ -109,8 +110,8 @@ static void torture_auth_autopubkey_nonblocking(void **state) {
static void torture_auth_kbdint(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
- char *password = getenv("TORTURE_PASSWORD");
+ const char *user = torture_libssh_user();
+ const char *password = torture_libssh_password();
int rc;
if (user == NULL) {
@@ -157,8 +158,8 @@ static void torture_auth_kbdint(void **state) {
static void torture_auth_kbdint_nonblocking(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
- char *password = getenv("TORTURE_PASSWORD");
+ const char *user = torture_libssh_user();
+ const char *password = torture_libssh_password();
int rc;
if (user == NULL) {
@@ -216,8 +217,8 @@ static void torture_auth_kbdint_nonblocking(void **state) {
static void torture_auth_password(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
- char *password = getenv("TORTURE_PASSWORD");
+ const char *user = torture_libssh_user();
+ const char *password = torture_libssh_password();
int rc;
if (user == NULL) {
@@ -252,8 +253,8 @@ static void torture_auth_password(void **state) {
static void torture_auth_password_nonblocking(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
- char *password = getenv("TORTURE_PASSWORD");
+ const char *user = torture_libssh_user();
+ const char *password = torture_libssh_password();
int rc;
if (user == NULL) {
@@ -296,7 +297,7 @@ static void torture_auth_password_nonblocking(void **state) {
static void torture_auth_agent(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
+ const char *user = torture_libssh_user();
int rc;
if (user == NULL) {
@@ -328,7 +329,7 @@ static void torture_auth_agent(void **state) {
static void torture_auth_agent_nonblocking(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
+ const char *user = torture_libssh_user();
int rc;
if (user == NULL) {
@@ -365,7 +366,7 @@ static void torture_auth_agent_nonblocking(void **state) {
static void torture_auth_none(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
+ const char *user = torture_libssh_user();
int rc;
if (user == NULL) {
@@ -390,7 +391,7 @@ static void torture_auth_none(void **state) {
static void torture_auth_none_nonblocking(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
+ const char *user = torture_libssh_user();
int rc;
if (user == NULL) {
diff --git a/tests/client/torture_connect.c b/tests/client/torture_connect.c
index a8829b85..ad8ae1c2 100644
--- a/tests/client/torture_connect.c
+++ b/tests/client/torture_connect.c
@@ -28,7 +28,7 @@
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
-#define HOST "localhost"
+
/* Should work until Apnic decides to assign it :) */
#define BLACKHOLE "1.1.1.1"
@@ -52,8 +52,11 @@ static void torture_connect_nonblocking(void **state) {
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, HOST);
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
+
ssh_set_blocking(session,0);
do {
@@ -96,7 +99,9 @@ static void torture_connect_double(void **state) {
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, HOST);
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_connect(session);
assert_true(rc == SSH_OK);
diff --git a/tests/client/torture_forward.c b/tests/client/torture_forward.c
index 876ed74b..7b6bc109 100644
--- a/tests/client/torture_forward.c
+++ b/tests/client/torture_forward.c
@@ -27,19 +27,9 @@
static void setup(void **state)
{
ssh_session session;
- 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, NULL, user, password);
+ session = torture_ssh_session(torture_libssh_host(), torture_libssh_port(),
+ torture_libssh_user(), torture_libssh_password());
assert_non_null(session);
*state = session;
diff --git a/tests/client/torture_knownhosts.c b/tests/client/torture_knownhosts.c
index ee7e04c8..5d6be287 100644
--- a/tests/client/torture_knownhosts.c
+++ b/tests/client/torture_knownhosts.c
@@ -65,6 +65,7 @@ static void teardown(void **state) {
static void torture_knownhosts_port(void **state) {
ssh_session session = *state;
char buffer[200];
+ char reference[200];
char *p;
FILE *file;
int rc;
@@ -73,7 +74,9 @@ static void torture_knownhosts_port(void **state) {
* the known hosts file. Then check that the entry written is
* [localhost]:1234
*/
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
@@ -92,7 +95,8 @@ static void torture_knownhosts_port(void **state) {
assert_false(p == NULL);
fclose(file);
buffer[sizeof(buffer) - 1] = '\0';
- assert_true(strstr(buffer,"[localhost]:1234 ") != NULL);
+ snprintf(reference, sizeof(reference),"[%s]:1234 ", torture_libssh_host());
+ assert_true(strstr(buffer, reference) != NULL);
ssh_disconnect(session);
ssh_free(session);
@@ -100,7 +104,8 @@ static void torture_knownhosts_port(void **state) {
/* Now, connect back to the ssh server and verify the known host line */
*state = session = ssh_new();
- ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
rc = ssh_connect(session);
@@ -116,7 +121,9 @@ static void torture_knownhosts_fail(void **state) {
FILE *file;
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
@@ -127,7 +134,7 @@ static void torture_knownhosts_fail(void **state) {
file = fopen(KNOWNHOSTFILES, "w");
assert_true(file != NULL);
- fprintf(file, "localhost ssh-rsa %s\n", BADRSA);
+ fprintf(file, "%s ssh-rsa %s\n",torture_libssh_host(), BADRSA);
fclose(file);
rc = ssh_connect(session);
@@ -142,7 +149,9 @@ static void torture_knownhosts_other(void **state) {
FILE *file;
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
@@ -153,7 +162,7 @@ static void torture_knownhosts_other(void **state) {
file = fopen(KNOWNHOSTFILES, "w");
assert_true(file != NULL);
- fprintf(file, "localhost ssh-rsa %s\n", BADRSA);
+ fprintf(file, "%s ssh-rsa %s\n", torture_libssh_host(), BADRSA);
fclose(file);
rc = ssh_connect(session);
@@ -167,9 +176,10 @@ static void torture_knownhosts_other_auto(void **state) {
ssh_session session = *state;
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
-
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
assert_true(rc == SSH_OK);
@@ -191,7 +201,9 @@ static void torture_knownhosts_other_auto(void **state) {
/* connect again and check host key */
*state = session = ssh_new();
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
@@ -210,7 +222,9 @@ static void torture_knownhosts_conflict(void **state) {
FILE *file;
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
@@ -221,8 +235,8 @@ static void torture_knownhosts_conflict(void **state) {
file = fopen(KNOWNHOSTFILES, "w");
assert_true(file != NULL);
- fprintf(file, "localhost ssh-rsa %s\n", BADRSA);
- fprintf(file, "localhost ssh-dss %s\n", BADDSA);
+ fprintf(file, "%s ssh-rsa %s\n", torture_libssh_host(), BADRSA);
+ fprintf(file, "%s ssh-dss %s\n", torture_libssh_host(), BADDSA);
fclose(file);
rc = ssh_connect(session);
@@ -240,7 +254,9 @@ static void torture_knownhosts_conflict(void **state) {
/* connect again and check host key */
*state = session = ssh_new();
- ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
+
ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
rc = ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, "ssh-rsa");
assert_true(rc == SSH_OK);
@@ -258,7 +274,9 @@ static void torture_knownhosts_precheck(void **state) {
int rc;
char **kex;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES);
@@ -266,8 +284,8 @@ static void torture_knownhosts_precheck(void **state) {
file = fopen(KNOWNHOSTFILES, "w");
assert_true(file != NULL);
- fprintf(file, "localhost ssh-rsa %s\n", BADRSA);
- fprintf(file, "localhost ssh-dss %s\n", BADDSA);
+ fprintf(file, "%s ssh-rsa %s\n", torture_libssh_host(), BADRSA);
+ fprintf(file, "%s ssh-dss %s\n", torture_libssh_host(), BADDSA);
fclose(file);
kex = ssh_knownhosts_algorithms(session);
diff --git a/tests/client/torture_proxycommand.c b/tests/client/torture_proxycommand.c
index a1508811..4911c96e 100644
--- a/tests/client/torture_proxycommand.c
+++ b/tests/client/torture_proxycommand.c
@@ -16,12 +16,14 @@ static void teardown(void **state) {
static void torture_options_set_proxycommand(void **state) {
ssh_session session = *state;
+ char command[200];
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
assert_true(rc == 0);
- rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "nc localhost 22");
+ snprintf(command, sizeof(command), "nc %s %s", torture_libssh_host(), torture_libssh_port());
+ rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, command);
assert_true(rc == 0);
rc = ssh_connect(session);
assert_true(rc == SSH_OK);
@@ -31,7 +33,7 @@ static void torture_options_set_proxycommand_notexist(void **state) {
ssh_session session = *state;
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
assert_true(rc == 0);
rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "this_command_does_not_exist");
diff --git a/tests/client/torture_request_env.c b/tests/client/torture_request_env.c
index 5296f7d2..752a487d 100644
--- a/tests/client/torture_request_env.c
+++ b/tests/client/torture_request_env.c
@@ -27,21 +27,11 @@
static void setup(void **state)
{
ssh_session session;
- 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(torture_libssh_host(), torture_libssh_port(),
+ torture_libssh_user(), torture_libssh_password());
- session = torture_ssh_session(host, NULL, user, password);
-
- assert_false(session == NULL);
+ assert_non_null(session);
*state = session;
}
diff --git a/tests/client/torture_session.c b/tests/client/torture_session.c
index 94296a3f..f11144d6 100644
--- a/tests/client/torture_session.c
+++ b/tests/client/torture_session.c
@@ -33,7 +33,8 @@ static void setup(void **state) {
int verbosity = torture_libssh_verbosity();
ssh_session session = ssh_new();
- ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ ssh_options_set(session, SSH_OPTIONS_HOST, torture_libssh_host());
+ ssh_options_set(session, SSH_OPTIONS_PORT_STR, torture_libssh_port());
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
*state = session;
@@ -46,7 +47,7 @@ static void teardown(void **state) {
static void torture_channel_read_error(void **state) {
ssh_session session = *state;
- char *user = getenv("TORTURE_USER");
+ const char *user = torture_libssh_user();
ssh_channel channel;
int rc;
int i;
diff --git a/tests/client/torture_sftp_dir.c b/tests/client/torture_sftp_dir.c
index 67303324..fe19c34c 100644
--- a/tests/client/torture_sftp_dir.c
+++ b/tests/client/torture_sftp_dir.c
@@ -6,20 +6,11 @@
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";
- }
+ session = torture_ssh_session(torture_libssh_host(), torture_libssh_port(),
+ torture_libssh_user(), torture_libssh_password());
- user = getenv("TORTURE_USER");
- password = getenv("TORTURE_PASSWORD");
-
- session = torture_ssh_session(host, NULL, user, password);
- assert_false(session == NULL);
+ assert_non_null(session);
t = torture_sftp_session(session);
assert_false(t == NULL);
diff --git a/tests/client/torture_sftp_read.c b/tests/client/torture_sftp_read.c
index eca8a8c6..9b337365 100644
--- a/tests/client/torture_sftp_read.c
+++ b/tests/client/torture_sftp_read.c
@@ -8,20 +8,11 @@
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(torture_libssh_host(), torture_libssh_port(),
+ torture_libssh_user(), torture_libssh_password());
- session = torture_ssh_session(host, NULL, user, password);
- assert_false(session == NULL);
+ assert_non_null(session);
t = torture_sftp_session(session);
assert_false(t == NULL);
diff --git a/tests/torture.c b/tests/torture.c
index b0c7a59f..85a975d3 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -220,6 +220,10 @@ static const char torture_ed25519_testkey_pp[]=
"-----END OPENSSH PRIVATE KEY-----\n";
static int verbosity = 0;
+static const char *libssh_host="localhost";
+static const char *libssh_user=NULL;
+static const char *libssh_port="22";
+static const char *libssh_password=NULL;
static const char *pattern = NULL;
#ifndef _WIN32
@@ -339,7 +343,7 @@ int torture_isdir(const char *path) {
}
ssh_session torture_ssh_session(const char *host,
- const unsigned int *port,
+ const char *port,
const char *user,
const char *password) {
ssh_session session;
@@ -365,7 +369,7 @@ ssh_session torture_ssh_session(const char *host,
}
if (port != NULL) {
- if (ssh_options_set(session, SSH_OPTIONS_PORT, port) < 0) {
+ if (ssh_options_set(session, SSH_OPTIONS_PORT_STR, port) < 0) {
goto failed;
}
}
@@ -425,7 +429,7 @@ failed:
#ifdef WITH_SERVER
ssh_bind torture_ssh_bind(const char *addr,
- const unsigned int port,
+ const char *port,
enum ssh_keytypes_e key_type,
const char *private_key_file) {
int rc;
@@ -442,7 +446,7 @@ ssh_bind torture_ssh_bind(const char *addr,
goto out_free;
}
- rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port);
+ rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, &port);
if (rc != 0) {
goto out_free;
}
@@ -651,6 +655,21 @@ int torture_libssh_verbosity(void){
return verbosity;
}
+const char *torture_libssh_host(void){
+ return libssh_host;
+}
+
+const char *torture_libssh_user(void){
+ return libssh_user;
+}
+const char *torture_libssh_port(void){
+ return libssh_port;
+}
+
+const char *torture_libssh_password(void){
+ return libssh_password;
+}
+
void _torture_filter_tests(UnitTest *tests, size_t ntests){
size_t i,j;
const char *name, *last_name=NULL;
@@ -687,12 +706,29 @@ void _torture_filter_tests(UnitTest *tests, size_t ntests){
int main(int argc, char **argv) {
struct argument_s arguments;
-
+ char *tmp;
arguments.verbose=0;
arguments.pattern=NULL;
torture_cmdline_parse(argc, argv, &arguments);
verbosity=arguments.verbose;
+
pattern=arguments.pattern;
+ tmp = getenv("TORTURE_HOST");
+ if (tmp != NULL){
+ libssh_host = tmp;
+ }
+ tmp = getenv("TORTURE_PORT");
+ if (tmp != NULL){
+ libssh_port = tmp;
+ }
+ tmp = getenv("TORTURE_USER");
+ if (tmp != NULL){
+ libssh_user = tmp;
+ }
+ tmp = getenv("TORTURE_PASSWORD");
+ if (tmp != NULL){
+ libssh_password = tmp;
+ }
return torture_run_tests();
}
diff --git a/tests/torture.h b/tests/torture.h
index d04f7071..719b2724 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -69,14 +69,18 @@ int torture_isdir(const char *path);
* Returns the verbosity level asked by user
*/
int torture_libssh_verbosity(void);
+const char *torture_libssh_host(void);
+const char *torture_libssh_user(void);
+const char *torture_libssh_port(void);
+const char *torture_libssh_password(void);
ssh_session torture_ssh_session(const char *host,
- const unsigned int *port,
+ const char *port,
const char *user,
const char *password);
ssh_bind torture_ssh_bind(const char *addr,
- const unsigned int port,
+ const char *port,
enum ssh_keytypes_e key_type,
const char *private_key_file);
diff --git a/tests/unittests/torture_server_x11.c b/tests/unittests/torture_server_x11.c
index 661656a7..52d582e6 100644
--- a/tests/unittests/torture_server_x11.c
+++ b/tests/unittests/torture_server_x11.c
@@ -9,7 +9,7 @@
#include <libssh/libssh.h>
#include "torture.h"
-#define TEST_SERVER_PORT 2222
+#define TEST_SERVER_PORT "2222"
struct hostkey_state {
const char *hostkey;
@@ -54,7 +54,7 @@ static void teardown(void **state) {
static const uint32_t x11_screen_number = 1;
static void *client_thread(void *arg) {
- unsigned int test_port = TEST_SERVER_PORT;
+ const char *test_port = TEST_SERVER_PORT;
int rc;
ssh_session session;
ssh_channel channel;
@@ -63,7 +63,7 @@ static void *client_thread(void *arg) {
(void)arg;
session = torture_ssh_session("localhost",
- &test_port,
+ test_port,
"foo", "bar");
assert_non_null(session);