oesmith / puffing-billy

A rewriting web proxy for testing interactions between your browser and external sites. Works with ruby + rspec.
MIT License
659 stars 170 forks source link

Request fails: Errno::ECONNREFUSED #300

Closed mostfamiliar closed 3 years ago

mostfamiliar commented 4 years ago

Trying to get puffing-billy operational with Capybara and Chrome. Used the default instructions for Capybara and added Capybara.javascript_driver = :selenium_chrome_billy to my rails-helper.rb

Also set up the following configuration: Billy.configure do |c| c.whitelist += [/example.test*/] c.cache = true c.persist_cache = true c.cache_path = 'spec/req_cache/' c.non_whitelisted_requests_disabled = false end

Where i'm running into trouble is the site i'm testing via Rspec uses a subdomain with a unique port on every spec file run. i.e. http://site12.example.test:59501/hi/workplease I'm logging puffing-billy and I can see: puffing-billy: Request to http://site12.example.test:59501/hi/workplease failed with error: Errno::ECONNREFUSED Is there a special config I need to add for this? I assumed that adding the whitelist regex would be enough. Weirdly if I change Capybara.register_driver from :selenium_chrome to :selenium_chrome_billy the site launches normally and the spec runs headed but then Billy stops caching requests other than the initial Proxy listening on http://localhost:57903

Hoping someone can help me out with this.

ronwsmith commented 4 years ago

Hmm, that whitelist config shouldn't be needed. There's already an option for this ignore_cache_port and it defaults to true which is what you want, so I don't think the port is the issue.

The last part you mentioned is confusing -- are you saying that you see the puffing-billy log files when the driver is :selenium_chrome but that nothing is logged when you use :selenium_chrome_billy? When you're not using a _billy driver, puffing-billy should not be running or be used by your specs.

mostfamiliar commented 4 years ago

@ronwsmith hi, thanks for responding! When I set both Capybara.register_driver to :selenium_chrome_billy and Capybara.javascript_driver = :selenium_chrome_billy I no longer get the Errno::ECONNREFUSED errors and the specs work normally but Billy stops proxying requests.

ronwsmith commented 4 years ago

What are your drivers when you do get the Errno::ECONNREFUSED errors?

mostfamiliar commented 4 years ago

Capybara.javascript_driver = :selenium_chrome_billy and Capybara.register_driver = :selenium_chrome

ronwsmith commented 4 years ago

register_driver is used to create additional drivers. Did you mean to say or use default_driver there?

Which driver is your spec using in that scenario?

mostfamiliar commented 4 years ago

I have determined that the Selenium::WebDriver::Chrome::Options arg: "--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}" is the line causing the the Errno::ECONNREFUSED error, but without it Billy does not intercept requests.

mostfamiliar commented 4 years ago

When I turn vcr: false, in the spec suite, I get a different error ``An error occurred in anafter(:suite)` hook. Failure/Error: super

RuntimeError: eventmachine not initialized: evma_get_sockname /.gem/ruby/2.4.9/gems/puffing-billy-2.3.1/lib/billy/proxy.rb:43:in `get_sockname'

which i've seen others have had but the patch does not work for me.

ronwsmith commented 4 years ago

Seems like you might have issues outside of this gem. If you remove puffing-billy, does everything work as expected?

ronwsmith commented 3 years ago

Stale issue, closing. Feel free to reopen.