pact-provider-verifier 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7a5fd688d1159700ffd162bbd72100520e2bfc6
4
+ data.tar.gz: 4c21909a48dfffe600806b01375eef4f94bb42ad
5
+ SHA512:
6
+ metadata.gz: a6967ba29737b5b2d2cba5f5033c9d358d43048c8e02cd690f88cc7abf1ef9461313021e95f23918b65cf385bfbd134a97433302fc3e6badd849287fe61e7df8
7
+ data.tar.gz: 79214d06a799bd5ad95d98c5fcd19e48ce7000113b45fa907a6e52bd7b24c17f902c4eef83b1f181295da0631ec964ca5d8ecb42732c5dbb2bfc2b521800708b
@@ -0,0 +1,5 @@
1
+ Do this to generate your change history
2
+
3
+ git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
4
+
5
+ ### 0.0.1 (8 May 2016)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Matt Fellows
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,84 @@
1
+ # Pact Provider Verification
2
+
3
+ This setup simplifies Pact Provider [verification](https://github.com/realestate-com-au/pact#2-tell-your-provider-that-it-needs-to-honour-the-pact-file-you-made-earlier)
4
+ process in any language, wrapping the Ruby implementation into a cross-platform,
5
+ binary-like CLI tool.
6
+
7
+ **Features**:
8
+
9
+ * Verify Pacts against Pacts published to an http endpoint, such as a [Pact Broker](https://github.com/bethesque/pact_broker)
10
+ * Verify local `*.json` Pacts on the file system
11
+ * Works with Pact [provider states](https://github.com/realestate-com-au/pact/wiki/Provider-states) should you need them
12
+
13
+ ## Installation
14
+
15
+ ### Native Installation
16
+
17
+ Download the appropriate [release](https://github.com/pact-foundation/pact-provider-verifier/releases)
18
+ for your OS and put somewhere on your `PATH`.
19
+
20
+ ### With Ruby on Mac OSX and Linux
21
+
22
+ ```
23
+ gem install pact-provider-verifier
24
+ pact-provider-verifier <args>
25
+ ```
26
+
27
+ Run `pact-mock-service help` for command line options.
28
+
29
+ ## Examples
30
+
31
+ See the [examples](examples) directory for a real working API example:
32
+
33
+ ```
34
+ cd examples
35
+ ./test.sh
36
+ ```
37
+
38
+ ### Simple API
39
+
40
+ *Steps*:
41
+
42
+ 1. Create an API and a corresponding Docker image for it
43
+ 1. Publish Pacts to the Pact broker (or create local ones)
44
+ 1. Run the CLI tool for your OS, passing the appropriate flags:
45
+ * `--pact_urls` - a comma delimited list of pact file urls
46
+ * `--provider_base_url` - the base url of the pact provider (i.e. your API)
47
+ 1.
48
+
49
+ ### API with Provider States
50
+
51
+ Execute pact provider verification against a provider which implements the following:
52
+
53
+ * an http get endpoint which returns pact provider_states by consumer
54
+
55
+ {
56
+ "myConsumer": [
57
+ "customer is logged in",
58
+ "customer has a million dollars"
59
+ ]
60
+ }
61
+
62
+ * an http post endpoint which sets the active pact consumer and provider state
63
+
64
+ consumer=web&state=customer%20is%20logged%20in
65
+
66
+ The following environment variables required:
67
+
68
+ * `pact_urls` - a comma delimited list of pact file urls
69
+ * `provider_base_url` - the base url of the pact provider
70
+ * `provider_states_url` - the full url of the endpoint which returns provider states by consumer
71
+ * `provider_states_setup_url` - the full url of the endpoint which sets the active pact consumer and provider state
72
+
73
+
74
+ ## Contributing
75
+
76
+ See [CONTRIBUTING.md](/CONTRIBUTING.md)
77
+
78
+ [pact]: https://github.com/realestate-com-au/pact
79
+ [releases]: https://github.com/bethesque/pact-mock_service/releases
80
+ [javascript]: https://github.com/DiUS/pact-consumer-js-dsl
81
+ [pact-dev]: https://groups.google.com/forum/#!forum/pact-dev
82
+ [windows]: https://github.com/bethesque/pact-mock_service/wiki/Building-a-Windows-standalone-executable
83
+ [install-windows]: https://github.com/bethesque/pact-mock_service/wiki/Installing-the-pact-mock_service-gem-on-Windows
84
+ [why-generated]: https://github.com/realestate-com-au/pact/wiki/FAQ#why-are-the-pacts-generated-and-not-static
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pact/provider_verifier/cli'
3
+ Pact::ProviderVerifier::CLI.start
@@ -0,0 +1 @@
1
+ require 'pact/provider_verifier/app'
@@ -0,0 +1,38 @@
1
+ require 'pact/provider/proxy/tasks'
2
+ require 'pact/provider_verifier/json_helper'
3
+
4
+ # make sure that the required environment variables are sets
5
+ required_environment_variables = ['pact_urls', 'provider_base_url']
6
+ missing_environment_variables = required_environment_variables.select { |ev| ENV[ev].to_s == '' }
7
+ if missing_environment_variables.count > 0 then
8
+ raise("ERROR: the following environment variables have not been specified: '#{missing_environment_variables}'")
9
+ end
10
+
11
+ # Non-mandatory, but probably useful environment variables
12
+ other_environment_variables = ['provider_states_url', 'provider_states_setup_url']
13
+ missing_environment_variables = other_environment_variables.select { |ev| ENV[ev].to_s == '' }
14
+ if missing_environment_variables.count > 0 then
15
+ warn("WARN: the following non-mandatory environment variables have not been specified: '#{missing_environment_variables}'")
16
+ end
17
+
18
+ pacts = ENV['pact_urls'].split(',')
19
+ # if you have duplicates in the pact_urls you will see more iterations than expected,
20
+ # but that shouldn't be the case except when you're trying stuff out in dev
21
+
22
+ def get_pact_consumer_name pact_url
23
+ json = get_json(pact_url)
24
+ json['consumer']['name']
25
+ end
26
+
27
+ task :verify_pacts do
28
+ pacts.each do |pact_url|
29
+ Pact::ProxyVerificationTask.new :"#{pact_url}" do | task |
30
+ ENV['pact_consumer'] = get_pact_consumer_name(pact_url)
31
+ task.pact_url pact_url, :pact_helper => './pact_helper'
32
+ task.provider_base_url ENV['provider_base_url']
33
+ end
34
+ task_name = "pact:verify:#{pact_url}"
35
+ Rake::Task[task_name].invoke
36
+ Rake::Task[task_name].reenable
37
+ end
38
+ end
@@ -0,0 +1,78 @@
1
+ require 'pact/provider/proxy/tasks'
2
+ require 'pact/provider/proxy'
3
+ require 'net/https'
4
+ require 'faraday_middleware'
5
+ require 'json'
6
+
7
+ module Pact
8
+ module ProviderVerifier
9
+
10
+ def self.new *args
11
+ App.new(*args)
12
+ end
13
+
14
+ class App
15
+ def initialize options = {}
16
+ require 'pp'
17
+ pp options
18
+ @options = options
19
+ end
20
+
21
+ def call env
22
+ @app.call env
23
+ end
24
+
25
+ def to_s
26
+ "#{@name} #{super.to_s}"
27
+ end
28
+
29
+ def get_pact_consumer_name pact_url
30
+ json = get_json(pact_url)
31
+ json['consumer']['name']
32
+ end
33
+
34
+ def verify_pacts
35
+ pacts = @options.pact_urls.split(',')
36
+ proxy_pact_helper = File.expand_path(File.join(File.dirname(__FILE__), "pact_helper.rb"))
37
+ ENV['provider_states_url'] = @options.provider_states_url
38
+ ENV['provider_states_setup_url'] = @options.provider_states_setup_url
39
+
40
+ pacts.each do |pact_url|
41
+ Pact::ProxyVerificationTask.new :"#{pact_url}" do | task |
42
+ ENV['pact_consumer'] = get_pact_consumer_name(pact_url)
43
+ task.pact_url pact_url, :pact_helper => proxy_pact_helper
44
+ task.provider_base_url @options.provider_base_url
45
+ end
46
+ task_name = "pact:verify:#{pact_url}"
47
+ Rake::Task[task_name].invoke
48
+ Rake::Task[task_name].reenable
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def get_json(path)
56
+ case path
57
+ when URI::regexp
58
+ return get_json_from_server(path)
59
+ else
60
+ return get_json_from_local_file(path)
61
+ end
62
+ end
63
+
64
+ def get_json_from_server(path)
65
+ url = URI.parse(path)
66
+ conn = Faraday.new("http://#{url.host}:#{url.port}") do |c|
67
+ c.use FaradayMiddleware::ParseJson
68
+ c.use Faraday::Adapter::NetHttp
69
+ end
70
+
71
+ response = conn.get(url.request_uri)
72
+ return response.body
73
+ end
74
+
75
+ def get_json_from_local_file(path)
76
+ file = File.read(path)
77
+ return JSON.parse(file)
78
+ end
@@ -0,0 +1,21 @@
1
+ require 'thor'
2
+ require 'socket'
3
+ require 'pact/provider_verifier/app'
4
+
5
+ module Pact
6
+ module ProviderVerifier
7
+ class CLI < Thor
8
+ desc 'verify', "Runs the Pact verification process"
9
+ method_option :pact_urls, aliases: "-u", desc: "Comma-separated list of Pact file URIs. Supports local and networked (http-based) files", :required => true
10
+ method_option :provider_base_url, aliases: "-h", desc: "Provide host URL", :required => true
11
+ method_option :provider_states_url, aliases: "-s", desc: "Base URL to retrieve the provider states from", :required => false
12
+ method_option :provider_states_setup_url, aliases: "-c", desc: "Base URL to setup the provider states at", :required => false
13
+
14
+ def verify
15
+ app = Pact::ProviderVerifier::App.new(options)
16
+ end
17
+
18
+ default_task :verify
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ require 'net/https'
2
+ require 'faraday_middleware'
3
+ require 'json'
4
+ require_relative './app'
5
+
6
+ # Responsible for making the call to the provider state server to set up the state
7
+ if ENV['provider_states_url']
8
+ module ProviderStateServerClient
9
+ def set_up_state provider_state
10
+ puts "Setting up provider state '#{provider_state}' for consumer '#{ENV['pact_consumer']}' using provider state server at #{ENV['provider_states_setup_url']}"
11
+
12
+ conn = Faraday.new(:url => ENV['provider_states_setup_url']) do |faraday|
13
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
14
+ end
15
+ conn.post do |req|
16
+ req.headers["Content-Type"] = "application/json"
17
+ req.body = JSON.dump ({"consumer" => ENV['pact_consumer'], "state" => provider_state })
18
+ end
19
+ end
20
+ end
21
+
22
+ Pact.configure do | config |
23
+ config.include ProviderStateServerClient
24
+ end
25
+
26
+ # get the consumer provider states from the provider
27
+ provider_states = get_json(ENV['provider_states_url'])
28
+
29
+ # register the consumer provider states with pact
30
+ provider_states.keys.each do |consumer|
31
+ Pact.provider_states_for consumer do
32
+ provider_states[consumer].each do |state|
33
+ provider_state state do
34
+ set_up do
35
+ set_up_state state
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module Pact
2
+ module ProviderVerifier
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pact-provider-verifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Fellows
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pact
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.9.1
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.9'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.9.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: pact-provider-proxy
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.1'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.1.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.1'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.1.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: faraday
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.9'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.9'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 0.9.0
87
+ - !ruby/object:Gem::Dependency
88
+ name: faraday_middleware
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: 0.10.0
94
+ type: :runtime
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 0.10.0
101
+ - !ruby/object:Gem::Dependency
102
+ name: rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '10.4'
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 10.4.2
111
+ type: :runtime
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.4'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 10.4.2
121
+ description: |-
122
+ A cross-platform Pact verification tool to validate API Providers.
123
+ Used in the pact-js-provider project to simplify development
124
+ email:
125
+ - m@onegeek.com.au
126
+ executables:
127
+ - pact-provider-verifier
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - CHANGELOG.md
132
+ - Gemfile
133
+ - LICENSE.txt
134
+ - README.md
135
+ - bin/pact-provider-verifier
136
+ - lib/pact/provider_verifier.rb
137
+ - lib/pact/provider_verifier/Rakefile
138
+ - lib/pact/provider_verifier/app.rb
139
+ - lib/pact/provider_verifier/cli.rb
140
+ - lib/pact/provider_verifier/pact_helper.rb
141
+ - lib/pact/provider_verifier/version.rb
142
+ homepage: https://github.com/pact-foundation/pact-provider-verifier
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.2.0
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Provides a Pact verification service for use with Pact
166
+ test_files: []