1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Setup phase is only called on OmniAuth endpoints. Closes #231

This commit is contained in:
Michael Bleigh 2011-04-05 13:01:54 -05:00
parent e6d0d4e790
commit 6a48fdb89d
2 changed files with 15 additions and 2 deletions

View file

@ -28,10 +28,10 @@ module OmniAuth
@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
@ -43,6 +43,7 @@ module OmniAuth
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'] == ''
@ -58,6 +59,7 @@ module OmniAuth
def mock_call!(env)
if current_path == request_path
setup_phase
if response = call_through_to_app
response
else
@ -69,6 +71,7 @@ module OmniAuth
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)

View file

@ -307,12 +307,17 @@ describe OmniAuth::Strategy do
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
@ -324,6 +329,11 @@ describe OmniAuth::Strategy do
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'