hoverfly icon indicating copy to clipboard operation
hoverfly copied to clipboard

Binary data in request not working

Open Khazrak opened this issue 7 years ago • 6 comments

I'm trying to record a http post to Docker using Remote API where I send a tar file (via a stream) in Java via OkHttp Client. Hoverfly records the binary data and shows green in captureMode but fails in simulation mode. My guess is that the JSON doesn't like the binary data in the request. (I got Wiremock to do this and I would like to avoid having Wiremock for one measly test).

image_tarball_import.json.txt

https://docs.docker.com/engine/api/v1.26/#operation/ImageLoad "Tar archive containing images"

Khazrak avatar Mar 20 '17 21:03 Khazrak

Hey @Khazrak,

There is some checks around binary data in the body, but this is only on response. These should be moved to request body too.

Was this simulation working before being exported? My assumption is that binary data worked as a body and the only issues occur when trying to encode the bianry data into a JSON document.

benjih avatar Mar 21 '17 18:03 benjih

I used the HoverflyRule.inCaptureOrSimulationMode and called, in this case my local, docker via HTTP and got a correct response that was recorded. It then fails when it uses simulation mode. But as you say, since I send binary data and it gets recorded and is used to match, this fails since it's binary in JSON. So it would be awesome if the encodining of body can be on both request and response (instead of just response).

Khazrak avatar Mar 22 '17 15:03 Khazrak

@Khazrak You are correct and we will aim to fix this after our v0.11 release.

If you want to workaround this temporarily, one way is to open your json file and change the matcher from type recording to type template. Once you've done this you can remove the body field from the json, meaning it won't use the body for matching.

mogronalol avatar Mar 22 '17 15:03 mogronalol

Having looked at this issue, I think the best way to go about implementing this would be implement a binaryMatch matcher for requests. The binaryMatch would work the same as the Response.Body field and the Response.BodyEncoded field. It would take a base64 encoded string of the binary data.

This seems cleaner than trying to overload exactMatch.

benjih avatar May 19 '17 12:05 benjih

Wouldn't it be easier to ignore the binary data in the request (which isn't of interest anyway and could be treated as noise) and match on using something in the JSON request?

JohnFDavenport avatar May 22 '17 08:05 JohnFDavenport

I think capturing and simulating the binary data in the request body is a bit overkill. One workaround is to remove the request body so that it's not used for matching.

We could provide a binary matcher but it'll be low priority in our roadmap.

tommysitu avatar Nov 28 '18 22:11 tommysitu