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