cypress-on-rails 1.15.1 → 1.16.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 +6 -0
- data/README.md +46 -0
- data/lib/cypress_on_rails/configuration.rb +2 -0
- data/lib/cypress_on_rails/middleware.rb +4 -0
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +9 -0
- data/spec/cypress_on_rails/configuration_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dc7073afd439183f15dbe8e33fd275ec4ec4121c2640e026ed5d7f80bc2736c
|
4
|
+
data.tar.gz: 2361d555bab1bae7072d8909275669a139b9c2ee255f5f8195660189208591fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717a48f1352f07b052683ba0699d2806191aed7ebc249e6c0f319af8f2e47d3eb0062787fa6d847ce326afe66325c59859806c9f93f3f95a8276e6aec85d580f
|
7
|
+
data.tar.gz: abee0f60bec8a8eca395b6a621c33c0caa731452f5e253d27b80c967cd7138a992cb29c68fa41bafcddc85a3f02e6767f6a3f5bcf77ffbaad543264c31d5630a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [1.16.0]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.15.1...v1.16.0
|
3
|
+
|
4
|
+
### Added
|
5
|
+
* Add support for `before_request` options on the middleware, for authentication [PR 138](https://github.com/shakacode/cypress-on-rails/pull/138) by [RomainEndelin]
|
6
|
+
|
1
7
|
## [1.15.1]
|
2
8
|
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.15.0...v1.15.1
|
3
9
|
|
data/README.md
CHANGED
@@ -395,6 +395,47 @@ describe('My First Test', () => {
|
|
395
395
|
})
|
396
396
|
```
|
397
397
|
|
398
|
+
## `before_request` configuration
|
399
|
+
|
400
|
+
You may perform any custom action before running a CypressOnRails command, such as authentication, or sending metrics. Please set `before_request` as part of the CypressOnRails configuration.
|
401
|
+
|
402
|
+
You should get familiar with [Rack middlewares](https://www.rubyguides.com/2018/09/rack-middleware/).
|
403
|
+
If your function returns a `[status, header, body]` response, CypressOnRails will halt, and your command will not be executed. To execute the command, `before_request` should return `nil`.
|
404
|
+
|
405
|
+
### Authenticate CypressOnRails
|
406
|
+
|
407
|
+
```ruby
|
408
|
+
CypressOnRails.configure do |c|
|
409
|
+
# ...
|
410
|
+
|
411
|
+
# Refer to https://www.rubydoc.info/gems/rack/Rack/Request for the `request` argument.
|
412
|
+
c.before_request = lambda { |request|
|
413
|
+
body = JSON.parse(request.body.string)
|
414
|
+
if body['cypress_token'] != ENV.fetch('SWEEP_CYPRESS_SECRET_TOKEN')
|
415
|
+
# You may also use warden for authentication:
|
416
|
+
# if !request.env['warden'].authenticate(:secret_key)
|
417
|
+
return [401, {}, ['unauthorized']]
|
418
|
+
end
|
419
|
+
|
420
|
+
}
|
421
|
+
end
|
422
|
+
```
|
423
|
+
|
424
|
+
### Send usage metrics
|
425
|
+
|
426
|
+
```ruby
|
427
|
+
CypressOnRails.configure do |c|
|
428
|
+
# ...
|
429
|
+
|
430
|
+
# Refer to https://www.rubydoc.info/gems/rack/Rack/Request for the `request` argument.
|
431
|
+
c.before_request = lambda { |request|
|
432
|
+
statsd = Datadog::Statsd.new('localhost', 8125)
|
433
|
+
|
434
|
+
statsd.increment('cypress_on_rails.requests')
|
435
|
+
}
|
436
|
+
end
|
437
|
+
```
|
438
|
+
|
398
439
|
## Usage with other rack applications
|
399
440
|
|
400
441
|
Add CypressOnRails to your config.ru
|
@@ -477,6 +518,11 @@ In `config/initializers/cypress_on_rails.rb`, add this line:
|
|
477
518
|
<img alt="ScoutAPM" src="https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png" height="120px">
|
478
519
|
</picture>
|
479
520
|
</a>
|
521
|
+
<a href="https://controlplane.com">
|
522
|
+
<picture>
|
523
|
+
<img alt="Control Plane" src="https://github.com/shakacode/.github/assets/20628911/90babd87-62c4-4de3-baa4-3d78ef4bec25" height="120px">
|
524
|
+
</picture>
|
525
|
+
</a>
|
480
526
|
<br />
|
481
527
|
<a href="https://www.browserstack.com">
|
482
528
|
<picture>
|
@@ -6,6 +6,7 @@ module CypressOnRails
|
|
6
6
|
attr_accessor :install_folder
|
7
7
|
attr_accessor :use_middleware
|
8
8
|
attr_accessor :use_vcr_middleware
|
9
|
+
attr_accessor :before_request
|
9
10
|
attr_accessor :logger
|
10
11
|
|
11
12
|
# Attributes for backwards compatibility
|
@@ -30,6 +31,7 @@ module CypressOnRails
|
|
30
31
|
self.install_folder = 'spec/e2e'
|
31
32
|
self.use_middleware = true
|
32
33
|
self.use_vcr_middleware = false
|
34
|
+
self.before_request = -> (request) {}
|
33
35
|
self.logger = Logger.new(STDOUT)
|
34
36
|
end
|
35
37
|
|
@@ -47,6 +47,10 @@ module CypressOnRails
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def handle_command(req)
|
50
|
+
maybe_env = configuration.before_request.call(req)
|
51
|
+
# Halt the middleware if an Rack Env was returned by `before_request`
|
52
|
+
return maybe_env unless maybe_env.nil?
|
53
|
+
|
50
54
|
body = JSON.parse(req.body.read)
|
51
55
|
logger.info "handle_command: #{body}"
|
52
56
|
commands = Command.from_body(body, configuration)
|
@@ -7,6 +7,15 @@ if defined?(CypressOnRails)
|
|
7
7
|
c.use_middleware = !Rails.env.production?
|
8
8
|
<% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production?
|
9
9
|
c.logger = Rails.logger
|
10
|
+
|
11
|
+
# If you want to enable a before_request logic, such as authentication, logging, sending metrics, etc.
|
12
|
+
# Refer to https://www.rubydoc.info/gems/rack/Rack/Request for the `request` argument.
|
13
|
+
# Return nil to continue through the Cypress command. Return a response [status, header, body] to halt.
|
14
|
+
# c.before_request = lambda { |request|
|
15
|
+
# unless request.env['warden'].authenticate(:secret_key)
|
16
|
+
# return [403, {}, ["forbidden"]]
|
17
|
+
# end
|
18
|
+
# }
|
10
19
|
end
|
11
20
|
|
12
21
|
# # if you compile your asssets on CI
|
@@ -8,19 +8,23 @@ RSpec.describe CypressOnRails::Configuration do
|
|
8
8
|
expect(CypressOnRails.configuration.install_folder).to eq('spec/e2e')
|
9
9
|
expect(CypressOnRails.configuration.use_middleware?).to eq(true)
|
10
10
|
expect(CypressOnRails.configuration.logger).to_not be_nil
|
11
|
+
expect(CypressOnRails.configuration.before_request).to_not be_nil
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'can be configured' do
|
14
15
|
my_logger = Logger.new(STDOUT)
|
16
|
+
before_request_lambda = -> (_) { return [200, {}, ['hello world']] }
|
15
17
|
CypressOnRails.configure do |config|
|
16
18
|
config.api_prefix = '/api'
|
17
19
|
config.install_folder = 'my/path'
|
18
20
|
config.use_middleware = false
|
19
21
|
config.logger = my_logger
|
22
|
+
config.before_request = before_request_lambda
|
20
23
|
end
|
21
24
|
expect(CypressOnRails.configuration.api_prefix).to eq('/api')
|
22
25
|
expect(CypressOnRails.configuration.install_folder).to eq('my/path')
|
23
26
|
expect(CypressOnRails.configuration.use_middleware?).to eq(false)
|
24
27
|
expect(CypressOnRails.configuration.logger).to eq(my_logger)
|
28
|
+
expect(CypressOnRails.configuration.before_request).to eq(before_request_lambda)
|
25
29
|
end
|
26
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cypress-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- miceportal team
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|