aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-05-16 14:16:46 +0200
committerAndreas Schneider <asn@cryptomilk.org>2019-06-12 10:17:54 +0200
commite7ef40c8f03f911ca69a00c7043ede44bd2d86b2 (patch)
tree9c0ad5f4818b79a9f14067dde0c443084512757e /tests
parent79f0c38fbd767f578d7b87fae15fb64faad32aab (diff)
downloadlibssh-e7ef40c8f03f911ca69a00c7043ede44bd2d86b2.tar.gz
libssh-e7ef40c8f03f911ca69a00c7043ede44bd2d86b2.tar.xz
libssh-e7ef40c8f03f911ca69a00c7043ede44bd2d86b2.zip
tests: Allow setting configuration file for test server
This allows testing the server with a configuration file. This also adds an option for the stand-alone test server to skip parsing the system-wide configuration file. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/server/test_server/main.c45
-rw-r--r--tests/server/test_server/test_server.c17
-rw-r--r--tests/server/test_server/test_server.h3
-rw-r--r--tests/server/torture_server.c3
4 files changed, 68 insertions, 0 deletions
diff --git a/tests/server/test_server/main.c b/tests/server/test_server/main.c
index 56b84145..87ff6c8e 100644
--- a/tests/server/test_server/main.c
+++ b/tests/server/test_server/main.c
@@ -58,6 +58,9 @@ struct arguments_st {
char *username;
char *password;
+
+ char *config_file;
+ bool with_global_config;
};
static void free_arguments(struct arguments_st *arguments)
@@ -81,6 +84,7 @@ static void free_arguments(struct arguments_st *arguments)
SAFE_FREE(arguments->username);
SAFE_FREE(arguments->password);
+ SAFE_FREE(arguments->config_file);
end:
return;
@@ -168,6 +172,11 @@ static void print_server_state(struct server_state_st *state)
printf("password = %s\n",
state->expected_password? state->expected_password: "NULL");
printf("=================================================\n");
+ printf("with_global_config = %s\n",
+ state->parse_global_config? "TRUE": "FALSE");
+ printf("config_file = %s\n",
+ state->config_file? state->config_file: "NULL");
+ printf("=================================================\n");
}
}
@@ -290,10 +299,18 @@ static int init_server_state(struct server_state_st *state,
}
}
+ state->parse_global_config = arguments->with_global_config;
+
+ if (arguments->config_file) {
+ state->config_file = arguments->config_file;
+ arguments->config_file = NULL;
+ }
+
/* TODO make configurable */
state->max_tries = 3;
state->error = 0;
+
if (state) {
print_server_state(state);
}
@@ -416,6 +433,22 @@ static struct argp_option options[] = {
.doc = "Use PCAP.",
.group = 0
},
+ {
+ .name = "without-global-config",
+ .key = 'g',
+ .arg = NULL,
+ .flags = 0,
+ .doc = "Do not use system-wide configuration file.",
+ .group = 0
+ },
+ {
+ .name = "config",
+ .key = 'C',
+ .arg = "CONFIG_FILE",
+ .flags = 0,
+ .doc = "Use this server configuration file.",
+ .group = 0
+ },
{ .name = NULL }
};
@@ -518,6 +551,17 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
case 'w':
arguments->with_pcap = true;
break;
+ case 'g':
+ arguments->with_global_config = false;
+ break;
+ case 'C':
+ arguments->config_file = strdup(arg);
+ if (arguments->config_file == NULL) {
+ fprintf(stderr, "Out of memory\n");
+ rc = ENOMEM;
+ goto end;
+ }
+ break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
/* Too many arguments. */
@@ -557,6 +601,7 @@ int main(UNUSED_PARAM(int argc), UNUSED_PARAM(char **argv))
struct arguments_st arguments = {
.address = NULL,
+ .with_global_config = true,
};
struct server_state_st state = {
.address = NULL,
diff --git a/tests/server/test_server/test_server.c b/tests/server/test_server/test_server.c
index 93a6f9a0..5587ca32 100644
--- a/tests/server/test_server/test_server.c
+++ b/tests/server/test_server/test_server.c
@@ -55,6 +55,7 @@ void free_server_state(struct server_state_st *state)
SAFE_FREE(state->expected_username);
SAFE_FREE(state->expected_password);
+ SAFE_FREE(state->config_file);
end:
return;
@@ -120,6 +121,22 @@ int run_server(struct server_state_st *state)
}
}
+ if (!state->parse_global_config) {
+ rc = ssh_bind_options_set(sshbind,
+ SSH_BIND_OPTIONS_PROCESS_CONFIG,
+ &(state->parse_global_config));
+ if (rc != 0) {
+ goto free_sshbind;
+ }
+ }
+
+ if (state->config_file) {
+ rc = ssh_bind_options_parse_config(sshbind, state->config_file);
+ if (rc != 0) {
+ goto free_sshbind;
+ }
+ }
+
rc = ssh_bind_options_set(sshbind,
SSH_BIND_OPTIONS_BINDADDR,
state->address);
diff --git a/tests/server/test_server/test_server.h b/tests/server/test_server/test_server.h
index 3c249f9e..b53894bb 100644
--- a/tests/server/test_server/test_server.h
+++ b/tests/server/test_server/test_server.h
@@ -50,6 +50,9 @@ struct server_state_st {
char *expected_username;
char *expected_password;
+ char *config_file;
+ bool parse_global_config;
+
/* State */
int max_tries;
int error;
diff --git a/tests/server/torture_server.c b/tests/server/torture_server.c
index 9121c180..6ed64238 100644
--- a/tests/server/torture_server.c
+++ b/tests/server/torture_server.c
@@ -191,6 +191,9 @@ static int setup_default_server(void **state)
ss->handle_session = default_handle_session_cb;
assert_non_null(ss->handle_session);
+ /* Do not use global configuration */
+ ss->parse_global_config = false;
+
/* Start the server using the default values */
pid = fork_run_server(ss);
if (pid < 0) {