diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-07 09:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-07 09:08:42 +0300 |
commit | 02b949f3b64f88e97abec62c355ca1b1da2bd460 (patch) | |
tree | fffb942e5c6b9f19d3903a709172423595308643 /spec/controllers | |
parent | 3e59f1f11a387ab3e0383f7beea8ea599291a293 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/graphql_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/omniauth_callbacks_controller_spec.rb | 55 |
2 files changed, 50 insertions, 7 deletions
diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index 2842ce93e3a..2a16fb1ea37 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -463,7 +463,7 @@ RSpec.describe GraphqlController, feature_category: :integrations do it 'fails if the GraphiQL gem version is not 1.8.0' do # We cache the IntrospectionQuery based on the default IntrospectionQuery by GraphiQL. If this spec fails, # GraphiQL has been updated, so we should check whether the IntropsectionQuery we cache is still valid. - # It is stored in `app/assets/javascripts/graphql_shared/queries/introspection.query.graphql` + # It is stored in `app/graphql/cached_introspection_query.rb#query_string` expect(GraphiQL::Rails::VERSION).to eq("1.8.0") end end diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index 2e9fc1cece5..21672cf5dbe 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -18,6 +18,39 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: Rails.application.env_config['omniauth.auth'] = @original_env_config_omniauth_auth end + context 'authentication succeeds' do + let(:extern_uid) { 'my-uid' } + let(:provider) { :github } + + context 'without signed-in user' do + it 'increments Prometheus counter' do + expect { post(provider) }.to( + change do + Gitlab::Metrics.registry + .get(:gitlab_omniauth_login_total) + .get(provider: 'github', status: 'succeeded') + end.by(1) + ) + end + end + + context 'with signed-in user' do + before do + sign_in user + end + + it 'increments Prometheus counter' do + expect { post(provider) }.to( + change do + Gitlab::Metrics.registry + .get(:gitlab_omniauth_login_total) + .get(provider: 'github', status: 'succeeded') + end.by(1) + ) + end + end + end + context 'a deactivated user' do let(:provider) { :github } let(:extern_uid) { 'my-uid' } @@ -96,21 +129,31 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: let(:extern_uid) { 'my-uid' } let(:provider) { :saml } - def stub_route_as(path) - allow(@routes).to receive(:generate_extras) { [path, []] } - end - - it 'calls through to the failure handler' do + before do request.env['omniauth.error'] = OneLogin::RubySaml::ValidationError.new("Fingerprint mismatch") request.env['omniauth.error.strategy'] = OmniAuth::Strategies::SAML.new(nil) - stub_route_as('/users/auth/saml/callback') + allow(@routes).to receive(:generate_extras).and_return(['/users/auth/saml/callback', []]) + end + it 'calls through to the failure handler' do ForgeryProtection.with_forgery_protection do post :failure end expect(flash[:alert]).to match(/Fingerprint mismatch/) end + + it 'increments Prometheus counter' do + ForgeryProtection.with_forgery_protection do + expect { post :failure }.to( + change do + Gitlab::Metrics.registry + .get(:gitlab_omniauth_login_total) + .get(provider: 'saml', status: 'failed') + end.by(1) + ) + end + end end context 'when a redirect fragment is provided' do |