shakacode / cypress-on-rails

Use cypress.io or playwright.dev with your rails application. This Ruby gem lets you use your regular Rails test setup and clean-up, such as FactoryBot.
MIT License
416 stars 61 forks source link

Authenticate CypressOnRails commands #137

Open RomainEndelin opened 1 year ago

RomainEndelin commented 1 year ago

Would it be possible to perform authentication on CypressOnRails Commands?

There is a workaround: by injecting another middleware before cypress_on_rails, checking for the /__e2e__/command route and performing authentication.

But it would be great if we could configure it directly in Cypress On Rails 🙏 . One idea would be to accept a before_request block:

CypressOnRails.configure do |c|
  # ...

  c.before_request = lambda { |request|
    if !request.env['warden'].authenticate(:secret_key)
      [403, {}, ["forbidden"]]
    end

    return request.env
  }
end

This block would be executed as part of the CypressOnRails middleware.

If you like the idea, I'm happy to open a PR 🙂

grantspeelman commented 1 year ago

I do like the idea, also like that it does not tie the code to anyone authentication solution. We could also add to the generated code examples that cover the most basics things but it's commented out.

A PR will be most Welcomed 👍🏽

cschambacher commented 1 year ago

Hi @grantspeelman , I am working with @RomainEndelin and taking over from where he left.

We're glad the PR was merged, thank you so much 😄 We are wondering if a release is planned? We'd need a stable version with it so we can move forward with some of our work. Also I can help in releasing the gem if needed.

grantspeelman commented 1 year ago

released 👍🏽

cschambacher commented 1 year ago

@grantspeelman thank you for your quick reply and for the release! We are now using the new release successfully