Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

style: do not pollute global namespace with test methods

Klaus Zandersc78e5474789d
diff --git a/modules/two_factor_authentication/spec/features/account_activation_spec.rb b/modules/two_factor_authentication/spec/features/account_activation_spec.rb
index 3c5ac03cf98..a9a2a406c0c 100644
--- a/modules/two_factor_authentication/spec/features/account_activation_spec.rb
+++ b/modules/two_factor_authentication/spec/features/account_activation_spec.rb
@@ -1,5 +1,5 @@
require_relative "../spec_helper"
-require_relative "shared_2fa_examples"
+require_relative "shared_two_factor_examples"
RSpec.describe "activating an invited account",
:js,
@@ -7,6 +7,8 @@ RSpec.describe "activating an invited account",
with_settings: {
plugin_openproject_two_factor_authentication: { "active_strategies" => [:developer] }
} do
+ include SharedTwoFactorExamples
+
let(:user) do
user = build(:user, first_login: true)
UserInvitation.invite_user! user
diff --git a/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes_spec.rb b/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes_spec.rb
index 681720b9900..674aebd2ee2 100644
--- a/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes_spec.rb
+++ b/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Generate 2FA backup codes", :js, with_config: { "2fa": { active_strategies: [:developer] } } do
let(:user_password) { "bob!" * 4 }
diff --git a/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb b/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb
index a8b1cd7fcef..f858e7f7aae 100644
--- a/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb
+++ b/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Login with 2FA backup code",
:js,
@@ -7,6 +7,8 @@ RSpec.describe "Login with 2FA backup code",
with_settings: {
plugin_openproject_two_factor_authentication: { "active_strategies" => [:developer] }
} do
+ include SharedTwoFactorExamples
+
let(:user_password) { "bob!" * 4 }
let(:user) do
create(:user,
diff --git a/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb b/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb
index 6701fd82b24..1e2dc96b06c 100644
--- a/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb
+++ b/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Login with enforced 2FA",
:js,
@@ -10,6 +10,7 @@ RSpec.describe "Login with enforced 2FA",
"enforced" => true
}
} do
+ include SharedTwoFactorExamples
let(:user_password) { "bob!" * 4 }
let(:user) do
create(:user,
diff --git a/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb b/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb
index 8eff3e7d0be..3b38562cad3 100644
--- a/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb
+++ b/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Login with 2FA device",
:js,
@@ -9,6 +9,7 @@ RSpec.describe "Login with 2FA device",
"active_strategies" => [:developer]
}
} do
+ include SharedTwoFactorExamples
let(:user_password) { "bob!" * 4 }
let(:user) do
create(:user,
diff --git a/modules/two_factor_authentication/spec/features/login/login_with_deleted_2fa_spec.rb b/modules/two_factor_authentication/spec/features/login/login_with_deleted_2fa_spec.rb
index 16ea18886bc..6eed2c36add 100644
--- a/modules/two_factor_authentication/spec/features/login/login_with_deleted_2fa_spec.rb
+++ b/modules/two_factor_authentication/spec/features/login/login_with_deleted_2fa_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Login after 2FA deleted 2FA was deleted (REGRESSION)",
:js,
@@ -9,6 +9,7 @@ RSpec.describe "Login after 2FA deleted 2FA was deleted (REGRESSION)",
"active_strategies" => %i[developer totp]
}
} do
+ include SharedTwoFactorExamples
let(:user_password) { "bob!" * 4 }
let(:user) do
create(:user,
diff --git a/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb b/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb
index 34565fca2a2..f68745efbd8 100644
--- a/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb
+++ b/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb
@@ -1,10 +1,11 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Login with no required OTP",
:js,
:with_cuprite,
with_config: { "2fa": { active_strategies: [:developer] } } do
+ include SharedTwoFactorExamples
let(:user_password) { "bob!" * 4 }
let(:user) do
create(:user,
diff --git a/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb b/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb
index 086daa515d8..a5ff551ac6c 100644
--- a/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb
+++ b/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Login by switching 2FA device",
:js,
@@ -7,6 +7,8 @@ RSpec.describe "Login by switching 2FA device",
with_settings: {
plugin_openproject_two_factor_authentication: { "active_strategies" => %i[developer totp] }
} do
+ include SharedTwoFactorExamples
+
let(:user_password) { "bob!" * 4 }
let(:user) do
create(:user,
diff --git a/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb b/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb
index 5a02d143809..c936c8d58c9 100644
--- a/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb
+++ b/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../spec_helper"
-require_relative "../shared_2fa_examples"
+require_relative "../shared_two_factor_examples"
RSpec.describe "Login with 2FA remember cookie",
:js,
@@ -10,6 +10,8 @@ RSpec.describe "Login with 2FA remember cookie",
allow_remember_for_days: 30
}
} do
+ include SharedTwoFactorExamples
+
let(:user_password) do
"user!user!"
end
diff --git a/modules/two_factor_authentication/spec/features/shared_2fa_examples.rb b/modules/two_factor_authentication/spec/features/shared_two_factor_examples.rb
similarity index 66%
rename from modules/two_factor_authentication/spec/features/shared_2fa_examples.rb
rename to modules/two_factor_authentication/spec/features/shared_two_factor_examples.rb
index 367cfbe75b1..3ef56d75a8a 100644
--- a/modules/two_factor_authentication/spec/features/shared_2fa_examples.rb
+++ b/modules/two_factor_authentication/spec/features/shared_two_factor_examples.rb
@@ -1,36 +1,38 @@
-def first_login_step
- visit signin_path
- within("#login-form") do
- fill_in("username", with: user.login)
- fill_in("password", with: user_password)
- click_link_or_button I18n.t(:button_login)
+module SharedTwoFactorExamples
+ def first_login_step
+ visit signin_path
+ within("#login-form") do
+ fill_in("username", with: user.login)
+ fill_in("password", with: user_password)
+ click_link_or_button I18n.t(:button_login)
+ end
+ wait_for_network_idle
end
- wait_for_network_idle
-end
-def switch_two_factor_device(device)
- within("#login-form") do
- click_link_or_button I18n.t(:text_otp_not_receive)
- click_link_or_button device.redacted_identifier
+ def switch_two_factor_device(device)
+ within("#login-form") do
+ click_link_or_button I18n.t(:text_otp_not_receive)
+ click_link_or_button device.redacted_identifier
+ end
end
-end
-def two_factor_step(token)
- expect(page).to have_css("input#otp")
- fill_in "otp", with: token
- click_button I18n.t(:button_login)
- wait_for_network_idle
-end
+ def two_factor_step(token)
+ expect(page).to have_css("input#otp")
+ fill_in "otp", with: token
+ click_button I18n.t(:button_login)
+ wait_for_network_idle
+ end
-def expect_logged_in
- visit my_account_path
- wait_for_network_idle
- expect(page).to have_css(".form--field-container", text: user.login)
-end
+ def expect_logged_in
+ visit my_account_path
+ wait_for_network_idle
+ expect(page).to have_css(".form--field-container", text: user.login)
+ end
-def expect_not_logged_in
- visit my_account_path
- expect(page).to have_no_css(".form--field-container", text: user.login)
+ def expect_not_logged_in
+ visit my_account_path
+ expect(page).to have_no_css(".form--field-container", text: user.login)
+ end
end
RSpec.shared_examples "login without 2FA" do