Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): use rack-reverse-proxy pact-foundation fork #140

Merged
merged 1 commit into from
Nov 29, 2024
Merged

Conversation

YOU54F
Copy link
Member

@YOU54F YOU54F commented Nov 29, 2024

## Reproduce

Create a simple ruby server, which returns a set-cookie header (Rack 3 so need to be lowercased)

require 'json'

class HttpRequestHandler
  def call(_env)
    response_body = JSON.generate(['foo'])
    [200, {
      'content-type' => 'application/json; charset=utf-8',
      'set-cookie' => '__cf_bm=_somebase64encodedstringwithequalsatthened=; array=awesome'
    }, [response_body]]
  end
end

run HttpRequestHandler.new

Save and run with rackup -p 9393

Save this following pact to pact.json

{
    "consumer": {
      "name": "a"
    },
    "provider": {
      "name": "b"
    },
    "interactions": [
      {
        "description": "A request",
        "request": {
          "method": "GET",
          "path": "/",
          "headers": {
            "accept": "application/json"
          }
        },
        "response": {
          "status": 200,
          "headers": {
            "Content-Type": "application/json; charset=utf-8"
          },
          "body": ["foo"],
          "matchingRules": {
            "$.body": {
              "match": "type"
            }
          }
        }
      }
    ],
    "metadata": {
      "pactSpecification": {
        "version": "2.0.0"
      }
    }
  }

Run the verifier from the repo locally - passes

bundle exec bin/pact verify pact.json --provider-base-url http://localhost:9393 --verbose --log-level debug

Build the image

docker build -t pact-cli .

run it

docker run --rm -v $PWD:/test -it pact-cli verify /test/pact.json --provider-base-url http://host.docker.internal:9393 --verbose --log-level debug

passes - output

INFO: Reading pact at /test/pact.json


Verifying a pact between a and b
  A request
    with GET /
      returns a response which
        has status code 200
        has a matching body
        includes headers
          "Content-Type" which equals "application/json; charset=utf-8"

1 interaction, 0 failure

versus this which fails

docker run --rm -v $PWD:/test -it pactfoundation/pact-cli:1.3.0.11 verify /test/pact.json --provider-base-url http://host.docker.internal:9393 --verbose --log-level debug

error

     Failure/Error: replay_interaction interaction, options[:request_customizer]
     
     NoMethodError:
       undefined method `strip' for nil
     # ./bin/pact:15:in `<top (required)>'

For completeness, I've also tested this out with the latest pact_verifier_cli (the rust based version, and it works)

pact_verifier_cli --file pact.json --hostname localhost:9393

Verifying a pact between a and b

  A request (3ms loading, 190ms verification)
    returns a response which
      has status code 200 (OK)
      includes headers
        "Content-Type" with value "application/json; charset=utf-8" (OK)
      has a matching body (OK)

- fixes issue #43

- update to rack-test 2.1.0
@YOU54F YOU54F merged commit 252f820 into master Nov 29, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant