1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-08 19:02:06 +03:00

Assorted changes from master to make torture_algorithms test working

Cherry-picked from the following commits:
cbd75c3e35
3014e3c458
This commit is contained in:
Jakub Jelen
2018-10-02 15:21:58 +02:00
committed by Andreas Schneider
parent d678f6a9ea
commit 74102dfd7a
4 changed files with 55 additions and 18 deletions

View File

@@ -1,6 +1,5 @@
project(clienttests C) project(clienttests C)
add_cmocka_test(torture_algorithms torture_algorithms.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_auth torture_auth.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_auth torture_auth.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_connect torture_connect.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_connect torture_connect.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY})
@@ -13,3 +12,25 @@ if (WITH_SFTP)
add_cmocka_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_sftp_read torture_sftp_read.c ${TORTURE_LIBRARY}) add_cmocka_test(torture_sftp_read torture_sftp_read.c ${TORTURE_LIBRARY})
endif (WITH_SFTP) endif (WITH_SFTP)
set(LIBSSH_CLIENT_TESTS
torture_algorithms)
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
if (OSX)
set_property(
TEST
${_CLI_TEST}
PROPERTY
ENVIRONMENT DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${SOCKET_WRAPPER_LIBRARY})
else ()
set_property(
TEST
${_CLI_TEST}
PROPERTY
ENVIRONMENT ${TORTURE_ENVIRONMENT})
endif()
endforeach()

View File

@@ -25,11 +25,37 @@
#include "libssh/libssh.h" #include "libssh/libssh.h"
#include "libssh/priv.h" #include "libssh/priv.h"
#include <errno.h>
#include <sys/types.h>
#include <pwd.h>
static int sshd_setup(void **state)
{
torture_setup_sshd_server(state);
return 0;
}
static int sshd_teardown(void **state) {
torture_teardown_sshd_server(state);
return 0;
}
static void setup(void **state) { static void setup(void **state) {
int verbosity=torture_libssh_verbosity(); int verbosity=torture_libssh_verbosity();
ssh_session session = ssh_new(); ssh_session session = ssh_new();
struct passwd *pwd;
int rc;
pwd = getpwnam("bob");
assert_non_null(pwd);
rc = setuid(pwd->pw_uid);
assert_return_code(rc, errno);
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER);
*state = session; *state = session;
} }
@@ -40,9 +66,6 @@ static void teardown(void **state) {
static void test_algorithm(ssh_session session, const char *algo, const char *hmac) { static void test_algorithm(ssh_session session, const char *algo, const char *hmac) {
int rc; int rc;
rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, algo); rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, algo);
assert_true(rc == SSH_OK); assert_true(rc == SSH_OK);
@@ -169,9 +192,6 @@ static void torture_algorithms_zlib(void **state) {
ssh_session session = *state; ssh_session session = *state;
int rc; int rc;
rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib"); rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib");
#ifdef WITH_ZLIB #ifdef WITH_ZLIB
assert_true(rc == SSH_OK); assert_true(rc == SSH_OK);
@@ -209,9 +229,6 @@ static void torture_algorithms_zlib_openssh(void **state) {
ssh_session session = *state; ssh_session session = *state;
int rc; int rc;
rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib@openssh.com"); rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib@openssh.com");
#ifdef WITH_ZLIB #ifdef WITH_ZLIB
assert_true(rc == SSH_OK); assert_true(rc == SSH_OK);
@@ -251,9 +268,6 @@ static void torture_algorithms_ecdh_sha2_nistp256(void **state) {
ssh_session session = *state; ssh_session session = *state;
int rc; int rc;
rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "ecdh-sha2-nistp256"); rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "ecdh-sha2-nistp256");
assert_true(rc == SSH_OK); assert_true(rc == SSH_OK);
@@ -273,9 +287,6 @@ static void torture_algorithms_dh_group1(void **state) {
ssh_session session = *state; ssh_session session = *state;
int rc; int rc;
rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
assert_true(rc == SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "diffie-hellman-group1-sha1"); rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "diffie-hellman-group1-sha1");
assert_true(rc == SSH_OK); assert_true(rc == SSH_OK);
@@ -291,6 +302,7 @@ static void torture_algorithms_dh_group1(void **state) {
} }
int torture_run_tests(void) { int torture_run_tests(void) {
int rc; int rc;
struct torture_state *s = NULL;
UnitTest tests[] = { UnitTest tests[] = {
unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha1, setup, teardown), unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha1, setup, teardown),
unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_256, setup, teardown), unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_256, setup, teardown),
@@ -328,7 +340,9 @@ int torture_run_tests(void) {
ssh_init(); ssh_init();
torture_filter_tests(tests); torture_filter_tests(tests);
sshd_setup((void **)&s);
rc = run_tests(tests); rc = run_tests(tests);
sshd_teardown((void **)&s);
ssh_finalize(); ssh_finalize();
return rc; return rc;

View File

@@ -380,7 +380,7 @@ int torture_terminate_process(const char *pidfile)
/* Make sure the daemon goes away! */ /* Make sure the daemon goes away! */
kill(pid, SIGTERM); kill(pid, SIGTERM);
usleep(200); usleep(10 * 1000);
rc = kill(pid, 0); rc = kill(pid, 0);
if (rc != 0) { if (rc != 0) {
@@ -872,7 +872,7 @@ void torture_setup_sshd_server(void **state)
assert_return_code(rc, errno); assert_return_code(rc, errno);
/* Give the process some time to start */ /* Give the process some time to start */
usleep(1000); usleep(100 * 1000);
setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "21", 1); setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "21", 1);
unsetenv("PAM_WRAPPER"); unsetenv("PAM_WRAPPER");

View File

@@ -46,6 +46,8 @@
assert_true(code >= 0) assert_true(code >= 0)
#endif /* assert_return_code */ #endif /* assert_return_code */
#define TORTURE_SSH_SERVER "127.0.0.10"
#define TORTURE_TESTKEY_PASSWORD "libssh-rocks" #define TORTURE_TESTKEY_PASSWORD "libssh-rocks"
/* Used by main to communicate with parse_opt. */ /* Used by main to communicate with parse_opt. */