Skip to content

Commit

Permalink
feat: allow bearer token to be used to retrieve a pact
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 21, 2019
1 parent 1183531 commit ab997c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pact/consumer_contract/pact_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/pact/consumer_contract/pact_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }

Expand Down

0 comments on commit ab997c5

Please sign in to comment.