Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara::InfiniteRedirectError

Using OmniAuth (with omniauth_crowd), I'd like user to be redirected back to the login page if he doesn't submit right username and password. It works fine in production, but I have annoying problem testing it.

To mock OmniAuth provider, I use the following code, as recommended by the author of OmniAuth plugin:

OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:someProvider] = :invalid_credentials
visit_page @page

The code above automatically (i.e. without entering username and password) redirects Capybara to the session#failure. My session#failure redirects to the login_path.

Thus I end up in a loop:

redirected more than 5 times, check for infinite redirects. (Capybara::InfiniteRedirectError)

What is the best workaround for my case?

like image 304
Alex Smolov Avatar asked Nov 12 '22 08:11

Alex Smolov


1 Answers

I had a simular issue with Omniauth.
Not sure if there is a workaround, since it is the way OmniAuth.config.mock_auth works.

My solution was to use fakeweb instead of the OmniAuth mocking.
You should probably start off by looking at how omniauth_crowd is tested itself.
Here is a good example: https://github.com/robdimarco/omniauth_crowd/blob/master/spec/omniauth/strategies/crowd_spec.rb#L49-69

like image 110
Ivan Zamylin Avatar answered Nov 15 '22 05:11

Ivan Zamylin