pact-provider-proxy 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fff4c4e689274a735a1c2790a49b418508a477f
4
- data.tar.gz: 62a90848138e3bdcd67d0328f20581615a7aad01
3
+ metadata.gz: a835258d02945701410cdc978b02b7b8e656477e
4
+ data.tar.gz: d4bc8f3a387ac064feade93602f6118271a3f9e7
5
5
  SHA512:
6
- metadata.gz: 7745ed6e4c846342d9569601dd7ae087d4e1c9622cf70d330aed46ac274caa85c11e060574315ff60742278e779d47f15e1364fb9926e57be5aa6ff8186e1ded
7
- data.tar.gz: 98daf31e5a6f7239d447c4a74c8ceb018acc4dc0189a407c1b940a2137351454927bb77fa53c0f8c6f8a4e2e6016c6f08567db57b9e73e430ae7e4c3d70c4937
6
+ metadata.gz: 1581af0784fef508920900b32eb51123b2a695a733fdc81e4ffd929c8a03dc8958631a9c34065d003132f020244365e614550b0628357f108f4f5a898b6c3dc4
7
+ data.tar.gz: f10756370ec4e5fe7de287c54d04d8def53b0aef61e5f80dec0b685fe8a80c9af4fe2d9fc5ba3b6fb98c0f7e6f7e3124c1a1983db709483278befbf051184095
@@ -1,5 +1,8 @@
1
1
  git log --pretty=format:' * %h - %s (%an, %ad)'
2
2
 
3
+ ### 2.3.0 (2017-10-31)
4
+ * e76a469 - feat: add provider_app_version and publish_verification_results to rake task (Beth Skurrie, Tue Oct 31 16:02:15 2017 +1100)
5
+
3
6
  ### 2.2.0 (3 Aug 2017)
4
7
  * 8a872c2 - feat(ssl verify none): Turn off SSL verification so that servers can run using self signed certificates. (Beth Skurrie, Thu Aug 3 14:04:26 2017 +1000)
5
8
 
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ __Note: This gem has been mostly superseeded by the [pact-provider-verifier](https://github.com/pact-foundation/pact-provider-verifier). The main difference between the two is that the pact-provider-proxy allowes you to set up your provider states using the Ruby DSL, and the pact-provider-verifier allows you to set up your provider states using a HTTP request to a URL that you specify.__
2
+
1
3
  # Pact::Provider::Proxy
2
4
 
3
5
  [![Build Status](https://travis-ci.org/pact-foundation/pact-provider-proxy.svg?branch=master)](https://travis-ci.org/pact-foundation/pact-provider-proxy)
@@ -33,6 +35,8 @@ require 'pact/provider/proxy/tasks'
33
35
  Pact::ProxyVerificationTask.new :monolith do | task |
34
36
  task.pact_url './spec/pacts/my-consumer_my-monolith.json', :pact_helper => './spec/support/monolith_pact_helper'
35
37
  task.provider_base_url 'http://my-monolith:8080' #scheme, host and optional port
38
+ task.provider_app_version '1.2.3'
39
+ task.publish_verification_results true
36
40
  end
37
41
  ```
38
42
 
@@ -68,11 +72,9 @@ end
68
72
 
69
73
  ```
70
74
 
71
- If a ruby adapter to the underlying datastore cannot be used to set up provider states, shell scripts that invoke code in the native language might work. If you have access to the code base, another alternative could be to provide an endpoint on your app that sets up data inside itself, that is only mounted in test mode. eg 'http://localhost:8080/set-up-provider-state?name=a%20thing%20exists' and 'http://localhost:8080/tear-down-provider-state?name=a%20thing%20exists'
72
-
73
- ## Feature support
75
+ If you need to modify your request before replaying it (eg. to set a valid token), then follow the example in [spec/support/middleware_pact_helper.rb](spec/support/middleware_pact_helper.rb).
74
76
 
75
- pact-provider-proxy is fully compatible with pacts generated by the Ruby implementation of Pact, including Pact::Terms. However, it does not yet support the v2.0 regular expression syntax implemented in the JVM version of Pact.
77
+ If a ruby adapter to the underlying datastore cannot be used to set up provider states, shell scripts that invoke code in the native language might work. If you have access to the code base, another alternative could be to provide an endpoint on your app that sets up data inside itself, that is only mounted in test mode. eg 'http://localhost:8080/set-up-provider-state?name=a%20thing%20exists' and 'http://localhost:8080/tear-down-provider-state?name=a%20thing%20exists'
76
78
 
77
79
  ## Contributing
78
80
 
@@ -11,6 +11,14 @@ Pact.service_provider "Running Provider Application" do
11
11
  reverse_proxy '/', ENV.fetch('PACT_PROVIDER_BASE_URL')
12
12
  end
13
13
  end
14
+
15
+ if ENV.fetch('PACT_PROVIDER_APP_VERSION', '') != ''
16
+ app_version ENV['PACT_PROVIDER_APP_VERSION']
17
+ end
18
+
19
+ if ENV.fetch('PACT_PUBLISH_VERIFICATION_RESULTS', '') != ''
20
+ publish_verification_results ENV['PACT_PUBLISH_VERIFICATION_RESULTS'] == 'true'
21
+ end
14
22
  end
15
23
 
16
24
  require ENV['PACT_PROJECT_PACT_HELPER'] if ENV.fetch('PACT_PROJECT_PACT_HELPER','') != ''
@@ -9,6 +9,8 @@ module Pact
9
9
  @pact_spec_configs = []
10
10
  @provider_base_url = nil
11
11
  @name = name
12
+ @publish_verification_results = false
13
+ @provider_app_version = nil
12
14
  yield self
13
15
  rake_task
14
16
  end
@@ -25,6 +27,14 @@ module Pact
25
27
  @provider_base_url = url
26
28
  end
27
29
 
30
+ def provider_app_version provider_app_version
31
+ @provider_app_version = provider_app_version
32
+ end
33
+
34
+ def publish_verification_results publish_verification_results
35
+ @publish_verification_results = publish_verification_results
36
+ end
37
+
28
38
  private
29
39
 
30
40
  attr_reader :name
@@ -41,6 +51,8 @@ module Pact
41
51
  exit_statuses = pact_spec_configs.collect do | config |
42
52
  ENV['PACT_PROVIDER_BASE_URL'] = @provider_base_url
43
53
  ENV['PACT_PROJECT_PACT_HELPER'] = config[:pact_helper]
54
+ ENV['PACT_PROVIDER_APP_VERSION'] = @provider_app_version
55
+ ENV['PACT_PUBLISH_VERIFICATION_RESULTS'] = "#{@publish_verification_results}"
44
56
  Pact::Provider::Proxy::TaskHelper.execute_pact_verify config[:uri], proxy_pact_helper
45
57
  end
46
58
 
@@ -1,7 +1,7 @@
1
1
  module Pact
2
2
  module Provider
3
3
  module Proxy
4
- VERSION = "2.2.0"
4
+ VERSION = "2.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,28 @@
1
+ require 'rack/reverse_proxy'
2
+ require 'rack/test'
3
+
4
+ module Rack
5
+ describe ReverseProxy do
6
+ include Rack::Test::Methods
7
+
8
+ before(:all) do
9
+ @pipe = IO.popen("ruby spec/support/echoing_server.rb")
10
+ sleep 2
11
+ end
12
+
13
+ after(:all) do
14
+ Process.kill 'KILL', @pipe.pid
15
+ end
16
+
17
+ let(:app) do
18
+ Rack::ReverseProxy.new do
19
+ reverse_proxy '/', 'http://localhost:2000'
20
+ end
21
+ end
22
+
23
+ it 'somehow converts all caps header names into properly capitalized headers' do
24
+ get '/', nil, {'HTTP_FOO_BAR' => 'wiffle' }
25
+ expect(last_response.body).to include('Foo-Bar: wiffle')
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'socket'
2
+
3
+ server = TCPServer.new 2000 # Server bind to port 2000
4
+ loop do
5
+ client = server.accept # Wait for a client to connect
6
+ request = ""
7
+ while (line = client.gets) != "\r\n"
8
+ request += line # Prints whatever the client enters on the server's output
9
+ end
10
+ client.puts "HTTP/1.1 200 OK"
11
+ client.puts "Content-Type: text/plain"
12
+ client.puts "\r\n"
13
+ # Echo back entire request in body
14
+ client.puts request
15
+ client.puts "\r\n"
16
+ client.close
17
+ end
@@ -0,0 +1,43 @@
1
+ require 'pact/provider/rspec'
2
+
3
+ Pact.provider_states_for "a consumer" do
4
+ provider_state "some state" do
5
+ no_op
6
+ end
7
+ end
8
+
9
+ class Middleware
10
+
11
+ DATE_PATTERN = /\d\d\d\d\-\d\d-\d\d/
12
+
13
+ def initialize app
14
+ @app = app
15
+ end
16
+
17
+ def call env
18
+ x_expiry = env['HTTP_X_EXPIRY']
19
+ if x_expiry =~ DATE_PATTERN
20
+ set_dynamic_expiry env
21
+ @app.call(env)
22
+ else
23
+ error_response(x_expiry)
24
+ end
25
+ end
26
+
27
+ def set_dynamic_expiry env
28
+ dynamic_expiry = (DateTime.now + 1).strftime('%Y-%m-%d')
29
+ puts "Setting dynamic expiry to #{dynamic_expiry}"
30
+ env['HTTP_X_EXPIRY'] = dynamic_expiry
31
+ end
32
+
33
+ def error_response x_expiry
34
+ error_message = "Error replaying request. Expected X-Expiry header to match #{DATE_PATTERN.inspect} but actual value was #{x_expiry.inspect}"
35
+ [500, {}, [error_message]]
36
+ end
37
+ end
38
+
39
+ reverse_proxy = Pact.configuration.provider.app
40
+
41
+ Pact.service_provider "Running Service Provider" do
42
+ app { Middleware.new(reverse_proxy) }
43
+ end
@@ -6,10 +6,17 @@
6
6
  "description": "a request for the index",
7
7
  "provider_state": "some state",
8
8
  "request" : {
9
- "method" : "get", "path": "/"
10
- },
9
+ "method" : "get",
10
+ "path": "/",
11
+ "headers": {
12
+ "X-Expiry": "2016-01-01"
13
+ }
14
+ },
11
15
  "response": {
12
16
  "status" : 200,
17
+ "headers": {
18
+ "Content-Type": "text/plain"
19
+ },
13
20
  "body": "Monolith!"
14
21
  }
15
22
  }
@@ -1,10 +1,22 @@
1
1
  require 'pact/provider/proxy/tasks'
2
2
 
3
+ Pact::ProxyVerificationTask.new :middleware do | task |
4
+ task.pact_url './spec/support/pact.json', :pact_helper => './spec/support/middleware_pact_helper'
5
+ task.provider_base_url 'http://localhost:9494'
6
+ end
7
+
3
8
  Pact::ProxyVerificationTask.new :monolith do | task |
4
9
  task.pact_url './spec/support/pact.json', :pact_helper => './spec/support/custom_pact_helper'
5
10
  task.provider_base_url 'http://localhost:9292'
6
11
  end
7
12
 
13
+ Pact::ProxyVerificationTask.new :monolith_with_verification do | task |
14
+ task.pact_url 'http://localhost:9293/pacts/provider/a%20running%20provider/consumer/a%20consumer/latest', :pact_helper => './spec/support/custom_pact_helper'
15
+ task.provider_base_url 'http://localhost:9292'
16
+ task.publish_verification_results true
17
+ task.provider_app_version '1.2.3'
18
+ end
19
+
8
20
  Pact::ProxyVerificationTask.new :monolith_ssl do | task |
9
21
  task.pact_url './spec/support/pact.json', :pact_helper => './spec/support/custom_pact_helper'
10
22
  task.provider_base_url 'https://localhost:9393'
@@ -24,11 +36,26 @@ namespace :pact do
24
36
  namespace :test do
25
37
  task :spawn_test_monolith do
26
38
  require 'pact/mock_service/app_manager'
27
- app = lambda { | env | [200, {}, ["Monolith!"]] }
39
+ app = lambda { | env | [200, {"Content-Type" => "text/plain"}, ["Monolith!"]] }
28
40
  Pact::MockService::AppManager.instance.register app, 9292
29
41
  Pact::MockService::AppManager.instance.spawn_all
30
42
  end
31
43
 
44
+ task :spawn_test_monolith_which_needs_dynamic_header do
45
+ require 'pact/mock_service/app_manager'
46
+ app = lambda { | env |
47
+ require 'date'
48
+ expiry = DateTime.strptime(env['HTTP_X_EXPIRY'], "%Y-%m-%d")
49
+ if expiry > DateTime.now
50
+ [200, {"Content-Type" => "text/plain"}, ["Monolith!"]]
51
+ else
52
+ [401, {"Content-Type" => "text/plain"}, ["Expired!"]]
53
+ end
54
+ }
55
+ Pact::MockService::AppManager.instance.register app, 9494
56
+ Pact::MockService::AppManager.instance.spawn_all
57
+ end
58
+
32
59
  task :spawn_test_monolith_ssl do
33
60
  @@ssl_server_pid = fork do
34
61
  trap 'INT' do @server.shutdown end
@@ -36,7 +63,7 @@ namespace :pact do
36
63
  require 'rack/handler/webrick'
37
64
  require 'webrick/https'
38
65
 
39
- app = lambda { | env | [200, {}, ["Monolith!"]] }
66
+ app = lambda { | env | [200, {"Content-Type" => "text/plain"}, ["Monolith!"]] }
40
67
  webrick_opts = {:Port => 9393, :SSLEnable => true, :SSLCertName => [%w[CN localhost]]}
41
68
  Rack::Handler::WEBrick.run(app, webrick_opts) do |server|
42
69
  @server = server
@@ -64,11 +91,13 @@ task 'create_custom_pact_helper' do
64
91
  end
65
92
 
66
93
  task 'pact:verify:monolith' => ['pact:test:spawn_test_monolith', 'delete_pact_helper', 'create_custom_pact_helper']
94
+ task 'pact:verify:monolith_with_verification' => ['pact:test:spawn_test_monolith', 'delete_pact_helper', 'create_custom_pact_helper']
67
95
  task 'pact:verify:monolith_ssl' => ['pact:test:spawn_test_monolith_ssl', 'delete_pact_helper', 'create_custom_pact_helper']
68
96
  task 'pact:verify:monolith_no_pact_helper' => ['pact:test:spawn_test_monolith', 'delete_pact_helper', 'create_pact_helper_that_should_not_be_loaded']
97
+ task 'pact:verify:middleware' => ['pact:test:spawn_test_monolith_which_needs_dynamic_header']
69
98
 
70
99
  require 'rspec/core/rake_task'
71
100
 
72
101
  RSpec::Core::RakeTask.new(:spec)
73
102
 
74
- task :default => [:spec, 'pact:verify:monolith_no_pact_helper','pact:verify:monolith', 'pact:verify:monolith_ssl']
103
+ task :default => [:spec, 'pact:verify:monolith_no_pact_helper','pact:verify:monolith', 'pact:verify:monolith_ssl', 'pact:verify:middleware']
@@ -105,7 +105,7 @@ module Rack
105
105
  end
106
106
 
107
107
  def reconstruct_header_name(name)
108
- name.sub(/^HTTP_/, "").split("_").collect(&:capitalize).join("-")
108
+ name.sub(/^HTTP_/, "").gsub("_", "-")
109
109
  end
110
110
 
111
111
  def get_matcher(path, headers, rackreq)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-provider-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pact
@@ -125,7 +125,10 @@ files:
125
125
  - spec/fixtures/do_not_load_pact_helper.rb
126
126
  - spec/fixtures/template_pact_helper.rb
127
127
  - spec/lib/pact/provider/proxy/task_helper_spec.rb
128
+ - spec/lib/rack/reverse_proxy_spec.rb
128
129
  - spec/support/custom_pact_helper.rb
130
+ - spec/support/echoing_server.rb
131
+ - spec/support/middleware_pact_helper.rb
129
132
  - spec/support/pact-with-no-provider-states.json
130
133
  - spec/support/pact.json
131
134
  - spec/tasks.rake
@@ -167,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
170
  version: '0'
168
171
  requirements: []
169
172
  rubyforge_project:
170
- rubygems_version: 2.4.5.2
173
+ rubygems_version: 2.6.11
171
174
  signing_key:
172
175
  specification_version: 4
173
176
  summary: Allows verification of a pact against a running provider
@@ -175,7 +178,10 @@ test_files:
175
178
  - spec/fixtures/do_not_load_pact_helper.rb
176
179
  - spec/fixtures/template_pact_helper.rb
177
180
  - spec/lib/pact/provider/proxy/task_helper_spec.rb
181
+ - spec/lib/rack/reverse_proxy_spec.rb
178
182
  - spec/support/custom_pact_helper.rb
183
+ - spec/support/echoing_server.rb
184
+ - spec/support/middleware_pact_helper.rb
179
185
  - spec/support/pact-with-no-provider-states.json
180
186
  - spec/support/pact.json
181
187
  - spec/tasks.rake