Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont attempt to parse a invalid response(nil) when using hook_into :excon #916

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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