Wrong encoding in grpc wiremock request body

82 Views Asked by At

I am using

testImplementation('org.wiremock:wiremock-grpc-extension:0.4.0')

to mock an external grpc call with the following libraries/versions:

build.gradle:

id 'org.springframework.boot' version '3.1.7'
id 'com.google.protobuf' version '0.9.3'
implementation "io.grpc:grpc-protobuf:1.59.0"
implementation "io.grpc:grpc-services:1.59.0"
implementation "io.grpc:grpc-stub:1.59.0"
implementation "io.grpc:grpc-okhttp:1.59.0"
implementation "io.grpc:grpc-netty-shaded:1.59.0"
implementation 'com.google.protobuf:protobuf-java-util:3.22.3'
testImplementation 'org.wiremock:wiremock:3.3.1'
com.google.protobuf:protoc:3.22.3
io.grpc:protoc-gen-grpc-java:1.56.1

And my test works fine


    WireMockGrpcService service =
                    new WireMockGrpcService(
                            new WireMock(wireMockServer.port()),
                            "XXX.YYY"
                    );
    
    service.stubFor(
                    method("ZZZ")
                            .withRequestMessage(equalToMessage(Object.builder()...))
                            .willReturn(message(Response.builder()...)
            );

Wiremock successfully registers the stub:


    "id": "1a15546c-fc8c-45dc-bcd8-bbf6d4c0b6ff",
          "request": {
            "urlPath": "/XXX.YYY/ZZZ",
            "method": "POST",
            "bodyPatterns": [
              {
                "equalToJson": "{\n  \"field\": \"value\"\n}",
                "ignoreArrayOrder": true,
                "ignoreExtraElements": false
              }
            ]
          },
          "response": {
            "status": 200,
            "body": "{\n}",
            "headers": {
              "grpc-status-name": "OK"
            }
          },
          "uuid": "1a15546c-fc8c-45dc-bcd8-bbf6d4c0b6ff"
        }

and the request is logged correctly in wiremock /__admin/requests:


    "bodyAsBase64": "ewogICJhY2NvdW50SWQiOiAiNDE0MTE0NSIKfQ==",
            "body": "{\n  \"accountId\": \"4141145\"\n}",

However when I am trying to migrate to the following versions:


    id 'org.springframework.boot' version '3.2.1'
    id 'com.google.protobuf' version '0.9.4'
    implementation "io.grpc:grpc-protobuf:1.59.0"
    implementation "io.grpc:grpc-services:1.60.1"
    implementation "io.grpc:grpc-stub:1.60.1"
    implementation "io.grpc:grpc-okhttp:1.60.1"
    implementation "io.grpc:grpc-netty-shaded:1.60.1"
    implementation 'com.google.protobuf:protobuf-java-util:3.25.1'
    testImplementation 'org.wiremock:wiremock-standalone:3.3.1'
    com.google.protobuf:protoc:3.25.1
    io.grpc:protoc-gen-grpc-java:1.60.1

The same test fails with a wiremock mismatch:

Request was not matched
                                               =======================

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
POST                                                       | POST
[path]                                                     | /xm.protobuf.services.trading_mesh.meta_proxy.v1.Trades/G
/xm.protobuf.services.trading_mesh.meta_proxy.v1.Trades/G  | etPositionTrades
etPositionTrades                                           |
                                                           |
[equalToJson]                                              |                                                     <<<<< Body does not match
{                                                          |    ???
  "accountId" : "4141145"                                  |
}                                                          |

Wiremock /__admin/requests enter image description here

I am suspecting that the version upgrades changed the grpc client stub to include a binary request body instead of a json but I don't know how to verify that.

0

There are 0 best solutions below