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
{{ message }}
Repository navigation
mocking request.env['omniauth.origin'] when request. #934
Hi I would like to rspec testing with request.env['omniauth.origin']. I successfully mocked OmniAuth.config.mock_auth[:google_oauth2]. but I can't set the request.env['omniauth.origin'] value. The callback controller doesn't know it. How can i do it?
Configuration
Provider Gem: omniauth-google-oauth
Ruby Version: 2.4.2
Framework: rails
RSpec
it 'should redirect to another page' do
valid_google_oauth2_login_setup
get '/auth/google_oauth2/callback'
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:google_oauth2]
request.env['omniauth.origin'] = 'http://www.xxxx.com'
end
There's literally zero documentation on this, but this worked for me:
OmniAuth.config.before_callback_phase do |env|
env['omniauth.origin'] = 'https://example.com/'
end
Reacted by Phenixer, julien pierlot, Yaro Shm and mnort9
@jeremyk3 I had the same problem, the work around I came up with was adding in a blank block in the setup e.g.
classOauthTestdefsetup# set stuff up# ...OmniAuth.config.before_callback_phasedo |env|
# intentionally left blankendendtest"when origin is blank"doOmniAuth.config.before_callback_phasedo |env|
env['omniauth.origin']=nilend# test stuffendtest"Another thing"do# test other stuffendend
Pro-tip: if you want to be 100% sure your config is not leaking you can use
defself.test_order:alphaend
at the top and make sure your test with the config override starts with an earlier letter in the alphabet.
Activity
jeremyk3 commentedon May 1, 2019
There's literally zero documentation on this, but this worked for me:
qnm commentedon May 8, 2019
@jeremyk3 Thanks - however what you suggest affects Omniauth across all specs. Any ideas how to isolate the change to only a particular test?
speckins commentedon Nov 13, 2019
You're setting the request.env values after you've performed the GET request. You need to set them before you invoke the request.
njcameron commentedon Dec 13, 2020
@jeremyk3 I had the same problem, the work around I came up with was adding in a blank block in the setup e.g.
Pro-tip: if you want to be 100% sure your config is not leaking you can use
at the top and make sure your test with the config override starts with an earlier letter in the alphabet.
yshmarov commentedon Sep 2, 2023
I can confirm that this works for me. Thanks a lot! 🙇♂️