omniauth.origin nil when test_mode=true

For some reason I had request['omniauth.origin'] == nil in my system test but not in development.

After banging my head, I noticed

   def mock_request_call
      setup_phase

      session['omniauth.params'] = request.GET

      OmniAuth.config.request_validation_phase.call(env) if OmniAuth.config.request_validation_phase
      OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase

      if options.origin_param
        if request.params[options.origin_param]
          session['omniauth.origin'] = request.params[options.origin_param]
        elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
          session['omniauth.origin'] = env['HTTP_REFERER']
        end
      end

      redirect(callback_url)
    end

session.keys returns` 'omniauth.origin', 'omniauth.params',..`

Then when we get to

    def mock_callback_call
      setup_phase
      @env['omniauth.origin'] = session.delete('omniauth.origin')
      @env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
      @env['omniauth.params'] = session.delete('omniauth.params') || {}

      mocked_auth = OmniAuth.mock_auth_for(name.to_s)
      if mocked_auth.is_a?(Symbol)
        fail!(mocked_auth)
      else
        @env['omniauth.auth'] = mocked_auth
        OmniAuth.config.before_callback_phase.call(@env) if OmniAuth.config.before_callback_phase
        call_app!
      end
    end

session.keys returns []

It was because I broke the session store in test env in initializers/session_store.rb :

if Rails.env.production?
  Rails.application.config.session_store :cookie_store, key: '_app_session', domain: 'app.fr', tld_length: 2
else
  Rails.application.config.session_store :cookie_store, key: '_app_session', domain: 'app.dev', tld_length: 2
end

I did this to handle cross subdomain session so authenticated user (oauth) from en.app.dev would still be connected when going to app.dev for ex.

I've corrected it for test :

if Rails.env.production?
  Rails.application.config.session_store :cookie_store, key: '_app_session', domain: 'app.fr', tld_length: 2
elsif 
  Rails.application.config.session_store :cookie_store, key: '_app_session', domain: 'app.dev', tld_length: 2
else
  Rails.application.config.session_store :cookie_store, key: '_app_session', tld_length: 2  
end