pact-foundation / pact-support

Shared code for Pact gems
MIT License
7 stars 46 forks source link

Query parameters aren't failing the verify method for a consumer #40

Open lirantal opened 7 years ago

lirantal commented 7 years ago

Original discussion from gitter with @bethesque asking to track it here:

@lirantal the detailed logic for what matches and doesn't match can be found in the pact specification. The ruby impl is up to v2 https://github.com/pact-foundation/pact-specification/tree/version-2/testcases/request I'm a bit suspicious about that params anomaly you mentioned earlier. Can you raise an issue in the pact-support repository please?

This is reproduced on:

To reproduce:

  1. Setup an interaction where the query parameters are omitted from the request interaction
  2. Make an actual request with query parameters
  3. pact.verify() doesn't throw an error
bethesque commented 7 years ago

@uglyog do you know what the behaviour is for jvm/rust?

YOU54F commented 1 month ago

The rust core when utilised via FFI will fail in this scenario

require 'pact/ffi'
require 'pact/ffi/logger'
require 'pact/ffi/mock_server'
require 'pact/ffi/http_consumer'
require 'pact/ffi/utils'
require 'json'
require 'httparty'

PactFfi::Logger::log_to_stdout(5);
@pact = PactFfi::HttpConsumer::new_pact("V4-consumer","V4-provider");
@interaction = PactFfi::HttpConsumer::new_interaction(@pact, "interaction for a consumer test")
PactFfi::HttpConsumer.with_specification(@pact, PactFfi::FfiSpecificationVersion['SPECIFICATION_VERSION_V2'])
@mock_server_port = PactFfi::MockServer.create_for_transport(@pact, '127.0.0.1', 0, "http", nil)
response = HTTParty.get("http://127.0.0.1:#{@mock_server_port}/?name=ron&status=good")
puts response
matched = PactFfi::MockServer::matched(@mock_server_port)
puts matched
mismatches = PactFfi::MockServer::mismatches(@mock_server_port)
puts mismatches

which returns the mismatch

[
  {
    "method": "GET",
    "mismatches": [
      {
        "actual": "[\"good\"]",
        "expected": "",
        "mismatch": "Unexpected query parameter 'status' received",
        "parameter": "status",
        "type": "QueryMismatch"
      },
      {
        "actual": "[\"ron\"]",
        "expected": "",
        "mismatch": "Unexpected query parameter 'name' received",
        "parameter": "name",
        "type": "QueryMismatch"
      }
    ],
    "path": "/",
    "type": "request-mismatch"
  }
]

however the ruby core does appear to exhibit the behaviour where additional query params in the consumer request are not considered when ascertaining if a correct request as per the users expectations (not specifying query params should enforce that it only matches incoming requests which do not have query params)

https://github.com/pact-foundation/pact-ruby-e2e-example/tree/pact-support-issue-40