From 7e0e15bac81451fb6f1ac9b29e7d6db42df4d7ae Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 18 Dec 2018 09:19:18 +0100 Subject: [PATCH] tests: added OPENSSL library initialization to tests --- core/src/tests/CMakeLists.txt | 10 ++++- core/src/tests/bsock_test.cc | 2 + core/src/tests/bsock_test_connection_setup.cc | 3 ++ core/src/tests/init_openssl.cc | 37 +++++++++++++++++++ core/src/tests/init_openssl.h | 27 ++++++++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 core/src/tests/init_openssl.cc create mode 100644 core/src/tests/init_openssl.h diff --git a/core/src/tests/CMakeLists.txt b/core/src/tests/CMakeLists.txt index d30cceb2869..f74801802e7 100644 --- a/core/src/tests/CMakeLists.txt +++ b/core/src/tests/CMakeLists.txt @@ -22,6 +22,10 @@ IF(HAVE_WIN32) user32 gdi32 winspool shell32 ole32 oleaut32 uuid comdlg32 advapi32) ENDIF() +IF(HAVE_OPENSSL) + set(SSL_UNIT_TEST_FILES init_openssl.cc) +ENDIF() + set(LINK_LIBRARIES stored_objects dird_objects @@ -107,7 +111,8 @@ add_executable(test_bsock bsock_constructor_test.cc bsock_cert_verify_common_names_test.cc create_resource.cc -) + ${SSL_UNIT_TEST_FILES} + ) target_link_libraries(test_bsock ${LINK_LIBRARIES}) @@ -120,9 +125,10 @@ set_property(TEST test_bsock add_dependencies(check test_bsock) -####### test_bsock ############################### +####### test_connection_setup ############################### add_executable(test_connection_setup bsock_test_connection_setup.cc + ${SSL_UNIT_TEST_FILES} ) target_link_libraries(test_connection_setup ${LINK_LIBRARIES}) diff --git a/core/src/tests/bsock_test.cc b/core/src/tests/bsock_test.cc index ae3fadce8b9..9a41fdd495d 100644 --- a/core/src/tests/bsock_test.cc +++ b/core/src/tests/bsock_test.cc @@ -21,6 +21,7 @@ #include "bsock_test.h" #include "create_resource.h" #include "tests/bareos_test_sockets.h" +#include "tests/init_openssl.h" #include "gtest/gtest.h" #include #include @@ -64,6 +65,7 @@ static std::unique_ptr cons_cons_config; void InitForTest() { + InitOpenSsl(); dir_cons_config.reset(directordaemon::CreateAndInitializeNewConsoleResource()); dir_dir_config.reset(directordaemon::CreateAndInitializeNewDirectorResource()); cons_dir_config.reset(console::CreateAndInitializeNewDirectorResource()); diff --git a/core/src/tests/bsock_test_connection_setup.cc b/core/src/tests/bsock_test_connection_setup.cc index 0e3d95a5021..bc15024f222 100644 --- a/core/src/tests/bsock_test_connection_setup.cc +++ b/core/src/tests/bsock_test_connection_setup.cc @@ -31,6 +31,7 @@ #include "lib/tls_openssl.h" #include "lib/bnet.h" #include "lib/bstringlist.h" +#include "tests/init_openssl.h" #include "include/jcr.h" #include @@ -176,6 +177,7 @@ static bool do_connection_test(std::string path_to_config, TlsPolicy tls_policy) TEST(bsock, console_director_connection_test_tls_psk) { + InitOpenSsl(); do_connection_test(std::string(CMAKE_SOURCE_DIR "/src/tests/configs/console-director/tls_psk_default_enabled/"), TlsPolicy::kBnetTlsEnabled); @@ -183,6 +185,7 @@ TEST(bsock, console_director_connection_test_tls_psk) TEST(bsock, console_director_connection_test_cleartext) { + InitOpenSsl(); do_connection_test(std::string(CMAKE_SOURCE_DIR "/src/tests/configs/console-director/tls_disabled/"), TlsPolicy::kBnetTlsNone); diff --git a/core/src/tests/init_openssl.cc b/core/src/tests/init_openssl.cc new file mode 100644 index 00000000000..ff9e1a85e6a --- /dev/null +++ b/core/src/tests/init_openssl.cc @@ -0,0 +1,37 @@ +/* + BAREOSĀ® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2018-2018 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include + +void InitOpenSsl() +{ + static bool init_once_per_test_application = true; + + if (init_once_per_test_application) { + init_once_per_test_application = false; + SSL_load_error_strings(); +#if OPENSSL_VERSION_NUMBER < 0x10100000L + SSL_library_init(); +#else + OPENSSL_init_ssl(0, NULL); +#endif + } +} diff --git a/core/src/tests/init_openssl.h b/core/src/tests/init_openssl.h new file mode 100644 index 00000000000..99ad1c5ac40 --- /dev/null +++ b/core/src/tests/init_openssl.h @@ -0,0 +1,27 @@ +/* + BAREOSĀ® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2018-2018 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef BAREOS_TESTS_INIT_OPENSSL_H_INCLUDED_ +#define BAREOS_TESTS_INIT_OPENSSL_H_INCLUDED_ + +void InitOpenSsl(); + +#endif /* BAREOS_TESTS_INIT_OPENSSL_H_INCLUDED_ */