From 3a102c45f479d0830d924ca7d03ab5b24457ae97 Mon Sep 17 00:00:00 2001 From: Victoria Plows Date: Thu, 21 Feb 2019 09:52:11 +1100 Subject: [PATCH] feat: add support for bearer token --- lib/pact/provider_verifier/app.rb | 3 ++- lib/pact/provider_verifier/cli/verify.rb | 1 + spec/integration_with_pact_broker_config_spec.rb | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pact/provider_verifier/app.rb b/lib/pact/provider_verifier/app.rb index 7bb0ab5..0b2f839 100644 --- a/lib/pact/provider_verifier/app.rb +++ b/lib/pact/provider_verifier/app.rb @@ -137,6 +137,7 @@ def verify_pact(config) backtrace: ENV['BACKTRACE'] == 'true', pact_broker_username: options.broker_username, pact_broker_password: options.broker_password, + pact_broker_token: options.broker_token, format: options.format, out: options.out, ignore_failures: config.pending, @@ -164,7 +165,7 @@ def reset_pact_configuration end def all_pact_urls - http_client_options = { username: options.broker_username, password: options.broker_password, verbose: options.verbose } + http_client_options = { username: options.broker_username, password: options.broker_password, token: options.broker_token, verbose: options.verbose } AggregatePactConfigs.call(pact_urls, options.provider, consumer_version_tags, options.pact_broker_base_url, http_client_options) end diff --git a/lib/pact/provider_verifier/cli/verify.rb b/lib/pact/provider_verifier/cli/verify.rb index fe3235f..7fcde84 100644 --- a/lib/pact/provider_verifier/cli/verify.rb +++ b/lib/pact/provider_verifier/cli/verify.rb @@ -16,6 +16,7 @@ class InvalidArgumentsError < ::Thor::Error; end method_option :pact_broker_base_url, desc: "Base URL of the Pact Broker from which to retrieve the pacts.", :required => false method_option :broker_username, aliases: "-n", desc: "Pact Broker basic auth username", :required => false method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password", :required => false + method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token", :required => false method_option :provider, required: false method_option :consumer_version_tag, type: :array, banner: "TAG", desc: "Retrieve the latest pacts with this consumer version tag. Used in conjunction with --provider. May be specified multiple times.", :required => false method_option :provider_app_version, aliases: "-a", desc: "Provider application version, required when publishing verification results", :required => false diff --git a/spec/integration_with_pact_broker_config_spec.rb b/spec/integration_with_pact_broker_config_spec.rb index 94959f5..ce8c29f 100644 --- a/spec/integration_with_pact_broker_config_spec.rb +++ b/spec/integration_with_pact_broker_config_spec.rb @@ -9,7 +9,7 @@ allow(ENV).to receive(:[]).with('PACT_INCLUDE_PENDING').and_return('true') end - let(:args) { %W{pact-provider-verifier --provider Foo --consumer-version-tag master --consumer-version-tag prod --pact-broker-base-url http://localhost:5738 --broker-username username --broker-password password --provider-base-url http://localhost:4567} } + let(:args) { %W{pact-provider-verifier --provider Foo --consumer-version-tag master --consumer-version-tag prod --pact-broker-base-url http://localhost:5738 --broker-username username --broker-password password --broker-token token --provider-base-url http://localhost:4567} } let(:pact_uris) { ["http://non-pending-pact"] } let(:pending_pact_uris) { ["http://pending-pact"] } let(:pact_broker_api) { class_double(Pact::PactBroker).as_stubbed_const } @@ -23,12 +23,12 @@ end it "fetches the pact URIs from the broker" do - expect(pact_broker_api).to receive(:fetch_pact_uris).with("Foo", ["master", "prod"], "http://localhost:5738", { username: "username", password: "password", verbose: nil }) + expect(pact_broker_api).to receive(:fetch_pact_uris).with("Foo", ["master", "prod"], "http://localhost:5738", { username: "username", password: "password", token: "token", verbose: nil }) subject end it "fetches the pending pacts URIs from the broker" do - expect(pact_broker_api).to receive(:fetch_pending_pact_uris).with("Foo", "http://localhost:5738", { username: "username", password: "password", verbose: nil }) + expect(pact_broker_api).to receive(:fetch_pending_pact_uris).with("Foo", "http://localhost:5738", { username: "username", password: "password", token: "token", verbose: nil }) subject end