Skip to content

Commit

Permalink
Merge branch 'master' into snyk-fix-eb2db8b40f29216a80c489ed6479d911
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F authored Nov 30, 2024
2 parents c533e2f + 3c7814c commit bd50acc
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 38 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ruby_version: ["2.7", "3.0", "3.1", "3.2", "3.3"]
os: ["ubuntu-latest","windows-latest","macos-latest"]
rack_version: ["2", "3"]
runs-on: ${{ matrix.os }}
env:
RACK_VERSION: ${{ matrix.rack_version }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
- run: "bundle install"
- run: "bundle exec rake"
- run: "bundle exec rake"
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<a name="v1.39.0"></a>
### v1.39.0 (2024-11-29)

#### Features

* rack 3 support with rack 2 backwards compat ([c534282](/../../commit/c534282))

* **generators**
* More test cases ([78a42d7](/../../commit/78a42d7))
* Pass provider state results back so we can use ProviderState generator ([89fe1c4](/../../commit/89fe1c4))

#### Bug Fixes

* support rack 2 and 3 ([b812dc0](/../../commit/b812dc0))

<a name="v1.38.2"></a>
### v1.38.2 (2024-10-23)

Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ if ENV['X_PACT_DEVELOPMENT']
gem "pact-message", path: '../pact-message-ruby'
gem "pact-support", path: '../pact-support'
end

gem 'rack-reverse-proxy', git: 'https://github.com/pact-foundation/rack-reverse-proxy.git',
branch: 'feat/rack_2_and_3_compat'
2 changes: 1 addition & 1 deletion examples/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source 'https://rubygems.org'

gem 'sinatra', '>= 4.1.0'
gem 'sinatra-contrib', '>= 4.1.0'
gem 'pact-provider-verifier', '>= 1.38.1'
gem 'pact-provider-verifier', '>= 1.39.0'
64 changes: 36 additions & 28 deletions examples/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,37 @@ GEM
specs:
awesome_print (1.9.2)
base64 (0.2.0)
bigdecimal (3.1.8)
diff-lcs (1.5.1)
expgen (0.1.1)
parslet
faraday (2.8.1)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
faraday (2.12.1)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
faraday-retry (2.2.1)
faraday (~> 2.0)
find_a_port (1.0.1)
json (2.7.2)
json (2.8.2)
jsonpath (1.1.5)
multi_json
logger (1.6.1)
multi_json (1.15.0)
mustermann (3.0.0)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
pact (1.65.0)
net-http (0.5.0)
uri
ostruct (0.6.1)
pact (1.66.0)
jsonpath (~> 1.0)
pact-mock_service (~> 3.0, >= 3.3.1)
pact-support (~> 1.16, >= 1.16.9)
pact-support (~> 1.19, >= 1.19.0)
rack-test (>= 0.6.3, < 3.0.0)
rainbow (~> 3.1)
rspec (~> 3.0)
term-ansicolor (~> 1.7)
string_pattern (~> 2.0)
thor (>= 0.20, < 2.0)
webrick (~> 1.8)
pact-message (0.11.1)
pact-mock_service (~> 3.1)
pact-support (~> 1.8)
Expand All @@ -39,23 +46,26 @@ GEM
rspec (>= 2.14)
thor (>= 0.19, < 2.0)
webrick (~> 1.8)
pact-provider-verifier (1.38.1)
pact-provider-verifier (1.38.2)
faraday (~> 2.5)
faraday-retry (~> 2.2)
json (> 1.8)
ostruct
pact (~> 1.59)
pact-message (~> 0.5)
rack (~> 2.1)
rack-reverse-proxy
rspec (~> 3.5)
rspec_junit_formatter (~> 0.3)
pact-support (1.20.0)
pact-support (1.21.1)
awesome_print (~> 1.9)
diff-lcs (~> 1.5)
expgen (~> 0.1)
jsonpath (~> 1.0)
rainbow (~> 3.1.1)
string_pattern (~> 2.0)
parslet (2.0.0)
rack (2.2.9)
rack (2.2.10)
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
Expand All @@ -67,16 +77,17 @@ GEM
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
regexp_parser (2.9.2)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
Expand All @@ -94,15 +105,12 @@ GEM
rack-protection (= 3.2.0)
sinatra (= 3.2.0)
tilt (~> 2.0)
sync (0.5.0)
term-ansicolor (1.11.2)
tins (~> 1.0)
thor (1.3.1)
tilt (2.3.0)
tins (1.33.0)
bigdecimal
sync
webrick (1.8.1)
string_pattern (2.3.0)
regexp_parser (~> 2.5, >= 2.5.0)
thor (1.3.2)
tilt (2.4.0)
uri (1.0.2)
webrick (1.9.0)

PLATFORMS
ruby
Expand All @@ -113,4 +121,4 @@ DEPENDENCIES
sinatra-contrib (>= 3.1.0)

BUNDLED WITH
2.4.10
2.5.23
5 changes: 5 additions & 0 deletions lib/pact/provider_verifier/set_up_provider_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def call
log_request
response = post_to_provider_state
check_for_error response
begin
JSON.parse(response.body)
rescue
{}
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider_verifier/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Pact
module ProviderVerifier
VERSION = "1.38.2"
VERSION = "1.39.0"
end
end
8 changes: 7 additions & 1 deletion pact-provider-verifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'faraday', '~> 2.5'
gem.add_runtime_dependency 'faraday-retry', '~> 2.2'
gem.add_runtime_dependency 'json', '>1.8'
gem.add_runtime_dependency 'rack', '~> 2.1'
if ENV['RACK_VERSION'] == '2'
gem.add_runtime_dependency 'rack', '>= 2.0', '< 3.0'
else
gem.add_runtime_dependency 'rack', '>= 3.0', '< 4.0'
gem.add_runtime_dependency 'rackup', '~> 2.0'
end

gem.add_runtime_dependency 'rack-reverse-proxy'
gem.add_runtime_dependency 'rspec_junit_formatter', '~> 0.3'
gem.add_runtime_dependency 'ostruct'
Expand Down
1 change: 1 addition & 0 deletions spec/integration_with_pact_broker_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'pact/provider_verifier/cli/verify'
require 'pact/pact_broker'
require 'pact/cli/run_pact_verification'
require 'ostruct'

describe "pact-provider-verifier with pact broker config" do
before do
Expand Down
27 changes: 27 additions & 0 deletions spec/integration_with_provider_state_in_headers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'json'

describe "pact-provider-verifier with a provider state injected to a pact file" do
before(:all) do
@pipe = IO.popen("bundle exec rackup -p 5837 spec/support/provider_with_state_generator.rb")
sleep 2
end

subject { `bundle exec bin/pact-provider-verifier spec/support/pacts/pact-with-provider-state-in-headers.json -a 1 --provider-base-url http://localhost:5837/ --provider-states-setup-url http://localhost:5837/provider_state -v` }

it "exits with a 0 exit code" do
subject
expect($?).to eq 0
end

it "the output contains a success message" do
expect(subject).to include "1 interaction, 0 failures"
end

after(:all) do
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
27 changes: 27 additions & 0 deletions spec/integration_with_provider_state_in_path.spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'json'

describe "pact-provider-verifier with a provider state injected to a pact file" do
before(:all) do
@pipe = IO.popen("bundle exec rackup -p 5837 spec/support/provider_with_state_generator.rb")
sleep 2
end

subject { `bundle exec bin/pact-provider-verifier spec/support/pacts/pact-with-provider-state-in-path.json -a 1 --provider-base-url http://localhost:5837/ --provider-states-setup-url http://localhost:5837/provider_state -v` }

it "exits with a 0 exit code" do
subject
expect($?).to eq 0
end

it "the output contains a success message" do
expect(subject).to include "1 interaction, 0 failures"
end

after(:all) do
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'pact/provider_verifier/aggregate_pact_configs'
require 'ostruct'

module Pact
module ProviderVerifier
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pact/provider_verifier/set_up_provider_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ module ProviderVerifier

before do
ENV['PROVIDER_STATES_SETUP_URL'] = provider_states_setup_url
stub_request(:post, provider_states_setup_url)
stub_request(:post, provider_states_setup_url).to_return(status: 200, body: '{"id":2}')
allow($stdout).to receive(:puts)
allow($stderr).to receive(:puts)
end

it "makes a HTTP request to the configured URL with a JSON body containing the consumer and provider state names" do
subject
expect(subject).to eq({"id" => 2})
expect(WebMock).to have_requested(:post, provider_states_setup_url).
with(body: {consumer: consumer, state: provider_state, states: [provider_state], params: params}, headers: {'Content-Type' => "application/json"})
end
Expand Down
3 changes: 2 additions & 1 deletion spec/support/message_producer_verifier.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO provider states

require 'json'
require 'ostruct'

class Provider
def a_test_message
Expand Down Expand Up @@ -31,7 +32,7 @@ class HttpRequestHandler
request_body = JSON.parse(env['rack.input'].read)
message_descriptor = OpenStruct.new(request_body)
response_body = @message_creator.create(message_descriptor)
[200, {'Content-Type' => 'application/json'}, [response_body.to_json]]
[200, {'content-type' => 'application/json'}, [response_body.to_json]]
end

end
Expand Down
44 changes: 44 additions & 0 deletions spec/support/pacts/pact-with-provider-state-in-headers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"provider": {
"name": "Foo"
},
"consumer": {
"name": "Bar"
},
"interactions": [
{
"description": "requires access token",
"request": {
"method": "GET",
"path": "/requires_auth",
"headers": {
"Authorization": "Bearer EXAMPLE_TOKEN"
},
"generators": {
"header": {
"$.Authorization": {
"expression": "Bearer ${accessToken}",
"type": "ProviderState"
}
}
}
},
"response": {
"status": 200
},
"providerStates": [
{
"name": "returns access token"
}
]
}
],
"metadata": {
"pactSpecification": {
"version": "3.0.0"
},
"pact-jvm": {
"version": "4.0.5"
}
}
}
Loading

0 comments on commit bd50acc

Please sign in to comment.