Skip to content

Commit ab997c5

Browse files
committed
feat: allow bearer token to be used to retrieve a pact
1 parent 1183531 commit ab997c5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/pact/consumer_contract/pact_file.rb

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def get_remote_with_retry(uri_string, options)
7878
def get_remote(uri, options)
7979
request = Net::HTTP::Get.new(uri)
8080
request.basic_auth(options[:username], options[:password]) if options[:username]
81+
request['Authorization'] = "Bearer #{options[:token]}" if options[:token]
8182
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
8283
http.open_timeout = options[:open_timeout] || OPEN_TIMEOUT
8384
http.read_timeout = options[:read_timeout] || READ_TIMEOUT

spec/lib/pact/consumer_contract/pact_file_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ module Pact
7575
end
7676
end
7777

78+
context 'with a token' do
79+
let(:token) { 'askfjlksjf'}
80+
let(:options) { { token: token } }
81+
82+
let!(:request) do
83+
stub_request(:get, uri_without_userinfo).with(headers: {'Authorization' => 'Bearer askfjlksjf'}).to_return(body: pact_content)
84+
end
85+
86+
it 'sets the Bearer Authorization header' do
87+
PactFile.render_pact(uri_without_userinfo, options)
88+
expect(request).to have_been_made
89+
end
90+
91+
end
92+
7893
describe 'retry feature' do
7994
before { allow(PactFile).to receive(:delay_retry).with(kind_of(Integer)) }
8095

0 commit comments

Comments
 (0)