2013-02-25 19:05:37 -05:00
|
|
|
require 'helper'
|
2012-03-05 23:11:35 -05:00
|
|
|
|
|
|
|
describe OmniAuth::FailureEndpoint do
|
2014-01-15 23:00:46 -05:00
|
|
|
subject { OmniAuth::FailureEndpoint }
|
2012-03-05 23:11:35 -05:00
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
context 'raise-out environment' do
|
2012-04-10 14:42:02 -04:00
|
|
|
before do
|
2013-09-01 14:29:57 -04:00
|
|
|
@rack_env = ENV['RACK_ENV']
|
|
|
|
ENV['RACK_ENV'] = 'test'
|
|
|
|
|
2013-09-01 14:16:35 -04:00
|
|
|
@default = OmniAuth.config.failure_raise_out_environments
|
|
|
|
OmniAuth.config.failure_raise_out_environments = ['test']
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'raises out the error' do
|
2012-04-11 20:13:22 -04:00
|
|
|
expect do
|
2014-01-15 23:00:46 -05:00
|
|
|
subject.call('omniauth.error' => StandardError.new('Blah'))
|
|
|
|
end.to raise_error(StandardError, 'Blah')
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'raises out an OmniAuth::Error if no omniauth.error is set' do
|
|
|
|
expect { subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error, 'example')
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2013-09-01 14:29:57 -04:00
|
|
|
ENV['RACK_ENV'] = @rack_env
|
2013-06-20 17:17:16 -04:00
|
|
|
OmniAuth.config.failure_raise_out_environments = @default
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
context 'non-raise-out environment' do
|
|
|
|
let(:env) do
|
|
|
|
{'omniauth.error.type' => 'invalid_request', 'omniauth.error.strategy' => ExampleStrategy.new({})}
|
|
|
|
end
|
2012-04-10 14:42:02 -04:00
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'is a redirect' do
|
2015-05-25 05:17:51 -04:00
|
|
|
status, = *subject.call(env)
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(status).to eq(302)
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'includes the SCRIPT_NAME' do
|
2015-05-25 05:17:51 -04:00
|
|
|
_, head, = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(head['Location']).to eq('/random/auth/failure?message=invalid_request&strategy=test')
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
|
|
|
|
2018-03-15 07:14:50 -04:00
|
|
|
it 'respects the globally configured path prefix' do
|
2013-07-09 04:08:41 -04:00
|
|
|
allow(OmniAuth.config).to receive(:path_prefix).and_return('/boo')
|
2015-05-25 05:17:51 -04:00
|
|
|
_, head, = *subject.call(env)
|
2014-01-15 23:00:46 -05:00
|
|
|
expect(head['Location']).to eq('/boo/failure?message=invalid_request&strategy=test')
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
2012-03-20 21:47:03 -04:00
|
|
|
|
2018-03-15 07:14:50 -04:00
|
|
|
it 'respects the custom path prefix configured on the strategy' do
|
|
|
|
env['omniauth.error.strategy'] = ExampleStrategy.new({}, path_prefix: "/some/custom/path")
|
|
|
|
_, head, = *subject.call(env)
|
|
|
|
expect(head['Location']).to eq('/some/custom/path/failure?message=invalid_request&strategy=test')
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'includes the origin (escaped) if one is provided' do
|
2016-08-08 13:54:19 -04:00
|
|
|
env['omniauth.origin'] = '/origin-example'
|
2015-05-25 05:17:51 -04:00
|
|
|
_, head, = *subject.call(env)
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(head['Location']).to be_include('&origin=%2Forigin-example')
|
2012-03-20 21:47:03 -04:00
|
|
|
end
|
2013-06-20 16:07:10 -04:00
|
|
|
|
|
|
|
it 'escapes the message key' do
|
|
|
|
_, head = *subject.call(env.merge('omniauth.error.type' => 'Connection refused!'))
|
|
|
|
expect(head['Location']).to be_include('message=Connection+refused%21')
|
|
|
|
end
|
2012-03-05 23:11:35 -05:00
|
|
|
end
|
2012-10-10 04:32:55 -04:00
|
|
|
end
|