puffing-billy 0.5.1 → 0.6.0
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +75 -58
- data/README.md +15 -6
- data/lib/billy/config.rb +5 -2
- data/lib/billy/handlers/proxy_handler.rb +12 -3
- data/lib/billy/handlers/request_handler.rb +2 -0
- data/lib/billy/proxy.rb +1 -1
- data/lib/billy/version.rb +1 -1
- data/puffing-billy.gemspec +1 -1
- data/spec/lib/billy/handlers/proxy_handler_spec.rb +16 -0
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7dab062648498106cd36d92beb9ac60d785258e
|
|
4
|
+
data.tar.gz: 2eb64804cc5f68b5dba48b20c589140609136f7f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4187b46b234b85781c70d0b7c6b627741b97618036cc28fe6f1e9129aa26623f72e2bd7b9b17b913d55427ea7b88e7afa8b0ae6852d7ebfa75ac0b690f372c37
|
|
7
|
+
data.tar.gz: ad0efae508e1016672e7b37185e4b04c5701bb22615fb40d8d1169023a4ad9e0587286ea3c8bc79394a4b21c7cc9d88ccf4aa40109fb0084a19a71e57e4bda9b
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
puffing-billy (0.5.
|
|
4
|
+
puffing-billy (0.5.1)
|
|
5
5
|
addressable
|
|
6
6
|
em-http-request (~> 1.1.0)
|
|
7
7
|
em-synchrony
|
|
8
|
-
eventmachine
|
|
8
|
+
eventmachine (= 1.0.4)
|
|
9
9
|
eventmachine_httpserver
|
|
10
10
|
http_parser.rb (~> 0.6.0)
|
|
11
11
|
multi_json
|
|
@@ -13,31 +13,32 @@ PATH
|
|
|
13
13
|
GEM
|
|
14
14
|
remote: https://rubygems.org/
|
|
15
15
|
specs:
|
|
16
|
-
addressable (2.3.
|
|
16
|
+
addressable (2.3.8)
|
|
17
17
|
builder (3.2.2)
|
|
18
|
-
capybara (2.
|
|
18
|
+
capybara (2.4.4)
|
|
19
19
|
mime-types (>= 1.16)
|
|
20
20
|
nokogiri (>= 1.3.3)
|
|
21
21
|
rack (>= 1.0.0)
|
|
22
22
|
rack-test (>= 0.5.4)
|
|
23
23
|
xpath (~> 2.0)
|
|
24
|
-
capybara-webkit (1.
|
|
25
|
-
capybara (>= 2.0
|
|
24
|
+
capybara-webkit (1.6.0)
|
|
25
|
+
capybara (>= 2.3.0, < 2.5.0)
|
|
26
26
|
json
|
|
27
|
-
|
|
28
|
-
timers (~> 1.1.0)
|
|
29
|
-
childprocess (0.4.0)
|
|
27
|
+
childprocess (0.5.6)
|
|
30
28
|
ffi (~> 1.0, >= 1.0.11)
|
|
31
29
|
cliver (0.3.2)
|
|
32
30
|
coderay (1.1.0)
|
|
33
31
|
cookiejar (0.3.2)
|
|
34
|
-
cucumber (
|
|
32
|
+
cucumber (2.0.2)
|
|
35
33
|
builder (>= 2.1.2)
|
|
34
|
+
cucumber-core (~> 1.2.0)
|
|
36
35
|
diff-lcs (>= 1.1.3)
|
|
37
36
|
gherkin (~> 2.12)
|
|
38
37
|
multi_json (>= 1.7.5, < 2.0)
|
|
39
|
-
multi_test (>= 0.
|
|
40
|
-
|
|
38
|
+
multi_test (>= 0.1.2)
|
|
39
|
+
cucumber-core (1.2.0)
|
|
40
|
+
gherkin (~> 2.12.0)
|
|
41
|
+
daemons (1.2.3)
|
|
41
42
|
diff-lcs (1.2.5)
|
|
42
43
|
em-http-request (1.1.2)
|
|
43
44
|
addressable (>= 2.3.4)
|
|
@@ -47,75 +48,88 @@ GEM
|
|
|
47
48
|
http_parser.rb (>= 0.6.0)
|
|
48
49
|
em-socksify (0.3.0)
|
|
49
50
|
eventmachine (>= 1.0.0.beta.4)
|
|
50
|
-
em-synchrony (1.0.
|
|
51
|
+
em-synchrony (1.0.4)
|
|
51
52
|
eventmachine (>= 1.0.0.beta.1)
|
|
52
|
-
eventmachine (1.0.
|
|
53
|
+
eventmachine (1.0.4)
|
|
53
54
|
eventmachine_httpserver (0.2.1)
|
|
54
|
-
faraday (0.9.
|
|
55
|
+
faraday (0.9.1)
|
|
55
56
|
multipart-post (>= 1.2, < 3)
|
|
56
|
-
ffi (1.9.
|
|
57
|
-
formatador (0.2.
|
|
57
|
+
ffi (1.9.10)
|
|
58
|
+
formatador (0.2.5)
|
|
58
59
|
gherkin (2.12.2)
|
|
59
60
|
multi_json (~> 1.3)
|
|
60
|
-
guard (2.
|
|
61
|
+
guard (2.13.0)
|
|
61
62
|
formatador (>= 0.2.4)
|
|
62
|
-
listen (
|
|
63
|
+
listen (>= 2.7, <= 4.0)
|
|
63
64
|
lumberjack (~> 1.0)
|
|
65
|
+
nenv (~> 0.1)
|
|
66
|
+
notiffany (~> 0.0)
|
|
64
67
|
pry (>= 0.9.12)
|
|
68
|
+
shellany (~> 0.0)
|
|
65
69
|
thor (>= 0.18.1)
|
|
66
70
|
http_parser.rb (0.6.0)
|
|
67
|
-
json (1.8.
|
|
68
|
-
listen (
|
|
69
|
-
celluloid (>= 0.15.2)
|
|
71
|
+
json (1.8.3)
|
|
72
|
+
listen (3.0.3)
|
|
70
73
|
rb-fsevent (>= 0.9.3)
|
|
71
74
|
rb-inotify (>= 0.9)
|
|
72
|
-
lumberjack (1.0.
|
|
75
|
+
lumberjack (1.0.9)
|
|
73
76
|
method_source (0.8.2)
|
|
74
|
-
mime-types (2.1)
|
|
75
|
-
mini_portile (0.
|
|
76
|
-
multi_json (1.
|
|
77
|
-
multi_test (0.
|
|
77
|
+
mime-types (2.6.1)
|
|
78
|
+
mini_portile (0.6.2)
|
|
79
|
+
multi_json (1.11.2)
|
|
80
|
+
multi_test (0.1.2)
|
|
78
81
|
multipart-post (2.0.0)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
nenv (0.2.0)
|
|
83
|
+
nokogiri (1.6.6.2)
|
|
84
|
+
mini_portile (~> 0.6.0)
|
|
85
|
+
notiffany (0.0.7)
|
|
86
|
+
nenv (~> 0.1)
|
|
87
|
+
shellany (~> 0.0)
|
|
88
|
+
poltergeist (1.6.0)
|
|
82
89
|
capybara (~> 2.1)
|
|
83
90
|
cliver (~> 0.3.1)
|
|
84
91
|
multi_json (~> 1.0)
|
|
85
92
|
websocket-driver (>= 0.2.0)
|
|
86
|
-
pry (0.
|
|
87
|
-
coderay (~> 1.0)
|
|
88
|
-
method_source (~> 0.8)
|
|
93
|
+
pry (0.10.1)
|
|
94
|
+
coderay (~> 1.1.0)
|
|
95
|
+
method_source (~> 0.8.1)
|
|
89
96
|
slop (~> 3.4)
|
|
90
|
-
rack (1.
|
|
91
|
-
rack-test (0.6.
|
|
97
|
+
rack (1.6.4)
|
|
98
|
+
rack-test (0.6.3)
|
|
92
99
|
rack (>= 1.0)
|
|
93
|
-
rb-fsevent (0.9.
|
|
94
|
-
rb-inotify (0.9.
|
|
100
|
+
rb-fsevent (0.9.5)
|
|
101
|
+
rb-inotify (0.9.5)
|
|
95
102
|
ffi (>= 0.5.0)
|
|
96
|
-
rspec (
|
|
97
|
-
rspec-core (~>
|
|
98
|
-
rspec-expectations (~>
|
|
99
|
-
rspec-mocks (~>
|
|
100
|
-
rspec-core (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
rspec (3.3.0)
|
|
104
|
+
rspec-core (~> 3.3.0)
|
|
105
|
+
rspec-expectations (~> 3.3.0)
|
|
106
|
+
rspec-mocks (~> 3.3.0)
|
|
107
|
+
rspec-core (3.3.2)
|
|
108
|
+
rspec-support (~> 3.3.0)
|
|
109
|
+
rspec-expectations (3.3.1)
|
|
110
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
111
|
+
rspec-support (~> 3.3.0)
|
|
112
|
+
rspec-mocks (3.3.2)
|
|
113
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
114
|
+
rspec-support (~> 3.3.0)
|
|
115
|
+
rspec-support (3.3.0)
|
|
116
|
+
rubyzip (1.1.7)
|
|
117
|
+
selenium-webdriver (2.47.1)
|
|
118
|
+
childprocess (~> 0.5)
|
|
107
119
|
multi_json (~> 1.0)
|
|
108
120
|
rubyzip (~> 1.0)
|
|
109
|
-
websocket (~> 1.0
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
websocket (1.
|
|
118
|
-
websocket-driver (0.
|
|
121
|
+
websocket (~> 1.0)
|
|
122
|
+
shellany (0.0.1)
|
|
123
|
+
slop (3.6.0)
|
|
124
|
+
thin (1.6.3)
|
|
125
|
+
daemons (~> 1.0, >= 1.0.9)
|
|
126
|
+
eventmachine (~> 1.0)
|
|
127
|
+
rack (~> 1.0)
|
|
128
|
+
thor (0.19.1)
|
|
129
|
+
websocket (1.2.2)
|
|
130
|
+
websocket-driver (0.6.2)
|
|
131
|
+
websocket-extensions (>= 0.1.0)
|
|
132
|
+
websocket-extensions (0.1.2)
|
|
119
133
|
xpath (2.0.0)
|
|
120
134
|
nokogiri (~> 1.3)
|
|
121
135
|
|
|
@@ -136,3 +150,6 @@ DEPENDENCIES
|
|
|
136
150
|
rspec
|
|
137
151
|
selenium-webdriver
|
|
138
152
|
thin
|
|
153
|
+
|
|
154
|
+
BUNDLED WITH
|
|
155
|
+
1.10.6
|
data/README.md
CHANGED
|
@@ -133,9 +133,9 @@ And /^a stub for google$/ do
|
|
|
133
133
|
end
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
It's good practice to reset the driver after each scenario, so having an
|
|
137
|
-
`@billy` tag switches the drivers on for a given scenario. Also note that
|
|
138
|
-
stubs are reset after each step, so any usage of a stub should be in the
|
|
136
|
+
It's good practice to reset the driver after each scenario, so having an
|
|
137
|
+
`@billy` tag switches the drivers on for a given scenario. Also note that
|
|
138
|
+
stubs are reset after each step, so any usage of a stub should be in the
|
|
139
139
|
same step that it was created in.
|
|
140
140
|
|
|
141
141
|
## Minitest Usage
|
|
@@ -194,6 +194,10 @@ Billy.configure do |c|
|
|
|
194
194
|
c.non_successful_error_level = :warn
|
|
195
195
|
c.non_whitelisted_requests_disabled = false
|
|
196
196
|
c.cache_path = 'spec/req_cache/'
|
|
197
|
+
c.proxy_host = 'example.com' # defaults to localhost
|
|
198
|
+
c.proxy_port = 12345 # defaults to random
|
|
199
|
+
c.proxied_request_host = nil
|
|
200
|
+
c.proxied_request_port = 80
|
|
197
201
|
end
|
|
198
202
|
```
|
|
199
203
|
|
|
@@ -216,10 +220,10 @@ generally the same as: `proxy.stub('http://myapi.com/user/')`. When you need to
|
|
|
216
220
|
you may set this config value to false.
|
|
217
221
|
|
|
218
222
|
`c.dynamic_jsonp` is used to rewrite the body of JSONP responses based on the
|
|
219
|
-
callback parameter. For example, if a request to `http://example.com/foo?callback=bar`
|
|
223
|
+
callback parameter. For example, if a request to `http://example.com/foo?callback=bar`
|
|
220
224
|
returns `bar({"some": "json"});` and is recorded, then a later request to
|
|
221
225
|
`http://example.com/foo?callback=baz` will be a cache hit and respond with
|
|
222
|
-
`baz({"some": "json"});` This is useful because most JSONP implementations
|
|
226
|
+
`baz({"some": "json"});` This is useful because most JSONP implementations
|
|
223
227
|
base the callback name off of a timestamp or something else dynamic.
|
|
224
228
|
|
|
225
229
|
`c.dynamic_jsonp_keys` is used to configure which parameters to ignore when
|
|
@@ -256,6 +260,11 @@ allowed, all others will throw an error with the URL attempted to be accessed.
|
|
|
256
260
|
This is useful for debugging issues in isolated environments (ie.
|
|
257
261
|
continuous integration).
|
|
258
262
|
|
|
263
|
+
`c.proxy_host` and `c.proxy_port` are used for the Billy proxy itself which runs locally.
|
|
264
|
+
|
|
265
|
+
`c.proxied_request_host` and `c.proxied_request_port` are used if an internal proxy
|
|
266
|
+
server is required to access the internet. Most common in larger companies.
|
|
267
|
+
|
|
259
268
|
### Cache Scopes
|
|
260
269
|
|
|
261
270
|
If you need to cache different responses to the same HTTP request, you can use
|
|
@@ -294,7 +303,7 @@ context 'with a cache scope' do
|
|
|
294
303
|
end
|
|
295
304
|
|
|
296
305
|
# Or you can run a block within the context of a cache scope:
|
|
297
|
-
# Note: When using scope blocks, be sure that both the action that triggers a
|
|
306
|
+
# Note: When using scope blocks, be sure that both the action that triggers a
|
|
298
307
|
# request and the assertion that a response has been received are within the block
|
|
299
308
|
it 'can execute a block against a named cache' do
|
|
300
309
|
expect(proxy.cache.scope).to eq("my_cache")
|
data/lib/billy/config.rb
CHANGED
|
@@ -8,9 +8,9 @@ module Billy
|
|
|
8
8
|
|
|
9
9
|
attr_accessor :logger, :cache, :cache_request_headers, :whitelist, :path_blacklist, :ignore_params,
|
|
10
10
|
:persist_cache, :ignore_cache_port, :non_successful_cache_disabled, :non_successful_error_level,
|
|
11
|
-
:non_whitelisted_requests_disabled, :cache_path, :proxy_port, :proxied_request_inactivity_timeout,
|
|
11
|
+
:non_whitelisted_requests_disabled, :cache_path, :proxy_host, :proxy_port, :proxied_request_inactivity_timeout,
|
|
12
12
|
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :merge_cached_responses_whitelist,
|
|
13
|
-
:strip_query_params
|
|
13
|
+
:strip_query_params, :proxied_request_host, :proxied_request_port
|
|
14
14
|
|
|
15
15
|
def initialize
|
|
16
16
|
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
|
@@ -32,10 +32,13 @@ module Billy
|
|
|
32
32
|
@non_successful_error_level = :warn
|
|
33
33
|
@non_whitelisted_requests_disabled = false
|
|
34
34
|
@cache_path = File.join(Dir.tmpdir, 'puffing-billy')
|
|
35
|
+
@proxy_host = 'localhost'
|
|
35
36
|
@proxy_port = RANDOM_AVAILABLE_PORT
|
|
36
37
|
@proxied_request_inactivity_timeout = 10 # defaults from https://github.com/igrigorik/em-http-request/wiki/Redirects-and-Timeouts
|
|
37
38
|
@proxied_request_connect_timeout = 5
|
|
38
39
|
@strip_query_params = true
|
|
40
|
+
@proxied_request_host = nil
|
|
41
|
+
@proxied_request_port = 80
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
|
|
@@ -13,10 +13,15 @@ module Billy
|
|
|
13
13
|
|
|
14
14
|
def handle_request(method, url, headers, body)
|
|
15
15
|
if handles_request?(method, url, headers, body)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
connect_timeout: Billy.config.proxied_request_connect_timeout)
|
|
16
|
+
opts = { inactivity_timeout: Billy.config.proxied_request_inactivity_timeout,
|
|
17
|
+
connect_timeout: Billy.config.proxied_request_connect_timeout }
|
|
19
18
|
|
|
19
|
+
if Billy.config.proxied_request_host && !bypass_internal_proxy?(url)
|
|
20
|
+
opts.merge!({ proxy: { host: Billy.config.proxied_request_host,
|
|
21
|
+
port: Billy.config.proxied_request_port }} )
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
req = EventMachine::HttpRequest.new(url, opts)
|
|
20
25
|
req = req.send(method.downcase, build_request_options(headers, body))
|
|
21
26
|
|
|
22
27
|
if req.error
|
|
@@ -109,5 +114,9 @@ module Billy
|
|
|
109
114
|
def cacheable_status?(status)
|
|
110
115
|
Billy.config.non_successful_cache_disabled ? successful_status?(status) : true
|
|
111
116
|
end
|
|
117
|
+
|
|
118
|
+
def bypass_internal_proxy?(url)
|
|
119
|
+
url.include?('localhost') || url.include?('127.') || url.include?('.dev') || url.include?('.fin')
|
|
120
|
+
end
|
|
112
121
|
end
|
|
113
122
|
end
|
data/lib/billy/proxy.rb
CHANGED
data/lib/billy/version.rb
CHANGED
data/puffing-billy.gemspec
CHANGED
|
@@ -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'
|
|
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'
|
|
@@ -168,6 +168,22 @@ describe Billy::ProxyHandler do
|
|
|
168
168
|
request[:headers],
|
|
169
169
|
request[:body])
|
|
170
170
|
end
|
|
171
|
+
|
|
172
|
+
it 'uses the internal proxy settings defined in configuration' do
|
|
173
|
+
allow(Billy.config).to receive(:proxied_request_host).and_return('10.10.10.10')
|
|
174
|
+
allow(Billy.config).to receive(:proxied_request_port).and_return('2080')
|
|
175
|
+
|
|
176
|
+
expect(EventMachine::HttpRequest).to receive(:new).with(request[:url],
|
|
177
|
+
inactivity_timeout: 10,
|
|
178
|
+
connect_timeout: 5,
|
|
179
|
+
proxy: { host: '10.10.10.10', port: '2080' }
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
subject.handle_request(request[:method],
|
|
183
|
+
request[:url],
|
|
184
|
+
request[:headers],
|
|
185
|
+
request[:body])
|
|
186
|
+
end
|
|
171
187
|
end
|
|
172
188
|
end
|
|
173
189
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puffing-billy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Olly Smith
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -196,16 +196,16 @@ dependencies:
|
|
|
196
196
|
name: eventmachine
|
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
|
198
198
|
requirements:
|
|
199
|
-
- -
|
|
199
|
+
- - '='
|
|
200
200
|
- !ruby/object:Gem::Version
|
|
201
|
-
version:
|
|
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
|
-
version:
|
|
208
|
+
version: 1.0.4
|
|
209
209
|
- !ruby/object:Gem::Dependency
|
|
210
210
|
name: em-synchrony
|
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -356,7 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
356
356
|
version: '0'
|
|
357
357
|
requirements: []
|
|
358
358
|
rubyforge_project:
|
|
359
|
-
rubygems_version: 2.
|
|
359
|
+
rubygems_version: 2.4.8
|
|
360
360
|
signing_key:
|
|
361
361
|
specification_version: 4
|
|
362
362
|
summary: Easy request stubs for browser tests.
|
|
@@ -376,3 +376,4 @@ test_files:
|
|
|
376
376
|
- spec/lib/proxy_spec.rb
|
|
377
377
|
- spec/spec_helper.rb
|
|
378
378
|
- spec/support/test_server.rb
|
|
379
|
+
has_rdoc:
|