diff --git a/lib/pact/consumer_contract/pact_file.rb b/lib/pact/consumer_contract/pact_file.rb index b373839..174f332 100644 --- a/lib/pact/consumer_contract/pact_file.rb +++ b/lib/pact/consumer_contract/pact_file.rb @@ -78,6 +78,7 @@ def get_remote_with_retry(uri_string, options) def get_remote(uri, options) request = Net::HTTP::Get.new(uri) request.basic_auth(options[:username], options[:password]) if options[:username] + request['Authorization'] = "Bearer #{options[:token]}" if options[:token] Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| http.open_timeout = options[:open_timeout] || OPEN_TIMEOUT http.read_timeout = options[:read_timeout] || READ_TIMEOUT diff --git a/spec/lib/pact/consumer_contract/pact_file_spec.rb b/spec/lib/pact/consumer_contract/pact_file_spec.rb index cc63632..0af0f91 100644 --- a/spec/lib/pact/consumer_contract/pact_file_spec.rb +++ b/spec/lib/pact/consumer_contract/pact_file_spec.rb @@ -75,6 +75,21 @@ module Pact end end + context 'with a token' do + let(:token) { 'askfjlksjf'} + let(:options) { { token: token } } + + let!(:request) do + stub_request(:get, uri_without_userinfo).with(headers: {'Authorization' => 'Bearer askfjlksjf'}).to_return(body: pact_content) + end + + it 'sets the Bearer Authorization header' do + PactFile.render_pact(uri_without_userinfo, options) + expect(request).to have_been_made + end + + end + describe 'retry feature' do before { allow(PactFile).to receive(:delay_retry).with(kind_of(Integer)) }