Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
Jul 19, 2012
Myron Marston Fix excon so real requests are made with a connection constructed wit…
…h same args.

I got this warning from VCR on some tests using fog/excon to download a file from S3 over SSL:

WARNING: VCR could not extract a response from Excon error (#<OpenSSL::SSL::SSLError: hostname does not match the server certificate>)

I discovered that the SSL cert verification for a real request w/o VCR was made against
`s3.amazonaws.com`, while the verification for the request being recorded by VCR was made
against `<bucket_name>.s3.amazonaws.com`. The difference is due to the fact that fog
constructs an Excon::Connection instance with a URI of `s3.amazonaws.com`, then makes a
request with a :host param set to the FQDN. Before this commit, VCR made the real
request by constructing a new Excon::Connection instance with the URI set to the full
URI, and it caused the SSL cert verification failure.

This fixes it by ensuring the "real request" connection instance is constructed with
the same args as the original connection instance.
981112f
Myron Marston Excon 0.15 is out and works fine with VCR. ae9a0b3
Myron Marston Update relish.
I got this message from relish just now:
Sorry, your relish gem 0.5.3 is out of date. Please update to at least version 0.6
7f86b74
Myron Marston 2.2.4 release. 93b5f13
13 CHANGELOG.md
Source Rendered
... ... @@ -1,6 +1,15 @@
1   -## In git
  1 +## 2.2.4 (July 19, 2012)
2 2
3   -[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.2.2...master)
  3 +[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.2.3...v2.2.4)
  4 +
  5 +Bug Fixes:
  6 +
  7 +* Fix excon so real requests are made with a connection constructed with
  8 + same args as the original connection.
  9 +
  10 +## 2.2.3 (July 9, 2012)
  11 +
  12 +[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.2.2...v2.2.3)
4 13
5 14 Bug Fixes:
6 15
2  Gemfile
@@ -11,7 +11,7 @@ gem 'yard'
11 11
12 12 # Additional gems that are useful, but not required for development.
13 13 group :extras do
14   - gem 'relish', '~> 0.5.0'
  14 + gem 'relish', '~> 0.6'
15 15 gem 'fuubar'
16 16 gem 'fuubar-cucumber'
17 17
29 lib/vcr/library_hooks/excon.rb
@@ -2,7 +2,7 @@
2 2 require 'vcr/request_handler'
3 3 require 'excon'
4 4
5   -VCR::VersionChecker.new('Excon', Excon::VERSION, '0.9.6', '0.14').check_version!
  5 +VCR::VersionChecker.new('Excon', Excon::VERSION, '0.9.6', '0.15').check_version!
6 6
7 7 module VCR
8 8 class LibraryHooks
@@ -58,9 +58,15 @@ def real_request_params
58 58 end
59 59 end
60 60
  61 + def new_connection
  62 + # Ensure the connection is constructed with the exact same args
  63 + # that the orginal connection was constructed with.
  64 + ::Excon::Connection.new(*params.fetch(:__construction_args))
  65 + end
  66 +
61 67 def perform_real_request
62 68 begin
63   - response = ::Excon.new(uri).request(real_request_params)
  69 + response = new_connection.request(real_request_params)
64 70 rescue ::Excon::Errors::Error => excon_error
65 71 response = response_from_excon_error(excon_error)
66 72 end
@@ -151,7 +157,24 @@ def normalized_headers(headers)
151 157 end
152 158 end
153 159
154   -Excon.defaults[:mock] = true
  160 +::Excon.defaults[:mock] = true
  161 +
  162 +# We want to get at the Excon::Connection class but WebMock does
  163 +# some constant-replacing stuff to it, so we need to take that into
  164 +# account.
  165 +excon_connection = if defined?(::WebMock::HttpLibAdapters::ExconConnection)
  166 + ::WebMock::HttpLibAdapters::ExconConnection.superclass
  167 +else
  168 + ::Excon::Connection
  169 +end
  170 +
  171 +excon_connection.class_eval do
  172 + def self.new(*args)
  173 + super.tap do |instance|
  174 + instance.connection[:__construction_args] = args
  175 + end
  176 + end
  177 +end
155 178
156 179 VCR.configuration.after_library_hooks_loaded do
157 180 # ensure WebMock's Excon adapter does not conflict with us here
2  lib/vcr/version.rb
@@ -10,7 +10,7 @@ module VCR
10 10 # * `parts` [Array<Integer>] List of the version parts.
11 11 def version
12 12 @version ||= begin
13   - string = '2.2.3'
  13 + string = '2.2.4'
14 14
15 15 def string.parts
16 16 split('.').map { |p| p.to_i }
41 spec/vcr/library_hooks/excon_spec.rb
@@ -25,6 +25,44 @@
25 25 end
26 26 end
27 27
  28 + context 'when the request overrides the connection params' do
  29 + let!(:excon) { ::Excon.new("http://localhost:#{VCR::SinatraApp.port}/") }
  30 +
  31 + def deep_dup(hash)
  32 + Marshal.load(Marshal.dump hash)
  33 + end
  34 +
  35 + def intercept_request(&interception)
  36 + orig_new = ::Excon::Connection.method(:new)
  37 +
  38 + ::Excon::Connection.stub(:new) do |*args1|
  39 + orig_new.call(*args1).tap do |inst|
  40 +
  41 + meth = inst.method(:request)
  42 + inst.stub(:request) do |*args2|
  43 + interception.call(inst, *args2)
  44 + meth.call(*args2)
  45 + end
  46 + end
  47 + end
  48 + end
  49 +
  50 + it 'runs the real request with the same connection params' do
  51 + connection_params_1 = deep_dup(excon.connection)
  52 + connection_params_2 = nil
  53 +
  54 + intercept_request do |instance, *args|
  55 + connection_params_2 = deep_dup(instance.connection)
  56 + end
  57 +
  58 + VCR.use_cassette("excon") do
  59 + excon.request(:method => :get, :path => '/foo')
  60 + end
  61 +
  62 + connection_params_2.should eq(connection_params_1)
  63 + end
  64 + end
  65 +
28 66 context "when Excon's streaming API is used" do
29 67 it 'properly records and plays back the response' do
30 68 VCR.stub(:real_http_connections_allowed? => true)
@@ -63,8 +101,7 @@
63 101 it 'performs the right number of retries' do
64 102 connection = Excon.new("http://localhost:#{VCR::SinatraApp.port}/not_found")
65 103
66   - # Excon define's .stub so we can't use RSpec's here...
67   - Excon.should_receive(:new).at_least(:once).and_return(connection)
  104 + Excon::Connection.stub(:new => connection)
68 105
69 106 connection.extend Module.new {
70 107 def request_kernel_call_counts

No commit comments for this range

Something went wrong with that request. Please try again.