testinggospels / camouflage

Camouflage is a backend mocking tool for HTTP, gRPC, Websockets and Thrift protocols, which helps you carry out your front end prototyping, unit testing, functional/performance testing in silos, in absence of one or more Microservices/APIs.
https://testinggospels.github.io/camouflage/
MIT License
270 stars 26 forks source link

Doesn't support grpc package names with "." #71

Closed ctoomey closed 3 years ago

ctoomey commented 3 years ago

Describe the bug When a grpc package name contains one or more periods, e.g. foo.package, the mock grpc server fails to find the mocks and returns the error "The server does not implement the method /foo.package.HelloWorld/SayAnything".

Replacing the . in the package name with _ works around it, but when needing to use this for real projects with such package names and clients that use them, that's a costly workaround.

To Reproduce Steps to reproduce the behavior:

  1. Mock File Content grpc/mocks/foo.package/HelloWorld/SayAnything.mock:
    {
    "message": "foobar!!!!!"
    }
  2. Proto file grpc/protos/hw5.proto:
    
    syntax = "proto3";

package foo.package;

service HelloWorld { rpc SayAnything (Greeting) returns (Greeting) { } }

message Greeting { string message = 1; }

3. Error Stack Trace
`grpcurl -v -d '{"message":"foobar!!"}' -proto grpc/protos/hw5.proto -plaintext localhost:4312 foo.package.HelloWorld/SayAnything`

Resolved method descriptor: rpc SayAnything ( .foo.package.Greeting ) returns ( .foo.package.Greeting );

Request metadata to send: (empty)

Response headers received: content-type: application/grpc+proto date: Fri, 23 Jul 2021 18:14:16 GMT grpc-accept-encoding: identity

Response trailers received: (empty) Sent 1 request and received 0 responses ERROR: Code: Unimplemented Message: The server does not implement the method /foo.package.HelloWorld/SayAnything


**Expected behavior**
It should work like it does when the package has no `.`:

`grpcurl -v -d '{"message":"foobar!!"}' -proto grpc/protos/hw4.proto -plaintext localhost:4312 foo_package.HelloWorld/SayAnything`

Resolved method descriptor: rpc SayAnything ( .foo_package.Greeting ) returns ( .foo_package.Greeting );

Request metadata to send: (empty)

Response headers received: content-type: application/grpc+proto date: Fri, 23 Jul 2021 18:16:01 GMT grpc-accept-encoding: identity

Response contents: { "message": "foobar!!!!!" }

Response trailers received: (empty) Sent 1 request and received 1 response


**Desktop (please complete the following information):**
 - OS: MacOS Catalina
 - camouflage-server 0.5.1

** Log file **

2021-07-23 11:10:10 debug: Camouflage configuration:

mocks_dir | ws.mocks_dir | http.port | http.enable | https.enable | http2.enable | grpc.enable | ws.enable | cache.enable | injection.enable | origins | ssl.key | ssl.cert | https.port | http2.port | grpc.host | grpc.port | grpc.mocks_dir | grpc.protos_dir | loglevel | backup.enable | backup.cron | configFile | ext_helpers | cache.ttl_seconds

./mocks | ./ws_mocks | 8080 | false | false | false | true | false | false | false | http://localhost:3000/,http://localhost:3001/,http://localhost:5000/ | ./certs/server.key | ./certs/server.cert | 8443 | 8081 | 8082 | localhost | 4312 | ./grpc/mocks | ./grpc/protos | debug | false | 0 | config.yml | ./custom_handlebar.json | 300

2021-07-23 11:10:10 info: [33656] Master Started 2021-07-23 11:10:10 info: Cluster metrics server listening to 5555, metrics exposed on http://localhost:5555/metrics (node:33656) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated. (Use node --trace-deprecation ... to show where the warning was created) 2021-07-23 11:10:12 info: CORS enabled for http://localhost:3000/, http://localhost:3001/, http://localhost:5000/ 2021-07-23 11:10:12 info: [33659] Worker started 2021-07-23 11:10:12 info: Handlebar helpers registration started 2021-07-23 11:10:12 warn: Code Injection is disabled. Handlebars such as code and inject and functionalities such as external helpers, will not work.
2021-07-23 11:10:12 info: Handlebar helpers registration completed 2021-07-23 11:10:12 debug: Registering Unary method: createBlog 2021-07-23 11:10:12 debug: Registering Unary method: listBlogs 2021-07-23 11:10:12 debug: Registering Unary method: SayHello 2021-07-23 11:10:12 debug: Registering Unary method: SayAnything 2021-07-23 11:10:12 debug: Registering method with server side streaming: GenIntStream 2021-07-23 11:10:12 debug: Registering method with BIDI streaming: IntStreamToStatsStream 2021-07-23 11:10:12 debug: Registering Unary method: SayAnything 2021-07-23 11:10:12 debug: Registering Unary method: createTodo 2021-07-23 11:10:12 debug: Registering Unary method: readTodo 2021-07-23 11:10:12 debug: Registering method with server side streaming: readTodoStream 2021-07-23 11:10:12 debug: Registering method with client side streaming: createTodoStream 2021-07-23 11:10:12 debug: Registering method with BIDI streaming: createTodoBidiStream (node:33659) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated. (Use node --trace-deprecation ... to show where the warning was created) 2021-07-23 11:10:12 info: Worker sharing gRPC server at localhost:4312 ⛳ 2021-07-23 11:10:34 debug: Mock file path: grpc/mocks/foo_package/HelloWorld/SayAnything.mock 2021-07-23 11:10:34 debug: Response: { "message": "foobar!!!!!" }

shubhendumadhukar commented 3 years ago

Thanks @ctoomey for bringing this to notice. Great catch!

From initial debugging, it appears grpc proto loader isn't loading the protofiles correctly if the package name contains a '.'

I'll run few more isolated tests to determine if it is a Camouflage issue or if needs to be raised in proto loader project. I hope the workaround, i.e. not having a dot in package name, works for you in the meantime.

shubhendumadhukar commented 3 years ago

Update

It was a Camouflage issue caused due to incorrect parsing of the packageDefinition object. The fix is available in dev branch and I'd merge it to main for a new release after few more tests.

If you'd like to test the changes yourself, you could checkout develop branch and build from source

shubhendumadhukar commented 3 years ago

Please upgrade to 0.5.2:

ctoomey commented 3 years ago

Thanks so much for the quick fix @shubhendumadhukar ! I updated and verified it works correctly now.

I ran into a couple other issues that I was able to workaround by editing the code locally; I'll create separate tickets for those.