Skip to content

Commit

Permalink
Added Tls 1.3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Iandiehard committed Aug 8, 2024
1 parent d0cb170 commit c920b03
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TlsServer::TlsServerImpl final {
* @brief Type alias for secured tcp connection
*/
using TcpConnectionSecured =
connection::tcp::TcpConnection<connection::tcp::ConnectionType::kClient, TlsSocket>;
connection::tcp::TcpConnection<connection::tcp::ConnectionType::kServer, TlsSocket>;

/**
* @brief Constructs an instance of TcpServerImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,16 @@ auto ToOpenSslString(server::tls::Tls13CipherSuites cipher) noexcept -> std::str
template<typename CipherType>
auto ConvertCipherListToString(std::initializer_list<CipherType> ciphers) noexcept -> std::string {
return std::accumulate(ciphers.begin(), ciphers.end(), std::string{},
[](std::string const& result, CipherType const& cipher) {
return result + ':' + ToOpenSslString(cipher);
[](std::string const& result, CipherType const& cipher) -> std::string {
std::string calculated_ssl_string{};
if (result.empty()) {
calculated_ssl_string.append(ToOpenSslString(cipher));
} else {
calculated_ssl_string.append(result);
calculated_ssl_string.append(":");
calculated_ssl_string.append(ToOpenSslString(cipher));
}
return calculated_ssl_string;
});
}
} // namespace
Expand Down Expand Up @@ -173,4 +181,4 @@ TlsContext::TlsContext(Tls13VersionServer server, std::string_view certificate_p
}
} // namespace tls
} // namespace socket
} // namespace boost_support
} // namespace boost_support
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,33 @@ TlsSocket::TlsSocket(std::string_view local_ip_address, std::uint16_t local_port
local_endpoint_{boost::asio::ip::make_address(local_ip_address), local_port_num} {}

TlsSocket::TlsSocket(TlsSocket::TcpSocket tcp_socket, TlsContext &tls_context) noexcept
: ssl_stream_{std::move(tcp_socket), tls_context.GetContext()} {}
: ssl_stream_{std::move(tcp_socket), tls_context.GetContext()},
local_endpoint_{} {
TcpErrorCodeType ec{};

// Perform TLS handshake
ssl_stream_.handshake(boost::asio::ssl::stream_base::server, ec);

if (ec.value() == boost::system::errc::success) {
printf("Connected with %s encryption\n", SSL_get_cipher(ssl_stream_.native_handle()));
} else {
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError(
__FILE__, __LINE__, __func__, [ec](std::stringstream &msg) {
msg << "Tls client handshake with host failed with error: " << ec.message();
});
}
}

TlsSocket::TlsSocket(TlsSocket &&other) noexcept
: ssl_stream_{std::move(other.ssl_stream_)},
local_endpoint_{std::move(other.local_endpoint_)} {}

TlsSocket &TlsSocket::operator=(TlsSocket &&other) noexcept {
ssl_stream_ = std::move(std::move(other.ssl_stream_));
local_endpoint_ = std::move(other.local_endpoint_);
return *this;
}

TlsSocket::~TlsSocket() noexcept = default;

core_type::Result<void, TlsSocket::SocketError> TlsSocket::Open() noexcept {
Expand All @@ -49,8 +70,8 @@ core_type::Result<void, TlsSocket::SocketError> TlsSocket::Open() noexcept {
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug(
__FILE__, __LINE__, __func__, [this](std::stringstream &msg) {
Tcp::endpoint const endpoint_{GetNativeTcpSocket().local_endpoint()};
msg << "Tls Socket opened and bound to "
<< "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">";
msg << "Tls Socket opened and bound to " << "<" << endpoint_.address().to_string()
<< "," << endpoint_.port() << ">";
});
result.EmplaceValue();
} else {
Expand Down Expand Up @@ -83,8 +104,8 @@ core_type::Result<void, TlsSocket::SocketError> TlsSocket::Connect(
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug(
__FILE__, __LINE__, __func__, [this](std::stringstream &msg) {
Tcp::endpoint const endpoint_{GetNativeTcpSocket().remote_endpoint()};
msg << "Tls client socket connected to host "
<< "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">";
msg << "Tls socket connected to host " << "<" << endpoint_.address().to_string() << ","
<< endpoint_.port() << ">";
});
// Perform TLS handshake
ssl_stream_.handshake(boost::asio::ssl::stream_base::client, ec);
Expand Down Expand Up @@ -140,8 +161,8 @@ core_type::Result<void, TlsSocket::SocketError> TlsSocket::Transmit(
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug(
__FILE__, __LINE__, __func__, [this](std::stringstream &msg) {
Tcp::endpoint const endpoint_{GetNativeTcpSocket().remote_endpoint()};
msg << "Tcp message sent to "
<< "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">";
msg << "Tcp message sent to " << "<" << endpoint_.address().to_string() << ","
<< endpoint_.port() << ">";
});
result.EmplaceValue();
} else {
Expand Down Expand Up @@ -194,8 +215,8 @@ core_type::Result<TlsSocket::TcpMessagePtr, TlsSocket::SocketError> TlsSocket::R
endpoint_.address().to_string(), endpoint_.port(), std::move(rx_buffer))};
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug(
__FILE__, __LINE__, __func__, [endpoint_](std::stringstream &msg) {
msg << "Tcp Message received from "
<< "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">";
msg << "Tcp Message received from " << "<" << endpoint_.address().to_string() << ","
<< endpoint_.port() << ">";
});
result.EmplaceValue(std::move(tcp_rx_message));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class TlsSocket final {
TlsSocket &operator=(const TlsSocket &other) noexcept = delete;

/**
* @brief Deleted move assignment
* @brief Move assignment
*/
TlsSocket &operator=(TlsSocket &&other) noexcept = delete;
TlsSocket &operator=(TlsSocket &&other) noexcept;

/**
* @brief Move constructor
Expand Down
18 changes: 11 additions & 7 deletions test/component/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ add_executable(${PROJECT_NAME}
${MAIN}
${COMMON}
${TEST_SRCS}
)
)

# include directories
target_include_directories(${PROJECT_NAME} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
)
)

target_link_libraries(${PROJECT_NAME}
diag-client
Expand All @@ -25,12 +25,16 @@ target_link_libraries(${PROJECT_NAME}
utility-support
GTest::gtest_main
GTest::gmock_main
)
)

gtest_discover_tests(${PROJECT_NAME})

# Copy the default config file
set(DEFAULT_CONFIG "etc/diag_client_config.json")
# Copy etc directory
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMENT "Copying file '${CMAKE_CURRENT_SOURCE_DIR}/${DEFAULT_CONFIG}' for '${PROJECT_BINARY_DIR}' to working directory..."
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${DEFAULT_CONFIG} ${PROJECT_BINARY_DIR}/)
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/etc $<TARGET_FILE_DIR:${PROJECT_NAME}>/etc)

# Copy cert directory
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/cert $<TARGET_FILE_DIR:${PROJECT_NAME}>/cert)
Empty file added test/component/cert/.empty
Empty file.
20 changes: 20 additions & 0 deletions test/component/cert/DiagClientLibRootCA.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDTzCCAjegAwIBAgIUazi2eSuhQxKyqFqooZwpjd63OGowDQYJKoZIhvcNAQEL
BQAwNzEWMBQGA1UEAwwNRGlhZ0NsaWVudExpYjELMAkGA1UEBhMCREUxEDAOBgNV
BAcMB0JlcmxpbiAwHhcNMjQwODA4MTY0NjA0WhcNMjUwNzMwMTY0NjA0WjA3MRYw
FAYDVQQDDA1EaWFnQ2xpZW50TGliMQswCQYDVQQGEwJERTEQMA4GA1UEBwwHQmVy
bGluIDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALYz9mzArC1wcMuj
CR/be6gr1MXRxN2b+4NreX9D2aQXolup5BS2gs0GDcUsVarE7LfeQS8pMGM7dtaw
ZlQT8Cepw/OexmrQiqgdeCOUVEm6/IHfmc6qtU7CsjCxvNkK6WamBVmtOBHMLZ3m
jMAZh06o1+mW3iefCAYkyu1kBAQSaAOJmkIXeNMVbasQ+GJtfEs4LYQrrQl2krmd
2k9c9MjmIsZuJUjZwUj236mhdARAZChmIjsbOQofpfoSuEJg56CfKeK0nKz9HS/a
lAR3X3PBUQU8Eools5868W9mL6qzM+r285ML9+hdNe8ODZHtpFcE6uPBnMjpQoWD
qFieaJUCAwEAAaNTMFEwHQYDVR0OBBYEFGU6jQE4B0krhXiGPzB5KBlOLbb3MB8G
A1UdIwQYMBaAFGU6jQE4B0krhXiGPzB5KBlOLbb3MA8GA1UdEwEB/wQFMAMBAf8w
DQYJKoZIhvcNAQELBQADggEBAB+idtEXL1RUpUBznBaAy/ie/4I6f7SgRoN+mlwv
mSWZuFXK+uqE3USVy4LSareUGNI2EwNYdp3lPQj3S0KFjxlIuvJ9Zz5/wlzQn5JZ
6EJXgVR/MuHDU5RG1t9d/PaL4cOXJGyntr1pCO6JmS2my42U1LiHoN6aURa+//KI
Fte5Gxl87/unO/GM7OsnjraGsVyAr9vMeU5HXWzfYIcNAtA4KjTV5joTzX7XKEQp
V6KiGvxjFdSZnUQfdQMg5Y3+HE1po4cEkG4bVGgQsd8tkrkGm9AZzXbXiQvCwMJE
/1rB3HFQdE6uo+ZRPawtpM+tgVnkfY9HdG0Xv1E35cxRBFk=
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions test/component/cert/DiagClientLibServer.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7bQbR/yFJPaOD
/SOjvM9BcXeAsDW+bcdDmZ26NytAMF3kAQitqDx9cfg9lt7ucatjEmkW1GwyK1wz
RyNtDYTfZSCatoV6SWsJ383PxgoguVuIK3vtvTo+qCw8T214xSDAVnxCeo5ZEu58
hL2n/BuEHV9CgzCW3fN1Y35QkYJCxRj4PyjN+vgS+CGtvPznrJiMPCAgivU3vRKY
uIXZlPJ+1k8RksNZeBeG6QPvLZoMHr6Lrh4tAaIxC4YQkfHUOfXKDp/iElVbTs00
mtZgYakc8Sqj40DDd/78GdwO4hME5TiorYjhPh/Wjre9h27NUcJsxPduU84DjPOG
HFGuttznAgMBAAECggEAXKnTKOjD+rN8T+nMAIx9RYRFSn0UHTGmRmBBEIttGT+w
c+Uk9sKKIZVC36RjVK0jSIiWJ2Dfm1A/teRyedyouFAFtigORv7calXZqeNmJ3as
795b15bqIIdB05GLdJ21ixJXPgDctuI6wZpZMB/fNMrWyYoV8EkMsJl/nnLKXZq9
2ZDZ8wrmks9nyUcYGsue9/tp6kto7fykrqQugOJch+cul5dlj5k6jLrSxewbGSis
zWjpcMnz+EROWgaq9p3o2DdaBIrmr64RUegrPMdJaJDybUngMm246YLfZDQud86o
xcOQOesRCsbbLY6NQ2s1T8BIqveo/XekD2gVqux2FQKBgQD0AGJRIMdvWQG07uLC
yHIT8TasfM8nNnWNb9KedZ5FlMXjmyZ6OH85TDupDV8KigC1AeZwhktYC+zQlJ4n
AkS0+JI+V3aFwn9wgcntJ4rZ3n4r8W45RfuJlyHY27Z6iYwFSnbbSCaBCCTozL10
LLsyE18Lg8T+WzRom4nTw/ZNvQKBgQDEpHCTpqMJwwFb3CNRo8me0d++4cG+kEXN
6KEoQpJVyAyZiMrnvyYxts0Cg0osZ9Q4QV/u5iIYTfkhpwEFuQsrpqBE1JzeKlyc
IX3UC05jQYsk2z83cCp6/INbYH44uC0c+T7oLd0CD+yWfVPr9KNHS01ex/IM5GxM
bY4+m3ZFcwKBgQDFUUIwpTdifjH5JW3PYtWN9vTlzBChf1LUy+chKbCSSFs3UpJt
KB8KMPHWJfADz9H+jsjRmmh3jT0299hlZ1o0lwd8zrIUPVNdojevRtjskxapZpZi
Tou5mrROcG9C7NSEutEfR1uL4RAoCtnyhvHi7vNflnHJ1+ur5Iwy6jfWaQKBgFfO
VbaYohSpzuGF2v+Jc25HqPFDPZAqPAFF7zBbCZzkRzwHqRLyd8ubJNAKcASEGG9G
QeAbQv43UxeDyyETD7neHZKena1WnSPakKUup0IK8mbyv7exjkZ8musimzoYg4x8
f2qNkDJrielo7SBfjMk5BsNb5Ol81h8KjInIQXehAoGAYFfvtizkz3gybyOwkJaw
1GpVyeV9CwoHl5eOSOq/ihQwrRWgu5o8eleFMctmxriaBXjhvrx/S0mJqzxkNamY
m+Smp2l+p1CWcBhitBkXvZchkHqP9CffIM25uDuxQgv9MgLeLWkLsoa4a5gaBA/3
G+CF9qI4OSvssvK1A/uHSRo=
-----END PRIVATE KEY-----
22 changes: 22 additions & 0 deletions test/component/cert/DiagClientLibServer.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIDrDCCApSgAwIBAgIUAbUEHaoKcAGrJC5pycdfw9V15MkwDQYJKoZIhvcNAQEL
BQAwNzEWMBQGA1UEAwwNRGlhZ0NsaWVudExpYjELMAkGA1UEBhMCREUxEDAOBgNV
BAcMB0JlcmxpbiAwHhcNMjQwODA4MTY0NjA0WhcNMjUwODA4MTY0NjA0WjBzMQsw
CQYDVQQGEwJERTELMAkGA1UECAwCQlcxDzANBgNVBAcMBkJFUkxJTjEWMBQGA1UE
CgwNRGlhZ0NsaWVudExpYjEWMBQGA1UECwwNRGlhZ0NsaWVudExpYjEWMBQGA1UE
AwwNRGlhZ0NsaWVudExpYjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
ALttBtH/IUk9o4P9I6O8z0Fxd4CwNb5tx0OZnbo3K0AwXeQBCK2oPH1x+D2W3u5x
q2MSaRbUbDIrXDNHI20NhN9lIJq2hXpJawnfzc/GCiC5W4gre+29Oj6oLDxPbXjF
IMBWfEJ6jlkS7nyEvaf8G4QdX0KDMJbd83VjflCRgkLFGPg/KM36+BL4Ia28/Oes
mIw8ICCK9Te9Epi4hdmU8n7WTxGSw1l4F4bpA+8tmgwevouuHi0BojELhhCR8dQ5
9coOn+ISVVtOzTSa1mBhqRzxKqPjQMN3/vwZ3A7iEwTlOKitiOE+H9aOt72Hbs1R
wmzE925TzgOM84YcUa623OcCAwEAAaN0MHIwHwYDVR0jBBgwFoAUZTqNATgHSSuF
eIY/MHkoGU4ttvcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBPAwGAYDVR0RBBEwD4IN
RGlhZ0NsaWVudExpYjAdBgNVHQ4EFgQUVSsSKqlFKDFLk8f6w11g8pAJaTYwDQYJ
KoZIhvcNAQELBQADggEBAHFQwJJtSPk+kzkC7/DAhrRg3R34nakf5adshejHOIMU
eeHpdNtzuaL+51In+VKyPYCmAd3JMzqA29Sq70s1SLdpfo6+eT4ybD3DgnLF/nKh
qmo5QDXUL2unfi5a9hSgcG77tNkSK3A/jwABguWOEzsWG/FIkuYw6q64bGiDAJBp
PlOV4Nzc7Ul1NBEIWgAvgBTh/VmyaKYFft0dMueWNZaYkbp4X1k6Srh83gWFOrAM
cDe5dt80HgFX7Jf1E8c1wE1fs1cEMn8XPGXZctSIYgiPSfZ5B1Ar89umbciziq3o
2oibDIb3X8mFR+iqKDTDJHZj6aZeJzFndx3vTJ5rI4g=
-----END CERTIFICATE-----
2 changes: 1 addition & 1 deletion test/component/test_cases/diagnostic_message_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const std::uint16_t kDiagClientLogicalAddress{0x0001U};
// Diag Test Server logical address
const std::uint16_t kDiagServerLogicalAddress{0xFA25U};
// Path to json file
constexpr std::string_view kDiagClientConfigPath{"diag_client_config.json"};
constexpr std::string_view kDiagClientConfigPath{"./etc/diag_client_config.json"};
// Default routing activation type
constexpr std::uint8_t kDoipRoutingActivationReqActTypeDefault{0x00U};
// Successful routing activation response code
Expand Down
2 changes: 1 addition & 1 deletion test/component/test_cases/routing_activation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const std::uint16_t kDiagClientLogicalAddress{0x0001U};
// Diag Test Server logical address
const std::uint16_t kDiagServerLogicalAddress{0xFA25U};
// Path to json file
constexpr std::string_view kDiagClientConfigPath{"diag_client_config.json"};
constexpr std::string_view kDiagClientConfigPath{"./etc/diag_client_config.json"};
// Default routing activation type
constexpr std::uint8_t kDoipRoutingActivationReqActTypeDefault{0x00};
constexpr std::uint8_t kDoipRoutingActivationResCodeUnknownSa{0x00};
Expand Down
89 changes: 79 additions & 10 deletions test/component/test_cases/tls_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ constexpr std::string_view kTlsClientIpAddress{"172.16.25.127"};
// Tls client port number
constexpr std::uint16_t kTlsClientTcpPortNum{3496U};
// Certificate path
constexpr std::string_view kCertificatePath{};
constexpr std::string_view kServerCertificatePath{"./cert/DiagClientLibServer.pem"};
// Private key path
constexpr std::string_view kPrivateKeyPath{};
constexpr std::string_view kServerPrivateKeyPath{"./cert/DiagClientLibServer.key"};
// CA certificate path
constexpr std::string_view kCACertificatePath{};
constexpr std::string_view kCACertificatePath{"./cert/DiagClientLibRootCA.pem"};

/*!
* @brief Test fixture to test tls 1.2
Expand Down Expand Up @@ -66,10 +66,10 @@ class Tls12Fixture : public component::ComponentTest {
kTlsServerTcpPortNum,
1u,
TlsServerVersion{
{TlsServerCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
TlsServerCipherSuite ::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}},
kCertificatePath,
kPrivateKeyPath},
{TlsServerCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
TlsServerCipherSuite ::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}},
kServerCertificatePath,
kServerPrivateKeyPath},
tls_server_{},
tls_client_{
kTlsClientIpAddress, kTlsClientTcpPortNum, kCACertificatePath,
Expand All @@ -87,7 +87,74 @@ class Tls12Fixture : public component::ComponentTest {
auto CreateServerWithExpectation(Functor expectation_functor) noexcept -> std::future<bool> {
return std::async(std::launch::async,
[this, expectation_functor = std::move(expectation_functor)]() {
std::optional<TlsServer> server{tls_acceptor_.GetTlsServer()};
std::optional<TlsServer> server{
tls_acceptor_.GetTlsServer()}; // blocks until client is connected
if (server.has_value()) {
tls_server_.emplace(std::move(server).value());
tls_server_->Initialize();
// Set Expectation
expectation_functor();
}
return tls_server_.has_value();
});
}

protected:
// Tls acceptor
TlsAcceptor tls_acceptor_;
// Tls Server
std::optional<TlsServer> tls_server_;
// Tls client with Tls version 1.2
TlsClient tls_client_;
};

/*!
* @brief Test fixture to test tls 1.3
*/
class Tls13Fixture : public component::ComponentTest {
public:
// Type Alias of acceptor
using TlsAcceptor = boost_support::server::tls::TlsAcceptor13;
// Type Alias of server
using TlsServer = boost_support::server::tls::TlsServer;
// Type Alias of client
using TlsClient = boost_support::client::tls::TlsClient13;
// Type Alias of tls server cipher suites version 1.2
using TlsServerCipherSuite = boost_support::server::tls::Tls13CipherSuites;
// Type Alias of tls server version
using TlsServerVersion = boost_support::server::tls::TlsVersion13;
// Type Alias of tls client cipher suites version 1.2
using TlsClientCipherSuite = boost_support::client::tls::Tls13CipherSuites;
// Type Alias of tls client version
using TlsClientVersion = boost_support::client::tls::TlsVersion13;

protected:
Tls13Fixture()
: tls_acceptor_{kTlsServerIpAddress,
kTlsServerTcpPortNum,
1u,
TlsServerVersion{{TlsServerCipherSuite::TLS_AES_128_GCM_SHA256,
TlsServerCipherSuite ::TLS_AES_256_GCM_SHA384}},
kServerCertificatePath,
kServerPrivateKeyPath},
tls_server_{},
tls_client_{kTlsClientIpAddress, kTlsClientTcpPortNum, kCACertificatePath,
TlsClientVersion{{TlsClientCipherSuite::TLS_AES_128_GCM_SHA256,
TlsClientCipherSuite::TLS_AES_256_GCM_SHA384}}} {}

void SetUp() override { tls_client_.Initialize(); }

void TearDown() override {
if (tls_server_.has_value()) { tls_server_->DeInitialize(); }
tls_client_.DeInitialize();
}

template<typename Functor>
auto CreateServerWithExpectation(Functor expectation_functor) noexcept -> std::future<bool> {
return std::async(std::launch::async,
[this, expectation_functor = std::move(expectation_functor)]() {
std::optional<TlsServer> server{
tls_acceptor_.GetTlsServer()}; // blocks until client is connected
if (server.has_value()) {
tls_server_.emplace(std::move(server).value());
tls_server_->Initialize();
Expand All @@ -110,20 +177,22 @@ class Tls12Fixture : public component::ComponentTest {
/**
* @brief Verify that sending of data from tls client to server works.
*/
TEST_F(Tls12Fixture, SendDataFromClientToServer) {
TEST_F(Tls13Fixture, SendDataFromClientToServer) {
std::vector<std::uint8_t> const kTestData{1u, 2u, 3u, 4u, 5u, 6u};

std::future<bool> is_server_created{CreateServerWithExpectation([this, &kTestData]() {
ASSERT_TRUE(tls_server_.has_value());
// Create expectation that Receive Handler is invoked with same data
tls_server_->SetReadHandler([&kTestData](TlsServer::MessagePtr message) {
EXPECT_THAT(kTestData, ::testing::ElementsAreArray(message->GetPayload()));
});
})};

ASSERT_TRUE(is_server_created.get());
// Try connecting to server and verify
EXPECT_TRUE(tls_client_.ConnectToHost(kTlsServerIpAddress, kTlsServerTcpPortNum).HasValue());
EXPECT_TRUE(tls_client_.IsConnectedToHost());

ASSERT_TRUE(is_server_created.get());
// Send test data to tls server
EXPECT_TRUE(tls_client_
.Transmit(std::make_unique<TlsClient::Message>(kTlsServerIpAddress,
Expand Down
2 changes: 1 addition & 1 deletion test/component/test_cases/vehicle_discovery_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ constexpr std::string_view kDiagUdpAnotherUnicastIpAddress{"172.16.25.129"};
// Port number
constexpr std::uint16_t kDiagUdpPortNum{13400u};
// Path to json file
constexpr std::string_view kDiagClientConfigPath{"diag_client_config.json"};
constexpr std::string_view kDiagClientConfigPath{"./etc/diag_client_config.json"};

// Fixture to test Vehicle discovery functionality
class VehicleDiscoveryFixture : public component::ComponentTest {
Expand Down
Loading

0 comments on commit c920b03

Please sign in to comment.