Skip to content

Commit

Permalink
Update from upstream repo (#2)
Browse files Browse the repository at this point in the history
* feat: allow mock service host to be configured

pact-foundation/pact-ruby#186

* chore(release): version 3.0.0

* fix: add missing host argument to server spawn

fixes: pact-foundation#102

* chore(release): version 3.0.1

* Improve logging robustness

Do not pretty print a JSON object when serialization or serialization fail, for details see pact-foundation#103.

* Update interaction_replay.rb

* Initial version of the unit test

* Move the test to appropriate context

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* Update interaction_replay.rb

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* feat: pact-stub-service log level cli opt

* chore(release): version 3.1.0

* chore(release): version 3.1.1

* feat(skip writing to pact): Use writable_interactions when writing to pact file

* Add test for #as_json

* Add feature spec

* Bump pact-support dependency

* Fix tests

* chore(release): version 3.2.0

* CI: Add 2.7 to travis ci

* fix: remove apparently unused require for thwait

* chore(release): version 3.2.1

* feat: log a warning when too many interactions are set on the mock service at once

* chore(release): version 3.3.0

* fix: put metadata on the correct decorator

* chore(release): version 3.3.1

* chore: remove jruby until somebody shows they're actually using it

* chore(release): version 3.4.0

* feat: add token, username and password options to stub service (pact-foundation#118)

Co-authored-by: Beth Skurrie <[email protected]>

* chore(release): version 3.5.0

* docs: document that you can set the broker token via an env var

[ci-skip]

* chore: separate test and deploy stages

* chore: update .travis.yml

[ci-skip]

* chore: update .travis.yml

* test: add expectations to make sure metadata: nil isn't stored in the pact (pact-foundation#119)

* feat: add 'Access-Control-Allow-Headers' = true to cors response headers (pact-foundation#121)

* chore(release): version 3.6.0

* fix:  fix Ruby 2.7 kwargs warning (pact-foundation#122)

* chore(release): version 3.6.1

* fix: update thor dependency (pact-foundation#124)

Co-authored-by: Lindsey Hattamer <[email protected]>

Co-authored-by: Lindsey Hattamer <[email protected]>

* chore: add github workflow for gem release

* chore: disable tests as they're not running properly on github workflow

* chore(release): version 3.6.2

* feat: do not require files until command is executing

* chore: update release workflow [ci-skip]

* feat: use Pact::Query.parse_string to parse query string

* chore(deps): update rake

* docs: update travis badge

* chore(release): version 3.7.0

* feat: include interaction diffs in verification response

cc: @TimothyJones

* chore: add tests to github actions

* chore: allow workflow dispatch to release

* chore(release): version 3.8.0

* chore: tests are hanging. try a subset

* chore: try rspec

* chore: disabling tests, they hang

* chore: create issue template

* feat: pass host into WEBrick options to allow configuration (pact-foundation#128)

Co-authored-by: Matthew Hall <[email protected]>

* chore(release): version 3.9.0

* chore: handle http 2

* fix: check for nil body rather than falsey body when determining how to render mocked response
Fixes: pact-foundation#99

* chore(release): version 3.9.1

Co-authored-by: Beth Skurrie <[email protected]>
Co-authored-by: Alexander Bolshakov <[email protected]>
Co-authored-by: YOU54F <[email protected]>
Co-authored-by: Beth Skurrie <[email protected]>
Co-authored-by: Simon Nizov <[email protected]>
Co-authored-by: Chavez <[email protected]>
Co-authored-by: Chavez <[email protected]>
Co-authored-by: Matt Fellows <[email protected]>
Co-authored-by: vandemark <[email protected]>
Co-authored-by: Bartek Bułat <[email protected]>
Co-authored-by: Michael R. Fleet <[email protected]>
Co-authored-by: Lindsey Hattamer <[email protected]>
Co-authored-by: mhall58 <[email protected]>
Co-authored-by: Matthew Hall <[email protected]>
  • Loading branch information
15 people committed Feb 4, 2022
1 parent 8d077e4 commit 36f20f0
Show file tree
Hide file tree
Showing 46 changed files with 721 additions and 244 deletions.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Pre issue-raising checklist

I have already (please mark the applicable with an `x`):

* [ ] Read through the relevant docs at https://docs.pact.io
* [ ] Upgraded to the latest version of the gem
* [ ] Checked the CHANGELOG to see if the issue I am about to raise has been fixed
* [ ] Created an executable example that demonstrates the issue using either a:
* Dockerfile
* Git repository with a Travis or Appveyor (or similar) build

## Software versions

* **OS**: e.g. Mac OSX 10.11.5
* **pact mock service:** eg. v 1.23.0

## Expected behaviour

Please complete.

## Actual behaviour

Please complete.

## Steps to reproduce

Provide a repository, gist or reproducible code snippet so that we can test the problem.

## Relevant log files

Please ensure you set logging to `DEBUG` and attach any relevant log files here (or link from a gist).
59 changes: 59 additions & 0 deletions .github/workflows/release_gem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release gem

on:
repository_dispatch:
types:
- release-triggered
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.6'
- run: |
gem install bundler -v 2.1
bundle install
# - name: Test
# run: bundle exec rake

release:
needs: test
runs-on: ubuntu-latest
outputs:
gem_name: ${{ steps.release-gem.outputs.gem_name }}
version: ${{ steps.release-gem.outputs.version }}
increment: ${{ steps.release-gem.outputs.increment }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: release-gem
uses: pact-foundation/[email protected]
env:
GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_API_KEY }}'
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
INCREMENT: '${{ github.event.client_payload.increment }}'

notify-gem-released:
needs: release
strategy:
matrix:
repository: [pact-foundation/pact-ruby-cli, pact-foundation/pact-ruby-standalone, pact-foundation/pact_broker-client]
runs-on: ubuntu-latest
steps:
- name: Notify ${{ matrix.repository }} of gem release
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.GHTOKENFORPACTCLIRELEASE }}
repository: ${{ matrix.repository }}
event-type: gem-released
client-payload: |
{
"name": "${{ needs.release.outputs.gem_name }}",
"version": "${{ needs.release.outputs.version }}",
"increment": "${{ needs.release.outputs.increment }}"
}
23 changes: 23 additions & 0 deletions .github/workflows/test.yml.hangs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on: [push, pull_request]

jobs:
test:
runs-on: "ubuntu-latest"
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
ruby_version: ["2.2", "2.7"]
experimental: [false]
include:
- ruby_version: "3.0"
experimental: true
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
- run: "bundle install"
- run: "bundle exec rspec"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ log
reports
Gemfile.lock
build
.byebug_history

vendor/bundle/
spec/examples.txt
48 changes: 26 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ language: ruby
sudo: false
rvm:
- 2.2.4
- 2.3.1
- jruby-9.0.5.0
- 2.7.0
env:
global:
secure: FqQ00zkw2heLh5XafaMMv1LXgy+DBxumbcSI3c9iDlRvi4KZQ+n+NqSp/feVEIxSMzA9FmH7ZqTVJmsA5jByrk71WiguU8RZ7NSVzonlLZK0tQ9idwzPtvc38abJwWm3cR9TJlkNxUgQ2iHXLobo4zFSEK/4s0Ob9ddf3x4BUmo=
deploy:
- provider: rubygems
api_key:
secure: EbS3ZRtfqoKrQ3pMGfkx/pqUBVUaEJE+KjUAnAy4h+6BF/6ZsY2H5vtpuDB8ypQ7au1AF2QuEoZsQZkHPngyhJ7Ebtn7XFh0c5WAB+c+mM7bSsNN+ZU176cUgY5PkS9GZ3rBZ/MEW+YyKcUpTmk+ClDx/WmofRjPFSD4n0x350Y=
gem: pact-mock_service
on:
tags: true
repo: pact-foundation/pact-mock_service
- provider: releases
api_key:
secure: O9g/8HkwonBZOthoN+NFCiZQZ+AyakmqMxb/HpuC/ZB79KZ6GTM0brr++Bm08RYLD2MX6+IC8dqA4vkl4D11VEd7TrtxdtS2huScDGTEntzPtRu2WDo4cm6/B9y/erp7Thalt08+V7dqsSBMN5FWf0c001WrG7qpdWs9BElxul8=
file: pkg/*
file_glob: true
skip_cleanup: true
on:
tags: true
repo: pact-foundation/pact-mock_service
after_deploy:
- bundle exec rake generate_release_notes[$TRAVIS_TAG]
- bundle exec rake upload_release_notes[$TRAVIS_REPO_SLUG,$TRAVIS_TAG]
jobs:
include:
- stage: release
rvm: 2.7.0
script: echo "Releasing"
deploy:
- provider: rubygems
api_key:
secure: EbS3ZRtfqoKrQ3pMGfkx/pqUBVUaEJE+KjUAnAy4h+6BF/6ZsY2H5vtpuDB8ypQ7au1AF2QuEoZsQZkHPngyhJ7Ebtn7XFh0c5WAB+c+mM7bSsNN+ZU176cUgY5PkS9GZ3rBZ/MEW+YyKcUpTmk+ClDx/WmofRjPFSD4n0x350Y=
gem: pact-mock_service
on:
tags: true
repo: pact-foundation/pact-mock_service
- provider: releases
api_key:
secure: O9g/8HkwonBZOthoN+NFCiZQZ+AyakmqMxb/HpuC/ZB79KZ6GTM0brr++Bm08RYLD2MX6+IC8dqA4vkl4D11VEd7TrtxdtS2huScDGTEntzPtRu2WDo4cm6/B9y/erp7Thalt08+V7dqsSBMN5FWf0c001WrG7qpdWs9BElxul8=
file: pkg/*
file_glob: true
skip_cleanup: true
on:
tags: true
repo: pact-foundation/pact-mock_service
after_deploy:
- bundle exec rake generate_release_notes[$TRAVIS_TAG]
- bundle exec rake upload_release_notes[$TRAVIS_REPO_SLUG,$TRAVIS_TAG]
127 changes: 127 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,130 @@
<a name="v3.9.1"></a>
### v3.9.1 (2021-06-03)

#### Bug Fixes

* check for nil body rather than falsey body when determining how to render mocked response Fixes: https://github.com/pact-foundation/pact-mock_service/issues/99 ([d26e520](/../../commit/d26e520))

<a name="v3.9.0"></a>
### v3.9.0 (2021-05-17)

#### Features

* pass host into WEBrick options to allow configuration (#128) ([ec234a4](/../../commit/ec234a4))

<a name="v3.8.0"></a>
### v3.8.0 (2021-02-25)

#### Features

* include interaction diffs in verification response ([6306693](/../../commit/6306693))

<a name="v3.7.0"></a>
### v3.7.0 (2020-11-13)

#### Features

* use Pact::Query.parse_string to parse query string ([6cd0733](/../../commit/6cd0733))
* do not require files until command is executing ([ad54d0b](/../../commit/ad54d0b))

<a name="v3.6.2"></a>
### v3.6.2 (2020-08-10)

#### Bug Fixes

* update thor dependency (#124) ([54b3f85](/../../commit/54b3f85))

<a name="v3.6.1"></a>
### v3.6.1 (2020-04-22)


#### Bug Fixes

* fix Ruby 2.7 kwargs warning (#122) ([4a46c21](/../../commit/4a46c21))


<a name="v3.6.0"></a>
### v3.6.0 (2020-03-14)


#### Features

* add 'Access-Control-Allow-Headers' = true to cors response headers (#121) ([61bd9d1](/../../commit/61bd9d1))


<a name="v3.5.0"></a>
### v3.5.0 (2020-01-17)


#### Features

* add token, username and password options to stub service (#118) ([76236d8](/../../commit/76236d8))


<a name="v3.3.1"></a>
### v3.3.1 (2020-01-16)


#### Bug Fixes

* put metadata on the correct decorator ([67ef5a6](/../../commit/67ef5a6))


<a name="v3.3.0"></a>
### v3.3.0 (2020-01-16)


#### Features

* log a warning when too many interactions are set on the mock service at once ([0ce6bef](/../../commit/0ce6bef))


<a name="v3.2.1"></a>
### v3.2.1 (2020-01-11)


#### Bug Fixes

* remove apparently unused require for thwait ([4a08fd5](/../../commit/4a08fd5))


<a name="v3.2.0"></a>
### v3.2.0 (2019-09-19)


#### Features

* **skip writing to pact**
* Use writable_interactions when writing to pact file ([44ea0c3](/../../commit/44ea0c3))


<a name="v3.1.0"></a>
### v3.1.0 (2019-05-01)


#### Features

* pact-stub-service log level cli opt ([9264a87](/../../commit/9264a87))


<a name="v3.0.1"></a>
### v3.0.1 (2019-03-08)


#### Bug Fixes

* add missing host argument to server spawn ([ee5cf90](/../../commit/ee5cf90))


<a name="v3.0.0"></a>
### v3.0.0 (2019-02-21)


#### Features

* allow mock service host to be configured ([7e2d810](/../../commit/7e2d810))


<a name="v2.11.0"></a>
### v2.11.0 (2018-08-28)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Pact Mock and Stub Service

[![Build Status](https://travis-ci.org/pact-foundation/pact-mock_service.svg?branch=master)](https://travis-ci.org/pact-foundation/pact-mock_service)
[![Build Status](https://travis-ci.com/pact-foundation/pact-mock_service.svg?branch=master)](https://travis-ci.com/pact-foundation/pact-mock_service)

This codebase provides the HTTP mock and stub service used by implementations of [Pact][pact]. It is packaged as a gem, and as a standalone executable for Mac OSX and Linux and Windows.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def shutdown
private

def add_cors_header env, response
[response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]]
cors_headers = { 'Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*'), 'Access-Control-Allow-Credentials' => 'true'}
[response[0], response[1].merge(cors_headers), response[2]]
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/pact/consumer/mock_service/rack_request_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'cgi/core'
require 'pact/consumer_contract/query'

module Pact
module Consumer

Expand All @@ -11,7 +13,7 @@ module RackRequestHelper
}

def params_hash env
CGI::parse env["QUERY_STRING"]
Pact::Query.parse_string(env["QUERY_STRING"])
end

def request_as_hash_from env
Expand Down
15 changes: 6 additions & 9 deletions lib/pact/consumer/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ def ports
end
end

attr_reader :app, :port, :options
attr_reader :app, :host, :port, :options

def initialize(app, port, options = {})
def initialize(app, host, port, options = {})
@app = app
@middleware = Middleware.new(@app)
@server_thread = nil
@host = host
@port = port
@options = options
end
Expand All @@ -52,10 +53,6 @@ def error
@middleware.error
end

def host
"localhost"
end

def responsive?
return false if @server_thread && @server_thread.join(0)
res = get_identity
Expand All @@ -70,7 +67,7 @@ def responsive?

def run_default_server(app, port)
require 'rack/handler/webrick'
Rack::Handler::WEBrick.run(app, webrick_opts) do |server|
Rack::Handler::WEBrick.run(app, **webrick_opts) do |server|
@port = server[:Port]
end
end
Expand All @@ -86,7 +83,7 @@ def get_identity
end

def webrick_opts
opts = { Port: port.nil? ? 0 : port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0) }
opts = { Host: host.nil? ? 'localhost' : host, Port: port.nil? ? 0 : port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0) }
opts.merge!({
:SSLCertificate => OpenSSL::X509::Certificate.new(File.open(options[:sslcert]).read) }) if options[:sslcert]
opts.merge!({
Expand All @@ -96,7 +93,7 @@ def webrick_opts
end

def ssl_opts
{ SSLEnable: true, SSLCertName: [ %w[CN localhost] ] }
{ SSLEnable: true, SSLCertName: [ ["CN", host] ] }
end

def boot
Expand Down
Loading

0 comments on commit 36f20f0

Please sign in to comment.