Permalink
Browse files

Set omniauth.origin when invoking callbacks in testmode.

  • Loading branch information...
1 parent dc44c54 commit 7b3644fd629117f10aeab52823cbb24a8970a0d6 @paulj paulj committed Mar 12, 2011
Showing with 24 additions and 1 deletion.
  1. +7 −1 oa-core/lib/omniauth/strategy.rb
  2. +17 −0 oa-core/spec/omniauth/strategy_spec.rb
View
8 oa-core/lib/omniauth/strategy.rb
@@ -61,7 +61,11 @@ def mock_call!(env)
if response = call_through_to_app
response
else
- env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
+ if request.params['origin']
+ env['rack.session']['omniauth.origin'] = request.params['origin']
+ elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
+ env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
+ end
redirect(callback_path)
end
elsif current_path == callback_path
@@ -70,6 +74,8 @@ def mock_call!(env)
fail!(mocked_auth)
else
@env['omniauth.auth'] = mocked_auth
+ env['omniauth.origin'] = session.delete('omniauth.origin')
+ env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
call_app!
end
else
View
17 oa-core/spec/omniauth/strategy_spec.rb
@@ -260,6 +260,23 @@ def make_env(path = '/auth/test', props = {})
strategy.call make_env('/auth/test/callback')
strategy.env['omniauth.error.type'].should == :invalid_credentials
end
+
+ it 'should set omniauth.origin on the request phase' do
+ strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))
+ strategy.env['rack.session']['omniauth.origin'].should == 'http://example.com/origin'
+ end
+
+ it 'should set omniauth.origin from the params if provided' do
+ strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo'))
+ strategy.env['rack.session']['omniauth.origin'].should == '/foo'
+ end
+
+ it 'should turn omniauth.origin into an env variable on the callback phase' do
+ OmniAuth.config.mock_auth[:test] = {}
+
+ strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
+ strategy.env['omniauth.origin'].should == 'http://example.com/origin'
+ end
end
context 'custom full_host' do

0 comments on commit 7b3644f

Please sign in to comment.