You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,6 @@
1
+
### Added
2
+
* Add support for `before_request` options on the middleware, for authentication [PR 138](https://github.com/shakacode/cypress-on-rails/pull/138) by [RomainEndelin]
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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.
0 commit comments