puffing-billy 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +82 -80
- data/lib/billy/browsers/capybara.rb +6 -13
- data/lib/billy/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f585918e52d40164c2b82384f2a10b9a88739bd0eaa35585a45c568749e2717
|
4
|
+
data.tar.gz: 217c17068c87dcbd0df9f135b4e87d0ccb3f311cd9019a9ef57ac4f181b365ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c252400a3d72b72680ee861c30322d96b62baa3bcf5f961a832671979acd066cb48a8ba3f108aee07b93167e602b28042ddac9bc2183f870b5c75f910650abf8
|
7
|
+
data.tar.gz: fe72b4f1c43d9ffba16fcf84cd0998954d60531f5c4a7528818a69c42a7ab6a8cab9e9430807ddb07811937479ab45bf436d83c5028a1c19dba5734d7fcf4de6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
v4.0.0, 2023-08-30
|
2
|
+
------------------
|
3
|
+
* Drop Ruby 2.6 support [#337](https://github.com/oesmith/puffing-billy/pull/337)
|
4
|
+
* Fix removed Selenium::WebDriver::Remote::Capabilities.firefox method [#336](https://github.com/oesmith/puffing-billy/pull/336)
|
5
|
+
* Use :options argument instead of :capabilities [#338](https://github.com/oesmith/puffing-billy/pull/338)
|
6
|
+
|
7
|
+
v3.2.0, 2023-08-27
|
8
|
+
------------------
|
9
|
+
* Replace deprecated headless! Selenium::WebDriver::Chrome::Options [#333](https://github.com/oesmith/puffing-billy/pull/333)
|
10
|
+
|
1
11
|
v3.1.0, 2023-03-10
|
2
12
|
------------------
|
3
13
|
* Add support for Ruby 3.2 [#330](https://github.com/oesmith/puffing-billy/pull/330)
|
data/README.md
CHANGED
@@ -289,6 +289,11 @@ you can turn on cache persistence. This way you don't have to manually mock out
|
|
289
289
|
everything as requests are automatically recorded and played back. With cache
|
290
290
|
persistence you can take tests completely offline.
|
291
291
|
|
292
|
+
The cache works with all types of requests and will distinguish between
|
293
|
+
different POST requests to the same URL.
|
294
|
+
|
295
|
+
### Params
|
296
|
+
|
292
297
|
```ruby
|
293
298
|
Billy.configure do |c|
|
294
299
|
c.cache = true
|
@@ -319,89 +324,123 @@ Billy.configure do |c|
|
|
319
324
|
end
|
320
325
|
```
|
321
326
|
|
322
|
-
|
323
|
-
different POST requests to the same URL.
|
324
|
-
|
325
|
-
`c.cache_request_headers` is used to store the outgoing request headers in the cache.
|
327
|
+
- `c.cache_request_headers` is used to store the outgoing request headers in the cache.
|
326
328
|
It is also saved to yml if `persist_cache` is enabled. This additional information
|
327
329
|
is useful for debugging (for example: viewing the referer of the request).
|
328
330
|
|
329
|
-
`c.ignore_params` is used to ignore parameters of certain requests when
|
331
|
+
- `c.ignore_params` is used to ignore parameters of certain requests when
|
330
332
|
caching. You should mostly use this for analytics and various social buttons as
|
331
333
|
they use cache avoidance techniques, but return practically the same response
|
332
334
|
that most often does not affect your test results.
|
333
335
|
|
334
|
-
`c.
|
335
|
-
has a large number of analytics and social buttons. `c.allow_params` is the opposite of `c.ignore_params`,
|
336
|
-
a whitelist to a blacklist. In order to toggle between using one or the other, use `c.use_ignore_params`.
|
337
|
-
|
338
|
-
`c.strip_query_params` is used to strip query parameters when you stub some requests
|
339
|
-
with query parameters. Default value is true. For example, `proxy.stub('http://myapi.com/user/?country=FOO')`
|
340
|
-
is considered the same as: `proxy.stub('http://myapi.com/user/?anything=FOO')` and
|
341
|
-
generally the same as: `proxy.stub('http://myapi.com/user/')`. When you need to distinguish between all these requests,
|
342
|
-
you may set this config value to false.
|
343
|
-
|
344
|
-
`c.dynamic_jsonp` is used to rewrite the body of JSONP responses based on the
|
345
|
-
callback parameter. For example, if a request to `http://example.com/foo?callback=bar`
|
346
|
-
returns `bar({"some": "json"});` and is recorded, then a later request to
|
347
|
-
`http://example.com/foo?callback=baz` will be a cache hit and respond with
|
348
|
-
`baz({"some": "json"});` This is useful because most JSONP implementations
|
349
|
-
base the callback name off of a timestamp or something else dynamic.
|
350
|
-
|
351
|
-
`c.dynamic_jsonp_keys` is used to configure which parameters to ignore when
|
352
|
-
using `c.dynamic_jsonp`. This is helpful when JSONP APIs use cache-busting
|
353
|
-
parameters. For example, if you want `http://example.com/foo?callback=bar&id=1&cache_bust=12345` and `http://example.com/foo?callback=baz&id=1&cache_bust=98765` to be cache hits for each other, you would set `c.dynamic_jsonp_keys = ['callback', 'cache_bust']` to ignore both params. Note
|
354
|
-
that in this example the `id` param would still be considered important.
|
355
|
-
|
356
|
-
`c.dynamic_jsonp_callback_name` is used to configure the name of the JSONP callback
|
357
|
-
parameter. The default is `callback`.
|
358
|
-
|
359
|
-
`c.path_blacklist = []` is used to always cache specific paths on any hostnames,
|
336
|
+
- `c.path_blacklist = []` is used to always cache specific paths on any hostnames,
|
360
337
|
including whitelisted ones. This is useful if your AUT has routes that get data
|
361
338
|
from external services, such as `/api` where the ajax request is a local URL but
|
362
339
|
the actual data is coming from a different application that you want to cache.
|
363
340
|
|
364
|
-
`c.merge_cached_responses_whitelist = []` is used to group together the cached
|
341
|
+
- `c.merge_cached_responses_whitelist = []` is used to group together the cached
|
365
342
|
responses for specific uri regexes that match any part of the url. This is useful
|
366
343
|
for ensuring that any kind of analytics and various social buttons that have
|
367
344
|
slightly different urls each time can be recorded once and reused nicely. Note
|
368
345
|
that the request body is ignored for requests that contain a body.
|
369
346
|
|
370
|
-
`c.ignore_cache_port` is used to strip the port from the URL if it exists. This
|
347
|
+
- `c.ignore_cache_port` is used to strip the port from the URL if it exists. This
|
371
348
|
is useful when caching local paths (via `path_blacklist`) or other local rack apps
|
372
349
|
that are running on random ports.
|
373
350
|
|
374
|
-
`c.non_successful_cache_disabled` is used to not cache responses without 200-series
|
351
|
+
- `c.non_successful_cache_disabled` is used to not cache responses without 200-series
|
375
352
|
or 304 status codes. This prevents unauthorized or internal server errors from
|
376
353
|
being cached and used for future test runs.
|
377
354
|
|
378
|
-
`c.non_successful_error_level` is used to log when non-successful responses are
|
355
|
+
- `c.non_successful_error_level` is used to log when non-successful responses are
|
379
356
|
received. By default, it just writes to the log file, but when set to `:error`
|
380
357
|
it throws an error with the URL and status code received for easier debugging.
|
381
358
|
|
382
|
-
`c.non_whitelisted_requests_disabled` is used to disable hitting new URLs when
|
359
|
+
- `c.non_whitelisted_requests_disabled` is used to disable hitting new URLs when
|
383
360
|
no cache file exists. Only whitelisted URLs (on non-blacklisted paths) are
|
384
361
|
allowed, all others will throw an error with the URL attempted to be accessed.
|
385
362
|
This is useful for debugging issues in isolated environments (ie.
|
386
363
|
continuous integration).
|
387
364
|
|
388
|
-
`c.cache_path` can be used to locate the cache directory to a different place
|
365
|
+
- `c.cache_path` can be used to locate the cache directory to a different place
|
389
366
|
other than `system temp directory/puffing-billy`.
|
390
367
|
|
391
|
-
`c.certs_path` can be used to locate the directory for dynamically generated
|
368
|
+
- `c.certs_path` can be used to locate the directory for dynamically generated
|
392
369
|
SSL certificates to a different place other than `system temp
|
393
370
|
directory/puffing-billy/certs`.
|
394
371
|
|
395
|
-
`c.proxy_host` and `c.proxy_port` are used for the Billy proxy itself which runs locally.
|
372
|
+
- `c.proxy_host` and `c.proxy_port` are used for the Billy proxy itself which runs locally.
|
396
373
|
|
397
|
-
`c.proxied_request_host` and `c.proxied_request_port` are used if an internal proxy
|
374
|
+
- `c.proxied_request_host` and `c.proxied_request_port` are used if an internal proxy
|
398
375
|
server is required to access the internet. Most common in larger companies.
|
399
376
|
|
400
|
-
`c.
|
377
|
+
- `c.allow_params` is used to allow parameters of certain requests when caching. This is best used when a site
|
378
|
+
has a large number of analytics and social buttons. `c.allow_params` is the opposite of `c.ignore_params`,
|
379
|
+
a whitelist to a blacklist. In order to toggle between using one or the other, use `c.use_ignore_params`.
|
380
|
+
|
381
|
+
- `c.strip_query_params` is used to strip query parameters when you stub some requests
|
382
|
+
with query parameters. Default value is true. For example, `proxy.stub('http://myapi.com/user/?country=FOO')`
|
383
|
+
is considered the same as: `proxy.stub('http://myapi.com/user/?anything=FOO')` and
|
384
|
+
generally the same as: `proxy.stub('http://myapi.com/user/')`. When you need to distinguish between all these requests,
|
385
|
+
you may set this config value to false.
|
386
|
+
|
387
|
+
- `c.dynamic_jsonp` is used to rewrite the body of JSONP responses based on the
|
388
|
+
callback parameter. For example, if a request to `http://example.com/foo?callback=bar`
|
389
|
+
returns `bar({"some": "json"});` and is recorded, then a later request to
|
390
|
+
`http://example.com/foo?callback=baz` will be a cache hit and respond with
|
391
|
+
`baz({"some": "json"});` This is useful because most JSONP implementations
|
392
|
+
base the callback name off of a timestamp or something else dynamic.
|
393
|
+
|
394
|
+
- `c.dynamic_jsonp_keys` is used to configure which parameters to ignore when
|
395
|
+
using `c.dynamic_jsonp`. This is helpful when JSONP APIs use cache-busting
|
396
|
+
parameters. For example, if you want `http://example.com/foo?callback=bar&id=1&cache_bust=12345` and `http://example.com/foo?callback=baz&id=1&cache_bust=98765` to be cache hits for each other, you would set `c.dynamic_jsonp_keys = ['callback', 'cache_bust']` to ignore both params. Note
|
397
|
+
that in this example the `id` param would still be considered important.
|
398
|
+
|
399
|
+
- `c.dynamic_jsonp_callback_name` is used to configure the name of the JSONP callback
|
400
|
+
parameter. The default is `callback`.
|
401
|
+
|
402
|
+
- `c.record_requests` can be used to record all requests that puffing billy proxied.
|
401
403
|
This can be useful for debugging purposes, for instance if you are unsure why
|
402
404
|
your stubbed requests are not being successfully proxied.
|
403
405
|
|
404
|
-
|
406
|
+
- `c.cache_request_body_methods` is used to specify HTTP methods of requests that you would like to cache separately based on the contents of the request body. The default is ['post'].
|
407
|
+
|
408
|
+
- `c.use_ignore_params` is used to choose whether to use the ignore_params blacklist or the allow_params whitelist. Set to `true` to use `c.ignore_params`,
|
409
|
+
`false` to use `c.allow_params`
|
410
|
+
|
411
|
+
- `c.before_handle_request` is used to modify `method`, `url`, `headers`, `body` before handle request by `stubs`, `cache` or `proxy`. Method accept 4 argumens and must return array of this arguments:
|
412
|
+
|
413
|
+
```ruby
|
414
|
+
c.before_handle_request = proc { |method, url, headers, body|
|
415
|
+
filtered_body = JSON.dump(filter_secret_data(JSON.load(body)))
|
416
|
+
[method, url, headers, filtered_body]
|
417
|
+
}
|
418
|
+
```
|
419
|
+
|
420
|
+
- `c.cache_simulates_network_delays` is used to add some delay before cache returns response. When set to `true`, cached requests will wait from configured delay time before responding. This allows to catch various race conditions in asynchronous front-end requests. The default is `false`.
|
421
|
+
|
422
|
+
- `c.cache_simulates_network_delay_time` is used to configure time (in seconds) to wait until responding from cache. The default is `0.1`.
|
423
|
+
|
424
|
+
- `c.after_cache_handles_request` is used to configure a callback that can operate on the response after it has been retrieved from the cache but before it is returned. The callback receives the request and response as arguments, with a request object like: `{ method: method, url: url, headers: headers, body: body }`. An example usage would be manipulating the Access-Control-Allow-Origin header so that your test server doesn't always have to run on the same port in order to accept cached responses to CORS requests:
|
425
|
+
|
426
|
+
```ruby
|
427
|
+
Billy.configure do |c|
|
428
|
+
...
|
429
|
+
fix_cors_header = proc do |_request, response|
|
430
|
+
allowed_origins = response[:headers]['Access-Control-Allow-Origin']
|
431
|
+
if allowed_origins.present?
|
432
|
+
localhost_port_pattern = %r{(?<=http://127\.0\.0\.1:)(\d+)}
|
433
|
+
allowed_origins.sub!(
|
434
|
+
localhost_port_pattern, Capybara.current_session.server.port.to_s
|
435
|
+
)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
c.after_cache_handles_request = fix_cors_header
|
439
|
+
...
|
440
|
+
end
|
441
|
+
```
|
442
|
+
|
443
|
+
### Example usage:
|
405
444
|
|
406
445
|
```ruby
|
407
446
|
require 'table_print' # Add this dependency to your gemfile
|
@@ -455,43 +494,6 @@ The handler column indicates how Puffing Billy handled your request:
|
|
455
494
|
If your `status` is set to `inflight` this request has not yet been handled fully. Either puffing billy crashed
|
456
495
|
internally on this request, or your test ended before it could complete successfully.
|
457
496
|
|
458
|
-
`c.cache_request_body_methods` is used to specify HTTP methods of requests that you would like to cache separately based on the contents of the request body. The default is ['post'].
|
459
|
-
|
460
|
-
`c.after_cache_handles_request` is used to configure a callback that can operate on the response after it has been retrieved from the cache but before it is returned. The callback receives the request and response as arguments, with a request object like: `{ method: method, url: url, headers: headers, body: body }`. An example usage would be manipulating the Access-Control-Allow-Origin header so that your test server doesn't always have to run on the same port in order to accept cached responses to CORS requests:
|
461
|
-
|
462
|
-
```
|
463
|
-
Billy.configure do |c|
|
464
|
-
...
|
465
|
-
fix_cors_header = proc do |_request, response|
|
466
|
-
allowed_origins = response[:headers]['Access-Control-Allow-Origin']
|
467
|
-
if allowed_origins.present?
|
468
|
-
localhost_port_pattern = %r{(?<=http://127\.0\.0\.1:)(\d+)}
|
469
|
-
allowed_origins.sub!(
|
470
|
-
localhost_port_pattern, Capybara.current_session.server.port.to_s
|
471
|
-
)
|
472
|
-
end
|
473
|
-
end
|
474
|
-
c.after_cache_handles_request = fix_cors_header
|
475
|
-
...
|
476
|
-
end
|
477
|
-
```
|
478
|
-
|
479
|
-
`c.use_ignore_params` is used to choose whether to use the ignore_params blacklist or the allow_params whitelist. Set to `true` to use `c.ignore_params`,
|
480
|
-
`false` to use `c.allow_params`
|
481
|
-
|
482
|
-
`c.before_handle_request` is used to modify `method`, `url`, `headers`, `body` before handle request by `stubs`, `cache` or `proxy`. Method accept 4 argumens and must return array of this arguments:
|
483
|
-
|
484
|
-
```
|
485
|
-
c.before_handle_request = proc { |method, url, headers, body|
|
486
|
-
filtered_body = JSON.dump(filter_secret_data(JSON.load(body)))
|
487
|
-
[method, url, headers, filtered_body]
|
488
|
-
}
|
489
|
-
```
|
490
|
-
|
491
|
-
`c.cache_simulates_network_delays` is used to add some delay before cache returns response. When set to `true`, cached requests will wait from configured delay time before responding. This allows to catch various race conditions in asynchronous front-end requests. The default is `false`.
|
492
|
-
|
493
|
-
`c.cache_simulates_network_delay_time` is used to configure time (in seconds) to wait until responding from cache. The default is `0.1`.
|
494
|
-
|
495
497
|
### Cache Scopes
|
496
498
|
|
497
499
|
If you need to cache different responses to the same HTTP request, you can use
|
@@ -618,7 +620,7 @@ end
|
|
618
620
|
|
619
621
|
## Proxy timeouts
|
620
622
|
|
621
|
-
By default, the Puffing Billy proxy will use the EventMachine
|
623
|
+
By default, the Puffing Billy proxy will use the `EventMachine::HttpRequest` timeouts of 5 seconds
|
622
624
|
for connect and 10 seconds for inactivity when talking to downstream servers.
|
623
625
|
|
624
626
|
These can be configured as follows:
|
@@ -48,24 +48,17 @@ module Billy
|
|
48
48
|
|
49
49
|
def self.register_selenium_driver
|
50
50
|
::Capybara.register_driver :selenium_billy do |app|
|
51
|
-
|
52
|
-
build_selenium_options_for_firefox,
|
53
|
-
Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
54
|
-
]
|
51
|
+
options = build_selenium_options_for_firefox
|
55
52
|
|
56
|
-
::Capybara::Selenium::Driver.new(app,
|
53
|
+
::Capybara::Selenium::Driver.new(app, options: options)
|
57
54
|
end
|
58
55
|
|
59
56
|
::Capybara.register_driver :selenium_headless_billy do |app|
|
60
57
|
options = build_selenium_options_for_firefox.tap do |opts|
|
61
58
|
opts.add_argument '-headless'
|
62
59
|
end
|
63
|
-
capabilities = [
|
64
|
-
options,
|
65
|
-
Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
66
|
-
]
|
67
60
|
|
68
|
-
::Capybara::Selenium::Driver.new(app,
|
61
|
+
::Capybara::Selenium::Driver.new(app, options: options)
|
69
62
|
end
|
70
63
|
|
71
64
|
::Capybara.register_driver :selenium_chrome_billy do |app|
|
@@ -76,7 +69,7 @@ module Billy
|
|
76
69
|
::Capybara::Selenium::Driver.new(
|
77
70
|
app,
|
78
71
|
browser: :chrome,
|
79
|
-
|
72
|
+
options: options,
|
80
73
|
clear_local_storage: true,
|
81
74
|
clear_session_storage: true
|
82
75
|
)
|
@@ -84,7 +77,7 @@ module Billy
|
|
84
77
|
|
85
78
|
::Capybara.register_driver :selenium_chrome_headless_billy do |app|
|
86
79
|
options = Selenium::WebDriver::Chrome::Options.new
|
87
|
-
options.headless
|
80
|
+
options.add_argument('--headless=new')
|
88
81
|
options.add_argument('--enable-features=NetworkService,NetworkServiceInProcess')
|
89
82
|
options.add_argument('--ignore-certificate-errors')
|
90
83
|
options.add_argument("--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}")
|
@@ -94,7 +87,7 @@ module Billy
|
|
94
87
|
::Capybara::Selenium::Driver.new(
|
95
88
|
app,
|
96
89
|
browser: :chrome,
|
97
|
-
|
90
|
+
options: options,
|
98
91
|
clear_local_storage: true,
|
99
92
|
clear_session_storage: true
|
100
93
|
)
|
data/lib/billy/version.rb
CHANGED
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:
|
4
|
+
version: 4.0.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: 2023-
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -379,7 +379,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
379
379
|
requirements:
|
380
380
|
- - ">="
|
381
381
|
- !ruby/object:Gem::Version
|
382
|
-
version: 2.
|
382
|
+
version: 2.7.0
|
383
383
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
384
384
|
requirements:
|
385
385
|
- - ">="
|