Forward feature RPC (#1440)

Fixes #1436 

This is a temporary implementation of the `feature` RPC that will always
return `noPermission` iff `vetoed` is set.
If `vetoed` isn't specified, Clio will always forward the request to
`rippled` instead.

In the future, #1131 will implement a Clio-native `feature` RPC. This
requires specific support from `libxrpl` side and that is not going to
be available till at least 2.2.1, hence the temporary forwarding.

It would be great to review the error message and code so that we pick
the right one from the start.

Co-authored-by: Sergey Kuznetsov <skuznetsov@ripple.com>
This commit is contained in:
Alex Kremer
2024-06-11 11:51:03 +02:00
committed by GitHub
parent 1125b09611
commit 42c970a2a3
8 changed files with 268 additions and 2 deletions

View File

@@ -67,6 +67,7 @@ target_sources(
rpc/handlers/BookOffersTests.cpp
rpc/handlers/DefaultProcessorTests.cpp
rpc/handlers/DepositAuthorizedTests.cpp
rpc/handlers/FeatureTests.cpp
rpc/handlers/GatewayBalancesTests.cpp
rpc/handlers/GetAggregatePriceTests.cpp
rpc/handlers/LedgerDataTests.cpp

View File

@@ -260,6 +260,38 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfAPIVersionIsV2)
});
}
TEST_F(RPCForwardingProxyTest, ShouldForwardFeatureWithoutVetoedFlag)
{
auto const apiVersion = 1u;
auto const method = "feature";
auto const params = json::parse(R"({"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_TRUE(res);
});
}
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

@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
/*
This file is part of clio: https://github.com/XRPLF/clio
Copyright (c) 2024, the clio developers.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "rpc/Errors.hpp"
#include "rpc/common/AnyHandler.hpp"
#include "rpc/common/Types.hpp"
#include "rpc/handlers/Feature.hpp"
#include "util/Fixtures.hpp"
#include <boost/json/parse.hpp>
#include <gtest/gtest.h>
using namespace rpc;
class RPCFeatureHandlerTest : public HandlerBaseTest {};
TEST_F(RPCFeatureHandlerTest, AlwaysNoPermissionForVetoed)
{
runSpawn([](auto yield) {
auto const handler = AnyHandler{FeatureHandler{}};
auto const output =
handler.process(boost::json::parse(R"({"vetoed": true, "feature": "foo"})"), Context{yield});
ASSERT_FALSE(output);
auto const err = rpc::makeError(output.result.error());
EXPECT_EQ(err.at("error").as_string(), "noPermission");
EXPECT_EQ(
err.at("error_message").as_string(), "The admin portion of feature API is not available through Clio."
);
});
}