From c906a1c0f454295ddb4006a6e55123f748d2fce7 Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Sat, 24 Aug 2019 10:26:02 +0100 Subject: [PATCH] No required options in TOML parsing (#2245) --- nano/core_test/toml.cpp | 51 +++++++++++++++++++++++++++++++++++ nano/lib/rpcconfig.cpp | 14 +++++----- nano/node/websocketconfig.cpp | 2 +- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 6645895a2..0de22167b 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -447,6 +447,36 @@ TEST (toml, daemon_config_deserialize_no_defaults) ASSERT_NE (conf.node.stat_config.log_samples_filename, defaults.node.stat_config.log_samples_filename); } +/** There should be no required values **/ +TEST (toml, daemon_config_no_required) +{ + std::stringstream ss; + + // A config with no values, only categories + ss << R"toml( + [node] + [node.diagnostics.txn_tracking] + [node.httpcallback] + [node.ipc.local] + [node.ipc.tcp] + [node.logging] + [node.statistics.log] + [node.statistics.sampling] + [node.websocket] + [opencl] + [rpc] + [rpc.child_process] + )toml"; + + nano::tomlconfig toml; + toml.read (ss); + nano::daemon_config conf; + nano::daemon_config defaults; + conf.deserialize_toml (toml); + + ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message (); +} + /** Deserialize an rpc config with non-default values */ TEST (toml, rpc_config_deserialize_no_defaults) { @@ -485,3 +515,24 @@ TEST (toml, rpc_config_deserialize_no_defaults) ASSERT_NE (conf.rpc_process.ipc_port, defaults.rpc_process.ipc_port); ASSERT_NE (conf.rpc_process.num_ipc_connections, defaults.rpc_process.num_ipc_connections); } + +/** There should be no required values **/ +TEST (toml, rpc_config_no_required) +{ + std::stringstream ss; + + // A config with no values, only categories + ss << R"toml( + [version] + [process] + [secure] + )toml"; + + nano::tomlconfig toml; + toml.read (ss); + nano::rpc_config conf; + nano::rpc_config defaults; + conf.deserialize_toml (toml); + + ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message (); +} diff --git a/nano/lib/rpcconfig.cpp b/nano/lib/rpcconfig.cpp index 7ef2477ce..90c73a891 100644 --- a/nano/lib/rpcconfig.cpp +++ b/nano/lib/rpcconfig.cpp @@ -43,13 +43,13 @@ nano::error nano::rpc_secure_config::serialize_toml (nano::tomlconfig & toml) co nano::error nano::rpc_secure_config::deserialize_toml (nano::tomlconfig & toml) { - toml.get_required ("enable", enable); - toml.get_required ("verbose_logging", verbose_logging); - toml.get_required ("server_key_passphrase", server_key_passphrase); - toml.get_required ("server_cert_path", server_cert_path); - toml.get_required ("server_key_path", server_key_path); - toml.get_required ("server_dh_path", server_dh_path); - toml.get_required ("client_certs_path", client_certs_path); + toml.get ("enable", enable); + toml.get ("verbose_logging", verbose_logging); + toml.get ("server_key_passphrase", server_key_passphrase); + toml.get ("server_cert_path", server_cert_path); + toml.get ("server_key_path", server_key_path); + toml.get ("server_dh_path", server_dh_path); + toml.get ("client_certs_path", client_certs_path); return toml.get_error (); } diff --git a/nano/node/websocketconfig.cpp b/nano/node/websocketconfig.cpp index 611519993..14a5ce9ab 100644 --- a/nano/node/websocketconfig.cpp +++ b/nano/node/websocketconfig.cpp @@ -18,7 +18,7 @@ nano::error nano::websocket::config::serialize_toml (nano::tomlconfig & toml) co nano::error nano::websocket::config::deserialize_toml (nano::tomlconfig & toml) { toml.get ("enable", enabled); - toml.get_required ("address", address); + toml.get ("address", address); toml.get ("port", port); return toml.get_error (); }