-
Notifications
You must be signed in to change notification settings - Fork 296
Add fuzzing for BlockLoader endpoints #1839
Conversation
iroha::network::proto::BlocksRequest request; | ||
if (protobuf_mutator::libfuzzer::LoadProtoInput(true, data, size, &request)) { | ||
grpc::ServerContext context; | ||
MockServerWriter writer; |
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.
ServerWriter cannot be mocked :( I've tried with ServerWriterInterface, but it cannot be casted safely (e.g only via reinterpret_cast
. Here's an example of such mock (path test/module/vendor/grpc/grpc_mocks.hpp):
class MockServerWriter
: public grpc::ServerWriterInterface<iroha::protocol::ToriiResponse> {
MOCK_METHOD1(Write, void(iroha::protocol::ToriiResponse));
MOCK_METHOD2(Write,
bool(const iroha::protocol::ToriiResponse &,
grpc::WriteOptions));
MOCK_METHOD0(SendInitialMetadata, void());
MOCK_METHOD1(NextMessageSize, bool(uint32_t *));
};
But it's not really a good idea to use it. Need to think about that issue
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.
LGTM
Works inside run-iroha-dev.sh container
@@ -15,7 +26,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) { | |||
iroha::network::proto::BlocksRequest request; | |||
if (protobuf_mutator::libfuzzer::LoadProtoInput(true, data, size, &request)) { | |||
grpc::ServerContext context; | |||
fixture.block_loader_service_->retrieveBlocks(&context, &request, nullptr); | |||
fuzzing::MockServerWriter serverWriter; |
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.
Should be static, I guess
Moreover some calls probably should be mocked (particularly the ones that return boolean)
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 don't think it should be static - we pass a non-const raw point to it and have no idea what will happen with it inside.
I'm not sure what call do you mean - the only one which returns boolean is Write
with 2 args but we are not interested in it.
Signed-off-by: Konstantin Munichev <[email protected]>
Signed-off-by: Konstantin Munichev <[email protected]>
Signed-off-by: Konstantin Munichev <[email protected]>
Signed-off-by: Konstantin Munichev <[email protected]>
Signed-off-by: Konstantin Munichev <[email protected]>
f2c15ac
to
47d97fb
Compare
Description of the Change
Fuzzing for block loader endpoints (retrieveBlock and retrieveBlocks).
Benefits
Another endpoint is covered by fuzzing.
Possible Drawbacks
Hard to support until fuzzing in CI is not ready.
Usage Examples or Tests