Adam Cox
05/09/2023, 1:28 PM<ws://localhost:9998/jsonrpc>
- specifically the /jsonrpc
bit
⢠Headers to send in the connection request
⢠Message payload encoding as text or binary
We are using synchronous message contracts to do the verification and we are trying to extend the plugin so that these metadata properties can be set, however we are struggling to find the code path that allows plugin config to be added to the contract files when a core matcher is being used.
Advice/guidance on how to achieve this would be greatly appreciatedAdam Cox
05/09/2023, 4:47 PMAdam Cox
05/10/2023, 8:03 AMYousaf Nabi (pactflow.io)
Adam Cox
05/10/2023, 12:23 PMAdam Cox
05/10/2023, 12:23 PMAdam Cox
05/10/2023, 12:26 PMpath
property of the ProviderInfo is being added to the verifyInteraction request. I can only see host and port being sent in the configAdam Cox
05/10/2023, 12:30 PMYousaf Nabi (pactflow.io)
Adam Cox
05/10/2023, 12:38 PMAdam Cox
05/10/2023, 12:40 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
⢠Add custom data in the consumer contract for use with a transport pluginYour consumers can add whatever they want in, ideally to a known spec, so the plugin knows where to read it
Yousaf Nabi (pactflow.io)
⢠Specify path / headers / metadata for sync message contractsonly if you are adhering to the pact specification, the idea with plugins is you can step outside these bounds
Yousaf Nabi (pactflow.io)
⢠Pass the path property for a transport from the verifier API over to a plugin handling verification requestsYour verifier side of the plugin needs to aware of the key in the contract, which is can use to do whatever it needs to do, to get in the right state
Yousaf Nabi (pactflow.io)
I guess if some contracts are using Sec-WebSocket-Protocol header and path different to other contracts then this information should be in the contract itself (or maybe these are 2 providers in that case??)could that header be optional? and therefore the plugin verifier is agnostic so it being set or not, if it is set use it, if the path differs from normal use that, otherwise ignore the header and path? maybe some diagrams might help our mentalmodel š
Adam Cox
05/11/2023, 9:30 AMadd_plugin_data
function is only called when the content matcher is not a core matcher. So are we saying here that we need our plugin to add a new content matcher which is essentially the same as the core application/json one but it facilitates us adding the custom plugin data fields?
On the verifier side I can see how to read the content from the plugin data in the contract but I cannot work out how to get it in the contract using the pact_consumer library.
Consumer Contract Metadata
Again, looking at the same function for defining consumer contracts it doesn't look like a metadata field is supported for either core or plugin based content types. We can set the request and response bodies but not much else.
Pact Verifier
ProviderInfo struct has a transports property which contains the transports and their config. We have a websockets transport in here with a port number. The ProviderTransport struct has a path property. However it seems impossible to set the path property when using the pact-standalone-verifier and even if we could set it it doesn't get sent over to the plugin at any point. Only the host and port get sent as part of the "config" in the verifyInteraction request.
https://github.com/pact-foundation/pact-reference/blob/46628a8bf6b4d514adcb317d749fb8a79130b472/rust/pact_verifier/src/lib.rs#L459
https://github.com/pact-foundation/pact-reference/blob/46628a8bf6b4d514adcb317d749fb8a79130b472/rust/pact_verifier/src/lib.rs#LL427C25-L427C25
https://github.com/pact-foundation/pact-plugins/blob/main/drivers/rust/driver/src/plugin_manager.rs#L579
From looking at this code I cannot work out how to get the additional info we need into the config in the contract in order for it to be sent to the provider when doing the verifications.
Diagrams
Let me see if I can put something together to help illustrate what we are trying to do.
Thank you very much for taking the time to assist us with this.Adam Cox
05/11/2023, 10:32 AMAdam Cox
05/11/2023, 10:42 AMYousaf Nabi (pactflow.io)
Adam Cox
05/12/2023, 2:51 PMuglyog
uglyog
PrepareInteractionForVerification
and VerifyInteraction
to do the actual verification.uglyog
should the plugin setup the connection before verifying the interactions?This is up to the plugin author to decide how best to handle this. It will depend on the protocol being used. For websockets, this does make sense as it is an upgrade over standard HTTP.
uglyog
uglyog
Adam Cox
05/15/2023, 7:58 AMcontents_from
or the sync message builder api.uglyog
uglyog
uglyog
Adam Cox
05/15/2023, 8:07 AMrequestMetadata
in the rust pact_consumer for handling sync messages. Let me see if it worksAdam Cox
05/15/2023, 8:20 AMlet ms = pb
.synchronous_message_interaction("sync message example", |mut i| async move {
i.contents_from(json!({
"pact:content-type": "application/json-rpc",
"request": {
"query": "matching(string, 'getMacAddress')"
},
"requestMetadata": {
"headers": {
"Sec-WebSocket-Protocol": "jsonrpc"
}
},
"response": {
"data": "matching(string, '00-B0-D0-63-C2-26')"
}
}))
.await;
i.test_name("sync message example");
i
})
.await
.start_mock_server_async(Some("websockets/transport/websockets"))
.await;
Adam Cox
05/15/2023, 8:20 AM{
"consumer": {
"name": "message-consumer"
},
"interactions": [
{
"comments": {
"testname": "sync message example"
},
"description": "sync message example",
"key": "8e58be3b3ff9c72b",
"pending": false,
"request": {
"contents": {
"content": {
"query": "matching(string, 'getMacAddress')"
},
"contentType": "application/json-rpc",
"encoded": false
}
},
"response": [
{
"contents": {
"content": {
"data": "matching(string, '00-B0-D0-63-C2-26')"
},
"contentType": "application/json-rpc",
"encoded": false
}
}
],
"type": "Synchronous/Messages"
}
],
"metadata": {
"pactRust": {
"consumer": "0.10.5",
"models": "1.0.13"
},
"pactSpecification": {
"version": "4.0"
},
"plugins": [
{
"configuration": {},
"name": "websockets",
"version": "test"
}
]
},
"provider": {
"name": "message-provider"
}
}
Adam Cox
05/15/2023, 8:34 AMAdam Cox
05/15/2023, 8:46 AMapplication/json
content type from the plugin and then use the generate_content functionality to support metadata? It seems like more work than the plugin should need to do but I can't see another way of doing it right nowAdam Cox
05/15/2023, 10:23 AMuglyog
uglyog
configure_interaction
callAdam Cox
05/16/2023, 8:07 AMmetadata
field of the contract.