Tien Vo
10/11/2023, 2:03 PMScenario: Request with a binary body (negative case)
When the mock server is started with interaction 7
And request 7 is made to the mock server with the following changes:
| body |
| file: spider.jpg |
Then a 500 error response is returned
And the mismatches will contain a "body" mismatch with error "Actual body [image/jpeg, 30922 bytes, starting with ffd8ffe000104a46494600010101004800480000ffe100ae4578696600004949] is not equal to the expected body [image/jpeg, 28058 bytes, starting with ffd8ffe000104a46494600010101012c012c0000ffe12db64578696600004949]"
According to document of pactffi_with_binary_file:
Will use a mime type matcher to match the body.I think the content of the binary file doesn't matter. If we change the content of the binary file, as long as the mime type doesn't change (image/jpeg), the mock server shouldn't consider this as a mismatch . The response code should be 200, not 500.
rholshausen
10/11/2023, 10:09 PMTien Vo
10/12/2023, 1:28 AMTien Vo
10/12/2023, 1:31 AMMatt (pactflow.io / pact-js / pact-go)
pactffi_with_binary_file:I think this is V3 only, right Ron? Itâs what adds the matcher Ronâs talking about. In V1 (and V2), you wouldnât use this function directly.
Matt (pactflow.io / pact-js / pact-go)
rholshausen
10/12/2023, 3:07 AMTien Vo
10/12/2023, 10:37 AMpactffi_with_body
⢠pactffi_with_binary_file
If I can't use pactffi_with_binary_file
, so pactffi_with_body
is the only option.
Does pactffi_with_body
support binary?Tien Vo
10/16/2023, 3:13 PMpactffi_with_body
support binary. So I updated pactffi_with_binary_file
to add matching rule conditionally https://github.com/pact-foundation/pact-reference/pull/327Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
pactffi_with_body
accepts binary in the body
attribute
bool pactffi_with_body(InteractionHandle interaction,
enum InteractionPart part,
const char *content_type,
const char *body);
Matt (pactflow.io / pact-js / pact-go)
rholshausen
10/17/2023, 5:38 AMconst char *
which can't have any zero bytes in it and must be ended with a NULL terminatorMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
...
* # Safety
*
* The content type must be a valid UTF-8 encoded NULL-terminated string. The body pointer must
* be valid for reads of `size` bytes, and it must be properly aligned and consecutive.
...
rholshausen
10/17/2023, 5:54 AMpactffi_with_binary_file
Matt (pactflow.io / pact-js / pact-go)
pact.h
vendored in the go repo (itâs not linked to code, but there as a reference. Perhaps it should be removed now)Tien Vo
10/17/2023, 8:04 AMpactffi_with_body
with binary string:
2023-10-14T02:55:28.212556Z TRACE ThreadId(01) pact_ffi::mock_server::handles: >>> pactffi_with_body(InteractionHandle { interaction_ref: 65537 }, Request, 0x7f0658eb9360, 0x7f0658f24018)
2023-10-14T02:55:28.212564Z WARN ThreadId(01) pact_ffi: Failed to parse body name as a UTF-8 string: invalid utf-8 sequence of 1 bytes from index 0
This is why I think it doesn't support binary string. Sorry I forgot to mention it.Matt (pactflow.io / pact-js / pact-go)
Tien Vo
10/17/2023, 10:48 AMYousaf Nabi (pactflow.io)
Tien Vo
10/17/2023, 12:19 PMTien Vo
10/17/2023, 12:19 PM$ffi->pactffi_with_body($interaction, $ffi->InteractionPart_Response, 'image/jpeg', file_get_contents(__DIR__ . '/../../compatibility-suite/pact-compatibility-suite/fixtures/spider.jpg'));
Tien Vo
10/17/2023, 12:20 PM2023-10-17T121640.733118Z WARN ThreadId(01) pact_ffi: Failed to parse body name as a UTF-8 string: invalid utf-8 sequence of 1 bytes from index 0
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
const char *
Matt (pactflow.io / pact-js / pact-go)
Failed to parse body namethatâs a bit confusing, whatâs ânameâ in this context. Might need to improve that error message
Joshua Ellis
11/10/2023, 1:55 AMwith_binary_file
to pass byte arrays which are invalid UTF-8 sequences. I think it might be worth tracking in a ticket on GitHub (which I'm starting to write now).Joshua Ellis
11/10/2023, 2:37 AM