Add more details to rpc http/ws apis error message (#4538)

* Return invalid RPC/WS api declared

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/4547/head
Gabriel Camargo Fukushima 2 years ago committed by GitHub
parent 59d30448e9
commit 226557af40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  2. 14
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  3. 5
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcApis.java

@ -27,6 +27,7 @@ import static org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration.DEF
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT; import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.VALID_APIS;
import static org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; import static org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT;
import static org.hyperledger.besu.ethereum.permissioning.GoQuorumPermissioningConfiguration.QIP714_DEFAULT_BLOCK; import static org.hyperledger.besu.ethereum.permissioning.GoQuorumPermissioningConfiguration.QIP714_DEFAULT_BLOCK;
import static org.hyperledger.besu.metrics.BesuMetricCategory.DEFAULT_METRIC_CATEGORIES; import static org.hyperledger.besu.metrics.BesuMetricCategory.DEFAULT_METRIC_CATEGORIES;
@ -1854,11 +1855,21 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|| rpcEndpointServiceImpl.hasNamespace(apiName); || rpcEndpointServiceImpl.hasNamespace(apiName);
if (!jsonRPCHttpOptionGroup.rpcHttpApis.stream().allMatch(configuredApis)) { if (!jsonRPCHttpOptionGroup.rpcHttpApis.stream().allMatch(configuredApis)) {
throw new ParameterException(this.commandLine, "Invalid value for option '--rpc-http-apis'"); List<String> invalidHttpApis = new ArrayList<String>(jsonRPCHttpOptionGroup.rpcHttpApis);
invalidHttpApis.removeAll(VALID_APIS);
throw new ParameterException(
this.commandLine,
"Invalid value for option '--rpc-http-api': invalid entries found "
+ invalidHttpApis.toString());
} }
if (!jsonRPCWebsocketOptionGroup.rpcWsApis.stream().allMatch(configuredApis)) { if (!jsonRPCWebsocketOptionGroup.rpcWsApis.stream().allMatch(configuredApis)) {
throw new ParameterException(this.commandLine, "Invalid value for option '--rpc-ws-apis'"); List<String> invalidWsApis = new ArrayList<String>(jsonRPCWebsocketOptionGroup.rpcWsApis);
invalidWsApis.removeAll(VALID_APIS);
throw new ParameterException(
this.commandLine,
"Invalid value for option '--rpc-ws-api': invalid entries found "
+ invalidWsApis.toString());
} }
final boolean validHttpApiMethods = final boolean validHttpApiMethods =

@ -2302,7 +2302,19 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
// PicoCLI uses longest option name for message when option has multiple names, so here plural. // PicoCLI uses longest option name for message when option has multiple names, so here plural.
assertThat(commandErrorOutput.toString(UTF_8)) assertThat(commandErrorOutput.toString(UTF_8))
.contains("Invalid value for option '--rpc-http-apis'"); .contains("Invalid value for option '--rpc-http-api': invalid entries found [BOB]");
}
@Test
public void rpcWsApisPropertyWithInvalidEntryMustDisplayError() {
parseCommand("--rpc-ws-api", "ETH,BOB,TEST");
Mockito.verifyNoInteractions(mockRunnerBuilder);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8).trim())
.contains("Invalid value for option '--rpc-ws-api': invalid entries found [BOB, TEST]");
} }
@Test @Test

@ -16,6 +16,8 @@ package org.hyperledger.besu.ethereum.api.jsonrpc;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public enum RpcApis { public enum RpcApis {
ETH, ETH,
@ -41,4 +43,7 @@ public enum RpcApis {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final List<RpcApis> ALL_JSON_RPC_APIS = public static final List<RpcApis> ALL_JSON_RPC_APIS =
Arrays.asList(ETH, DEBUG, MINER, NET, PERM, WEB3, ADMIN, EEA, PRIV, TXPOOL, TRACE, PLUGINS); Arrays.asList(ETH, DEBUG, MINER, NET, PERM, WEB3, ADMIN, EEA, PRIV, TXPOOL, TRACE, PLUGINS);
public static final List<String> VALID_APIS =
Stream.of(RpcApis.values()).map(RpcApis::name).collect(Collectors.toList());
} }

Loading…
Cancel
Save