diff --git a/lib/pact/provider/pact_uri.rb b/lib/pact/provider/pact_uri.rb index 1a43ed03..3bb4107b 100644 --- a/lib/pact/provider/pact_uri.rb +++ b/lib/pact/provider/pact_uri.rb @@ -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 diff --git a/spec/lib/pact/provider/pact_uri_spec.rb b/spec/lib/pact/provider/pact_uri_spec.rb index 357e88de..162acbde 100644 --- a/spec/lib/pact/provider/pact_uri_spec.rb +++ b/spec/lib/pact/provider/pact_uri_spec.rb @@ -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