diff --git a/oa-core/lib/omniauth/strategy.rb b/oa-core/lib/omniauth/strategy.rb index cebe31d..75498e1 100644 --- a/oa-core/lib/omniauth/strategy.rb +++ b/oa-core/lib/omniauth/strategy.rb @@ -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) diff --git a/oa-core/spec/omniauth/strategy_spec.rb b/oa-core/spec/omniauth/strategy_spec.rb index 30da25b..d7fa8f9 100644 --- a/oa-core/spec/omniauth/strategy_spec.rb +++ b/oa-core/spec/omniauth/strategy_spec.rb @@ -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'