Skip to content

Commit 36f20f0

Browse files
Michael YanbethesquelextizYOU54Fthatguysimon
authored
Update from upstream repo (#2)
* 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 <bethesque@users.noreply.github.com> * 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 <lindsey.hattamer@oddball.io> Co-authored-by: Lindsey Hattamer <lindsey.hattamer@oddball.io> * 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 <matthew.hall@partnerize.com> * 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 <beth@bethesque.com> Co-authored-by: Alexander Bolshakov <lextiz@gmail.com> Co-authored-by: YOU54F <yousafn@gmail.com> Co-authored-by: Beth Skurrie <bethesque@users.noreply.github.com> Co-authored-by: Simon Nizov <simon.nizov@gmail.com> Co-authored-by: Chavez <matthew@el-chavez.me> Co-authored-by: Chavez <mtchavez@users.noreply.github.com> Co-authored-by: Matt Fellows <matt.fellows@onegeek.com.au> Co-authored-by: vandemark <jnvbeach@gmail.com> Co-authored-by: Bartek Bułat <barthez@users.noreply.github.com> Co-authored-by: Michael R. Fleet <f1337@users.noreply.github.com> Co-authored-by: Lindsey Hattamer <lindsey.hattamer@oddball.io> Co-authored-by: mhall58 <matthewhall58@gmail.com> Co-authored-by: Matthew Hall <matthew.hall@partnerize.com>
1 parent 8d077e4 commit 36f20f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+721
-244
lines changed

.github/ISSUE_TEMPLATE.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Pre issue-raising checklist
2+
3+
I have already (please mark the applicable with an `x`):
4+
5+
* [ ] Read through the relevant docs at https://docs.pact.io
6+
* [ ] Upgraded to the latest version of the gem
7+
* [ ] Checked the CHANGELOG to see if the issue I am about to raise has been fixed
8+
* [ ] Created an executable example that demonstrates the issue using either a:
9+
* Dockerfile
10+
* Git repository with a Travis or Appveyor (or similar) build
11+
12+
## Software versions
13+
14+
* **OS**: e.g. Mac OSX 10.11.5
15+
* **pact mock service:** eg. v 1.23.0
16+
17+
## Expected behaviour
18+
19+
Please complete.
20+
21+
## Actual behaviour
22+
23+
Please complete.
24+
25+
## Steps to reproduce
26+
27+
Provide a repository, gist or reproducible code snippet so that we can test the problem.
28+
29+
## Relevant log files
30+
31+
Please ensure you set logging to `DEBUG` and attach any relevant log files here (or link from a gist).

.github/workflows/release_gem.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Release gem
2+
3+
on:
4+
repository_dispatch:
5+
types:
6+
- release-triggered
7+
workflow_dispatch:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-ruby@v1
15+
with:
16+
ruby-version: '2.6'
17+
- run: |
18+
gem install bundler -v 2.1
19+
bundle install
20+
# - name: Test
21+
# run: bundle exec rake
22+
23+
release:
24+
needs: test
25+
runs-on: ubuntu-latest
26+
outputs:
27+
gem_name: ${{ steps.release-gem.outputs.gem_name }}
28+
version: ${{ steps.release-gem.outputs.version }}
29+
increment: ${{ steps.release-gem.outputs.increment }}
30+
steps:
31+
- uses: actions/checkout@v2
32+
with:
33+
fetch-depth: 0
34+
- id: release-gem
35+
uses: pact-foundation/release-gem@v0.0.11
36+
env:
37+
GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_API_KEY }}'
38+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
39+
INCREMENT: '${{ github.event.client_payload.increment }}'
40+
41+
notify-gem-released:
42+
needs: release
43+
strategy:
44+
matrix:
45+
repository: [pact-foundation/pact-ruby-cli, pact-foundation/pact-ruby-standalone, pact-foundation/pact_broker-client]
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Notify ${{ matrix.repository }} of gem release
49+
uses: peter-evans/repository-dispatch@v1
50+
with:
51+
token: ${{ secrets.GHTOKENFORPACTCLIRELEASE }}
52+
repository: ${{ matrix.repository }}
53+
event-type: gem-released
54+
client-payload: |
55+
{
56+
"name": "${{ needs.release.outputs.gem_name }}",
57+
"version": "${{ needs.release.outputs.version }}",
58+
"increment": "${{ needs.release.outputs.increment }}"
59+
}

.github/workflows/test.yml.hangs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: "ubuntu-latest"
8+
continue-on-error: ${{ matrix.experimental }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
ruby_version: ["2.2", "2.7"]
13+
experimental: [false]
14+
include:
15+
- ruby_version: "3.0"
16+
experimental: true
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: ruby/setup-ruby@v1
20+
with:
21+
ruby-version: ${{ matrix.ruby_version }}
22+
- run: "bundle install"
23+
- run: "bundle exec rspec"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ log
2929
reports
3030
Gemfile.lock
3131
build
32+
.byebug_history
3233

3334
vendor/bundle/
3435
spec/examples.txt

.travis.yml

+26-22
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@ language: ruby
22
sudo: false
33
rvm:
44
- 2.2.4
5-
- 2.3.1
6-
- jruby-9.0.5.0
5+
- 2.7.0
76
env:
87
global:
98
secure: FqQ00zkw2heLh5XafaMMv1LXgy+DBxumbcSI3c9iDlRvi4KZQ+n+NqSp/feVEIxSMzA9FmH7ZqTVJmsA5jByrk71WiguU8RZ7NSVzonlLZK0tQ9idwzPtvc38abJwWm3cR9TJlkNxUgQ2iHXLobo4zFSEK/4s0Ob9ddf3x4BUmo=
10-
deploy:
11-
- provider: rubygems
12-
api_key:
13-
secure: EbS3ZRtfqoKrQ3pMGfkx/pqUBVUaEJE+KjUAnAy4h+6BF/6ZsY2H5vtpuDB8ypQ7au1AF2QuEoZsQZkHPngyhJ7Ebtn7XFh0c5WAB+c+mM7bSsNN+ZU176cUgY5PkS9GZ3rBZ/MEW+YyKcUpTmk+ClDx/WmofRjPFSD4n0x350Y=
14-
gem: pact-mock_service
15-
on:
16-
tags: true
17-
repo: pact-foundation/pact-mock_service
18-
- provider: releases
19-
api_key:
20-
secure: O9g/8HkwonBZOthoN+NFCiZQZ+AyakmqMxb/HpuC/ZB79KZ6GTM0brr++Bm08RYLD2MX6+IC8dqA4vkl4D11VEd7TrtxdtS2huScDGTEntzPtRu2WDo4cm6/B9y/erp7Thalt08+V7dqsSBMN5FWf0c001WrG7qpdWs9BElxul8=
21-
file: pkg/*
22-
file_glob: true
23-
skip_cleanup: true
24-
on:
25-
tags: true
26-
repo: pact-foundation/pact-mock_service
27-
after_deploy:
28-
- bundle exec rake generate_release_notes[$TRAVIS_TAG]
29-
- bundle exec rake upload_release_notes[$TRAVIS_REPO_SLUG,$TRAVIS_TAG]
9+
jobs:
10+
include:
11+
- stage: release
12+
rvm: 2.7.0
13+
script: echo "Releasing"
14+
deploy:
15+
- provider: rubygems
16+
api_key:
17+
secure: EbS3ZRtfqoKrQ3pMGfkx/pqUBVUaEJE+KjUAnAy4h+6BF/6ZsY2H5vtpuDB8ypQ7au1AF2QuEoZsQZkHPngyhJ7Ebtn7XFh0c5WAB+c+mM7bSsNN+ZU176cUgY5PkS9GZ3rBZ/MEW+YyKcUpTmk+ClDx/WmofRjPFSD4n0x350Y=
18+
gem: pact-mock_service
19+
on:
20+
tags: true
21+
repo: pact-foundation/pact-mock_service
22+
- provider: releases
23+
api_key:
24+
secure: O9g/8HkwonBZOthoN+NFCiZQZ+AyakmqMxb/HpuC/ZB79KZ6GTM0brr++Bm08RYLD2MX6+IC8dqA4vkl4D11VEd7TrtxdtS2huScDGTEntzPtRu2WDo4cm6/B9y/erp7Thalt08+V7dqsSBMN5FWf0c001WrG7qpdWs9BElxul8=
25+
file: pkg/*
26+
file_glob: true
27+
skip_cleanup: true
28+
on:
29+
tags: true
30+
repo: pact-foundation/pact-mock_service
31+
after_deploy:
32+
- bundle exec rake generate_release_notes[$TRAVIS_TAG]
33+
- bundle exec rake upload_release_notes[$TRAVIS_REPO_SLUG,$TRAVIS_TAG]

CHANGELOG.md

+127
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,130 @@
1+
<a name="v3.9.1"></a>
2+
### v3.9.1 (2021-06-03)
3+
4+
#### Bug Fixes
5+
6+
* 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))
7+
8+
<a name="v3.9.0"></a>
9+
### v3.9.0 (2021-05-17)
10+
11+
#### Features
12+
13+
* pass host into WEBrick options to allow configuration (#128) ([ec234a4](/../../commit/ec234a4))
14+
15+
<a name="v3.8.0"></a>
16+
### v3.8.0 (2021-02-25)
17+
18+
#### Features
19+
20+
* include interaction diffs in verification response ([6306693](/../../commit/6306693))
21+
22+
<a name="v3.7.0"></a>
23+
### v3.7.0 (2020-11-13)
24+
25+
#### Features
26+
27+
* use Pact::Query.parse_string to parse query string ([6cd0733](/../../commit/6cd0733))
28+
* do not require files until command is executing ([ad54d0b](/../../commit/ad54d0b))
29+
30+
<a name="v3.6.2"></a>
31+
### v3.6.2 (2020-08-10)
32+
33+
#### Bug Fixes
34+
35+
* update thor dependency (#124) ([54b3f85](/../../commit/54b3f85))
36+
37+
<a name="v3.6.1"></a>
38+
### v3.6.1 (2020-04-22)
39+
40+
41+
#### Bug Fixes
42+
43+
* fix Ruby 2.7 kwargs warning (#122) ([4a46c21](/../../commit/4a46c21))
44+
45+
46+
<a name="v3.6.0"></a>
47+
### v3.6.0 (2020-03-14)
48+
49+
50+
#### Features
51+
52+
* add 'Access-Control-Allow-Headers' = true to cors response headers (#121) ([61bd9d1](/../../commit/61bd9d1))
53+
54+
55+
<a name="v3.5.0"></a>
56+
### v3.5.0 (2020-01-17)
57+
58+
59+
#### Features
60+
61+
* add token, username and password options to stub service (#118) ([76236d8](/../../commit/76236d8))
62+
63+
64+
<a name="v3.3.1"></a>
65+
### v3.3.1 (2020-01-16)
66+
67+
68+
#### Bug Fixes
69+
70+
* put metadata on the correct decorator ([67ef5a6](/../../commit/67ef5a6))
71+
72+
73+
<a name="v3.3.0"></a>
74+
### v3.3.0 (2020-01-16)
75+
76+
77+
#### Features
78+
79+
* log a warning when too many interactions are set on the mock service at once ([0ce6bef](/../../commit/0ce6bef))
80+
81+
82+
<a name="v3.2.1"></a>
83+
### v3.2.1 (2020-01-11)
84+
85+
86+
#### Bug Fixes
87+
88+
* remove apparently unused require for thwait ([4a08fd5](/../../commit/4a08fd5))
89+
90+
91+
<a name="v3.2.0"></a>
92+
### v3.2.0 (2019-09-19)
93+
94+
95+
#### Features
96+
97+
* **skip writing to pact**
98+
* Use writable_interactions when writing to pact file ([44ea0c3](/../../commit/44ea0c3))
99+
100+
101+
<a name="v3.1.0"></a>
102+
### v3.1.0 (2019-05-01)
103+
104+
105+
#### Features
106+
107+
* pact-stub-service log level cli opt ([9264a87](/../../commit/9264a87))
108+
109+
110+
<a name="v3.0.1"></a>
111+
### v3.0.1 (2019-03-08)
112+
113+
114+
#### Bug Fixes
115+
116+
* add missing host argument to server spawn ([ee5cf90](/../../commit/ee5cf90))
117+
118+
119+
<a name="v3.0.0"></a>
120+
### v3.0.0 (2019-02-21)
121+
122+
123+
#### Features
124+
125+
* allow mock service host to be configured ([7e2d810](/../../commit/7e2d810))
126+
127+
1128
<a name="v2.11.0"></a>
2129
### v2.11.0 (2018-08-28)
3130

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Pact Mock and Stub Service
33

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

66
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.
77

lib/pact/consumer/mock_service/cors_origin_header_middleware.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def shutdown
2323
private
2424

2525
def add_cors_header env, response
26-
[response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]]
26+
cors_headers = { 'Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*'), 'Access-Control-Allow-Credentials' => 'true'}
27+
[response[0], response[1].merge(cors_headers), response[2]]
2728
end
2829
end
2930
end

lib/pact/consumer/mock_service/rack_request_helper.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'cgi/core'
2+
require 'pact/consumer_contract/query'
3+
24
module Pact
35
module Consumer
46

@@ -11,7 +13,7 @@ module RackRequestHelper
1113
}
1214

1315
def params_hash env
14-
CGI::parse env["QUERY_STRING"]
16+
Pact::Query.parse_string(env["QUERY_STRING"])
1517
end
1618

1719
def request_as_hash_from env

lib/pact/consumer/server.rb

+6-9
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ def ports
3434
end
3535
end
3636

37-
attr_reader :app, :port, :options
37+
attr_reader :app, :host, :port, :options
3838

39-
def initialize(app, port, options = {})
39+
def initialize(app, host, port, options = {})
4040
@app = app
4141
@middleware = Middleware.new(@app)
4242
@server_thread = nil
43+
@host = host
4344
@port = port
4445
@options = options
4546
end
@@ -52,10 +53,6 @@ def error
5253
@middleware.error
5354
end
5455

55-
def host
56-
"localhost"
57-
end
58-
5956
def responsive?
6057
return false if @server_thread && @server_thread.join(0)
6158
res = get_identity
@@ -70,7 +67,7 @@ def responsive?
7067

7168
def run_default_server(app, port)
7269
require 'rack/handler/webrick'
73-
Rack::Handler::WEBrick.run(app, webrick_opts) do |server|
70+
Rack::Handler::WEBrick.run(app, **webrick_opts) do |server|
7471
@port = server[:Port]
7572
end
7673
end
@@ -86,7 +83,7 @@ def get_identity
8683
end
8784

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

9895
def ssl_opts
99-
{ SSLEnable: true, SSLCertName: [ %w[CN localhost] ] }
96+
{ SSLEnable: true, SSLCertName: [ ["CN", host] ] }
10097
end
10198

10299
def boot

0 commit comments

Comments
 (0)