mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-05 16:58:00 +00:00
refactor: Replace all old instances of Config with New Config (#1627)
Fixes #1184 Previous PR's found [here](https://github.com/XRPLF/clio/pull/1593) and [here](https://github.com/XRPLF/clio/pull/1544)
This commit is contained in:
@@ -16,11 +16,18 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include "util/LoggerFixtures.hpp"
|
||||
#include "util/config/Config.hpp"
|
||||
#include "util/log/Logger.hpp"
|
||||
#include "util/newconfig/Array.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigFileJson.hpp"
|
||||
#include "util/newconfig/ConfigValue.hpp"
|
||||
#include "util/newconfig/Types.hpp"
|
||||
#include "web/dosguard/WhitelistHandler.hpp"
|
||||
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -29,10 +36,21 @@
|
||||
#include <vector>
|
||||
|
||||
using namespace util;
|
||||
using namespace util::config;
|
||||
using namespace web::dosguard;
|
||||
|
||||
struct WhitelistHandlerTest : NoLoggerFixture {};
|
||||
|
||||
inline ClioConfigDefinition
|
||||
getParseWhitelistHandlerConfig(boost::json::value val)
|
||||
{
|
||||
ConfigFileJson const jsonVal{val.as_object()};
|
||||
auto config = ClioConfigDefinition{{"dos_guard.whitelist.[]", Array{ConfigValue{ConfigType::String}}}};
|
||||
auto const errors = config.parse(jsonVal);
|
||||
[&]() { ASSERT_FALSE(errors.has_value()); }();
|
||||
return config;
|
||||
}
|
||||
|
||||
TEST_F(WhitelistHandlerTest, TestWhiteListIPV4)
|
||||
{
|
||||
struct MockResolver {
|
||||
@@ -58,7 +76,7 @@ TEST_F(WhitelistHandlerTest, TestWhiteListIPV4)
|
||||
.Times(3)
|
||||
.WillRepeatedly([](auto hostname) -> std::vector<std::string> { return {std::string{hostname}}; });
|
||||
|
||||
Config const cfg{boost::json::parse(JSONDataIPV4)};
|
||||
ClioConfigDefinition const cfg{getParseWhitelistHandlerConfig(boost::json::parse(JSONDataIPV4))};
|
||||
WhitelistHandler const whitelistHandler{cfg, mockResolver};
|
||||
|
||||
EXPECT_TRUE(whitelistHandler.isWhiteListed("192.168.1.10"));
|
||||
@@ -80,7 +98,7 @@ TEST_F(WhitelistHandlerTest, TestWhiteListResolvesHostname)
|
||||
}
|
||||
)JSON";
|
||||
|
||||
Config const cfg{boost::json::parse(JSONDataIPV4)};
|
||||
ClioConfigDefinition const cfg{getParseWhitelistHandlerConfig(boost::json::parse(JSONDataIPV4))};
|
||||
WhitelistHandler const whitelistHandler{cfg};
|
||||
|
||||
EXPECT_TRUE(whitelistHandler.isWhiteListed("127.0.0.1"));
|
||||
@@ -102,7 +120,7 @@ TEST_F(WhitelistHandlerTest, TestWhiteListIPV6)
|
||||
}
|
||||
)JSON";
|
||||
|
||||
Config const cfg{boost::json::parse(JSONDataIPV6)};
|
||||
ClioConfigDefinition const cfg{getParseWhitelistHandlerConfig(boost::json::parse(JSONDataIPV6))};
|
||||
WhitelistHandler const whitelistHandler{cfg};
|
||||
|
||||
EXPECT_TRUE(whitelistHandler.isWhiteListed("2002:1dd8:85a7:0000:0000:8a6e:0000:1111"));
|
||||
|
||||
Reference in New Issue
Block a user