Skip to content

Commit

Permalink
fix: updates to try and get tests to run in CI
Browse files Browse the repository at this point in the history
Signed-off-by: James Chapman <[email protected]>
  • Loading branch information
james-ctc committed Jul 8, 2024
1 parent 533eb99 commit c9d2f70
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
6 changes: 2 additions & 4 deletions lib/staging/tls/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ target_compile_definitions(${TLS_PATCH_NAME} PRIVATE
)

target_sources(${TLS_PATCH_NAME} PRIVATE
gtest_main.cpp
patched_test.cpp
../openssl_util.cpp
../tls.cpp
)

target_link_libraries(${TLS_PATCH_NAME} PRIVATE
GTest::gtest
GTest::gtest_main
OpenSSL::SSL
OpenSSL::Crypto
)
Expand All @@ -110,5 +109,4 @@ install(
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
)

# runs fine locally, fails in CI
# add_test(${TLS_GTEST_NAME} ${TLS_GTEST_NAME})
add_test(${TLS_GTEST_NAME} ${TLS_GTEST_NAME})
2 changes: 1 addition & 1 deletion lib/staging/tls/tests/crypto_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using openssl::conversions::to_X509Wrapper;

TEST(evseSecurity, certificateHash) {
auto chain = load_certificates("client_chain.pem");
EXPECT_GT(chain.size(), 0);
ASSERT_GT(chain.size(), 0);

std::vector<X509Wrapper> certs;

Expand Down
7 changes: 7 additions & 0 deletions lib/staging/tls/tests/gtest_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

#include <cstdlib>
#include <iostream>
#include <linux/limits.h>
#include <unistd.h>

#include <gtest/gtest.h>

int main(int argc, char** argv) {
// create test certificates and keys
if (std::system("./pki.sh") != 0) {
std::cerr << "Problem creating test certificates and keys" << std::endl;
char buf[PATH_MAX];
if (getcwd(&buf[0], sizeof(buf)) != nullptr) {
std::cerr << "./pki.sh not found in " << buf << std::endl;
}
return 1;
}
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
11 changes: 10 additions & 1 deletion lib/staging/tls/tests/patched_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <openssl/ssl.h>
#include <thread>
#include <tls.hpp>
#include <unistd.h>

namespace {

Expand Down Expand Up @@ -151,6 +152,11 @@ class OcspTest : public testing::Test {
sigaction(SIGPIPE, &action, nullptr);
if (std::system("./pki.sh > /dev/null") != 0) {
std::cerr << "Problem creating test certificates and keys" << std::endl;
char buf[PATH_MAX];
if (getcwd(&buf[0], sizeof(buf)) != nullptr) {
std::cerr << "./pki.sh not found in " << buf << std::endl;
}
exit(1);
}
}

Expand All @@ -162,6 +168,7 @@ class OcspTest : public testing::Test {
server_config.private_key_file = "server_priv.pem";
// server_config.verify_locations_file = "client_root_cert.pem";
server_config.ocsp_response_files = {"ocsp_response.der", "ocsp_response.der"};
server_config.host = "localhost";
server_config.service = "8444";
server_config.ipv6_only = false;
server_config.verify_client = false;
Expand Down Expand Up @@ -197,7 +204,9 @@ class OcspTest : public testing::Test {
void connect() {
client.init(client_config);
client.reset();
auto connection = client.connect("localhost", "8444");
// localhost works in some cases but not in the CI pipeline for IPv6
// use ip6-localhost
auto connection = client.connect("localhost", "8444", false);
if (connection) {
if (connection->connect()) {
set(ClientTest::flags_t::connected);
Expand Down
3 changes: 2 additions & 1 deletion lib/staging/tls/tests/tls_client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ int main(int argc, char** argv) {

client.init(config);

auto connection = client.connect("localhost", "8444");
// localhost works in some cases but not in the CI pipeline
auto connection = client.connect("ip6-localhost", "8444", true);
if (connection) {
if (connection->connect()) {
std::array<std::byte, 1024> buffer{};
Expand Down
9 changes: 5 additions & 4 deletions lib/staging/tls/tls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ bool Server::init_socket(const config_t& cfg) {
if (cfg.socket == INVALID_SOCKET) {
BIO_ADDRINFO* addrinfo{nullptr};

bRes =
BIO_lookup_ex(cfg.host, cfg.service, BIO_LOOKUP_SERVER, AF_INET6, SOCK_STREAM, IPPROTO_TCP, &addrinfo) != 0;
bRes = BIO_lookup_ex(cfg.host, cfg.service, BIO_LOOKUP_SERVER, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP,
&addrinfo) != 0;

if (!bRes) {
log_error("init_socket::BIO_lookup_ex");
Expand Down Expand Up @@ -1268,11 +1268,12 @@ bool Client::init(const config_t& cfg) {
return ctx != nullptr;
}

std::unique_ptr<ClientConnection> Client::connect(const char* host, const char* service) {
std::unique_ptr<ClientConnection> Client::connect(const char* host, const char* service, bool ipv6_only) {
BIO_ADDRINFO* addrinfo{nullptr};
std::unique_ptr<ClientConnection> result;

bool bRes = BIO_lookup_ex(host, service, BIO_LOOKUP_CLIENT, AF_INET6, SOCK_STREAM, IPPROTO_TCP, &addrinfo) != 0;
const int family = (ipv6_only) ? AF_INET6 : AF_UNSPEC;
bool bRes = BIO_lookup_ex(host, service, BIO_LOOKUP_CLIENT, family, SOCK_STREAM, IPPROTO_TCP, &addrinfo) != 0;

if (!bRes) {
log_error("connect::BIO_lookup_ex");
Expand Down
2 changes: 1 addition & 1 deletion lib/staging/tls/tls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class Client {
* \param[in] ipv6_only false - also support IPv4
* \return a connection pointer (nullptr on error)
*/
std::unique_ptr<ClientConnection> connect(const char* host, const char* service);
std::unique_ptr<ClientConnection> connect(const char* host, const char* service, bool ipv6_only);

/**
* \brief return the current server state (indicative only)
Expand Down
2 changes: 1 addition & 1 deletion modules/EvseV2G/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target_compile_definitions(${TLS_GTEST_NAME} PRIVATE
)

target_sources(${TLS_GTEST_NAME} PRIVATE
gtest_main.cpp
../../../lib/staging/tls/tests/gtest_main.cpp
log.cpp
openssl_test.cpp
../crypto/crypto_openssl.cpp
Expand Down
16 changes: 0 additions & 16 deletions modules/EvseV2G/tests/gtest_main.cpp

This file was deleted.

0 comments on commit c9d2f70

Please sign in to comment.