Make integration test mode more obvious

Print a warning during startup, and handling the missing key options
gracefully (rather than dumping an exception to the overall main()
exception handler).

Print a critical error if the integration test options are missing or
invalid; without this an exception is thrown but it isn't obvious where
it comes from (especially if you forgot you compiled with integration
tests enabled).
This commit is contained in:
Jason Rhinelander 2021-04-13 23:32:59 -03:00
parent 5ac1206d31
commit 09742a64e3
2 changed files with 24 additions and 7 deletions

View file

@ -33,20 +33,24 @@ void command_line_parser::parse_args(int argc, char* argv[]) {
("bind-ip", po::value(&options_.ip)->default_value("0.0.0.0"), "IP to which to bind the server")
("version,v", po::bool_switch(&options_.print_version), "Print the version of this binary")
("help", po::bool_switch(&options_.print_help),"Shows this help message")
("stats-access-key", po::value(&options_.stats_access_keys)->multitoken(), "A public key (x25519) that will be given access to the `get_stats` lmq endpoint");
("stats-access-key", po::value(&options_.stats_access_keys)->multitoken(), "A public key (x25519) that will be given access to the `get_stats` lmq endpoint")
#ifdef INTEGRATION_TEST
("oxend-key", po::value(&options_.oxend_key), "Legacy secret key (integration testing only)")
("oxend-x25519-key", po::value(&options_.oxend_x25519_key), "x25519 secret key (integration testing only)")
("oxend-ed25519-key", po::value(&options_.oxend_ed25519_key), "ed25519 public key (integration testing only)");
#endif
;
// Add hidden ip and port options. You technically can use the `--ip=` and `--port=` with
// these here, but they are meant to be positional. More usefully, you can specify `ip=`
// and `port=` in the config file to specify them.
hidden.add_options()
("ip", po::value<std::string>(), "(unused)")
("port", po::value(&options_.port), "Port to listen on")
("oxend-key", po::value(&options_.oxend_key), "Legacy secret key (test only)")
("oxend-rpc-ip", po::value(&old_rpc_ip), "Obsolete: oxend HTTP RPC IP; use --oxend-rpc with the zmq address instead")
("oxend-rpc-port", po::value(&old_rpc_port), "Obsolete: oxend HTTP RPC port; use --oxend-rpc with the zmq address instead")
("lokid-rpc-ip", po::value(&old_rpc_ip), "Backwards compatible option for oxend RPC IP")
("lokid-rpc-port", po::value(&old_rpc_port), "Backwards compatible option for oxend RPC port")
("oxend-x25519-key", po::value(&options_.oxend_x25519_key), "x25519 secret key (test only)")
("oxend-ed25519-key", po::value(&options_.oxend_ed25519_key), "ed25519 public key (test only)");
;
// clang-format on
all.add(desc_).add(hidden);

View file

@ -93,6 +93,10 @@ int main(int argc, char* argv[]) {
// Always print version for the logs
OXEN_LOG(info, "{}", oxen::STORAGE_SERVER_VERSION_INFO);
#ifdef INTEGRATION_TEST
OXEN_LOG(warn, "Compiled for integration tests; this binary will not function as a regular storage server!");
#endif
if (options.ip == "127.0.0.1") {
OXEN_LOG(critical,
"Tried to bind oxen-storage to localhost, please bind "
@ -145,9 +149,18 @@ int main(int argc, char* argv[]) {
// Normally we request the key from daemon, but in integrations/swarm
// testing we are not able to do that, so we extract the key as a
// command line option:
const auto private_key = legacy_seckey::from_hex(options.oxend_key);
const auto private_key_ed25519 = ed25519_seckey::from_hex(options.oxend_ed25519_key);
const auto private_key_x25519 = x25519_seckey::from_hex(options.oxend_x25519_key);
legacy_seckey private_key{};
ed25519_seckey private_key_ed25519{};
x25519_seckey private_key_x25519{};
try {
private_key = legacy_seckey::from_hex(options.oxend_key);
private_key_ed25519 = ed25519_seckey::from_hex(options.oxend_ed25519_key);
private_key_x25519 = x25519_seckey::from_hex(options.oxend_x25519_key);
} catch (...) {
OXEN_LOG(critical, "This storage server binary is compiled in integration test mode: "
"--oxend-key, --oxend-x25519-key, and --oxend-ed25519-key are required");
throw;
}
#endif
sn_record_t me{"0.0.0.0", options.port, options.lmq_port,