Skip to content

Commit

Permalink
Don't attempt to parse a nil response when hooking into Excon (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Jan 2, 2022
1 parent 717747a commit 45b0bfd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
- [patch] Improve error message for syntax error in ERB-using cassettes (#909)
- [patch] Handle `use_cassette(..., erb: {})` (#908)
- [fix] Use fiber-local for `global_hook_disabled_requests` (#907)
- [fix] Dont attempt to parse a nil response when hooking into `:excon` (#916)

## 6.0.0 (May 28, 2020)
[Full Changelog](https://github.com/vcr/vcr/compare/v5.1.0...v6.0.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/vcr/middleware/excon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def before_request(request_params)
def after_request(response)
vcr_response = vcr_response_for(response)

if should_record?
if vcr_response && should_record?
VCR.record_http_interaction(VCR::HTTPInteraction.new(vcr_request, vcr_response))
end

Expand Down
20 changes: 20 additions & 0 deletions spec/lib/vcr/library_hooks/excon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ def make_request
end
end

context "when Excon raises an internal error before body is processed" do
let(:excon) { ::Excon.new('https://expired.badssl.com') }
let(:ssl_error) { OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=error: certificate verify failed (certificate has expired)") }

before do
allow(excon).to receive(:socket) { raise ssl_error }
end

def make_request
VCR.use_cassette('with_errors', :record => :once) do
excon.request(method: :get, :expects => [200])
end
end

it 'raises SSL errors and does not try to record a cassette' do
expect(VCR).to_not receive(:record_http_interaction)
expect { make_request }.to raise_error(Excon::Error::Certificate)
end
end

include_examples "Excon streaming"

context 'when Excon raises an error due to an unexpected response status' do
Expand Down

0 comments on commit 45b0bfd

Please sign in to comment.