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

Fix OpenSSL test compilation in CAF::net

parent 33fbaf1a
[files] [files]
extend-exclude = ["*.pem"] extend-exclude = ["*.pem", "libcaf_net/test/pem.cpp"]
\ No newline at end of file
...@@ -74,6 +74,14 @@ if(MSVC AND CAF_SANITIZERS) ...@@ -74,6 +74,14 @@ if(MSVC AND CAF_SANITIZERS)
message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC") message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC")
endif() 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 --------------------------------------------------------- # -- base target setup ---------------------------------------------------------
# This target propagates compiler flags, extra dependencies, etc. All other CAF # This target propagates compiler flags, extra dependencies, etc. All other CAF
......
...@@ -8,8 +8,10 @@ caf_add_component( ...@@ -8,8 +8,10 @@ caf_add_component(
net net
DEPENDENCIES DEPENDENCIES
PUBLIC PUBLIC
CAF::core
$<$<CXX_COMPILER_ID:MSVC>:ws2_32> $<$<CXX_COMPILER_ID:MSVC>:ws2_32>
CAF::core
OpenSSL::Crypto
OpenSSL::SSL
PRIVATE PRIVATE
CAF::internal CAF::internal
ENUM_TYPES ENUM_TYPES
...@@ -48,6 +50,7 @@ caf_add_component( ...@@ -48,6 +50,7 @@ caf_add_component(
src/udp_datagram_socket.cpp src/udp_datagram_socket.cpp
TEST_SOURCES TEST_SOURCES
test/net-test.cpp test/net-test.cpp
test/pem.cpp
TEST_SUITES TEST_SUITES
detail.convert_ip_endpoint detail.convert_ip_endpoint
detail.rfc6455 detail.rfc6455
...@@ -74,8 +77,20 @@ caf_add_component( ...@@ -74,8 +77,20 @@ caf_add_component(
net.web_socket.handshake net.web_socket.handshake
net.web_socket.server) net.web_socket.server)
if(CAF_INC_ENABLE_TESTING AND TARGET OpenSSL::SSL AND TARGET OpenSSL::Crypto) # Our OpenSSL test currently depends on <filesystem>.
caf_incubator_add_test_suites(caf-net-test net.openssl_transport) check_cxx_source_compiles("
target_sources(caf-net-test PRIVATE test/net/openssl_transport_constants.cpp) #include <cstdlib>
target_link_libraries(caf-net-test PRIVATE OpenSSL::SSL OpenSSL::Crypto) #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() endif()
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#pragma once #pragma once
#include "caf/byte_buffer.hpp" #include "caf/byte_buffer.hpp"
#include "caf/byte_span.hpp"
#include "caf/defaults.hpp" #include "caf/defaults.hpp"
#include "caf/detail/has_after_reading.hpp" #include "caf/detail/has_after_reading.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
...@@ -189,12 +190,12 @@ public: ...@@ -189,12 +190,12 @@ public:
} }
/// Reads data from the SSL connection into the buffer. /// 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())); return SSL_read(conn_.get(), buf.data(), static_cast<int>(buf.size()));
} }
/// Writes data from the buffer to the SSL connection. /// 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())); return SSL_write(conn_.get(), buf.data(), static_cast<int>(buf.size()));
} }
......
...@@ -7,32 +7,18 @@ ...@@ -7,32 +7,18 @@
#include "caf/net/openssl_transport.hpp" #include "caf/net/openssl_transport.hpp"
#include "net-test.hpp" #include "net-test.hpp"
#include "pem.hpp"
#include "caf/binary_deserializer.hpp" #include "caf/binary_deserializer.hpp"
#include "caf/binary_serializer.hpp" #include "caf/binary_serializer.hpp"
#include "caf/byte.hpp"
#include "caf/byte_buffer.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/multiplexer.hpp"
#include "caf/net/socket_guard.hpp"
#include "caf/net/socket_manager.hpp" #include "caf/net/socket_manager.hpp"
#include "caf/net/stream_socket.hpp" #include "caf/net/stream_socket.hpp"
#include "caf/span.hpp"
#include <filesystem> #include <filesystem>
#include <random> #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;
using namespace caf::net; using namespace caf::net;
...@@ -139,7 +125,7 @@ public: ...@@ -139,7 +125,7 @@ public:
} }
template <class ParentPtr> 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"); MESSAGE("dummy app received " << data.size() << " bytes");
// Store the received bytes. // Store the received bytes.
recv_buf_->insert(recv_buf_->begin(), data.begin(), data.end()); 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 @@ ...@@ -2,12 +2,6 @@
file(GLOB_RECURSE CAF_OPENSSL_HEADERS "caf/*.hpp") 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 --------------------------------------------------------------- # -- add targets ---------------------------------------------------------------
caf_add_component( 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