puffing-billy 3.0.4 → 3.2.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 +8 -0
- data/README.md +82 -80
- data/lib/billy/browsers/capybara.rb +1 -1
- data/lib/billy/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac5d11bd30cfb97b7ee07fda89923ca24562a34c653e73c1a2c3d3fd1b22f715
|
4
|
+
data.tar.gz: bd7a279f65a2e3212db1f2bd0ad381753c7e82e0541d6c44b64dba27f3313456
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 899438bd13470f7c3363f10dc59b936805c253ef98d565b1149ddac1f5a618e6ce2966a41ccdae9390365ab01818812d7cc8b26a084e3f23498021124c30c67a
|
7
|
+
data.tar.gz: 8b6eae64b2637304a66dfd7375a37b4ac229e1eb53640cf3607bcdb063d59484f0fdf51e837cccbd54aa6c9afe41a3026e5f6d08edbe46ca9919d27aefed2eaf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
v3.2.0, 2023-08-27
|
2
|
+
------------------
|
3
|
+
* Replace deprecated headless! Selenium::WebDriver::Chrome::Options [#333](https://github.com/oesmith/puffing-billy/pull/333)
|
4
|
+
|
5
|
+
v3.1.0, 2023-03-10
|
6
|
+
------------------
|
7
|
+
* Add support for Ruby 3.2 [#330](https://github.com/oesmith/puffing-billy/pull/330)
|
8
|
+
|
1
9
|
v3.0.4, 2022-08-07
|
2
10
|
------------------
|
3
11
|
* Adds a configurable Cuprite driver [#327](https://github.com/oesmith/puffing-billy/pull/327)
|
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:
|
@@ -84,7 +84,7 @@ module Billy
|
|
84
84
|
|
85
85
|
::Capybara.register_driver :selenium_chrome_headless_billy do |app|
|
86
86
|
options = Selenium::WebDriver::Chrome::Options.new
|
87
|
-
options.headless
|
87
|
+
options.add_argument('--headless=new')
|
88
88
|
options.add_argument('--enable-features=NetworkService,NetworkServiceInProcess')
|
89
89
|
options.add_argument('--ignore-certificate-errors')
|
90
90
|
options.add_argument("--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}")
|
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: 3.0
|
4
|
+
version: 3.2.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:
|
11
|
+
date: 2023-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: thin
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.8.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.8.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|