nil error in `callback_path` after omniauth 2 update
Take a very simple strategy, such as the example from the readme. Then the following spec fails for me
# https://github.com/omniauth/omniauth-oauth2/blob/3a43234ab5dd36a75f9c125c58fcfe1a37b26805/spec/omniauth/strategies/oauth2_spec.rb#L4-L8
def app
lambda do |_env|
[200, {}, ["Hello."]]
end
end
subject { described_class.new(app) }
describe '#callback_path' do
it 'has the correct callback path' do
expect(subject.callback_path).to eq('/users/auth/custom/callback')
end
end
1) OmniAuth::Strategies::Custom#callback_path has the correct callback path
Failure/Error: expect(subject.callback_path).to eq('/users/auth/custom/callback')
NoMethodError:
undefined method `[]' for nil:NilClass
@env['SCRIPT_NAME'] || ''
^^^^^^^^^^^^^^^
# /usr/local/bundle/gems/omniauth-2.1.0/lib/omniauth/strategy.rb:501:in `script_name'
# /usr/local/bundle/gems/omniauth-2.1.0/lib/omniauth/strategy.rb:450:in `callback_path'
Do you have Omniauth.config.test_mode set?
@BobbyMcWho yes, I got this error with both true and false
The issue is that @env is nil, and actually lives in the Omniauth gem and not this one: https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategy.rb#L500-L502
We could return '' if @env is nil there, if you want to spin up a PR, I can take a look, else I'll get to it when I can find some time.
@BobbyMcWho Thanks. This works in production though, so I'm wondering if there's a way to set env in the test as a workaround. But yeah env can be nil so it should be treated accordingly. I can provide a PR tomorrow
@BobbyMcWho I have opened a PR for the same. Please do check.
Is there any workaround while we wait for the PR to be merged? I have the same issue with updating to 2.1.
Hmm, actually I don't believe callback path is supposed to be called without an @env having been created
I've released a fix for this in 2.1.1 which has been pushed to rubygems