Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pactfoundation/pact-cli 0.56.0.2 seems to be broken #121

Closed
id-ilych opened this issue Sep 13, 2023 · 11 comments
Closed

pactfoundation/pact-cli 0.56.0.2 seems to be broken #121

id-ilych opened this issue Sep 13, 2023 · 11 comments

Comments

@id-ilych
Copy link

The error:

bundler: failed to load command: /pact/bin/pact (/pact/bin/pact)
<internal:/usr/local/lib/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require': cannot load such file -- faraday_middleware (LoadError)
	from <internal:/usr/local/lib/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/pact_helper.rb:4:in `<top (required)>'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-1.63.0/lib/pact/cli/run_pact_verification.rb:44:in `load'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-1.63.0/lib/pact/cli/run_pact_verification.rb:44:in `load_pact_helper'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-1.63.0/lib/pact/cli/run_pact_verification.rb:20:in `call'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-1.63.0/lib/pact/cli/run_pact_verification.rb:13:in `call'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/app.rb:181:in `verify_pact'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/app.rb:50:in `block in pacts_pass_verification?'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/app.rb:49:in `collect'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/app.rb:49:in `pacts_pass_verification?'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/app.rb:41:in `call'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/app.rb:34:in `call'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/cli/verify.rb:49:in `verify'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
	from /usr/lib/ruby/gems/3.2.0/gems/pact-provider-verifier-1.38.0/lib/pact/provider_verifier/cli/custom_thor.rb:17:in `start'
	from /pact/lib/pact/cli.rb:64:in `verify'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
	from /usr/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/base.rb:485: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 `<main>'

The 0.56.0.1 works just fine.

@YOU54F
Copy link
Member

YOU54F commented Sep 13, 2023

Which command are you running, just tried a couple now. This was merged yesterday and released pact-foundation/pact-provider-verifier#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.

@id-ilych
Copy link
Author

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

@YOU54F
Copy link
Member

YOU54F commented Sep 13, 2023

are you requiring faraday_middleware in custom_middleware.rb

@id-ilych
Copy link
Author

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

@YOU54F
Copy link
Member

YOU54F commented Sep 13, 2023

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

@YOU54F
Copy link
Member

YOU54F commented Sep 13, 2023

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

https://github.com/pact-foundation/pact-provider-verifier/blob/master/spec/support/custom_middleware.rb

it's used in this test

https://github.com/pact-foundation/pact-provider-verifier/blob/master/spec/integration_with_custom_middleware_spec.rb

do you need to add

  def initialize app
    @app = app
  end

in your middleware? that looks to the be the only difference between those?

@YOU54F
Copy link
Member

YOU54F commented Sep 13, 2023

This was the thread where the change was introduced to the framework

pact-foundation/pact-ruby#49 (comment)

Beth's example shows the same with the initialize method. it might be a red-herring but just stands out to me

@YOU54F
Copy link
Member

YOU54F commented Sep 14, 2023

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

  • the current working directory examples in the cloned repo,
    • this contains the pact file me-they.json
    • also contains the custom_middleware.rb
  • The address of the provider, here I am using host.docker.internal because I am on a Mac using Docker. If you are using Linux, this can be localhost
docker 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

@kishorenaga
Copy link

kishorenaga commented Nov 6, 2023

@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

'

@YOU54F
Copy link
Member

YOU54F commented Nov 7, 2023

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

@YOU54F
Copy link
Member

YOU54F commented Sep 6, 2024

We haven't any further reports, so will close unless we can get a reproducible example. Thanks!

@YOU54F YOU54F closed this as completed Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

No branches or pull requests

3 participants