diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2023-01-18 14:26:14 +0100 |
---|---|---|
committer | Alberto Sartori <alberto.sartori@huawei.com> | 2023-01-20 11:58:07 +0100 |
commit | 3d95b0adc81d155ad9020e9efbc50799c89953ff (patch) | |
tree | f7b391ff47439a4d09b1309326b9d6bbcef13654 /test/utils/test_env.hpp | |
parent | fe8983f3444ca0f287d54d673ddda3aa9fb1a17c (diff) | |
download | justbuild-3d95b0adc81d155ad9020e9efbc50799c89953ff.tar.gz |
tests: pass tls certificates and key
Diffstat (limited to 'test/utils/test_env.hpp')
-rw-r--r-- | test/utils/test_env.hpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/utils/test_env.hpp b/test/utils/test_env.hpp index 0302f555..7013d2ff 100644 --- a/test/utils/test_env.hpp +++ b/test/utils/test_env.hpp @@ -21,6 +21,7 @@ #include <sstream> #include <string> +#include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "test/utils/logging/log_config.hpp" @@ -53,4 +54,31 @@ static inline void ReadCompatibilityFromEnv() { : std::make_optional(std::string{execution_address}); } +[[nodiscard]] static inline auto ReadTLSAuthArgsFromEnv() -> bool { + auto* ca_cert = std::getenv("TLS_CA_CERT"); + auto* client_cert = std::getenv("TLS_CLIENT_CERT"); + auto* client_key = std::getenv("TLS_CLIENT_KEY"); + if (ca_cert != nullptr) { + if (not Auth::TLS::SetCACertificate(ca_cert)) { + return false; + } + } + if (client_cert != nullptr) { + if (not Auth::TLS::SetClientCertificate(client_cert)) { + return false; + } + } + if (client_key != nullptr) { + if (not Auth::TLS::SetClientKey(client_key)) { + return false; + } + } + if (Auth::GetAuthMethod() == AuthMethod::kTLS) { + if (not Auth::TLS::Validate()) { + return false; + } + } + return true; +} + #endif // INCLUDED_SRC_TEST_UTILS_TEST_ENV_HPP |