mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-25 08:00:22 +00:00
refactor: Change config section and key string literals into constants (#7095)
Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/beast/unit_test/suite.h>
|
||||
#include <xrpl/config/Constants.h>
|
||||
#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger.pb.h>
|
||||
#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
|
||||
|
||||
@@ -368,7 +367,8 @@ public:
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Verify the server actually started by checking the port
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
// NOLINTBEGIN(bugprone-unchecked-optional-access) grpcPort.has_value() checked above
|
||||
BEAST_EXPECT(*grpcPort > 0);
|
||||
@@ -394,7 +394,8 @@ public:
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Verify the server actually started by checking the port
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
// NOLINTBEGIN(bugprone-unchecked-optional-access) grpcPort.has_value() checked above
|
||||
BEAST_EXPECT(*grpcPort > 0);
|
||||
@@ -431,7 +432,8 @@ public:
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Verify the server actually started by checking the port
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
// NOLINTBEGIN(bugprone-unchecked-optional-access) grpcPort.has_value() checked above
|
||||
BEAST_EXPECT(*grpcPort > 0);
|
||||
@@ -465,9 +467,9 @@ public:
|
||||
|
||||
// Create config with only cert (missing key)
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
// Intentionally omit ssl_key
|
||||
|
||||
try
|
||||
@@ -491,9 +493,9 @@ public:
|
||||
|
||||
// Create config with only key (missing cert)
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", getServerKeyPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, getServerKeyPath().string());
|
||||
// Intentionally omit ssl_cert
|
||||
|
||||
try
|
||||
@@ -518,9 +520,9 @@ public:
|
||||
// Test 1: ssl_client_ca specified without any TLS config
|
||||
{
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_client_ca", getCACertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, getCACertPath().string());
|
||||
// Intentionally omit both ssl_cert and ssl_key
|
||||
|
||||
try
|
||||
@@ -539,10 +541,10 @@ public:
|
||||
// Test 2: ssl_client_ca with only ssl_cert (missing ssl_key)
|
||||
{
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_client_ca", getCACertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, getCACertPath().string());
|
||||
// Intentionally omit ssl_key
|
||||
|
||||
try
|
||||
@@ -563,10 +565,10 @@ public:
|
||||
// Test 3: ssl_client_ca with only ssl_key (missing ssl_cert)
|
||||
{
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", getServerKeyPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_client_ca", getCACertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, getServerKeyPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, getCACertPath().string());
|
||||
// Intentionally omit ssl_cert
|
||||
|
||||
try
|
||||
@@ -595,9 +597,9 @@ public:
|
||||
// Test 1: ssl_cert_chain specified without any TLS config
|
||||
{
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert_chain", getCACertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCertChain, getCACertPath().string());
|
||||
// Intentionally omit both ssl_cert and ssl_key
|
||||
|
||||
try
|
||||
@@ -616,10 +618,10 @@ public:
|
||||
// Test 2: ssl_cert_chain with only ssl_cert (missing ssl_key)
|
||||
{
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert_chain", getCACertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCertChain, getCACertPath().string());
|
||||
// Intentionally omit ssl_key
|
||||
|
||||
try
|
||||
@@ -655,7 +657,8 @@ public:
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Verify the server actually started by checking the port
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
// NOLINTBEGIN(bugprone-unchecked-optional-access) grpcPort.has_value() checked above
|
||||
BEAST_EXPECT(*grpcPort > 0);
|
||||
@@ -684,15 +687,16 @@ public:
|
||||
using namespace jtx;
|
||||
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", "/nonexistent/path/to/cert.pem");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", getServerKeyPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, "/nonexistent/path/to/cert.pem");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, getServerKeyPath().string());
|
||||
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Server should fail to start - verify port is 0
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
BEAST_EXPECT(*grpcPort == 0); // NOLINT(bugprone-unchecked-optional-access)
|
||||
}
|
||||
@@ -705,15 +709,16 @@ public:
|
||||
using namespace jtx;
|
||||
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", "/nonexistent/path/to/key.pem");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, "/nonexistent/path/to/key.pem");
|
||||
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Server should fail to start - verify port is 0
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
BEAST_EXPECT(*grpcPort == 0); // NOLINT(bugprone-unchecked-optional-access)
|
||||
}
|
||||
@@ -726,16 +731,17 @@ public:
|
||||
using namespace jtx;
|
||||
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", getServerKeyPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert_chain", "/nonexistent/path/to/chain.pem");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, getServerKeyPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCertChain, "/nonexistent/path/to/chain.pem");
|
||||
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Server should fail to start - verify port is 0
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
BEAST_EXPECT(*grpcPort == 0); // NOLINT(bugprone-unchecked-optional-access)
|
||||
}
|
||||
@@ -748,16 +754,17 @@ public:
|
||||
using namespace jtx;
|
||||
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", getServerKeyPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_client_ca", "/nonexistent/path/to/ca.pem");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, getServerKeyPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, "/nonexistent/path/to/ca.pem");
|
||||
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Server should fail to start - verify port is 0
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
BEAST_EXPECT(*grpcPort == 0); // NOLINT(bugprone-unchecked-optional-access)
|
||||
}
|
||||
@@ -775,16 +782,17 @@ public:
|
||||
emptyFile.close();
|
||||
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", "127.0.0.1");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", getServerKeyPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_client_ca", emptyCAPath.string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, "127.0.0.1");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, getServerKeyPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, emptyCAPath.string());
|
||||
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Server should fail to start due to empty CA file
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
BEAST_EXPECT(*grpcPort == 0); // NOLINT(bugprone-unchecked-optional-access)
|
||||
}
|
||||
@@ -798,18 +806,19 @@ public:
|
||||
|
||||
// Test with all TLS features enabled: cert, key, cert_chain, and client_ca
|
||||
auto cfg = envconfig();
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", getServerCertPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", getServerKeyPath().string());
|
||||
(*cfg)[SECTION_PORT_GRPC].set(
|
||||
"ssl_cert_chain", getCACertPath().string()); // Using CA as intermediate
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_client_ca", getCACertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, getServerCertPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, getServerKeyPath().string());
|
||||
(*cfg)[Sections::kPortGrpc].set(
|
||||
Keys::kSslCertChain, getCACertPath().string()); // Using CA as intermediate
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, getCACertPath().string());
|
||||
|
||||
Env env(*this, std::move(cfg));
|
||||
|
||||
// Verify the server started successfully
|
||||
auto const grpcPort = env.app().config()[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const grpcPort =
|
||||
env.app().config()[Sections::kPortGrpc].get<unsigned int>(Keys::kPort);
|
||||
BEAST_EXPECT(grpcPort.has_value());
|
||||
// NOLINTBEGIN(bugprone-unchecked-optional-access) grpcPort.has_value() checked above
|
||||
BEAST_EXPECT(*grpcPort > 0);
|
||||
|
||||
Reference in New Issue
Block a user