Skip to content

Commit 4cd4d85

Browse files
authored
Make verify_peer configurable and default it to false (#294)
1 parent 4f1c0ec commit 4cd4d85

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,20 @@ the system store. So after a run of your the suite only one certificate will be
740740
left over. If this is not enough you can handling the cleanup again with a
741741
custom on-after hook.
742742

743+
### TLS hostname validation
744+
745+
em-http-request was modified to emit a warning if being used without the TLS
746+
``verify_peer`` option. Puffing Billy defaults to specifying ``verify_peer: false``
747+
but you can now modify configuration to do peer verification. So if you've
748+
gone to the trouble of setting up your own certificate authority and self-signed
749+
certs you can enable it like so:
750+
751+
```ruby
752+
Billy.configure do |c|
753+
c.verify_peer = true
754+
end
755+
```
756+
743757
## Resources
744758

745759
* [Bring Ruby VCR to Javascript testing with Capybara and puffing-billy](http://architects.dzone.com/articles/bring-ruby-vcr-javascript)

lib/billy/config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Config
88

99
attr_accessor :logger, :cache, :cache_request_headers, :whitelist, :cache_whitelist, :path_blacklist, :ignore_params, :allow_params,
1010
:persist_cache, :ignore_cache_port, :non_successful_cache_disabled, :non_successful_error_level,
11-
:non_whitelisted_requests_disabled, :cache_path, :certs_path, :proxy_host, :proxy_port, :proxied_request_inactivity_timeout,
11+
:non_whitelisted_requests_disabled, :cache_path, :certs_path, :verify_peer, :proxy_host, :proxy_port, :proxied_request_inactivity_timeout,
1212
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :dynamic_jsonp_callback_name, :merge_cached_responses_whitelist,
1313
:strip_query_params, :proxied_request_host, :proxied_request_port, :cache_request_body_methods, :after_cache_handles_request,
1414
:cache_simulates_network_delays, :cache_simulates_network_delay_time, :record_requests, :record_stub_requests, :use_ignore_params, :before_handle_request
@@ -37,6 +37,7 @@ def reset
3737
@non_whitelisted_requests_disabled = false
3838
@cache_path = File.join(Dir.tmpdir, 'puffing-billy')
3939
@certs_path = File.join(Dir.tmpdir, 'puffing-billy', 'certs')
40+
@verify_peer = false
4041
@proxy_host = 'localhost'
4142
@proxy_port = RANDOM_AVAILABLE_PORT
4243
@proxied_request_inactivity_timeout = 10 # defaults from https://github.com/igrigorik/em-http-request/wiki/Redirects-and-Timeouts

lib/billy/handlers/proxy_handler.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def handle_request(method, url, headers, body)
1616
opts = { inactivity_timeout: Billy.config.proxied_request_inactivity_timeout,
1717
connect_timeout: Billy.config.proxied_request_connect_timeout }
1818

19+
if url =~ /^https/
20+
opts.merge!({tls: {verify_peer: Billy.config.verify_peer}})
21+
end
22+
1923
if Billy.config.proxied_request_host && !bypass_internal_proxy?(url)
2024
opts.merge!({ proxy: { host: Billy.config.proxied_request_host,
2125
port: Billy.config.proxied_request_port }} )

0 commit comments

Comments
 (0)