Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- develop
- 'feature/**'
- 'release/**'
- 'bugfix/**'
pull_request:
branches:
- main
Expand Down Expand Up @@ -86,6 +87,7 @@ jobs:
git
boost
openssl
cmake
pkg-config
libxml2
spdlog
Expand Down Expand Up @@ -208,32 +210,40 @@ jobs:
if: matrix.os == 'ubuntu-22.04' && matrix.ssl == 'OFF'
run: >
sudo cp /usr/local/etc/uda.socket /usr/local/etc/[email protected] /etc/systemd/system &&
sudo chown -R $USER:$USER /usr/local/etc &&
echo "export UDA_SERVER_SSL_AUTHENTICATE=OFF" >> /usr/local/etc/udaserver.cfg &&
sudo systemctl start uda.socket &&
sudo systemctl enable uda.socket &&
sudo chown -R $USER:$USER /usr/local/etc &&
nc -4zv localhost 56565 &&
export UDA_HOST=localhost &&
export UDA_PORT=56565 &&
./build/test/plugins/plugin_test_testplugin
./build/test/plugins/plugin_test_testplugin &&
ctest -V --test-dir build/test/unit_tests --output-on-failure &&
uda_cli --help && uda_cli --request "help::help()"

- name: Run SSL system tests
if: matrix.os == 'ubuntu-22.04' && matrix.ssl == 'ON'
run: >
sudo cp /usr/local/etc/uda.socket /usr/local/etc/[email protected] /etc/systemd/system &&
sudo chown -R $USER:$USER /usr/local/etc &&
echo "export UDAHOSTNAME=github-ci-ssl" >> /usr/local/etc/udaserver.cfg &&
./scripts/create_certs.sh &&
mkdir /usr/local/etc/certs &&
cp rootCA.crt server.crt server.key /usr/local/etc/certs &&
sudo systemctl start uda.socket &&
sudo systemctl enable uda.socket &&
nc -4zv localhost 56565 &&
export UDA_HOST=localhost &&
export UDA_PORT=56565 &&
export UDA_CLIENT_SSL_AUTHENTICATE=1 &&
export UDA_CLIENT_CA_SSL_CERT=$PWD/rootCA.crt &&
export UDA_CLIENT_SSL_CERT=$PWD/client.crt &&
export UDA_CLIENT_SSL_KEY=$PWD/client.key &&
run: |
sudo cp /usr/local/etc/uda.socket /usr/local/etc/[email protected] /etc/systemd/system
sudo chown -R $USER:$USER /usr/local/etc
# pulls in extra config options from machine.d
echo "export UDAHOSTNAME=github-ci-ssl" >> /usr/local/etc/udaserver.cfg
./scripts/create_certs.sh
mkdir /usr/local/etc/certs
cp rootCA.crt server.crt server.key /usr/local/etc/certs
sudo systemctl start uda.socket
sudo systemctl enable uda.socket
nc -4zv localhost 56565
export UDA_HOST=localhost
export UDA_PORT=56565
export UDA_CLIENT_SSL_AUTHENTICATE=OFF
export UDA_CLIENT_CA_SSL_CERT=$PWD/rootCA.crt
export UDA_CLIENT_SSL_CERT=$PWD/client.crt
export UDA_CLIENT_SSL_KEY=$PWD/client.key
set +e
/usr/local/bin/uda_cli --request "help::help()" && exit 1 || echo "process failed successfully"
set -e
export UDA_CLIENT_SSL_AUTHENTICATE=ON
./build/test/plugins/plugin_test_testplugin

# - name: Test
Expand Down
3 changes: 2 additions & 1 deletion source/authentication/udaClientSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ctime>
#include <openssl/ssl.h>

#include <common/uda_env_options.hpp>
#include <client/updateSelectParms.h>
#include <clientserver/errorLog.h>
#include <logging/logging.h>
Expand Down Expand Up @@ -327,7 +328,7 @@ int initUdaClientSSL()
// Has the user directly specified SSL/TLS authentication?
// Does the connection entry in the client host configuration file have the three SSL authentication files

if (!g_sslProtocol && !getenv("UDA_CLIENT_SSL_AUTHENTICATE")) {
if (!g_sslProtocol && !uda::common::env_config::evaluate_bool_param("UDA_CLIENT_SSL_AUTHENTICATE", false)) {
g_sslDisabled = true;

if (g_host != nullptr) {
Expand Down
7 changes: 3 additions & 4 deletions source/authentication/udaServerSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <openssl/ssl.h>
#include <openssl/x509.h>

#include <common/uda_env_options.hpp>
#include <clientserver/errorLog.h>
#include <logging/logging.h>
#include <server/writer.h>
Expand Down Expand Up @@ -280,11 +281,9 @@ int startUdaServerSSL()
}

// Has the server disabled SSL/TLS authentication?
if (!getenv("UDA_SERVER_SSL_AUTHENTICATE")) {
g_sslDisabled = true;
g_sslDisabled = !uda::common::env_config::evaluate_bool_param("UDA_SERVER_SSL_AUTHENTICATE", false);
if (g_sslDisabled) {
return 0;
} else {
g_sslDisabled = false;
}

UDA_LOG(UDA_LOG_DEBUG, "SSL Authentication is Enabled!\n");
Expand Down
55 changes: 25 additions & 30 deletions source/bin/uda_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,27 +444,23 @@ void print_result(const uda::Result& res) {

void process_request(uda::Client& client, const std::string& request, const std::string& source) {
std::cout << "request: " << request << "\n";
try {
const auto& res = client.get(request, source);
print_result(res);
} catch (const std::exception& ex) {
std::cout << "error: " << ex.what() << "\n";
}
const auto& res = client.get(request, source); //throws
print_result(res);
}

void process_batch_requests(uda::Client& client, const std::vector<std::string>& requests, const std::string& source) {
size_t count = 0;
for (const auto& request : requests) {
process_request(client, request, source);
try {
process_request(client, request, source);
count++;
} catch (const std::exception& ex) {
std::cout << "error: " << ex.what() << "\n";
}
}
if (count == 0 and !requests.empty()) {
throw CLIException("All requests in batch failed");
}
// for (const auto& request : requests) {
// std::cout << "request: " << request << "\n";
// }
// const auto& res_list = client.get_batch(requests, source);
//
// for (const auto& handle : res_list.handles()) {
// const auto& res = res_list.at(handle);
// print_result(res);
// }
}

int main(int argc, const char** argv)
Expand All @@ -487,29 +483,28 @@ int main(int argc, const char** argv)
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm);

if (vm.count("help") && vm["help"].as<bool>()) {
std::cout << "Usage: " << argv[0] << " [options] request\n";
std::cout << desc << "\n";
return 0;
}

conflicting_options(vm, "ping", "request");
conflicting_options(vm, "ping", "batch-file");
conflicting_options(vm, "request", "batch-file");
if (!vm["ping"].as<bool>() && vm.count("request") == 0 && vm.count("batch-file") == 0) {
throw po::error("either 'ping', 'request' or 'batch-file' must be provided");
}
} catch (const po::unknown_option& err) {
std::cout << "Error: " << err.what() << "\n\n";
std::cout << "Usage: " << argv[0] << " [options] request\n";
std::cout << desc << "\n";
return -1;
} catch (po::error& err) {
if (vm["help"].as<bool>()) {
std::cout << "Usage: " << argv[0] << " [options] request\n";
std::cout << desc << "\n";
return 1;
} else {
std::cout << "Error: " << err.what() << "\n\n";
std::cout << "Usage: " << argv[0] << " [options] request\n";
std::cout << desc << "\n";
return -1;
}
};

if (vm["help"].as<bool>()) {
std::cout << "Error: " << err.what() << "\n\n";
std::cout << "Usage: " << argv[0] << " [options] request\n";
std::cout << desc << "\n";
return 1;
return -1;
}

if (vm.count("host")) {
Expand Down
64 changes: 64 additions & 0 deletions source/common/uda_env_options.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once

#include <cstdlib>
#include <string>
#include <algorithm>
#include <cctype>
#include <vector>
#include <optional>

namespace uda::common::env_config {

const std::vector<std::string> truthy_values = {"1", "true", "yes", "on"};
const std::vector<std::string> falsey_values = {"0", "false", "no", "off"};

inline bool strings_match(std::string_view val, const std::vector<std::string>& accepted_values) {
std::string value(val);
std::transform(value.begin(), value.end(), value.begin(),
[] (unsigned char c) {return std::tolower(c); });

// case insensitive comparison
return std::any_of(accepted_values.begin(), accepted_values.end(),
[&] (std::string v){
std::transform(v.begin(), v.end(), v.begin(),
[] (unsigned char c) {return std::tolower(c); });
return value == v; });
}

inline bool match_custom_values(std::string_view var_name, const std::vector<std::string>& accepted_values,
bool default_value=false) {
const char* value = std::getenv(var_name.data());
if (value == nullptr) {
return default_value;
}
return strings_match(value, accepted_values);
}

inline std::optional<std::string>
get_custom_param(std::string_view var_name, const std::vector<std::string>& accepted_values) {
const char* value = std::getenv(var_name.data());
if (value == nullptr) {
return {};
}
if (strings_match(value, accepted_values)) {
return value;
}
return {};
}

inline bool evaluate_bool_param(std::string_view var_name, bool default_value=false) {

const char* val = std::getenv(var_name.data());
if (val == nullptr) {
return default_value;
}
if (strings_match(val, truthy_values)) {
return true;
}
if (strings_match(val, falsey_values)) {
return false;
}
return default_value;
}

} // namespace
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ macro( BUILD_TEST NAME SOURCE )
endmacro( BUILD_TEST )

add_subdirectory( plugins )
add_subdirectory( imas )
# add_subdirectory( imas )
add_subdirectory( unit_tests )

add_definitions( -D__USE_XOPEN2K8 )

Expand Down
10 changes: 10 additions & 0 deletions test/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Include( FetchContent )

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.8.0
)

FetchContent_MakeAvailable( Catch2 )
add_subdirectory( common )
4 changes: 4 additions & 0 deletions test/unit_tests/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable( test_uda_env uda_env_options.test.cpp )
target_include_directories( test_uda_env PRIVATE ${CMAKE_SOURCE_DIR}/source )
target_link_libraries( test_uda_env PRIVATE Catch2::Catch2WithMain )
add_test( NAME TestUdaEnvOptions COMMAND test_uda_env )
Loading
Loading