diff options
author | Stan Hu <stanhu@gmail.com> | 2019-05-23 21:50:06 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-05-23 22:17:56 +0300 |
commit | bf8f4c135a0d893defb6dd97e07b84184f5270a7 (patch) | |
tree | 4d732d03feecdc9f6f183535994ca61071d6bc4b /spec/lib | |
parent | dd454852bc941130820b1c647a8580d56acb2a4f (diff) |
Fix OmniAuth OAuth2Generic strategy not loading
In https://github.com/rails/rails/commit/83b767ce, Rails 5.1 removed
support for using a String to specify a middleware. When the
strategy_class argument is passed from the GitLab YAML config to Devise,
Devise passes the string value straight through to Rails, and GitLab
would crash with a NoMethodError inside ActionDispatch::MiddlewareStack.
To make this OmniAuth strategy work again, we normalize the arguments by
converting the strategy_class value into an actual Class.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/62216
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/omniauth_initializer_spec.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/lib/gitlab/omniauth_initializer_spec.rb b/spec/lib/gitlab/omniauth_initializer_spec.rb index d808b4d49e0..f9c0daf1ef1 100644 --- a/spec/lib/gitlab/omniauth_initializer_spec.rb +++ b/spec/lib/gitlab/omniauth_initializer_spec.rb @@ -38,6 +38,28 @@ describe Gitlab::OmniauthInitializer do subject.execute([hash_config]) end + it 'normalizes a String strategy_class' do + hash_config = { 'name' => 'hash', 'args' => { strategy_class: 'OmniAuth::Strategies::OAuth2Generic' } } + + expect(devise_config).to receive(:omniauth).with(:hash, strategy_class: OmniAuth::Strategies::OAuth2Generic) + + subject.execute([hash_config]) + end + + it 'allows a class to be specified in strategy_class' do + hash_config = { 'name' => 'hash', 'args' => { strategy_class: OmniAuth::Strategies::OAuth2Generic } } + + expect(devise_config).to receive(:omniauth).with(:hash, strategy_class: OmniAuth::Strategies::OAuth2Generic) + + subject.execute([hash_config]) + end + + it 'throws an error for an invalid strategy_class' do + hash_config = { 'name' => 'hash', 'args' => { strategy_class: 'OmniAuth::Strategies::Bogus' } } + + expect { subject.execute([hash_config]) }.to raise_error(NameError) + end + it 'configures fail_with_empty_uid for shibboleth' do shibboleth_config = { 'name' => 'shibboleth', 'args' => {} } |