Skip to content

Commit f6a0b4d

Browse files
committed
fix: ensure the presence of basic auth credentials does not cause an error when displaying the path of a pact on the local filesystem
1 parent 03033f9 commit f6a0b4d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/pact/provider/pact_uri.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def password
2929
end
3030

3131
def to_s
32-
if(basic_auth?)
32+
if basic_auth? && uri.start_with?('http://', 'https://')
3333
URI(@uri).tap { |x| x.userinfo="#{username}:*****"}.to_s
3434
else
35-
@uri
35+
uri
3636
end
3737
end
3838
end

spec/lib/pact/provider/pact_uri_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
it 'should include user name and password' do
3131
expect(pact_uri.to_s).to eq('http://pact:*****@uri')
3232
end
33+
34+
context 'when basic auth credentials have been set for a local file (eg. via environment variables, unintentionally)' do
35+
let(:uri) { '/some/file thing.json' }
36+
37+
it 'does not blow up' do
38+
expect(pact_uri.to_s).to eq uri
39+
end
40+
end
3341
end
3442

3543
context 'without userinfo' do

0 commit comments

Comments
 (0)