fix: not forward admin API (#1628)

This commit is contained in:
cyan317
2024-09-05 15:06:57 +01:00
committed by Sergey Kuznetsov
parent 7b5e02731d
commit 443c74436e
6 changed files with 73 additions and 21 deletions

View File

@@ -259,22 +259,6 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfAPIVersionIsV2)
});
}
TEST_F(RPCForwardingProxyTest, ShouldNeverForwardFeatureWithVetoedFlag)
{
auto const apiVersion = 1u;
auto const method = "feature";
auto const params = json::parse(R"({"vetoed": true, "feature": "foo"})");
runSpawn([&](auto yield) {
auto const range = backend->fetchLedgerRange();
auto const ctx =
web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP, true);
auto const res = proxy.shouldForward(ctx);
ASSERT_FALSE(res);
});
}
TEST_F(RPCForwardingProxyTest, ShouldNeverForwardSubscribe)
{
auto const apiVersion = 1u;

View File

@@ -25,6 +25,7 @@
#include "util/AsioContextTestFixture.hpp"
#include "util/MockBackendTestFixture.hpp"
#include "util/MockPrometheus.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"
#include <boost/asio/impl/spawn.hpp>
@@ -539,3 +540,41 @@ TEST_F(RPCHelpersTest, ParseIssue)
std::runtime_error
);
}
struct IsAdminCmdParamTestCaseBundle {
std::string testName;
std::string method;
std::string testJson;
bool expected;
};
struct IsAdminCmdParameterTest : public TestWithParam<IsAdminCmdParamTestCaseBundle> {};
static auto
generateTestValuesForParametersTest()
{
return std::vector<IsAdminCmdParamTestCaseBundle>{
{"featureVetoedTrue", "feature", R"({"vetoed": true, "feature": "foo"})", true},
{"featureVetoedFalse", "feature", R"({"vetoed": false, "feature": "foo"})", true},
{"ledgerFullTrue", "ledger", R"({"full": true})", true},
{"ledgerAccountsTrue", "ledger", R"({"accounts": true})", true},
{"ledgerTypeTrue", "ledger", R"({"type": true})", true},
{"ledgerFullFalse", "ledger", R"({"full": false})", false},
{"ledgerAccountsFalse", "ledger", R"({"accounts": false})", false},
{"ledgerTypeFalse", "ledger", R"({"type": false})", false},
{"ledgerEntry", "ledger_entry", R"({"type": false})", false}
};
}
INSTANTIATE_TEST_CASE_P(
IsAdminCmdTest,
IsAdminCmdParameterTest,
ValuesIn(generateTestValuesForParametersTest()),
tests::util::NameGenerator
);
TEST_P(IsAdminCmdParameterTest, Test)
{
auto const testBundle = GetParam();
EXPECT_EQ(isAdminCmd(testBundle.method, boost::json::parse(testBundle.testJson).as_object()), testBundle.expected);
}