puffing-billy 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7dab062648498106cd36d92beb9ac60d785258e
4
- data.tar.gz: 2eb64804cc5f68b5dba48b20c589140609136f7f
3
+ metadata.gz: c947cba0ecd347fd64162b9d54f81b554332de78
4
+ data.tar.gz: 7f1d4c7bb3b60f1dd38aaeaafbe3ac908e5cbb42
5
5
  SHA512:
6
- metadata.gz: 4187b46b234b85781c70d0b7c6b627741b97618036cc28fe6f1e9129aa26623f72e2bd7b9b17b913d55427ea7b88e7afa8b0ae6852d7ebfa75ac0b690f372c37
7
- data.tar.gz: ad0efae508e1016672e7b37185e4b04c5701bb22615fb40d8d1169023a4ad9e0587286ea3c8bc79394a4b21c7cc9d88ccf4aa40109fb0084a19a71e57e4bda9b
6
+ metadata.gz: 2804533a54d46131aaf4545047a84813bea526ddd5129ee72caaf604e700faa55418bd09e5e7bce0abd4981fda98427ddda78b4cb5faf44beb25970e11cecbbb
7
+ data.tar.gz: e17d6928069e53f911b01bb64d29eb8a06a447b7688f883d37dfb133e0c05107344c4fa0e4d402dd743b00305dff6a1c0ff6211643e7b7973a160634d62b47fd
@@ -1,3 +1,11 @@
1
+ v0.6.1, 2015-08-25
2
+ ------------------
3
+
4
+ * Fix `instance variable not initialized` warnings (#107)
5
+ * Add regex support to whitelist (#111)
6
+ * Support basic auth in requests (#121)
7
+ * Added alternative to run VCR in parallel (#122)
8
+
1
9
  v0.6.0, 2015-08-25
2
10
  ------------------
3
11
 
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- puffing-billy (0.5.1)
4
+ puffing-billy (0.6.1)
5
5
  addressable
6
6
  em-http-request (~> 1.1.0)
7
7
  em-synchrony
8
- eventmachine (= 1.0.4)
8
+ eventmachine (~> 1.0.4)
9
9
  eventmachine_httpserver
10
10
  http_parser.rb (~> 0.6.0)
11
11
  multi_json
@@ -50,7 +50,7 @@ GEM
50
50
  eventmachine (>= 1.0.0.beta.4)
51
51
  em-synchrony (1.0.4)
52
52
  eventmachine (>= 1.0.0.beta.1)
53
- eventmachine (1.0.4)
53
+ eventmachine (1.0.8)
54
54
  eventmachine_httpserver (0.2.1)
55
55
  faraday (0.9.1)
56
56
  multipart-post (>= 1.2, < 3)
data/README.md CHANGED
@@ -363,6 +363,20 @@ RSpec.configure do |config|
363
363
  end
364
364
  ```
365
365
 
366
+ As an alternative if you're using VCR, you can ignore requests coming from the browser.
367
+ One way of doing that is by adding to your `rails_helper.rb` the excerpt below:
368
+
369
+ ```ruby
370
+ VCR.configure do |config|
371
+ config.ignore_request do |request|
372
+ request.headers.include?('Referer')
373
+ end
374
+ end
375
+ ```
376
+
377
+ Note that this approach may cause unexpected behavior if your backend sends the Referer HTTP header (which is unlikely).
378
+
379
+
366
380
  ## Resources
367
381
 
368
382
  * [Bring Ruby VCR to Javascript testing with Capybara and puffing-billy](http://architects.dzone.com/articles/bring-ruby-vcr-javascript)
@@ -22,7 +22,7 @@ module Billy
22
22
  end
23
23
 
24
24
  req = EventMachine::HttpRequest.new(url, opts)
25
- req = req.send(method.downcase, build_request_options(headers, body))
25
+ req = req.send(method.downcase, build_request_options(url, headers, body))
26
26
 
27
27
  if req.error
28
28
  return { error: "Request to #{url} failed with error: #{req.error}" }
@@ -50,12 +50,15 @@ module Billy
50
50
  nil
51
51
  end
52
52
 
53
- private
53
+ private
54
54
 
55
- def build_request_options(headers, body)
55
+ def build_request_options(url, headers, body)
56
56
  headers = Hash[headers.map { |k, v| [k.downcase, v] }]
57
57
  headers.delete('accept-encoding')
58
58
 
59
+ uri = Addressable::URI.parse(url)
60
+ headers.merge!({'authorization' => [uri.user, uri.password]}) if uri.userinfo
61
+
59
62
  req_opts = {
60
63
  redirects: 0,
61
64
  keepalive: false,
@@ -98,9 +101,13 @@ module Billy
98
101
  end
99
102
 
100
103
  def whitelisted_url?(url)
101
- !Billy.config.whitelist.index do |v|
102
- v =~ /^#{url.host}(?::#{url.port})?$/
103
- end.nil?
104
+ Billy.config.whitelist.any? do |value|
105
+ if value.is_a?(Regexp)
106
+ url.to_s =~ value || url.omit(:port).to_s =~ value
107
+ else
108
+ value =~ /^#{url.host}(?::#{url.port})?$/
109
+ end
110
+ end
104
111
  end
105
112
 
106
113
  def blacklisted_path?(path)
@@ -16,7 +16,7 @@ module Billy
16
16
  def start(threaded = true)
17
17
  if threaded
18
18
  Thread.new { main_loop }
19
- sleep(0.01) while @signature.nil?
19
+ sleep(0.01) while (not defined?(@signature)) || @signature.nil?
20
20
  else
21
21
  main_loop
22
22
  end
@@ -49,7 +49,7 @@ module Billy
49
49
 
50
50
  @signature = EM.start_server('127.0.0.1', Billy.config.proxy_port, ProxyConnection) do |p|
51
51
  p.handler = request_handler
52
- p.cache = @cache
52
+ p.cache = @cache if defined?(@cache)
53
53
  end
54
54
 
55
55
  Billy.log(:info, "puffing-billy: Proxy listening on #{url}")
@@ -35,7 +35,7 @@ module Billy
35
35
  if @parser.http_method == 'CONNECT'
36
36
  restart_with_ssl(@parser.request_url)
37
37
  else
38
- if @ssl
38
+ if defined?(@ssl) && @ssl
39
39
  uri = Addressable::URI.parse(@parser.request_url)
40
40
  @url = "https://#{@ssl}#{[uri.path, uri.query].compact.join('?')}"
41
41
  else
@@ -1,3 +1,3 @@
1
1
  module Billy
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
28
28
  gem.add_development_dependency 'pry'
29
29
  gem.add_development_dependency 'cucumber'
30
30
  gem.add_runtime_dependency 'addressable'
31
- gem.add_runtime_dependency 'eventmachine', '= 1.0.4'
31
+ gem.add_runtime_dependency 'eventmachine', '~> 1.0.4'
32
32
  gem.add_runtime_dependency 'em-synchrony'
33
33
  gem.add_runtime_dependency 'em-http-request', '~> 1.1.0'
34
34
  gem.add_runtime_dependency 'eventmachine_httpserver'
@@ -5,7 +5,7 @@ describe Billy::ProxyHandler do
5
5
  let(:request) do
6
6
  {
7
7
  method: 'post',
8
- url: 'http://example.test:8080/index?some=param',
8
+ url: 'http://usern:pw@example.test:8080/index?some=param',
9
9
  headers: { 'Accept-Encoding' => 'gzip',
10
10
  'Cache-Control' => 'no-cache' },
11
11
  body: 'Some body'
@@ -50,6 +50,27 @@ describe Billy::ProxyHandler do
50
50
  request[:body])).to be false
51
51
  end
52
52
  end
53
+
54
+ context 'as a regex' do
55
+ before do
56
+ expect(Billy.config).to receive(:whitelist) { [%r{example\.test\/a}] }
57
+ end
58
+
59
+ it 'handles requests for the host without a port' do
60
+ expect(subject.handles_request?(request[:method],
61
+ 'http://example.test/a',
62
+ request[:headers],
63
+ request[:body])).to be true
64
+ end
65
+
66
+ it 'handles requests for the host with a port' do
67
+ expect(subject.handles_request?(request[:method],
68
+ 'http://example.test:8080/a',
69
+ request[:headers],
70
+ request[:body])).to be true
71
+ end
72
+ end
73
+
53
74
  context 'without a port' do
54
75
  before do
55
76
  expect(Billy.config).to receive(:whitelist) { ['example.test'] }
@@ -186,4 +207,20 @@ describe Billy::ProxyHandler do
186
207
  end
187
208
  end
188
209
  end
210
+
211
+ describe '#build_request_options' do
212
+ it 'creates authorization header when URL has basic auth' do
213
+ request_options = subject.send(:build_request_options, request[:url],
214
+ request[:headers],
215
+ request[:body])
216
+ expect(request_options[:head]).to have_key 'authorization'
217
+ end
218
+
219
+ it 'does not include authorization header without basic auth' do
220
+ request_options = subject.send(:build_request_options, request[:url].gsub('usern:pw@',''),
221
+ request[:headers],
222
+ request[:body])
223
+ expect(request_options[:head]).not_to have_key 'authorization'
224
+ end
225
+ end
189
226
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puffing-billy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olly Smith
@@ -196,14 +196,14 @@ dependencies:
196
196
  name: eventmachine
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - '='
199
+ - - "~>"
200
200
  - !ruby/object:Gem::Version
201
201
  version: 1.0.4
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - '='
206
+ - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: 1.0.4
209
209
  - !ruby/object:Gem::Dependency