diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f3706bcf..1f9764c4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -159,7 +159,7 @@ add_library(session_fixture STATIC session_fixture.h session_fixture.c) target_link_libraries(session_fixture ${LIBRARIES} openssh_fixture libssh2) target_include_directories(session_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") -add_library(runner STATIC runner.c) +add_library(runner STATIC runner.h runner.c) target_link_libraries(runner session_fixture) target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/tests/Makefile.am b/tests/Makefile.am index 582c9141..0c01d911 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -55,6 +55,7 @@ EXTRA_DIST = \ openssh_server/ssh_host_ed25519_key \ openssh_server/ssh_host_rsa_key \ runner.c \ + runner.h \ session_fixture.c \ session_fixture.h \ simple.c \ diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index d4f7fd54..3a1588c2 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -216,7 +216,7 @@ static const char *docker_machine_name(void) return getenv("DOCKER_MACHINE_NAME"); } -static int is_running_inside_a_container() +static int is_running_inside_a_container(void) { #ifdef WIN32 return 0; @@ -413,7 +413,7 @@ cleanup: static char *running_container_id = NULL; -int start_openssh_fixture() +int start_openssh_fixture(void) { int ret; #ifdef HAVE_WINSOCK2_H @@ -438,7 +438,7 @@ int start_openssh_fixture() } } -void stop_openssh_fixture() +void stop_openssh_fixture(void) { if(running_container_id) { stop_openssh_server(running_container_id); @@ -450,7 +450,7 @@ void stop_openssh_fixture() } } -int open_socket_to_openssh_server() +int open_socket_to_openssh_server(void) { return open_socket_to_container(running_container_id); } diff --git a/tests/openssh_fixture.h b/tests/openssh_fixture.h index 2d2bb0ad..f8e3632c 100644 --- a/tests/openssh_fixture.h +++ b/tests/openssh_fixture.h @@ -38,8 +38,8 @@ #ifndef LIBSSH2_TESTS_OPENSSH_FIXTURE_H #define LIBSSH2_TESTS_OPENSSH_FIXTURE_H -int start_openssh_fixture(); -void stop_openssh_fixture(); -int open_socket_to_openssh_server(); +int start_openssh_fixture(void); +void stop_openssh_fixture(void); +int open_socket_to_openssh_server(void); #endif diff --git a/tests/runner.c b/tests/runner.c index b9f9328d..f3522bba 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -36,10 +36,9 @@ */ #include "session_fixture.h" +#include "runner.h" -extern int test(LIBSSH2_SESSION *session); - -int main() +int main(void) { int exit_code = 1; LIBSSH2_SESSION *session = start_session_fixture(); diff --git a/tests/runner.h b/tests/runner.h new file mode 100644 index 00000000..f32a7af2 --- /dev/null +++ b/tests/runner.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2016 Alexander Lamaison + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the copyright holder nor the names + * of any other contributors may be used to endorse or + * promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#ifndef LIBSSH2_TESTS_RUNNER_H +#define LIBSSH2_TESTS_RUNNER_H + +int test(LIBSSH2_SESSION *session); + +#endif diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 1f7e0f91..18df6624 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -61,7 +61,7 @@ LIBSSH2_SESSION *connected_session = NULL; int connected_socket = -1; -static int connect_to_server() +static int connect_to_server(void) { int rc; connected_socket = open_socket_to_openssh_server(); @@ -78,7 +78,7 @@ static int connect_to_server() return 0; } -void setup_fixture_workdir() +static void setup_fixture_workdir(void) { char *wd = getenv("FIXTURE_WORKDIR"); #ifdef FIXTURE_WORKDIR @@ -99,7 +99,7 @@ void setup_fixture_workdir() chdir(wd); } -LIBSSH2_SESSION *start_session_fixture() +LIBSSH2_SESSION *start_session_fixture(void) { int rc; @@ -146,7 +146,7 @@ void print_last_session_error(const char *function) } } -void stop_session_fixture() +void stop_session_fixture(void) { if(connected_session) { libssh2_session_disconnect(connected_session, "test ended"); diff --git a/tests/session_fixture.h b/tests/session_fixture.h index d3824b79..bbb8e596 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -40,8 +40,8 @@ #include -LIBSSH2_SESSION *start_session_fixture(); -void stop_session_fixture(); +LIBSSH2_SESSION *start_session_fixture(void); +void stop_session_fixture(void); void print_last_session_error(const char *function); #endif diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index daf7bd5a..569663b3 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index e33f68f9..80588b00 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_hostkey_hash.c b/tests/test_hostkey_hash.c index 112b491f..6f22d68f 100644 --- a/tests/test_hostkey_hash.c +++ b/tests/test_hostkey_hash.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include "libssh2_config.h" #include diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c index c1ab9730..f41d0ce6 100644 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index da6989d6..fc9e3d6a 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -46,27 +46,27 @@ struct expected { int rc; int last_error_code; - char *last_error_message; + const char *last_error_message; }; struct test_case { - char *data; + const char *data; int data_len; struct expected expected; }; #define TEST_CASES_LEN 16 struct test_case test_cases[TEST_CASES_LEN] = { - /* to small */ + /* too small */ { NULL, 0, {FAIL, -38, "userauth keyboard data buffer too small to get length"}}, - /* to small */ + /* too small */ { "1234", 4, {FAIL, -38, "userauth keyboard data buffer too small to get length"}}, - /* smalest valid packet possible */ + /* smallest valid packet possible */ { "<" "\0\0\0\0" @@ -219,9 +219,8 @@ static int free_count = 0; static LIBSSH2_ALLOC_FUNC(test_alloc) { - alloc_count++; - int *threshold_int_ptr = *abstract; + alloc_count++; if (*abstract != NULL && *threshold_int_ptr == alloc_count) { return NULL; } @@ -241,12 +240,15 @@ LIBSSH2_FREE_FUNC(test_free) static int test_case(int num, - char *data, int data_len, void *abstract, + const char *data, int data_len, void *abstract, struct expected expected) { + int rc; + char *message; + int error_code; + LIBSSH2_SESSION *session = NULL; alloc_count = 0; free_count = 0; - LIBSSH2_SESSION *session = NULL; session = libssh2_session_init_ex(test_alloc, test_free, NULL, abstract); if(session == NULL) { fprintf(stderr, "libssh2_session_init_ex failed\n"); @@ -257,7 +259,7 @@ int test_case(int num, session->userauth_kybd_data_len = data_len; memcpy(session->userauth_kybd_data, data, data_len); - int rc = userauth_keyboard_interactive_decode_info_request(session); + rc = userauth_keyboard_interactive_decode_info_request(session); if(rc != expected.rc) { fprintf(stdout, @@ -266,8 +268,7 @@ int test_case(int num, return 1; } - char *message; - int error_code = libssh2_session_last_error(session, &message, NULL, 0); + error_code = libssh2_session_last_error(session, &message, NULL, 0); if(expected.last_error_code != error_code) { fprintf(stdout, @@ -291,7 +292,7 @@ int test_case(int num, return 0; } -int main() +int main(void) { int i; @@ -332,4 +333,4 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, return -1; } -#endif \ No newline at end of file +#endif diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c index 093e4a22..224189ae 100644 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_password_auth_fails_with_wrong_password.c b/tests/test_password_auth_fails_with_wrong_password.c index 2b895d08..d888c78e 100644 --- a/tests/test_password_auth_fails_with_wrong_password.c +++ b/tests/test_password_auth_fails_with_wrong_password.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_password_auth_fails_with_wrong_username.c b/tests/test_password_auth_fails_with_wrong_username.c index b78617a4..e0630aa2 100644 --- a/tests/test_password_auth_fails_with_wrong_username.c +++ b/tests/test_password_auth_fails_with_wrong_username.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_password_auth_succeeds_with_correct_credentials.c b/tests/test_password_auth_succeeds_with_correct_credentials.c index 94b86b87..48e62373 100644 --- a/tests/test_password_auth_succeeds_with_correct_credentials.c +++ b/tests/test_password_auth_succeeds_with_correct_credentials.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c index dd2d254f..8b79edb6 100644 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ b/tests/test_public_key_auth_fails_with_wrong_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c index 187c1313..c04d7682 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c index 2ea3a369..febec6bb 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c index c52830d9..0ef9cf50 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index a79d1b51..6553baeb 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c index 553023a9..39e8cca5 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c index ba98ac7c..35cb5048 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c index 0cf2a633..40d9b80a 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c index a067d729..22a9937f 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c index 10b33cbb..398bfe38 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c index 39130e65..8843196f 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include