-
Notifications
You must be signed in to change notification settings - Fork 130
[WIP] 3116 valid number rpc params #1901
base: master
Are you sure you want to change the base?
Conversation
@@ -69,6 +70,15 @@ public String getVersion() { | |||
return params; | |||
} | |||
|
|||
@JsonIgnore | |||
public void assertMaxLength(final int expectedLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest reworking the structure of this code a bit by:
- Adding a method
int getMaxAllowedParams()
to theJsonRpcMethod
interface - Adding a
default
methodassertValidRequest(JsonRpcRequest request)
toJsonRpcMethod
that throws anInvalidJsonRcpParameters
exception as you have here if there are too many params - Validating the request by calling
jsonRpcMethod.assertValidRequest(request)
before executingjsonRpcMethod.response(request)
inJsonRpcHttpService
This will make it straightforward to consistently enforce this validation without expecting every method to run these checks manually. And it allows methods to override the default validation if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much! Definitely a better code structure, I will do my best to implement it.
Quick question : should I still manually add a tooManyParams test for every method, or should I just add one test for one method and "assume" that it will be correct for other methods ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems kind of painful to handcraft tests for every method. But if there was some way to "automatically" test each method, that would be cool. One idea:
- Write a parameterized test (example) that runs for every method and constructs a request with 1 too many parameters, then verifies that the expected exception is thrown
Otherwise, I think we can probably get away with just adding a single test to JsonRpcHttpServiceTest
.
PR description
WIP:
Fixed Issue(s)
Fixes #3116