Skip to content

Commit

Permalink
fix: ensure the presence of basic auth credentials does not cause an …
Browse files Browse the repository at this point in the history
…error when displaying the path of a pact on the local filesystem
  • Loading branch information
bethesque committed Mar 15, 2020
1 parent 03033f9 commit f6a0b4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pact/provider/pact_uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def password
end

def to_s
if(basic_auth?)
if basic_auth? && uri.start_with?('http://', 'https://')
URI(@uri).tap { |x| x.userinfo="#{username}:*****"}.to_s
else
@uri
uri
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/pact/provider/pact_uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
it 'should include user name and password' do
expect(pact_uri.to_s).to eq('http://pact:*****@uri')
end

context 'when basic auth credentials have been set for a local file (eg. via environment variables, unintentionally)' do
let(:uri) { '/some/file thing.json' }

it 'does not blow up' do
expect(pact_uri.to_s).to eq uri
end
end
end

context 'without userinfo' do
Expand Down

0 comments on commit f6a0b4d

Please sign in to comment.