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

Merge pull request #962 from hynkle/fix-ambiguous-provider-constant-lookup

limit Builder#provider's symbol lookup to constants under OmniAuth::Strategies
This commit is contained in:
Bobby McDonald 2020-12-10 09:45:42 -05:00 committed by GitHub
commit 94f8f05c95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -31,7 +31,7 @@ module OmniAuth
middleware = klass middleware = klass
else else
begin begin
middleware = OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(klass.to_s).to_s) middleware = OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(klass.to_s).to_s, false)
rescue NameError rescue NameError
raise(LoadError.new("Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omniauth-#{klass}).")) raise(LoadError.new("Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omniauth-#{klass})."))
end end

View file

@ -3,7 +3,7 @@ require 'helper'
describe OmniAuth::Builder do describe OmniAuth::Builder do
describe '#provider' do describe '#provider' do
it 'translates a symbol to a constant' do it 'translates a symbol to a constant' do
expect(OmniAuth::Strategies).to receive(:const_get).with('MyStrategy').and_return(Class.new) expect(OmniAuth::Strategies).to receive(:const_get).with('MyStrategy', false).and_return(Class.new)
OmniAuth::Builder.new(nil) do OmniAuth::Builder.new(nil) do
provider :my_strategy provider :my_strategy
end end
@ -26,6 +26,16 @@ describe OmniAuth::Builder do
end end
end.to raise_error(LoadError, 'Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).') end.to raise_error(LoadError, 'Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).')
end end
it "doesn't translate a symbol to a top-level constant" do
class MyStrategy; end
expect do
OmniAuth::Builder.new(nil) do
provider :my_strategy
end
end.to raise_error(LoadError, 'Could not find matching strategy for :my_strategy. You may need to install an additional gem (such as omniauth-my_strategy).')
end
end end
describe '#options' do describe '#options' do