pact-mock_service 3.4.0 → 3.7.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
  SHA256:
3
- metadata.gz: 1e2f124e5c5dcc30b7da04339d08060ebff78da1ea42124b70e38bb8dc9640e2
4
- data.tar.gz: d3bd8504db25fe694049c4781afa05475ec685650be7f95a731b89a3cdb7e86e
3
+ metadata.gz: 9c3129a847616f140d536b6123ab116f691ca5cfd4ded15918d481896a48349f
4
+ data.tar.gz: ddd7f7761c5f0e49e553047387a0bb90a909de764d317c0dd78ebb1935461656
5
5
  SHA512:
6
- metadata.gz: 4ddbe4e7896061f66dde24509fe19530cf2a3da38f74d1bf1c87631c383c73a774cec603cc4df2d4b8c1a9d3d5189fc2ab04ce4dec53eb61cb47c5c0c6648dfa
7
- data.tar.gz: 322eb829df216e995d2d763260f81b87ee302696fa1195b9f6a6a14208d44de346b26e08d626c62ac511ddd696a941dc7bfe2942e3b0aa36a2b54727acce80a9
6
+ metadata.gz: 1dc4daeac63353379b94f0a4ba9be811b14cf90d14c37de74d6922aecfc765407270df3cc843907817a54570415f72a26d4fac17f9fd726d0aede35e5fb47168
7
+ data.tar.gz: 5c311e4d4cd99f18aca430e0cfd7d1f9255eec52145843edc84da8c8d72eb39a86ea66aa4fd2c572a7581548bbcf1f4620ca6e75d641f2431afd3ac04f5d553d
@@ -1,3 +1,45 @@
1
+ <a name="v3.7.0"></a>
2
+ ### v3.7.0 (2020-11-13)
3
+
4
+ #### Features
5
+
6
+ * use Pact::Query.parse_string to parse query string ([6cd0733](/../../commit/6cd0733))
7
+ * do not require files until command is executing ([ad54d0b](/../../commit/ad54d0b))
8
+
9
+ <a name="v3.6.2"></a>
10
+ ### v3.6.2 (2020-08-10)
11
+
12
+ #### Bug Fixes
13
+
14
+ * update thor dependency (#124) ([54b3f85](/../../commit/54b3f85))
15
+
16
+ <a name="v3.6.1"></a>
17
+ ### v3.6.1 (2020-04-22)
18
+
19
+
20
+ #### Bug Fixes
21
+
22
+ * fix Ruby 2.7 kwargs warning (#122) ([4a46c21](/../../commit/4a46c21))
23
+
24
+
25
+ <a name="v3.6.0"></a>
26
+ ### v3.6.0 (2020-03-14)
27
+
28
+
29
+ #### Features
30
+
31
+ * add 'Access-Control-Allow-Headers' = true to cors response headers (#121) ([61bd9d1](/../../commit/61bd9d1))
32
+
33
+
34
+ <a name="v3.5.0"></a>
35
+ ### v3.5.0 (2020-01-17)
36
+
37
+
38
+ #### Features
39
+
40
+ * add token, username and password options to stub service (#118) ([76236d8](/../../commit/76236d8))
41
+
42
+
1
43
  <a name="v3.3.1"></a>
2
44
  ### v3.3.1 (2020-01-16)
3
45
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # Pact Mock and Stub Service
3
3
 
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)
5
5
 
6
6
  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.
7
7
 
@@ -23,7 +23,8 @@ module Pact
23
23
  private
24
24
 
25
25
  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]]
27
28
  end
28
29
  end
29
30
  end
@@ -1,4 +1,6 @@
1
1
  require 'cgi/core'
2
+ require 'pact/consumer_contract/query'
3
+
2
4
  module Pact
3
5
  module Consumer
4
6
 
@@ -11,7 +13,7 @@ module Pact
11
13
  }
12
14
 
13
15
  def params_hash env
14
- CGI::parse env["QUERY_STRING"]
16
+ Pact::Query.parse_string(env["QUERY_STRING"])
15
17
  end
16
18
 
17
19
  def request_as_hash_from env
@@ -67,7 +67,7 @@ module Pact
67
67
 
68
68
  def run_default_server(app, port)
69
69
  require 'rack/handler/webrick'
70
- Rack::Handler::WEBrick.run(app, webrick_opts) do |server|
70
+ Rack::Handler::WEBrick.run(app, **webrick_opts) do |server|
71
71
  @port = server[:Port]
72
72
  end
73
73
  end
@@ -17,6 +17,7 @@ module Pact
17
17
  class App
18
18
  def initialize options = {}
19
19
  logger = Logger.from_options(options)
20
+ @options = options
20
21
  stubbing = options[:stub_pactfile_paths] && options[:stub_pactfile_paths].any?
21
22
  @name = options.fetch(:name, "MockService")
22
23
  @session = Session.new(options.merge(logger: logger, warn_on_too_many_interactions: !stubbing))
@@ -40,7 +41,7 @@ module Pact
40
41
  def setup_stub stub_pactfile_paths
41
42
  interactions = stub_pactfile_paths.collect do | pactfile_path |
42
43
  $stdout.puts "INFO: Loading interactions from #{pactfile_path}"
43
- hash_interactions = JSON.parse(Pact::PactFile.read(pactfile_path))['interactions']
44
+ hash_interactions = JSON.parse(Pact::PactFile.read(pactfile_path, pactfile_options))['interactions']
44
45
  hash_interactions.collect { | hash | Interaction.from_hash(hash) }
45
46
  end.flatten
46
47
  @session.set_expected_interactions interactions
@@ -57,6 +58,20 @@ module Pact
57
58
  def to_s
58
59
  "#{@name} #{super.to_s}"
59
60
  end
61
+
62
+ private
63
+
64
+ def pactfile_options
65
+ {
66
+ :token => broker_token,
67
+ :username => @options[:broker_username],
68
+ :password => @options[:broker_password],
69
+ }
70
+ end
71
+
72
+ def broker_token
73
+ @options[:broker_token] || ENV['PACT_BROKER_TOKEN']
74
+ end
60
75
  end
61
76
 
62
77
  # Can't write to a file in a TRAP, might deadlock
@@ -1,14 +1,11 @@
1
1
  require 'thor'
2
- require 'webrick/https'
3
- require 'rack/handler/webrick'
4
- require 'fileutils'
5
- require 'pact/mock_service/server/wait_for_server_up'
6
- require 'pact/mock_service/cli/pidfile'
7
- require 'socket'
8
2
 
9
3
  module Pact
10
4
  module MockService
11
5
  class CLI < Thor
6
+ def self.exit_on_failure? # Thor 1.0 deprecation guard
7
+ false
8
+ end
12
9
 
13
10
  PACT_FILE_WRITE_MODE_DESC = "`overwrite` or `merge`. Use `merge` when running multiple mock service instances in parallel for the same consumer/provider pair." +
14
11
  " Ensure the pact file is deleted before running tests when using this option so that interactions deleted from the code are not maintained in the file."
@@ -30,6 +27,7 @@ module Pact
30
27
  method_option :monkeypatch, hide: true
31
28
 
32
29
  def service
30
+ require_common_dependencies
33
31
  require 'pact/mock_service/run'
34
32
  Run.(options)
35
33
  end
@@ -48,6 +46,7 @@ module Pact
48
46
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
49
47
 
50
48
  def control
49
+ require_common_dependencies
51
50
  require 'pact/mock_service/control_server/run'
52
51
  ControlServer::Run.(options)
53
52
  end
@@ -70,6 +69,7 @@ module Pact
70
69
  method_option :monkeypatch, hide: true
71
70
 
72
71
  def start
72
+ require_common_dependencies
73
73
  start_server(mock_service_pidfile) do
74
74
  service
75
75
  end
@@ -80,6 +80,7 @@ module Pact
80
80
  method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"
81
81
 
82
82
  def stop
83
+ require_common_dependencies
83
84
  mock_service_pidfile.kill_process
84
85
  end
85
86
 
@@ -100,6 +101,7 @@ module Pact
100
101
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
101
102
 
102
103
  def restart
104
+ require_common_dependencies
103
105
  restart_server(mock_service_pidfile) do
104
106
  service
105
107
  end
@@ -120,6 +122,7 @@ module Pact
120
122
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written", default: "."
121
123
 
122
124
  def control_start
125
+ require_common_dependencies
123
126
  start_server(control_server_pidfile) do
124
127
  control
125
128
  end
@@ -130,6 +133,7 @@ module Pact
130
133
  method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"
131
134
 
132
135
  def control_stop
136
+ require_common_dependencies
133
137
  control_server_pidfile.kill_process
134
138
  end
135
139
 
@@ -148,6 +152,7 @@ module Pact
148
152
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
149
153
 
150
154
  def control_restart
155
+ require_common_dependencies
151
156
  restart_server(control_server_pidfile) do
152
157
  control
153
158
  end
@@ -164,6 +169,15 @@ module Pact
164
169
 
165
170
  no_commands do
166
171
 
172
+ def require_common_dependencies
173
+ require 'webrick/https'
174
+ require 'rack/handler/webrick'
175
+ require 'fileutils'
176
+ require 'pact/mock_service/server/wait_for_server_up'
177
+ require 'pact/mock_service/cli/pidfile'
178
+ require 'socket'
179
+ end
180
+
167
181
  def control_server_pidfile
168
182
  Pidfile.new(pid_dir: options[:pid_dir], name: control_pidfile_name)
169
183
  end
@@ -11,6 +11,9 @@ module Pact
11
11
  # `script --help` to display the help for the default task instead of the command list
12
12
  #
13
13
  class CustomThor < ::Thor
14
+ def self.exit_on_failure? # Thor 1.0 deprecation guard
15
+ false
16
+ end
14
17
 
15
18
  no_commands do
16
19
  def self.start given_args = ARGV, config = {}
@@ -3,9 +3,11 @@ require 'fileutils'
3
3
  module Pact
4
4
  module MockService
5
5
  class CLI < Thor
6
+ def self.exit_on_failure? # Thor 1.0 deprecation guard
7
+ false
8
+ end
6
9
 
7
10
  class Pidfile
8
-
9
11
  attr_accessor :pid_dir, :name, :pid
10
12
 
11
13
  def initialize options
@@ -24,7 +24,7 @@ module Pact
24
24
  # server, and can't shut it down. So, keep a manual reference to the Webrick server, and
25
25
  # shut it down directly rather than use Rack::Handler::WEBrick.shutdown
26
26
  # Ruby!
27
- Rack::Handler::WEBrick.run(control_server, webbrick_opts) do | server |
27
+ Rack::Handler::WEBrick.run(control_server, **webbrick_opts) do | server |
28
28
  @webrick_server = server
29
29
  end
30
30
  end
@@ -25,7 +25,7 @@ module Pact
25
25
 
26
26
  require_monkeypatch
27
27
 
28
- Rack::Handler::WEBrick.run(mock_service, webbrick_opts)
28
+ Rack::Handler::WEBrick.run(mock_service, **webbrick_opts)
29
29
  end
30
30
 
31
31
  private
@@ -58,6 +58,9 @@ module Pact
58
58
  unique_pact_file_names: options[:unique_pact_file_names],
59
59
  consumer: options[:consumer],
60
60
  provider: options[:provider],
61
+ broker_token: options[:broker_token],
62
+ broker_username: options[:broker_username],
63
+ broker_password: options[:broker_password],
61
64
  cors_enabled: options[:cors],
62
65
  pact_specification_version: options[:pact_specification_version] || Pact::SpecificationVersion::NIL_VERSION.to_s,
63
66
  pactfile_write_mode: options[:pact_file_write_mode],
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module MockService
3
- VERSION = "3.4.0"
3
+ VERSION = "3.7.0"
4
4
  end
5
5
  end
@@ -27,6 +27,9 @@ module Pact
27
27
  method_option :port, aliases: "-p", desc: "Port on which to run the service"
28
28
  method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
29
29
  method_option :log, aliases: "-l", desc: "File to which to log output"
30
+ method_option :broker_username, aliases: "-n", desc: "Pact Broker basic auth username", :required => false
31
+ method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password", :required => false
32
+ method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token (can also be set using the PACT_BROKER_TOKEN environment variable)", :required => false
30
33
  method_option :log_level, desc: "Log level. Options are DEBUG INFO WARN ERROR", default: "DEBUG"
31
34
  method_option :cors, aliases: "-o", desc: "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses"
32
35
  method_option :ssl, desc: "Use a self-signed SSL cert to run the service over HTTPS", type: :boolean, default: false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-mock_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-01-16 00:00:00.000000000 Z
15
+ date: 2020-11-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack
@@ -60,16 +60,22 @@ dependencies:
60
60
  name: thor
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - "~>"
63
+ - - ">="
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0.19'
66
+ - - "<"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
66
69
  type: :runtime
67
70
  prerelease: false
68
71
  version_requirements: !ruby/object:Gem::Requirement
69
72
  requirements:
70
- - - "~>"
73
+ - - ">="
71
74
  - !ruby/object:Gem::Version
72
75
  version: '0.19'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '2.0'
73
79
  - !ruby/object:Gem::Dependency
74
80
  name: json
75
81
  requirement: !ruby/object:Gem::Requirement
@@ -118,20 +124,20 @@ dependencies:
118
124
  requirements:
119
125
  - - "~>"
120
126
  - !ruby/object:Gem::Version
121
- version: '1.12'
127
+ version: '1.16'
122
128
  - - ">="
123
129
  - !ruby/object:Gem::Version
124
- version: 1.12.0
130
+ version: 1.16.4
125
131
  type: :runtime
126
132
  prerelease: false
127
133
  version_requirements: !ruby/object:Gem::Requirement
128
134
  requirements:
129
135
  - - "~>"
130
136
  - !ruby/object:Gem::Version
131
- version: '1.12'
137
+ version: '1.16'
132
138
  - - ">="
133
139
  - !ruby/object:Gem::Version
134
- version: 1.12.0
140
+ version: 1.16.4
135
141
  - !ruby/object:Gem::Dependency
136
142
  name: filelock
137
143
  requirement: !ruby/object:Gem::Requirement
@@ -166,14 +172,20 @@ dependencies:
166
172
  requirements:
167
173
  - - "~>"
168
174
  - !ruby/object:Gem::Version
169
- version: 10.0.3
175
+ version: '13.0'
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: 13.0.1
170
179
  type: :development
171
180
  prerelease: false
172
181
  version_requirements: !ruby/object:Gem::Requirement
173
182
  requirements:
174
183
  - - "~>"
175
184
  - !ruby/object:Gem::Version
176
- version: 10.0.3
185
+ version: '13.0'
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: 13.0.1
177
189
  - !ruby/object:Gem::Dependency
178
190
  name: webmock
179
191
  requirement: !ruby/object:Gem::Requirement
@@ -399,8 +411,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
399
411
  - !ruby/object:Gem::Version
400
412
  version: '0'
401
413
  requirements: []
402
- rubyforge_project:
403
- rubygems_version: 2.7.7
414
+ rubygems_version: 3.1.4
404
415
  signing_key:
405
416
  specification_version: 4
406
417
  summary: Provides a mock service for use with Pact