From 5acdcb178bccf41d3aa2425aaba3af69952241cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 10 Oct 2022 21:14:00 +0200 Subject: [PATCH] Add helper to disable 2FA stage redirects Many specs depend on not redirecting to 2FA, so provide a helper to skip that stage --- .../spec/requests/openid_connect_spec.rb | 4 +- spec/controllers/account_controller_spec.rb | 4 +- .../concerns/auth_source_sso_spec.rb | 4 +- .../concerns/omniauth_login_spec.rb | 4 +- spec/features/auth/auth_stages_spec.rb | 4 +- spec/requests/auth/auth_source_sso_spec.rb | 1 + spec/support/shared/with_2fa.rb | 37 +++++++++++++++++++ 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 spec/support/shared/with_2fa.rb diff --git a/modules/openid_connect/spec/requests/openid_connect_spec.rb b/modules/openid_connect/spec/requests/openid_connect_spec.rb index 170930c4301..e206e0b799e 100644 --- a/modules/openid_connect/spec/requests/openid_connect_spec.rb +++ b/modules/openid_connect/spec/requests/openid_connect_spec.rb @@ -33,7 +33,9 @@ RSpec.configure do |c| c.include OpenIDConnectSpecHelpers end -describe 'OpenID Connect', type: :rails_request do +describe 'OpenID Connect', + skip_2fa_stage: true, # Prevent redirects to 2FA stage + type: :rails_request do let(:host) { OmniAuth::OpenIDConnect::Heroku.new('foo', {}).host } let(:user_info) do { diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb index 781c767f575..c83b9391375 100644 --- a/spec/controllers/account_controller_spec.rb +++ b/spec/controllers/account_controller_spec.rb @@ -28,7 +28,9 @@ require 'spec_helper' -describe AccountController, type: :controller do +describe AccountController, + skip_2fa_stage: true, # Prevent redirects to 2FA stage + type: :controller do class UserHook < OpenProject::Hook::ViewListener attr_reader :registered_user, :first_login_user diff --git a/spec/controllers/concerns/auth_source_sso_spec.rb b/spec/controllers/concerns/auth_source_sso_spec.rb index e3c4262f776..3f387220911 100644 --- a/spec/controllers/concerns/auth_source_sso_spec.rb +++ b/spec/controllers/concerns/auth_source_sso_spec.rb @@ -28,7 +28,9 @@ require 'spec_helper' -describe MyController, type: :controller do +describe MyController, + skip_2fa_stage: true, # Prevent redirects to 2FA stage + type: :controller do render_views let(:sso_config) do diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rb index e9116042b1c..59352c3d587 100644 --- a/spec/controllers/concerns/omniauth_login_spec.rb +++ b/spec/controllers/concerns/omniauth_login_spec.rb @@ -29,7 +29,9 @@ require 'spec_helper' # Concern is included into AccountController and depends on methods available there -describe AccountController, type: :controller do +describe AccountController, + skip_2fa_stage: true, # Prevent redirects to 2FA stage + type: :controller do let(:omniauth_strategy) { double('Google Strategy', name: 'google') } let(:omniauth_hash) do OmniAuth::AuthHash.new( diff --git a/spec/features/auth/auth_stages_spec.rb b/spec/features/auth/auth_stages_spec.rb index 1f925b8de18..1c567e1814e 100644 --- a/spec/features/auth/auth_stages_spec.rb +++ b/spec/features/auth/auth_stages_spec.rb @@ -28,7 +28,9 @@ require 'spec_helper' -describe 'Authentication Stages', type: :feature do +describe 'Authentication Stages', + skip_2fa_stage: true, # Prevent redirects to 2FA stage + type: :feature do before do @capybara_ignore_elements = Capybara.ignore_hidden_elements Capybara.ignore_hidden_elements = true diff --git a/spec/requests/auth/auth_source_sso_spec.rb b/spec/requests/auth/auth_source_sso_spec.rb index 91aa8ab9578..9cb837b3d3e 100644 --- a/spec/requests/auth/auth_source_sso_spec.rb +++ b/spec/requests/auth/auth_source_sso_spec.rb @@ -29,6 +29,7 @@ require 'spec_helper' describe AuthSourceSSO, + skip_2fa_stage: true, # Prevent redirects to 2FA stage type: :rails_request do let(:sso_config) do { diff --git a/spec/support/shared/with_2fa.rb b/spec/support/shared/with_2fa.rb new file mode 100644 index 00000000000..a0b692e64da --- /dev/null +++ b/spec/support/shared/with_2fa.rb @@ -0,0 +1,37 @@ +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2012-2022 the OpenProject GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# Copyright (C) 2010-2013 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See COPYRIGHT and LICENSE files for more details. +#++ + +RSpec.configure do |config| + config.before do |example| + if example.metadata[:skip_2fa_stage] + allow(::OpenProject::TwoFactorAuthentication::TokenStrategyManager) + .to receive(:enabled?) + .and_return false + end + end +end