Skip to content

Commit

Permalink
Add tests for handling Client/Server configuration
Browse files Browse the repository at this point in the history
Re ECFLOW-1985
  • Loading branch information
marcosbento committed Nov 18, 2024
1 parent 00b1ac8 commit abcda5f
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 37 deletions.
11 changes: 8 additions & 3 deletions libs/base/src/ecflow/base/Openssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,14 @@ std::string Openssl::get_password() const {
}

std::string Openssl::certificates_dir() const {
std::string home_path = getenv("HOME");
home_path += "/.ecflowrc/ssl/";
return home_path;
if (auto found = getenv("ECF_SSL_DIR"); found) {
return found;
}
else {
std::string home_path = getenv("HOME");
home_path += "/.ecflowrc/ssl/";
return home_path;
}
}

std::string Openssl::pem() const {
Expand Down
1 change: 1 addition & 0 deletions libs/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ set(test_srcs
test/InvokeServer.hpp
# Sources
test/TestClient_main.cpp # test entry point
test/TestClientConfigurations.cpp
test/TestClientEnvironment.cpp
test/TestClientOptions.cpp
test/TestClientInterface.cpp
Expand Down
1 change: 1 addition & 0 deletions libs/client/src/ecflow/client/ClientEnvironment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class ClientEnvironment final : public AbstractClientEnv {
#ifdef ECF_OPENSSL
/// return true if this is a ssl enabled server
ecf::Openssl& openssl() { return ssl_; }
const ecf::Openssl& openssl() const { return ssl_; }
bool ssl() const { return ssl_.enabled(); }
void enable_ssl_if_defined() {
ssl_.enable_if_defined(host(), port());
Expand Down
10 changes: 9 additions & 1 deletion libs/client/src/ecflow/client/ClientInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ void ClientInvoker::set_connection_attempts(unsigned int attempts) {
connection_attempts_ = 1;
}

std::optional<Cmd_ptr> ClientInvoker::get_cmd_from_args(const CommandLine& cl) const {
Cmd_ptr cts_cmd;
if (get_cmd_from_args(cl, cts_cmd) == 1)
return std::nullopt;
return cts_cmd;
}

int ClientInvoker::get_cmd_from_args(const CommandLine& cl, Cmd_ptr& cts_cmd) const {
try {
// read in program option, and construct the client to server commands from them.
Expand Down Expand Up @@ -267,8 +274,9 @@ int ClientInvoker::invoke(const CommandLine& cl) const {
server_reply_.get_error_msg().clear();

Cmd_ptr cts_cmd;
if (get_cmd_from_args(cl, cts_cmd) == 1)
if (get_cmd_from_args(cl, cts_cmd) == 1) {
return 1;
}
if (!cts_cmd)
return 0; // For --help and --debug, --load defs check_only, no command is created

Expand Down
8 changes: 8 additions & 0 deletions libs/client/src/ecflow/client/ClientInvoker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class ClientInvoker {
ClientInvoker(const std::string& host, const std::string& port);
ClientInvoker(const std::string& host, int port);

const ClientEnvironment& environment() const { return clientEnv_; }

/// for debug allow the current client environment to be printed
std::string to_string() const { return clientEnv_.toString(); }

Expand Down Expand Up @@ -395,7 +397,13 @@ class ClientInvoker {
bool alias = false,
bool run = true); // ecFlowview SUBMIT_FILE

std::optional<Cmd_ptr> get_cmd_from_args(const CommandLine& cl) const;

private:
/**
* @return 1 when command is selected; 0 if no command is selected (e.g. --help)
* @throws std::runtime_error if the command could not be selected
*/
int get_cmd_from_args(const CommandLine& cl, Cmd_ptr& cts_cmd) const;

/// returns 1 on error and 0 on success. The errorMsg can be accessed via errorMsg()
Expand Down
17 changes: 12 additions & 5 deletions libs/client/src/ecflow/client/ClientOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,25 @@ Cmd_ptr ClientOptions::parse(const CommandLine& cl, ClientEnvironment* env) cons

#ifdef ECF_OPENSSL
if (auto ecf_ssl = getenv("ECF_SSL"); vm.count("ssl") || ecf_ssl) {
if (env->debug()) {
if (!vm.count("ssl") && ecf_ssl) {
if (!vm.count("ssl") && ecf_ssl) {
if (env->debug()) {
std::cout << " ssl enabled via environment variable\n";
}
else if (!vm.count("ssl") && ecf_ssl) {
env->enable_ssl_if_defined();
}
else if (vm.count("ssl") && !ecf_ssl) {
if (env->debug()) {
std::cout << " ssl explicitly enabled via command line\n";
}
else {
env->enable_ssl();
}
else {
if (env->debug()) {
std::cout << " ssl explicitly enabled via command line, but also enabled via environment variable\n";
}
env->enable_ssl();
}
env->enable_ssl();

if (env->debug()) {
std::cout << " ssl certificate: '" << env->openssl().info() << "' \n";
}
Expand Down
Loading

0 comments on commit abcda5f

Please sign in to comment.