2013-02-26 00:05:37 +00:00
|
|
|
require 'helper'
|
2012-03-06 04:11:35 +00:00
|
|
|
|
|
|
|
describe OmniAuth::FailureEndpoint do
|
|
|
|
subject{ OmniAuth::FailureEndpoint }
|
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
context "development" do
|
2012-04-10 18:42:02 +00:00
|
|
|
before do
|
2012-03-06 04:11:35 +00:00
|
|
|
@rack_env = ENV['RACK_ENV']
|
|
|
|
ENV['RACK_ENV'] = 'development'
|
|
|
|
end
|
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
it "raises out the error" do
|
2012-04-12 00:13:22 +00:00
|
|
|
expect do
|
|
|
|
subject.call('omniauth.error' => StandardError.new("Blah"))
|
|
|
|
end.to raise_error(StandardError, "Blah")
|
2012-03-06 04:11:35 +00:00
|
|
|
end
|
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
it "raises out an OmniAuth::Error if no omniauth.error is set" do
|
2012-03-06 04:11:35 +00:00
|
|
|
expect{ subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error, "example")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
ENV['RACK_ENV'] = @rack_env
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
context "non-development" do
|
2012-04-10 18:42:02 +00:00
|
|
|
let(:env){ {'omniauth.error.type' => 'invalid_request',
|
|
|
|
'omniauth.error.strategy' => ExampleStrategy.new({}) } }
|
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
it "is a redirect" do
|
2013-01-10 17:40:44 +00:00
|
|
|
status, _, _ = *subject.call(env)
|
2012-10-10 08:32:55 +00:00
|
|
|
expect(status).to eq(302)
|
2012-03-06 04:11:35 +00:00
|
|
|
end
|
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
it "includes the SCRIPT_NAME" do
|
2013-01-10 17:40:44 +00:00
|
|
|
_, head, _ = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
|
2012-10-10 08:32:55 +00:00
|
|
|
expect(head['Location']).to eq('/random/auth/failure?message=invalid_request&strategy=test')
|
2012-03-06 04:11:35 +00:00
|
|
|
end
|
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
it "respects the configured path prefix" do
|
2012-03-06 04:11:35 +00:00
|
|
|
OmniAuth.config.stub(:path_prefix => '/boo')
|
2013-01-10 17:40:44 +00:00
|
|
|
_, head, _ = *subject.call(env)
|
2012-10-10 08:32:55 +00:00
|
|
|
expect(head["Location"]).to eq('/boo/failure?message=invalid_request&strategy=test')
|
2012-03-06 04:11:35 +00:00
|
|
|
end
|
2012-03-21 01:47:03 +00:00
|
|
|
|
2012-10-10 08:32:55 +00:00
|
|
|
it "includes the origin (escaped) if one is provided" do
|
2012-03-21 01:47:03 +00:00
|
|
|
env.merge! 'omniauth.origin' => '/origin-example'
|
2013-01-10 17:40:44 +00:00
|
|
|
_, head, _ = *subject.call(env)
|
2012-10-10 08:32:55 +00:00
|
|
|
expect(head['Location']).to be_include('&origin=%2Forigin-example')
|
2012-03-21 01:47:03 +00:00
|
|
|
end
|
2012-03-06 04:11:35 +00:00
|
|
|
end
|
2012-10-10 08:32:55 +00:00
|
|
|
end
|