Skip to content

Commit

Permalink
tests: added OPENSSL library initialization to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Dec 18, 2018
1 parent 3e3364a commit 7e0e15b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/tests/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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})

Expand All @@ -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})
Expand Down
2 changes: 2 additions & 0 deletions core/src/tests/bsock_test.cc
Expand Up @@ -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 <iostream>
#include <fstream>
Expand Down Expand Up @@ -64,6 +65,7 @@ static std::unique_ptr<console::ConsoleResource> cons_cons_config;

void InitForTest()
{
InitOpenSsl();
dir_cons_config.reset(directordaemon::CreateAndInitializeNewConsoleResource());
dir_dir_config.reset(directordaemon::CreateAndInitializeNewDirectorResource());
cons_dir_config.reset(console::CreateAndInitializeNewDirectorResource());
Expand Down
3 changes: 3 additions & 0 deletions core/src/tests/bsock_test_connection_setup.cc
Expand Up @@ -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 <signal.h>
Expand Down Expand Up @@ -176,13 +177,15 @@ 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);
}

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);
Expand Down
37 changes: 37 additions & 0 deletions 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 <openssl/ssl.h>

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
}
}
27 changes: 27 additions & 0 deletions 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_ */

0 comments on commit 7e0e15b

Please sign in to comment.