Skip to content

Commit

Permalink
Setup phase is only called on OmniAuth endpoints. Closes omniauth#231
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Apr 5, 2011
1 parent e6d0d4e commit 6a48fdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion oa-core/lib/omniauth/strategy.rb
Expand Up @@ -28,10 +28,10 @@ def call!(env)
@env = env
@env['omniauth.strategy'] = self

setup_phase
return mock_call!(env) if OmniAuth.config.test_mode

if current_path == request_path && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
setup_phase
if response = call_through_to_app
response
else
Expand All @@ -43,6 +43,7 @@ def call!(env)
request_phase
end
elsif current_path == callback_path
setup_phase
@env['omniauth.origin'] = session.delete('omniauth.origin')
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''

Expand All @@ -58,6 +59,7 @@ def call!(env)

def mock_call!(env)
if current_path == request_path
setup_phase
if response = call_through_to_app
response
else
Expand All @@ -69,6 +71,7 @@ def mock_call!(env)
redirect(callback_path)
end
elsif current_path == callback_path
setup_phase
mocked_auth = OmniAuth.mock_auth_for(name.to_sym)
if mocked_auth.is_a?(Symbol)
fail!(mocked_auth)
Expand Down
12 changes: 11 additions & 1 deletion oa-core/spec/omniauth/strategy_spec.rb
Expand Up @@ -307,12 +307,17 @@ def make_env(path = '/auth/test', props = {})
context 'setup phase' do
context 'when options[:setup] = true' do
let(:strategy){ ExampleStrategy.new(app, 'test', :setup => true) }
let(:app){lambda{|env| env['omniauth.strategy'].options[:awesome] = 'sauce'; [404, {}, 'Awesome']}}
let(:app){lambda{|env| env['omniauth.strategy'].options[:awesome] = 'sauce' if env['PATH_INFO'] == '/auth/test/setup'; [404, {}, 'Awesome'] }}

it 'should call through to /auth/:provider/setup' do
strategy.call(make_env('/auth/test'))
strategy.options[:awesome].should == 'sauce'
end

it 'should not call through on a non-omniauth endpoint' do
strategy.call(make_env('/somewhere/else'))
strategy.options[:awesome].should_not == 'sauce'
end
end

context 'when options[:setup] is an app' do
Expand All @@ -324,6 +329,11 @@ def make_env(path = '/auth/test', props = {})

let(:strategy){ ExampleStrategy.new(app, 'test', :setup => setup_proc) }

it 'should not call the app on a non-omniauth endpoint' do
strategy.call(make_env('/somehwere/else'))
strategy.options[:awesome].should_not == 'sauce'
end

it 'should call the rack app' do
strategy.call(make_env('/auth/test'))
strategy.options[:awesome].should == 'sauce'
Expand Down

0 comments on commit 6a48fdb

Please sign in to comment.