fix: check obj type in protobufBinding (#2851)

* fix: check obj type in protobufBinding

* fix: UnitTest for invalid proto obj
This commit is contained in:
Tevic
2021-09-07 10:10:32 +08:00
committed by GitHub
parent deb83b6365
commit eab47b5423
2 changed files with 13 additions and 1 deletions
+7
View File
@@ -1339,6 +1339,13 @@ func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body
err := b.Bind(req, &obj)
assert.Error(t, err)
invalid_obj := FooStruct{}
req.Body = ioutil.NopCloser(strings.NewReader(`{"msg":"hello"}`))
req.Header.Add("Content-Type", MIMEPROTOBUF)
err = b.Bind(req, &invalid_obj)
assert.Error(t, err)
assert.Equal(t, err.Error(), "obj is not ProtoMessage")
obj = protoexample.Test{}
req = requestWithBody("POST", badPath, badBody)
req.Header.Add("Content-Type", MIMEPROTOBUF)