mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 09:21:11 +00:00
feature/require-mfa-by-admin - Using ClimateControl
This commit is contained in:
parent
1c52aa76eb
commit
6fda7a9f56
|
@ -14,7 +14,7 @@ module MfaForceConcern
|
|||
return if current_user.otp_enabled?
|
||||
return if mfa_setup_allowed_paths?
|
||||
|
||||
flash[:warning] = I18n.t('require_multi_factor_auth.required_message')
|
||||
flash[:alert] = I18n.t('require_multi_factor_auth.required_message')
|
||||
redirect_to settings_otp_authentication_path
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
module FlashesHelper
|
||||
def user_facing_flashes
|
||||
flash.to_hash.slice('alert', 'error', 'notice', 'success', 'warning')
|
||||
flash.to_hash.slice('alert', 'error', 'notice', 'success')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,8 +18,9 @@ RSpec.describe MfaForceConcern do
|
|||
describe 'MFA force functionality' do
|
||||
context 'when REQUIRE_MULTI_FACTOR_AUTH is enabled' do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with('REQUIRE_MULTI_FACTOR_AUTH').and_return('true')
|
||||
sign_in user, scope: :user
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user has MFA enabled' do
|
||||
|
@ -28,8 +29,10 @@ RSpec.describe MfaForceConcern do
|
|||
end
|
||||
|
||||
it 'allows access to normal pages' do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -39,32 +42,42 @@ RSpec.describe MfaForceConcern do
|
|||
end
|
||||
|
||||
it 'redirects to MFA setup page' do
|
||||
get :index
|
||||
expect(response).to redirect_to(settings_otp_authentication_path)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
get :index
|
||||
expect(response).to redirect_to(settings_otp_authentication_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows the required message' do
|
||||
get :index
|
||||
expect(flash[:warning]).to eq(I18n.t('require_multi_factor_auth.required_message'))
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
get :index
|
||||
expect(flash[:alert]).to eq(I18n.t('require_multi_factor_auth.required_message'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when accessing MFA setup pages' do
|
||||
it 'allows access to OTP authentication page' do
|
||||
allow(controller.request).to receive(:path).and_return('/settings/otp_authentication')
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
allow(controller.request).to receive(:path).and_return('/settings/otp_authentication')
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
it 'allows access to MFA confirmation page' do
|
||||
allow(controller.request).to receive(:path).and_return('/settings/two_factor_authentication/confirmation')
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
allow(controller.request).to receive(:path).and_return('/settings/two_factor_authentication/confirmation')
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
it 'allows access to logout' do
|
||||
allow(controller.request).to receive(:path).and_return('/auth/sign_out')
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
allow(controller.request).to receive(:path).and_return('/auth/sign_out')
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -72,25 +85,26 @@ RSpec.describe MfaForceConcern do
|
|||
|
||||
context 'when REQUIRE_MULTI_FACTOR_AUTH is disabled' do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with('REQUIRE_MULTI_FACTOR_AUTH').and_return('false')
|
||||
sign_in user, scope: :user
|
||||
user.update(otp_required_for_login: false)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'false') do
|
||||
sign_in user, scope: :user
|
||||
user.update(otp_required_for_login: false)
|
||||
end
|
||||
end
|
||||
|
||||
it 'allows access to normal pages' do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'false') do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not signed in' do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with('REQUIRE_MULTI_FACTOR_AUTH').and_return('true')
|
||||
end
|
||||
|
||||
it 'allows access to normal pages' do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
ClimateControl.modify(REQUIRE_MULTI_FACTOR_AUTH: 'true') do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,6 @@ RSpec.describe FlashesHelper do
|
|||
flash[:error] = 'an error'
|
||||
flash[:notice] = 'a notice'
|
||||
flash[:success] = 'a success'
|
||||
flash[:warning] = 'a warning'
|
||||
flash[:not_user_facing] = 'a not user facing flash'
|
||||
# rubocop:enable Rails/I18nLocaleTexts
|
||||
end
|
||||
|
@ -20,8 +19,7 @@ RSpec.describe FlashesHelper do
|
|||
'alert' => 'an alert',
|
||||
'error' => 'an error',
|
||||
'notice' => 'a notice',
|
||||
'success' => 'a success',
|
||||
'warning' => 'a warning'
|
||||
'success' => 'a success'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user