puffing-billy 2.4.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +2 -2
  4. data/lib/billy/browsers/capybara.rb +13 -9
  5. data/lib/billy/browsers/watir.rb +4 -2
  6. data/lib/billy/proxy.rb +1 -1
  7. data/lib/billy/version.rb +1 -1
  8. metadata +29 -79
  9. data/.gitignore +0 -6
  10. data/.rspec +0 -2
  11. data/.travis.yml +0 -36
  12. data/Dockerfile +0 -14
  13. data/Gemfile +0 -4
  14. data/Guardfile +0 -23
  15. data/Rakefile +0 -11
  16. data/bin/proxy.rb +0 -3
  17. data/examples/README.md +0 -1
  18. data/examples/facebook_api.html +0 -59
  19. data/examples/intercept_request.html +0 -10
  20. data/examples/post_api.html +0 -16
  21. data/examples/preflight_request.html +0 -22
  22. data/examples/tumblr_api.html +0 -22
  23. data/examples/tumblr_api_https.html +0 -22
  24. data/log/.gitkeep +0 -0
  25. data/puffing-billy.gemspec +0 -39
  26. data/spec/features/examples/facebook_api_spec.rb +0 -23
  27. data/spec/features/examples/intercept_request_spec.rb +0 -31
  28. data/spec/features/examples/post_api_spec.rb +0 -15
  29. data/spec/features/examples/preflight_request_spec.rb +0 -29
  30. data/spec/features/examples/tumblr_api_spec.rb +0 -59
  31. data/spec/lib/billy/browsers/capybara_spec.rb +0 -28
  32. data/spec/lib/billy/cache_spec.rb +0 -158
  33. data/spec/lib/billy/handlers/cache_handler_spec.rb +0 -191
  34. data/spec/lib/billy/handlers/handler_spec.rb +0 -16
  35. data/spec/lib/billy/handlers/proxy_handler_spec.rb +0 -254
  36. data/spec/lib/billy/handlers/request_handler_spec.rb +0 -200
  37. data/spec/lib/billy/handlers/request_log_spec.rb +0 -74
  38. data/spec/lib/billy/handlers/stub_handler_spec.rb +0 -117
  39. data/spec/lib/billy/proxy_connection_spec.rb +0 -20
  40. data/spec/lib/billy/proxy_request_stub_spec.rb +0 -252
  41. data/spec/lib/billy/resource_utils_spec.rb +0 -55
  42. data/spec/lib/billy/ssl/authority_spec.rb +0 -84
  43. data/spec/lib/billy/ssl/certificate_chain_spec.rb +0 -39
  44. data/spec/lib/billy/ssl/certificate_spec.rb +0 -89
  45. data/spec/lib/billy/watir/watir_spec.rb +0 -18
  46. data/spec/lib/proxy_spec.rb +0 -431
  47. data/spec/spec_helper.rb +0 -52
  48. data/spec/support/test_server.rb +0 -79
@@ -1,254 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Billy::ProxyHandler do
4
- subject { Billy::ProxyHandler.new }
5
- let(:request) do
6
- {
7
- method: 'post',
8
- url: 'http://usern:pw@example.test:8080/index?some=param',
9
- headers: { 'Accept-Encoding' => 'gzip',
10
- 'Cache-Control' => 'no-cache' },
11
- body: 'Some body'
12
- }
13
- end
14
-
15
- describe '#handles_request?' do
16
- context 'with non-whitelisted requests enabled' do
17
- before do
18
- expect(Billy.config).to receive(:non_whitelisted_requests_disabled).and_return(false)
19
- end
20
-
21
- it 'handles all requests' do
22
- expect(subject.handles_request?(request[:method],
23
- request[:url],
24
- request[:headers],
25
- request[:body])).to be true
26
- end
27
- end
28
- context 'with non-whitelisted requests disabled' do
29
- before do
30
- expect(Billy.config).to receive(:non_whitelisted_requests_disabled).and_return(true)
31
- end
32
-
33
- it 'does not handle requests that are not white or black listed' do
34
- expect(subject.handles_request?(request[:method],
35
- request[:url],
36
- request[:headers],
37
- request[:body])).to be false
38
- end
39
-
40
- context 'a whitelisted host' do
41
- context 'with a blacklisted path' do
42
- before do
43
- expect(Billy.config).to receive(:path_blacklist) { ['/index'] }
44
- end
45
-
46
- it 'does not handle requests for blacklisted paths' do
47
- expect(subject.handles_request?(request[:method],
48
- 'http://example.test:8080/index?some=param',
49
- request[:headers],
50
- request[:body])).to be false
51
- end
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
-
74
- context 'without a port' do
75
- before do
76
- expect(Billy.config).to receive(:whitelist) { ['example.test'] }
77
- end
78
-
79
- it 'handles requests for the host without a port' do
80
- expect(subject.handles_request?(request[:method],
81
- 'http://example.test',
82
- request[:headers],
83
- request[:body])).to be true
84
- end
85
-
86
- it 'handles requests for the host with a port' do
87
- expect(subject.handles_request?(request[:method],
88
- 'http://example.test:8080',
89
- request[:headers],
90
- request[:body])).to be true
91
- end
92
- end
93
-
94
- context 'with a port' do
95
- before do
96
- expect(Billy.config).to receive(:whitelist) { ['example.test:8080'] }
97
- end
98
-
99
- it 'does not handle requests whitelisted for a specific port' do
100
- expect(subject.handles_request?(request[:method],
101
- 'http://example.test',
102
- request[:headers],
103
- request[:body])).to be false
104
- end
105
-
106
- it 'handles requests for the host with a port' do
107
- expect(subject.handles_request?(request[:method],
108
- 'http://example.test:8080',
109
- request[:headers],
110
- request[:body])).to be true
111
- end
112
- end
113
- end
114
- end
115
- end
116
-
117
- describe '#handle_request' do
118
- it 'returns nil if it does not handle the request' do
119
- expect(subject).to receive(:handles_request?).and_return(false)
120
- expect(subject.handle_request(request[:method],
121
- request[:url],
122
- request[:headers],
123
- request[:body])).to be nil
124
- end
125
-
126
- context 'with a handled request' do
127
- let(:response_header) do
128
- header = Struct.new(:status, :raw).new
129
- header.status = 200
130
- header.raw = {}
131
- header
132
- end
133
-
134
- let(:em_response) { double('response') }
135
- let(:em_request) do
136
- double('EM::HttpRequest', error: nil, response: em_response, response_header: response_header)
137
- end
138
-
139
- before do
140
- allow(subject).to receive(:handles_request?).and_return(true)
141
- allow(em_response).to receive(:force_encoding).and_return('The response body')
142
- allow(EventMachine::HttpRequest).to receive(:new).and_return(em_request)
143
- expect(em_request).to receive(:post).and_return(em_request)
144
- end
145
-
146
- it 'returns any error in the response' do
147
- allow(em_request).to receive(:error).and_return('ERROR!')
148
- expect(subject.handle_request(request[:method],
149
- request[:url],
150
- request[:headers],
151
- request[:body])).to eql(error: "Request to #{request[:url]} failed with error: ERROR!")
152
- end
153
-
154
- it 'returns a hashed response if the request succeeds' do
155
- expect(subject.handle_request(request[:method],
156
- request[:url],
157
- request[:headers],
158
- request[:body])).to eql(status: 200, headers: { 'Connection' => 'close' }, content: 'The response body')
159
- end
160
-
161
- it 'returns nil if both the error and response are for some reason nil' do
162
- allow(em_request).to receive(:response).and_return(nil)
163
- expect(subject.handle_request(request[:method],
164
- request[:url],
165
- request[:headers],
166
- request[:body])).to be nil
167
- end
168
-
169
- it 'caches the response if cacheable' do
170
- expect(subject).to receive(:allowed_response_code?).and_return(true)
171
- expect(Billy::Cache.instance).to receive(:store)
172
- subject.handle_request(request[:method],
173
- request[:url],
174
- request[:headers],
175
- request[:body])
176
- end
177
-
178
- it 'does NOT cache the response if the host is whitelisted but not cache_whitelisted' do
179
- uri = Addressable::URI.parse(request[:url])
180
-
181
- expect(subject).to receive(:allowed_response_code?).and_return(true)
182
- expect(Billy.config).to receive(:whitelist).and_return([uri.host])
183
- expect(Billy.config).to receive(:cache_whitelist).and_return([])
184
-
185
- expect(Billy::Cache.instance).not_to receive(:store)
186
- subject.handle_request(request[:method],
187
- request[:url],
188
- request[:headers],
189
- request[:body])
190
- end
191
-
192
- it 'caches the response if the host is whitelisted AND cache_whitelisted' do
193
- uri = Addressable::URI.parse(request[:url])
194
-
195
- expect(subject).to receive(:allowed_response_code?).and_return(true)
196
- expect(Billy.config).to receive(:whitelist).and_return([uri.host])
197
- expect(Billy.config).to receive(:cache_whitelist).and_return([uri.host])
198
-
199
- expect(Billy::Cache.instance).to receive(:store)
200
- subject.handle_request(request[:method],
201
- request[:url],
202
- request[:headers],
203
- request[:body])
204
- end
205
-
206
- it 'uses the timeouts defined in configuration' do
207
- allow(Billy.config).to receive(:proxied_request_inactivity_timeout).and_return(42)
208
- allow(Billy.config).to receive(:proxied_request_connect_timeout).and_return(24)
209
-
210
- expect(EventMachine::HttpRequest).to receive(:new).with(request[:url],
211
- inactivity_timeout: 42,
212
- connect_timeout: 24
213
- )
214
-
215
- subject.handle_request(request[:method],
216
- request[:url],
217
- request[:headers],
218
- request[:body])
219
- end
220
-
221
- it 'uses the internal proxy settings defined in configuration' do
222
- allow(Billy.config).to receive(:proxied_request_host).and_return('10.10.10.10')
223
- allow(Billy.config).to receive(:proxied_request_port).and_return('2080')
224
-
225
- expect(EventMachine::HttpRequest).to receive(:new).with(request[:url],
226
- inactivity_timeout: 10,
227
- connect_timeout: 5,
228
- proxy: { host: '10.10.10.10', port: '2080' }
229
- )
230
-
231
- subject.handle_request(request[:method],
232
- request[:url],
233
- request[:headers],
234
- request[:body])
235
- end
236
- end
237
- end
238
-
239
- describe '#build_request_options' do
240
- it 'creates authorization header when URL has basic auth' do
241
- request_options = subject.send(:build_request_options, request[:url],
242
- request[:headers],
243
- request[:body])
244
- expect(request_options[:head]).to have_key 'authorization'
245
- end
246
-
247
- it 'does not include authorization header without basic auth' do
248
- request_options = subject.send(:build_request_options, request[:url].gsub('usern:pw@',''),
249
- request[:headers],
250
- request[:body])
251
- expect(request_options[:head]).not_to have_key 'authorization'
252
- end
253
- end
254
- end
@@ -1,200 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Billy::RequestHandler do
4
- subject { Billy::RequestHandler.new }
5
-
6
- it 'implements Handler' do
7
- expect(subject).to be_a Billy::Handler
8
- end
9
-
10
- describe '#handlers' do
11
- it 'has a stub handler' do
12
- expect(subject.handlers[:stubs]).to be_a Billy::StubHandler
13
- end
14
-
15
- it 'has a cache handler' do
16
- expect(subject.handlers[:cache]).to be_a Billy::CacheHandler
17
- end
18
-
19
- it 'has a proxy handler' do
20
- expect(subject.handlers[:proxy]).to be_a Billy::ProxyHandler
21
- end
22
- end
23
-
24
- context 'with stubbed handlers' do
25
- let(:args) { %w(get url headers body) }
26
- let(:stub_handler) { double('StubHandler') }
27
- let(:cache_handler) { double('CacheHandler') }
28
- let(:proxy_handler) { double('ProxyHandler') }
29
- let(:handlers) do
30
- {
31
- stubs: stub_handler,
32
- cache: cache_handler,
33
- proxy: proxy_handler
34
- }
35
- end
36
-
37
- before do
38
- allow(subject).to receive(:handlers).and_return(handlers)
39
- end
40
-
41
- describe '#handles_request?' do
42
- it 'returns false if no handlers handle the request' do
43
- handlers.each do |_key, handler|
44
- expect(handler).to receive(:handles_request?).with(*args).and_return(false)
45
- end
46
- expect(subject.handles_request?(*args)).to be false
47
- end
48
-
49
- it 'returns true immediately if the stub handler handles the request' do
50
- expect(stub_handler).to receive(:handles_request?).with(*args).and_return(true)
51
- expect(cache_handler).to_not receive(:handles_request?)
52
- expect(proxy_handler).to_not receive(:handles_request?)
53
- expect(subject.handles_request?(*args)).to be true
54
- end
55
-
56
- it 'returns true if the cache handler handles the request' do
57
- expect(stub_handler).to receive(:handles_request?).with(*args).and_return(false)
58
- expect(cache_handler).to receive(:handles_request?).with(*args).and_return(true)
59
- expect(proxy_handler).to_not receive(:handles_request?)
60
- expect(subject.handles_request?(*args)).to be true
61
- end
62
-
63
- it 'returns true if the proxy handler handles the request' do
64
- expect(stub_handler).to receive(:handles_request?).with(*args).and_return(false)
65
- expect(cache_handler).to receive(:handles_request?).with(*args).and_return(false)
66
- expect(proxy_handler).to receive(:handles_request?).with(*args).and_return(true)
67
- expect(subject.handles_request?(*args)).to be true
68
- end
69
- end
70
-
71
- describe '#handle_request' do
72
- before do
73
- allow(Billy::config).to receive(:record_requests).and_return(true)
74
- end
75
-
76
- it 'returns stubbed responses' do
77
- expect(stub_handler).to receive(:handle_request).with(*args).and_return('foo')
78
- expect(cache_handler).to_not receive(:handle_request)
79
- expect(proxy_handler).to_not receive(:handle_request)
80
- expect(subject.handle_request(*args)).to eql 'foo'
81
- expect(subject.requests).to eql([{status: :complete, handler: :stubs, method: 'get', url: 'url', headers: 'headers', body: 'body'}])
82
- end
83
-
84
- it 'returns cached responses' do
85
- expect(stub_handler).to receive(:handle_request).with(*args)
86
- expect(cache_handler).to receive(:handle_request).with(*args).and_return('bar')
87
- expect(proxy_handler).to_not receive(:handle_request)
88
- expect(subject.handle_request(*args)).to eql 'bar'
89
- expect(subject.requests).to eql([{status: :complete, handler: :cache, method: 'get', url: 'url', headers: 'headers', body: 'body'}])
90
- end
91
-
92
- it 'returns proxied responses' do
93
- expect(stub_handler).to receive(:handle_request).with(*args)
94
- expect(cache_handler).to receive(:handle_request).with(*args)
95
- expect(proxy_handler).to receive(:handle_request).with(*args).and_return('baz')
96
- expect(subject.handle_request(*args)).to eql 'baz'
97
- expect(subject.requests).to eql([{status: :complete, handler: :proxy, method: 'get', url: 'url', headers: 'headers', body: 'body'}])
98
- end
99
-
100
- it 'returns an error hash if request is not handled' do
101
- expect(stub_handler).to receive(:handle_request).with(*args)
102
- expect(cache_handler).to receive(:handle_request).with(*args)
103
- expect(proxy_handler).to receive(:handle_request).with(*args)
104
- expect(subject.handle_request(*args)).to eql(error: 'Connection to url not cached and new http connections are disabled')
105
- expect(subject.requests).to eql([{status: :complete, handler: :error, method: 'get', url: 'url', headers: 'headers', body: 'body'}])
106
- end
107
-
108
- it 'returns an error hash with body message if request cached based on body is not handled' do
109
- args[0] = Billy.config.cache_request_body_methods[0]
110
- expect(stub_handler).to receive(:handle_request).with(*args)
111
- expect(cache_handler).to receive(:handle_request).with(*args)
112
- expect(proxy_handler).to receive(:handle_request).with(*args)
113
- expect(subject.handle_request(*args)).to eql(error: "Connection to url with body 'body' not cached and new http connections are disabled")
114
- expect(subject.requests).to eql([{status: :complete, handler: :error, method: 'post', url: 'url', headers: 'headers', body: 'body'}])
115
- end
116
-
117
- it 'returns an error hash on unhandled exceptions' do
118
- # Allow handling requests initially
119
- allow(stub_handler).to receive(:handle_request)
120
- allow(cache_handler).to receive(:handle_request)
121
-
122
- allow(proxy_handler).to receive(:handle_request).and_raise("Any Proxy Error")
123
- expect(subject.handle_request(*args)).to eql(error: "Any Proxy Error")
124
-
125
- allow(cache_handler).to receive(:handle_request).and_raise("Any Cache Error")
126
- expect(subject.handle_request(*args)).to eql(error: "Any Cache Error")
127
-
128
- allow(stub_handler).to receive(:handle_request).and_raise("Any Stub Error")
129
- expect(subject.handle_request(*args)).to eql(error: "Any Stub Error")
130
- end
131
-
132
- context 'before_handle_request activated' do
133
- before do
134
- handle_request = proc { |method, url, headers, body|
135
- [method, url, headers, "#{body}_modified"]
136
- }
137
- allow(Billy::config).to receive(:before_handle_request).and_return(handle_request)
138
- end
139
-
140
- after do
141
- allow(Billy::config).to receive(:before_handle_request).and_call_original
142
- end
143
-
144
- it 'modify request before handling' do
145
- new_args = %w(get url headers body_modified)
146
- expect(stub_handler).to receive(:handle_request).with(*new_args)
147
- expect(cache_handler).to receive(:handle_request).with(*new_args).and_return('bar')
148
- expect(proxy_handler).to_not receive(:handle_request)
149
- expect(subject.handle_request(*args)).to eql 'bar'
150
- expect(subject.requests).to eql([{status: :complete, handler: :cache, method: 'get', url: 'url', headers: 'headers', body: 'body'}])
151
- end
152
- end
153
- end
154
-
155
- describe '#stubs' do
156
- it 'delegates to the stub_handler' do
157
- expect(stub_handler).to receive(:stubs)
158
- subject.stubs
159
- end
160
- end
161
-
162
- describe '#stub' do
163
- it 'delegates to the stub_handler' do
164
- expect(stub_handler).to receive(:stub).with('some args')
165
- subject.stub('some args')
166
- end
167
- end
168
-
169
- describe '#reset' do
170
- it 'resets all of the handlers' do
171
- handlers.each do |_key, handler|
172
- expect(handler).to receive(:reset)
173
- end
174
- expect(subject.request_log).to receive(:reset)
175
- subject.reset
176
- end
177
- end
178
-
179
- describe '#reset_stubs' do
180
- it 'resets the stub handler' do
181
- expect(stub_handler).to receive(:reset)
182
- subject.reset_stubs
183
- end
184
- end
185
-
186
- describe '#reset_cache' do
187
- it 'resets the cache handler' do
188
- expect(cache_handler).to receive(:reset)
189
- subject.reset_cache
190
- end
191
- end
192
-
193
- describe '#restore_cache' do
194
- it 'resets the cache handler' do
195
- expect(cache_handler).to receive(:reset)
196
- subject.reset_cache
197
- end
198
- end
199
- end
200
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Billy::RequestLog do
4
- let(:request_log) { Billy::RequestLog.new }
5
-
6
- describe '#record' do
7
- it 'returns the request details if record_requests is enabled' do
8
- allow(Billy::config).to receive(:record_requests).and_return(true)
9
- expected_request = {
10
- status: :inflight,
11
- handler: nil,
12
- method: :method,
13
- url: :url,
14
- headers: :headers,
15
- body: :body
16
- }
17
- expect(request_log.record(:method, :url, :headers, :body)).to eql(expected_request)
18
- end
19
-
20
- it 'returns nil if record_requests is disabled' do
21
- allow(Billy::config).to receive(:record_requests).and_return(false)
22
- expect(request_log.record(:method, :url, :headers, :body)).to be_nil
23
- end
24
- end
25
-
26
- describe '#complete' do
27
- it 'marks the request as complete if record_requests is enabled' do
28
- allow(Billy::config).to receive(:record_requests).and_return(true)
29
-
30
- request = request_log.record(:method, :url, :headers, :body)
31
- expected_request = {
32
- status: :complete,
33
- handler: :handler,
34
- method: :method,
35
- url: :url,
36
- headers: :headers,
37
- body: :body
38
- }
39
- expect(request_log.complete(request, :handler)).to eql(expected_request)
40
- end
41
-
42
- it 'marks the request as complete if record_requests is disabled' do
43
- allow(Billy::config).to receive(:record_requests).and_return(false)
44
- expect(request_log.complete(nil, :handler)).to be_nil
45
- end
46
- end
47
-
48
- describe '#requests' do
49
- it 'returns an empty array when there are no requests' do
50
- expect(request_log.requests).to be_empty
51
- end
52
-
53
- it 'returns the currently known requests' do
54
- allow(Billy::config).to receive(:record_requests).and_return(true)
55
-
56
- request1 = request_log.record(:method, :url, :headers, :body)
57
- request2 = request_log.record(:method, :url, :headers, :body)
58
- expect(request_log.requests).to eql([request1, request2])
59
- end
60
- end
61
-
62
- describe '#reset' do
63
- it 'resets known requests' do
64
- allow(Billy::config).to receive(:record_requests).and_return(true)
65
-
66
- request1 = request_log.record(:method, :url, :headers, :body)
67
- request2 = request_log.record(:method, :url, :headers, :body)
68
- expect(request_log.requests).to eql([request1, request2])
69
-
70
- request_log.reset
71
- expect(request_log.requests).to be_empty
72
- end
73
- end
74
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Billy::StubHandler do
4
- let(:handler) { Billy::StubHandler.new }
5
- let(:request) do
6
- {
7
- method: 'GET',
8
- url: 'http://example.test:8080/index?some=param',
9
- headers: { 'Accept-Encoding' => 'gzip',
10
- 'Cache-Control' => 'no-cache' },
11
- body: 'Some body'
12
- }
13
- end
14
-
15
- describe '#handles_request?' do
16
- it 'handles the request if it is stubbed' do
17
- expect(handler).to receive(:find_stub).and_return('a stub')
18
- expect(handler.handles_request?(nil, nil, nil, nil)).to be true
19
- end
20
-
21
- it 'does not handle the request if it is not stubbed' do
22
- expect(handler).to receive(:find_stub).and_return(nil)
23
- expect(handler.handles_request?(nil, nil, nil, nil)).to be false
24
- end
25
- end
26
-
27
- describe '#handle_request' do
28
- it 'returns nil if the request is not stubbed' do
29
- expect(handler).to receive(:handles_request?).and_return(false)
30
- expect(handler.handle_request(nil, nil, nil, nil)).to be nil
31
- end
32
-
33
- it 'returns a response hash if the request is stubbed' do
34
- stub = double('stub', call: [200, { 'Content-Type' => 'application/json' }, 'Some content'])
35
- expect(handler).to receive(:handles_request?).and_return(true)
36
- expect(handler).to receive(:find_stub).and_return(stub)
37
- expect(handler.handle_request('GET',
38
- request[:url],
39
- request[:headers],
40
- request[:body])).to eql(status: 200,
41
- headers: { 'Content-Type' => 'application/json' },
42
- content: 'Some content')
43
- end
44
- end
45
-
46
- describe '#reset' do
47
- it 'resets the stubs' do
48
- # Can't use request params when creating the stub.
49
- # See https://github.com/oesmith/puffing-billy/issues/21
50
- stub = handler.stub('http://example.test:8080/index')
51
-
52
- expect(handler.stubs).to eql([stub])
53
- expect(handler.handles_request?('GET',
54
- request[:url],
55
- request[:headers],
56
- request[:body])).to be true
57
- handler.reset
58
- expect(handler.stubs).to be_empty
59
- expect(handler.handles_request?('GET',
60
- request[:url],
61
- request[:headers],
62
- request[:body])).to be false
63
- end
64
- end
65
-
66
- describe '#unstub' do
67
- let!(:get_stub) { handler.stub('http://example.get/') }
68
- let!(:post_stub) { handler.stub('http://example.post/', method: :post) }
69
-
70
- it 'removes a single stub' do
71
- expect(handler.handles_request?('GET',
72
- 'http://example.get/',
73
- request[:headers],
74
- request[:body])).to be true
75
- expect(handler.handles_request?('POST',
76
- 'http://example.post/',
77
- request[:headers],
78
- request[:body])).to be true
79
-
80
- handler.unstub get_stub
81
-
82
- expect(handler.handles_request?('GET',
83
- 'http://example.get/',
84
- request[:headers],
85
- request[:body])).to be false
86
- expect(handler.handles_request?('POST',
87
- 'http://example.post/',
88
- request[:headers],
89
- request[:body])).to be true
90
- end
91
-
92
- it 'does not raise errors for not existing stub' do
93
- expect { handler.unstub 'http://example.option/' }.not_to raise_error
94
- end
95
- end
96
-
97
- it '#stubs requests' do
98
- handler.stub('http://example.test:8080/index')
99
- expect(handler.handles_request?('GET',
100
- request[:url],
101
- request[:headers],
102
- request[:body])).to be true
103
- end
104
-
105
- describe '#stubs' do
106
- it 'is empty by default' do
107
- expect(handler.stubs).to be_empty
108
- end
109
-
110
- it 'keeps track of created stubs' do
111
- stub1 = handler.stub('http://example.test:8080/index')
112
- stub2 = handler.stub('http://example.test:8080/index')
113
-
114
- expect(handler.stubs).to eql([stub2, stub1])
115
- end
116
- end
117
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Billy::ProxyConnection do
4
- context '#prepare_response_headers_for_evma_httpserver' do
5
- let(:subject) { Billy::ProxyConnection.new('') }
6
-
7
- it 'should remove duplicated headers fields' do
8
- provided_headers = {
9
- 'transfer-encoding' => '',
10
- 'content-length' => '',
11
- 'content-encoding' => '',
12
- 'key' => 'value'
13
- }
14
- expected_headers = { 'key' => 'value' }
15
- headers = subject.send(:prepare_response_headers_for_evma_httpserver, provided_headers)
16
-
17
- expect(headers).to eql expected_headers
18
- end
19
- end
20
- end