Skip to content

Webmock breaks peer_cert method #50

pyrat opened this Issue Oct 14, 2010 · 4 comments

2 participants

pyrat commented Oct 14, 2010


The inclusion of the webmock gem breaks the peer_cert method for getting x509 Certificates. The following code does not work when webmock has been added to the Gemfile.

http.start do |conn|
  cert = conn.peer_cert
  @cert = cert

Sorry I havent had time to look through and propose a solution. Any suggestions would be welcome.

Am using Ruby 1.9.2


bblimke commented Oct 16, 2010

I can confirm it breaks it but I'll have to look more into it to figure out the solution.

I'm also not sure what should be the behaviour if net connect is disabled.

bblimke commented Oct 17, 2010

I investigated the issue. The problem is that webmock overwrites Net::HTTP#connect
and delays it's execution, until the real request is executed. This way it only connects, if a request is not stubbed and net connections are allowed. In your example there is no request executed yet.

The problem is that when Net::HTTP.start method is called, Net::HTTP makes connection to the remote server and webmock has no way of knowing what will be the request url yet, and whether the connection should be allowed or not. The requests are stubbed based on uri, not just host.

Obviously WebMock should not modify the default behaviour of Net::HTTP so I'll
have to change it to execute normal connect when real request is made.

I'm not sure how to do it yet, because at the time of start execution, webmock doesn't know yet if the request is real on stubbed.

Suggestions are welcome.

pyrat commented Oct 18, 2010

Would it be possible to add a force_web_connect attribute which would alter the behaviour of the Net::HTTP overwrite to always make the connection when start is called.

Making this a flag would mean that you could satisfy this edgecase and not add any fundamental changes?

pyrat commented Oct 18, 2010

The pull request I sent you works with the test but still didnt work when testing in my app. I solved the problem by using mocha to stub out the peer_cert method in my tests.


This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.