Commit 8681cc92 authored by Dominik Charousset's avatar Dominik Charousset

Fix OpenSSL test compilation in CAF::net

parent 33fbaf1a
[files]
extend-exclude = ["*.pem"]
\ No newline at end of file
extend-exclude = ["*.pem", "libcaf_net/test/pem.cpp"]
......@@ -74,6 +74,14 @@ if(MSVC AND CAF_SANITIZERS)
message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC")
endif()
# -- get dependencies that are used in more than one module --------------------
if(CAF_ENABLE_OPENSSL_MODULE OR CAF_ENABLE_NET_MODULE)
if(NOT TARGET OpenSSL::SSL OR NOT TARGET OpenSSL::Crypto)
find_package(OpenSSL REQUIRED)
endif()
endif()
# -- base target setup ---------------------------------------------------------
# This target propagates compiler flags, extra dependencies, etc. All other CAF
......
......@@ -8,8 +8,10 @@ caf_add_component(
net
DEPENDENCIES
PUBLIC
CAF::core
$<$<CXX_COMPILER_ID:MSVC>:ws2_32>
CAF::core
OpenSSL::Crypto
OpenSSL::SSL
PRIVATE
CAF::internal
ENUM_TYPES
......@@ -48,6 +50,7 @@ caf_add_component(
src/udp_datagram_socket.cpp
TEST_SOURCES
test/net-test.cpp
test/pem.cpp
TEST_SUITES
detail.convert_ip_endpoint
detail.rfc6455
......@@ -74,8 +77,20 @@ caf_add_component(
net.web_socket.handshake
net.web_socket.server)
if(CAF_INC_ENABLE_TESTING AND TARGET OpenSSL::SSL AND TARGET OpenSSL::Crypto)
caf_incubator_add_test_suites(caf-net-test net.openssl_transport)
target_sources(caf-net-test PRIVATE test/net/openssl_transport_constants.cpp)
target_link_libraries(caf-net-test PRIVATE OpenSSL::SSL OpenSSL::Crypto)
# Our OpenSSL test currently depends on <filesystem>.
check_cxx_source_compiles("
#include <cstdlib>
#include <filesystem>
int main(int, char**) {
auto cwd = std::filesystem::current_path();
auto str = cwd.string();
return str.empty() ? EXIT_FAILURE : EXIT_SUCCESS;
}
"
CAF_NET_HAS_STD_FILESYSTEM)
if(CAF_NET_HAS_STD_FILESYSTEM)
caf_add_test_suites(caf-net-test net.openssl_transport)
else()
message(STATUS "<filesystem> not working, skip OpenSSL test in CAF::net")
endif()
......@@ -5,6 +5,7 @@
#pragma once
#include "caf/byte_buffer.hpp"
#include "caf/byte_span.hpp"
#include "caf/defaults.hpp"
#include "caf/detail/has_after_reading.hpp"
#include "caf/fwd.hpp"
......@@ -189,12 +190,12 @@ public:
}
/// Reads data from the SSL connection into the buffer.
ptrdiff_t read(stream_socket, span<byte> buf) {
ptrdiff_t read(stream_socket, byte_span buf) {
return SSL_read(conn_.get(), buf.data(), static_cast<int>(buf.size()));
}
/// Writes data from the buffer to the SSL connection.
ptrdiff_t write(stream_socket, span<const byte> buf) {
ptrdiff_t write(stream_socket, const_byte_span buf) {
return SSL_write(conn_.get(), buf.data(), static_cast<int>(buf.size()));
}
......
......@@ -7,32 +7,18 @@
#include "caf/net/openssl_transport.hpp"
#include "net-test.hpp"
#include "pem.hpp"
#include "caf/binary_deserializer.hpp"
#include "caf/binary_serializer.hpp"
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/make_actor.hpp"
#include "caf/net/actor_proxy_impl.hpp"
#include "caf/net/multiplexer.hpp"
#include "caf/net/socket_guard.hpp"
#include "caf/net/socket_manager.hpp"
#include "caf/net/stream_socket.hpp"
#include "caf/span.hpp"
#include <filesystem>
#include <random>
// Note: these constants are defined in openssl_transport_constants.cpp.
extern std::string_view ca_pem;
extern std::string_view cert_1_pem;
extern std::string_view cert_2_pem;
extern std::string_view key_1_enc_pem;
extern std::string_view key_1_pem;
extern std::string_view key_2_pem;
using namespace caf;
using namespace caf::net;
......@@ -139,7 +125,7 @@ public:
}
template <class ParentPtr>
size_t consume(ParentPtr down, span<const byte> data, span<const byte>) {
size_t consume(ParentPtr down, const_byte_span data, const_byte_span) {
MESSAGE("dummy app received " << data.size() << " bytes");
// Store the received bytes.
recv_buf_->insert(recv_buf_->begin(), data.begin(), data.end());
......
#pragma once
#include <string_view>
extern std::string_view ca_pem;
extern std::string_view cert_1_pem;
extern std::string_view cert_2_pem;
extern std::string_view key_1_enc_pem;
extern std::string_view key_1_pem;
extern std::string_view key_2_pem;
......@@ -2,12 +2,6 @@
file(GLOB_RECURSE CAF_OPENSSL_HEADERS "caf/*.hpp")
# -- dependencies --------------------------------------------------------------
if(NOT TARGET OpenSSL::SSL OR NOT TARGET OpenSSL::Crypto)
find_package(OpenSSL REQUIRED)
endif()
# -- add targets ---------------------------------------------------------------
caf_add_component(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment