Open id-ilych opened 11 months ago
Which command are you running, just tried a couple now. This was merged yesterday and released https://github.com/pact-foundation/pact-provider-verifier/pull/107 so it would be related to that
docker run --rm -it --init pactfoundation/pact-cli:0.56.0.2 pact
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Commands:
help [COMMAND] # Describe available commands or one specific command
mock-service # Run a Pact mock service
pact-broker # Interact with a Pact Broker (also aliased as the subcommand `broker`)
pactflow # Interact with PactFlow
publish PACT_DIRS_OR_FILES ... # Publish pacts to a Pact Broker.
stub-service # Run a Pact stub service
verify PACT_URL ... # Verify pact(s) against a provider. Supports local and networked (http-based) files.
version # Print the version of the CLI
mock-service
docker run --rm -it --init pactfoundation/pact-cli:0.56.0.2 mock-service
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
mock WARN: Please note: we are tracking events anonymously to gather important usage statistics like Pact-Ruby version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.
INFO WEBrick 1.8.1
INFO ruby 3.2.2 (2023-03-30) [x86_64-linux-musl]
INFO WEBrick::HTTPServer#start: pid=25 port=35127
^CINFO going to shutdown ...
INFO WEBrick::HTTPServer#start done.
The command is something like
verify https://my-pact-broker.net/pacts/provider/MyProvider/consumer/MyConsumer/version/123 \
--provider-base-url http://my-provider.net \
--broker-username=*** \
--broker-*** \
--provider "MyProvider" \
--provider-states-setup-url "http://my-provider.net/setup" \
--provider-app-version=234 \
--custom-middleware /ext/custom_middleware.rb \
--wait 20 \
--publish-verification-results
are you requiring faraday_middleware
in custom_middleware.rb
I don't think so
# frozen_string_literal: true
require 'pact/provider_verifier/custom_middleware'
class CustomVerifierMiddleware < Pact::ProviderVerifier::CustomMiddleware
def call(env)
env['HTTP_X_GATEWAY_PACT_DESCRIPTION'] = env['X_PACT_DESCRIPTION']
env['HTTP_X_GATEWAY_PACT_STATES'] = env['X_PACT_PROVIDER_STATES']
@app.call(env)
end
end
Thanks for sharing and raising an issue, its useful for others if they also see the same, not sure of the remedy atm but its related to the above commit ☝🏾
have tagged the author and will also take a look.
Could you try again but without this arg --custom-middleware /ext/custom_middleware.rb
- I appreciate the test may fail, but hopefully it shouldn't blow up and it would pinpoint the issue to being in that area
I don't think so
# frozen_string_literal: true require 'pact/provider_verifier/custom_middleware' class CustomVerifierMiddleware < Pact::ProviderVerifier::CustomMiddleware def call(env) env['HTTP_X_GATEWAY_PACT_DESCRIPTION'] = env['X_PACT_DESCRIPTION'] env['HTTP_X_GATEWAY_PACT_STATES'] = env['X_PACT_PROVIDER_STATES'] @app.call(env) end end
Heres an example of the custom middleware in the repo
it's used in this test
do you need to add
def initialize app
@app = app
end
in your middleware? that looks to the be the only difference between those?
This was the thread where the change was introduced to the framework
https://github.com/pact-foundation/pact-ruby/issues/49#issuecomment-419273373
Beth's example shows the same with the initialize method. it might be a red-herring but just stands out to me
Hey,
So I've tried to reproduce this but can't seem to.
Pull down the pact-provider-verifier repo, and update it to use the latest version of pact-provider-verifier.
git clone git@github.com:pact-foundation/pact-provider-verifier.git
cd examples
bundle update # pull in latest pact-provider-verifier
Add a file called custom_middleware.rb
in the examples
folder
echo "# frozen_string_literal: true
require 'pact/provider_verifier/custom_middleware'
class CustomVerifierMiddleware < Pact::ProviderVerifier::CustomMiddleware
def call(env)
env['HTTP_X_GATEWAY_PACT_DESCRIPTION'] = env['X_PACT_DESCRIPTION']
env['HTTP_X_GATEWAY_PACT_STATES'] = env['X_PACT_PROVIDER_STATES']
@app.call(env)
end
end">custom_middleware.rb
In terminal 1, run the test api
❯ ruby api.rb
[2023-09-14 12:50:06] INFO WEBrick 1.8.1
[2023-09-14 12:50:06] INFO ruby 3.2.2 (2023-03-30) [arm64-darwin23]
== Sinatra (v3.1.0) has taken the stage on 4567 for development with backup from WEBrick
[2023-09-14 12:50:06] INFO WEBrick::HTTPServer#start: pid=17974 port=4567
In terminal 2, run the verifier via pact-cli docker image
passing in
examples
in the cloned repo,
me-they.json
custom_middleware.rb
host.docker.internal
because I am on a Mac using Docker. If you are using Linux, this can be localhostdocker run --rm -it -v $(pwd):/pact_pwd pactfoundation/pact-cli:0.56.0.2 verify --provider-base-url http://host.docker.internal:4567 /pact_pwd/me-they.json --custom-middleware /pact_pwd/custom_middleware.rb --provider-states-setup-url "http://host.docker.internal:4567/provider-state"
Output from verifier
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
INFO: Adding custom middleware CustomVerifierMiddleware
pact WARN: Please note: we are tracking events anonymously to gather important usage statistics like Pact-Ruby version
and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment
variable to 'true'.
INFO: Reading pact at /pact_pwd/me-they.json
Verifying a pact between me and they
Greeting
with GET /
returns a response which
has status code 200
has a matching body
Given There is a greeting
Provider state success
with GET /somestate
returns a response which
has status code 200
has a matching body
Output from test api
I, [2023-09-14T12:51:24.083098 #17974] INFO -- : Provider state request: {}
127.0.0.1 - - [14/Sep/2023:12:51:24 +0100] "POST /provider-state HTTP/1.1" 201 - 0.0039
127.0.0.1 - - [14/Sep/2023:12:51:24 BST] "POST /provider-state HTTP/1.1" 201 0
- -> /provider-state
127.0.0.1 - - [14/Sep/2023:12:51:24 +0100] "GET / HTTP/1.1" 200 20 0.0014
127.0.0.1 - - [14/Sep/2023:12:51:24 BST] "GET / HTTP/1.1" 200 20
- -> /
I, [2023-09-14T12:51:24.142308 #17974] INFO -- : Provider state request: {}
127.0.0.1 - - [14/Sep/2023:12:51:24 +0100] "POST /provider-state HTTP/1.1" 201 - 0.0003
127.0.0.1 - - [14/Sep/2023:12:51:24 BST] "POST /provider-state HTTP/1.1" 201 0
- -> /provider-state
127.0.0.1 - - [14/Sep/2023:12:51:24 +0100] "GET /somestate HTTP/1.1" 200 26 0.0003
127.0.0.1 - - [14/Sep/2023:12:51:24 BST] "GET /somestate HTTP/1.1" 200 26
- -> /somestate
@YOU54F I am new to pact and trying publish contract using cli, i am seeing this response . aim i missing anything in the command ? PS C:> docker run --rm -v ${PWD}/pacts/Consumer-Provider.json:/pacts/Consumer-Provider.json -e PACT_BROKER_BASE_URL="https://coll***xxx.pactflow.io" -e PACT_BROKER_USERNAME="naga.appari@colli5454545.com" -e ACT_BROKER_TOKEN="MNQcvY4I5U***" pactfoundation/pact-cli:latest publish /pacts --consumer-app-version collinson-demo-1
bundler: failed to load command: /pact/bin/pact (/pact/bin/pact)
/usr/lib/ruby/3.2.0/net/protocol.rb:46:in connect_nonblock': SSL_connect returned=1 errno=0 peeraddr=15.197.177.201:443 state=error: certificate verify failed (self-signed certificate in certificate chain) (OpenSSL::SSL::SSLError) from /usr/lib/ruby/3.2.0/net/protocol.rb:46:in
ssl_socket_connect'
from /usr/lib/ruby/3.2.0/net/http.rb:1342:in connect' from /usr/lib/ruby/3.2.0/net/http.rb:1248:in
do_start'
from /usr/lib/ruby/3.2.0/net/http.rb:1237:in start' from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/hal/http_client.rb:86:in
block in perform_request'
from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/hal/http_client.rb:100:in until_truthy_or_max_times' from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/hal/http_client.rb:65:in
perform_request'
from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/hal/http_client.rb:25:in get' from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/hal/link.rb:41:in
get'
from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/hal/link.rb:45:in get!' from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/hal_client_methods.rb:24:in
index_resource'
from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/publish_pacts.rb:32:in call' from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/publish_pacts.rb:15:in
call'
from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/cli/pact_commands.rb:74:in publish_pacts' from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/cli/pact_commands.rb:33:in
publish'
from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/command.rb:28:in run' from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in
invoke_command'
from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor.rb:527:in dispatch' from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/base.rb:584:in
start'
from /usr/lib/ruby/gems/3.2.0/gems/pact_broker-client-1.74.0/lib/pact_broker/client/cli/custom_thor.rb:34:in start' from /pact/lib/pact/cli.rb:71:in
publish'
from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/command.rb:28:in run' from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in
invoke_command'
from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor.rb:527:in dispatch' from /usr/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/base.rb:584:in
start'
from /pact/bin/pact:15:in <top (required)>' from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/cli/exec.rb:58:in
load'
from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/cli/exec.rb:58:in kernel_load' from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/cli/exec.rb:23:in
run'
from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/cli.rb:492:in exec' from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/command.rb:27:in
run'
from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in invoke_command' from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor.rb:392:in
dispatch'
from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/cli.rb:34:in dispatch' from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/base.rb:485:in
start'
from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/cli.rb:28:in start' from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/exe/bundle:45:in
block in <top (required)>'
from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/lib/bundler/friendly_errors.rb:117:in with_friendly_errors' from /usr/lib/ruby/gems/3.2.0/gems/bundler-2.4.12/exe/bundle:33:in
<top (required)>'
from /usr/bin/bundle:25:in load' from /usr/bin/bundle:25:in
you don't need to pass in PACT_BROKER_USERNAME
if you are using PACT_BROKER_TOKEN
and unless your command you've pasted is incorrect, it shows ACT_BROKER_TOKEN
Also I would consider those credentials comprised and you should rotate your token, and avoid posting them in the public domain.
Also lastly, if you see the same issue with the versions below 0.56.0.2, then this issue isn't relevant to your particular problem, and it would be better to raise a new topic.
You can alternatively try publishing via the pact-cli via the executable directly, just to work out if you have an issue with Docker on Windows, rather than a connectivity issue with your broker
The error:
The
0.56.0.1
works just fine.