summaryrefslogtreecommitdiff
path: root/test/utils/test_env.hpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-02 16:47:13 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-04 16:05:08 +0200
commitc2f7ead468d5e65c57e7ecb49d7fbba4254c46b7 (patch)
treeb96ce2e63d9d6a2d486cb4133c290187156b97ac /test/utils/test_env.hpp
parent0d60cd9ba4a5c18b01b6ef996434953071f0576e (diff)
downloadjustbuild-c2f7ead468d5e65c57e7ecb49d7fbba4254c46b7.tar.gz
Replace the Auth and Auth::TLS singletons
Use a builder pattern for creation and validation, in a manner that allows also other authentication methods to be added in the future besides the current TLS/SSL. The main Auth instances are built early and then passed by not_null const pointers, to avoid passing temporaries, replacing the previous Auth::TLS instances passed by simple nullable const pointers. Where needed, these passed Auth instances are also stored, by const ref. Tests also build Auth instances as needed, either with the default 'no certification' or from the test environment arguments.
Diffstat (limited to 'test/utils/test_env.hpp')
-rw-r--r--test/utils/test_env.hpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/test/utils/test_env.hpp b/test/utils/test_env.hpp
index d9c60fb8..30eba26c 100644
--- a/test/utils/test_env.hpp
+++ b/test/utils/test_env.hpp
@@ -16,6 +16,7 @@
#define INCLUDED_SRC_TEST_UTILS_TEST_ENV_HPP
#include <cstdlib>
+#include <filesystem>
#include <map>
#include <optional>
#include <sstream>
@@ -62,31 +63,28 @@ static inline void ReadCompatibilityFromEnv() {
: std::make_optional(std::string{serve_address});
}
-[[nodiscard]] static inline auto ReadTLSAuthArgsFromEnv() -> bool {
+[[nodiscard]] static inline auto ReadTLSAuthCACertFromEnv()
+ -> std::optional<std::filesystem::path> {
auto* ca_cert = std::getenv("TLS_CA_CERT");
+ return ca_cert == nullptr
+ ? std::nullopt
+ : std::make_optional(std::filesystem::path(ca_cert));
+}
+
+[[nodiscard]] static inline auto ReadTLSAuthClientCertFromEnv()
+ -> std::optional<std::filesystem::path> {
auto* client_cert = std::getenv("TLS_CLIENT_CERT");
+ return client_cert == nullptr
+ ? std::nullopt
+ : std::make_optional(std::filesystem::path(client_cert));
+}
+
+[[nodiscard]] static inline auto ReadTLSAuthClientKeyFromEnv()
+ -> std::optional<std::filesystem::path> {
auto* client_key = std::getenv("TLS_CLIENT_KEY");
- if (ca_cert != nullptr) {
- if (not Auth::TLS::Instance().SetCACertificate(ca_cert)) {
- return false;
- }
- }
- if (client_cert != nullptr) {
- if (not Auth::TLS::Instance().SetClientCertificate(client_cert)) {
- return false;
- }
- }
- if (client_key != nullptr) {
- if (not Auth::TLS::Instance().SetClientKey(client_key)) {
- return false;
- }
- }
- if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) {
- if (not Auth::TLS::Instance().Validate()) {
- return false;
- }
- }
- return true;
+ return client_key == nullptr
+ ? std::nullopt
+ : std::make_optional(std::filesystem::path(client_key));
}
[[nodiscard]] static inline auto ReadRemoteServeReposFromEnv()