[Minor] Ignore extra json rpc params (#1261)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
mbaxter 6 years ago committed by GitHub
parent d994cb820d
commit 4607f9c5d2
  1. 2
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/JsonRpcRequest.java
  2. 22
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java

@ -19,12 +19,14 @@ import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.google.common.base.Objects;
@JsonIgnoreProperties(ignoreUnknown = true)
public class JsonRpcRequest {
private JsonRpcRequestId id;

@ -202,6 +202,28 @@ public class JsonRpcHttpServiceTest {
}
}
@Test
public void handleUnknownRequestFields() throws Exception {
final String id = "123";
// Create a request with an extra "beta" param
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":"
+ Json.encode(id)
+ ",\"method\":\"net_version\", \"beta\":true}");
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidJsonRpcResult(json, id);
// Check result
final String result = json.getString("result");
assertThat(result).isEqualTo(String.valueOf(CHAIN_ID));
}
}
@Test
public void getSocketAddressWhenActive() {
final InetSocketAddress socketAddress = service.socketAddress();

Loading…
Cancel
Save