I have a grpc interaction which validates token. T...
# protobufs
s
I have a grpc interaction which validates token. The token gets passed in header and hence request is empty. Looks like when request is empty, pact plugin is not working. I am getting an error as below. Can someone please help ?
Copy code
Error:      	Received unexpected error:
        	    retreived an empty message
Copy code
UsingPlugin(message.PluginConfig{
			Plugin:  "protobuf",
			Version: "0.2.4",
		}).
u
Is the token being pass in gRPC metadata, or as an HTTP header?
s
It gets passed in metadata
@uglyog can you help me with this ? Our team is looking to use grpc contract testing and we are stuck with this issue.
j
I think this is an issue i brought up with @Matt (pactflow.io / pact-js / pact-go) and he pointed me to this existing issue: https://github.com/pact-foundation/pact-go/issues/250 I added a comment on the issue with a bit of detail
πŸ‘ 1
s
Thanks @Jason Taylor for pointing out the issue. @uglyog @Matt (pactflow.io / pact-js / pact-go) Could you please let us know when can we expect a fix for this ?
@uglyog @Matt (pactflow.io / pact-js / pact-go) can you provide us any update ?
m
I’m confused Sathish. Are you trying to send an empty request? The above issue is where there is no request being sent
s
Actually we are sending empty request. proto file is something like below. message ValidateToken { }
m
Can you please share what the code would look like that needs to be supported?
j
i think it is simply this?
Copy code
grpcInteraction := `{
		"pact:content-type": "application/protobuf",
		"request": {
		},
all fields are optional, no fields passed in request
πŸ‘ 1
m
so are you expecting a response with a token or something, is that the use case? I’m confused about how the token is being sent across the wire?
s
Token is sent in metadata and the request is empty
gRPC empty request with metadata containing token is sent on the wire, the gRPC response will contain response based on token validation
m
I’m just struggling with the metadata bit. It might be outside of my knowledge - where is the metadata specified? In the plugin json configuration or something?
u
It is the message metadata that is mapped to the gRPC metadata. I.e. the key-values that can be associated with the RPC call (not encoded in the body which is represented by the proto file.
s
Yeah it would look something like below:
Copy code
"pact:proto": "` + path + `",
		"pact:proto-service": "Service/ValidateToken",
		"pact:content-type": "application/protobuf",
		"request": {
		},
		"metadata" : {
			"Auth": "matching(type, 'value')"
		}
j
i think the metadata aspect can be ignored - i don’t think it is relevant.
s
Its not relevant to the issue here yep !
j
so here is the diff for the example grpc consumer in pact-go that demonstrates the issue:
Copy code
import (
@@ -37,8 +34,6 @@ func TestGrpcInteraction(t *testing.T) {
                "pact:proto-service": "RouteGuide/GetFeature",
                "pact:content-type": "application/protobuf",
                "request": {
-                       "latitude": "matching(number, 180)",
-                       "longitude": "matching(number, 200)"
                },
                "response": {
trying to run the consumer:
Copy code
$ go test .
2023-02-02T15:38:13.418161Z  WARN tokio-runtime-worker pact_plugin_driver::metrics: 

Please note:
We are tracking this plugin load anonymously to gather important usage statistics.
To disable tracking, set the 'pact_do_not_track' environment variable to 'true'.


--- FAIL: TestGrpcInteraction (0.66s)
    grpc_consumer_test.go:89: 
                Error Trace:    grpc_consumer_test.go:89
                Error:          Received unexpected error:
                                retreived an empty message
                Test:           TestGrpcInteraction
FAIL
FAIL    <http://github.com/pact-foundation/pact-go/v2/examples/grpc|github.com/pact-foundation/pact-go/v2/examples/grpc>     0.670s
FAIL
u
I have released version 0.2.5 of the plugin with a fix for the empty message issue
m
Awesome, thanks Ron
I think the issue is in the protobuf plugin, but if it’s in Go I can fix. Would you mind please re-testing with the latest plugin?
s
Great thanks @uglyog @Matt (pactflow.io / pact-js / pact-go) yes we will retest it and post here
πŸ‘ 1
j
looks like still getting error with newer plugin:
Copy code
$ ~/.pact/bin/pact-plugin-cli list
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Name     ┆ Version ┆ Interface Version ┆ Directory                              ┆ Status  β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•ͺ═════════β•ͺ═══════════════════β•ͺ════════════════════════════════════════β•ͺ═════════║
β”‚ protobuf ┆ 0.2.5   ┆ 1                 ┆ /home/dev/.pact/plugins/protobuf-0.2.5 ┆ enabled β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
(.venv) dev ➜ ~/ws/pact-go/examples/grpc (2.x.x βœ—) $ go test -v .
=== RUN   TestGrpcInteraction
2023-02-03T14:31:21.293882Z  WARN tokio-runtime-worker pact_plugin_driver::metrics: 

Please note:
We are tracking this plugin load anonymously to gather important usage statistics.
To disable tracking, set the 'pact_do_not_track' environment variable to 'true'.


    grpc_consumer_test.go:89: 
                Error Trace:    grpc_consumer_test.go:89
                Error:          Received unexpected error:
                                retreived an empty message
                Test:           TestGrpcInteraction
--- FAIL: TestGrpcInteraction (0.65s)
FAIL
FAIL    <http://github.com/pact-foundation/pact-go/v2/examples/grpc|github.com/pact-foundation/pact-go/v2/examples/grpc>     0.652s
FAIL
s
Interestingly it works with version: v2.0.0-beta.14.0.20221026030030-3bb31bcc34a1 But does not work with version: v2.0.0-beta.17.0.20221222235702-6e805a539d1b - which has provider_state capability
@Matt (pactflow.io / pact-js / pact-go) we might need fix from go as well to add both provider_state and fix for empty request
u
I tested Go, but I may have had the older version
s
ah cool, yeah if newer version is made available that would be great.
m
Taking a look now gents
OK looks like I had a check when fetching the bodies that threw an error if it was of zero-length. The latest in the 2.x.x should allow that use case. I’m not quite sure of the side effects of that change as this is on the boundary between Golang and the shared library. I think it’s a valid scenario though, and it was just too cautious type guarding on my part
s
Ok yeah it works now thanks @Matt (pactflow.io / pact-js / pact-go) @uglyog
πŸ™Œ 1