pact-foundation / pact-stub-server

Standalone pact stub server
MIT License
75 stars 19 forks source link

Pact-stub server is matching multiple requests where no request body is provided #23

Closed YOU54F closed 5 years ago

YOU54F commented 5 years ago

Issue

NB:- an example repo with this issue is available here https://github.com/YOU54F/pact-consumer-example-typescript

Where a pact provider is setup with the following 2 request matchers

  withRequest: {
    body: requestResponse.TestRequest("happyPath"),
    headers: {
      "Content-Type": "application/json"
    },
    method: "POST",
    path: "/test"
  }
};
  withRequest: {
    body: requestResponse.TestRequest(""),
    headers: {
      "Content-Type": "application/json"
    },
    method: "POST",
    path: "/test"
  }

When a request is sent with no body, a duplicate match is found and the first result is returned

curl -X POST \
  http://localhost:8080/test \
  -H 'Content-Type: application/json'

Pact stub server logs :- [WARN] Found more than one pact request for method POST and path '/test', using the first one

Actual Result :- Returns the first matching response (false positive) Expected Result :- Return a 404 and no body, as only a portion of the request was matched (no body)

Reproduction Steps

Versions

Installation

Run pact tests

Start the mock server

Run the following request -

curl -X POST \
  http://localhost:8080/test \
  -H 'Content-Type: application/json'

Expected Result = Returns an empty response body and a 404 Actual Result = Returns the below body and a 200

{
    "testResult": "validRequest"
}

Pact stub server logs spit out the following

[WARN] Found more than one pact request for method POST and path '/test', using the first one

#

YOU54F commented 5 years ago

Switched over to the ruby implementation in the following commit

https://github.com/YOU54F/pact-consumer-example-typescript/pull/10/commits/14e0ceed636eb7861e80ec93938a3ee09dcf3ccf

and seeing a server error returned where we send a request without a content-type header and no body, or with a content-type header of application/json but no body.

Feel free to close this issue 👍

uglyog commented 5 years ago

No prob.