Ho uno scenario che funziona bene quando sto usando omniauth reale, ma fallisce quando lo eseguo con l'autenticazione fittizia in cetriolo/capibara.Reindirizzamento callback non preservando la sessione
Nella richiamata, quando eseguo sign_in @user
, viene creato correttamente l'utente e si registra in ... current_user
impostato. Ma quando poi faccio redirect_to request.env['omniauth.origin'] || '/'
, all'interno dell'azione che segue, current_user
è ora nullo.
Ho confermato tramite screenshot/mettendo in pausa il browser che non funziona con l'autenticazione fittizia. Lo stesso errore si verifica nei driver firefox e chrome.
Qualche idea sul motivo per cui ciò avverrebbe?
/features/support/env.rb:
Cucumber::Rails::Database.javascript_strategy = :truncation
Scenario:
@javascript
Scenario:
Given I am on the home page
When I press "Login"
And I should see "Login with Twitter" in the selector "#login-modal"
Given Omniauth returns a user with provider "twitter" and uid "1" and nickname "foo"
When I login with Twitter
Then I should be logged in as "foo"
Definizioni Passo:
Given(/^Omniauth returns a user with provider "(.*?)" and uid "(.*?)" and nickname "(.*?)"$/) do |provider, uid, nickname|
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(provider.to_sym, {
:uid => uid,
:info => {
:name => nickname
}
})
end
Then(/^I should be logged in as "(.*?)"$/) do |nickname|
expect(page).to have_content(nickname)
end
Auth callback:
def twitter
@user = User.from_omniauth(request.env["omniauth.auth"]) # this works-- I get the mock
sign_in @user
puts ">> in auth callback: just signed in user #{current_user.id}"
redirect_to request.env['omniauth.origin'] || '/'
end
Controller:
def new
puts ">> in my_controller#new: current_user = #{current_user.id if current_user}"
end
Cetriolo uscita:
Given Omniauth returns a user with provider "twitter" and uid "1" and nickname "foo"
>> in auth callback: just signed in user 1
>> in my_controller#new: current_user =
When I login with Twitter
Then I should be logged in as "foo"
expected to find text "foo" in [redacted] (RSpec::Expectations::ExpectationNotMetError)
Qualsiasi soluzione a questo problema? Hai trovato qualcosa? –
No, ancora bloccato. – joshwa
bene si prega di rivedere l'intestazione della richiesta per reale e per il mock, potrebbe essere si dovrebbe aggiungere qualcosa nel simulatore – ikirachen