pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.09k stars 480 forks source link

Incorrect URL decoding in PactBrokerClient when fetching pacts #1154

Closed mszczygiel closed 3 years ago

mszczygiel commented 4 years ago

Hello, While versioning contracts, we append git branch name to the version so we always have separate contract per branch. Unfortunately, when version contains special characters (like '/' in my case) fetching pacts via PactBrokerClient.fetchLatestConsumersWithNoTag or PactBrokerClient.fetchConsumersWithSelectors fails with au.com.dius.pact.core.pactbroker.NotFoundHalResponse: No HAL document found at path .... For example for response from the broker containing:

{
"href": "http://broker-url/pacts/provider/provider.name/consumer/consumer.name/version/3.0.2-SNAPSHOT-feature%2F123",
"title": "title",
"name": "consumer.name"
}

PactBrokerClient would go to http://broker-url/pacts/provider/provider.name/consumer/consumer.name/version/3.0.2-SNAPSHOT-feature/123 which is incorrect in this case. Pact jvm version that we're using is 4.0.10, but I can see nothing has changed in this area on current master.

It seems that href decoding is unnecessary, if you agree (or have other suggestion on how to approach it) then I'm happy to contribute a fix for that.

uglyog commented 4 years ago

The problem is that if we don't decode the URL, when the HTTP client encodes it before sending the request, and it will end up double encoded.

uglyog commented 4 years ago

4.1.7 has been released with this fix