Skip to content

Commit 6e75075

Browse files
committed
protovalidate: don't panic in streaming interceptor
The streaming interceptor should match the behavior of the unary interceptor and gracefully handle non-protobuf messages. Signed-off-by: Akshay Shah <[email protected]>
1 parent 01f9948 commit 6e75075

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

interceptors/protovalidate/protovalidate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ func (w *wrappedServerStream) RecvMsg(m interface{}) error {
6363
return err
6464
}
6565

66-
msg := m.(proto.Message)
66+
msg, ok := m.(proto.Message)
67+
if !ok {
68+
return errors.New("unsupported message type")
69+
}
6770
if w.options.shouldIgnoreMessage(msg.ProtoReflect().Type()) {
6871
return nil
6972
}

interceptors/protovalidate/protovalidate_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func TestUnaryServerInterceptor(t *testing.T) {
4545
assert.Equal(t, codes.InvalidArgument, status.Code(err))
4646
})
4747

48+
t.Run("not_protobuf", func(t *testing.T) {
49+
_, err = interceptor(context.Background(), "not protobuf", info, handler)
50+
assert.Error(t, err)
51+
assert.Equal(t, codes.Unknown, status.Code(err))
52+
})
53+
4854
interceptor = protovalidate_middleware.UnaryServerInterceptor(validator,
4955
protovalidate_middleware.WithIgnoreMessages(testvalidate.BadUnaryRequest.ProtoReflect().Type()),
5056
)

0 commit comments

Comments
 (0)