mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Merge pull request #913 from 97jaz/origin-mock-request
Updates mock request phase to use options.origin correctly
This commit is contained in:
commit
ef7f7c2349
2 changed files with 33 additions and 11 deletions
|
@ -276,10 +276,12 @@ module OmniAuth
|
||||||
|
|
||||||
session['omniauth.params'] = request.GET
|
session['omniauth.params'] = request.GET
|
||||||
OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase
|
OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase
|
||||||
if request.params['origin']
|
if options.origin_param
|
||||||
session['omniauth.origin'] = request.params['origin']
|
if request.params[options.origin_param]
|
||||||
elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
|
session['omniauth.origin'] = request.params[options.origin_param]
|
||||||
session['omniauth.origin'] = env['HTTP_REFERER']
|
elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
|
||||||
|
session['omniauth.origin'] = env['HTTP_REFERER']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect(callback_url)
|
redirect(callback_url)
|
||||||
|
|
|
@ -689,14 +689,34 @@ describe OmniAuth::Strategy do
|
||||||
expect(strategy.env['omniauth.error.type']).to eq(:invalid_credentials)
|
expect(strategy.env['omniauth.error.type']).to eq(:invalid_credentials)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets omniauth.origin on the request phase' do
|
context 'omniauth.origin' do
|
||||||
strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))
|
context 'disabled' do
|
||||||
expect(strategy.env['rack.session']['omniauth.origin']).to eq('http://example.com/origin')
|
it 'does not set omniauth.origin' do
|
||||||
end
|
@options = {:origin_param => false}
|
||||||
|
strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))
|
||||||
|
expect(strategy.env['rack.session']['omniauth.origin']).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'sets omniauth.origin from the params if provided' do
|
context 'default flow' do
|
||||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo'))
|
it 'sets omniauth.origin to the HTTP_REFERER on the request phase by default' do
|
||||||
expect(strategy.env['rack.session']['omniauth.origin']).to eq('/foo')
|
strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))
|
||||||
|
expect(strategy.env['rack.session']['omniauth.origin']).to eq('http://example.com/origin')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sets omniauth.origin from the params if provided' do
|
||||||
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo'))
|
||||||
|
expect(strategy.env['rack.session']['omniauth.origin']).to eq('/foo')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'custom' do
|
||||||
|
it 'sets omniauth.origin from a custom param' do
|
||||||
|
@options = {:origin_param => 'return'}
|
||||||
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'return=/foo'))
|
||||||
|
expect(strategy.env['rack.session']['omniauth.origin']).to eq('/foo')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'turns omniauth.origin into an env variable on the callback phase' do
|
it 'turns omniauth.origin into an env variable on the callback phase' do
|
||||||
|
|
Loading…
Reference in a new issue