diff --git a/Gemfile b/Gemfile index 1a1a79dff21..082cba0404f 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,7 @@ gem 'bootsnap', '~> 1.18.0', require: false gem 'browser' gem 'charlock_holmes', '~> 0.7.7' gem 'chewy', '~> 7.3' -gem 'devise', '~> 4.9' +gem 'devise' gem 'devise-two-factor' group :pam_authentication, optional: true do diff --git a/Gemfile.lock b/Gemfile.lock index 553cac49fe3..80c20f596d8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,29 +10,29 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (8.0.2.1) - actionpack (= 8.0.2.1) - activesupport (= 8.0.2.1) + actioncable (8.0.4.1) + actionpack (= 8.0.4.1) + activesupport (= 8.0.4.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (8.0.2.1) - actionpack (= 8.0.2.1) - activejob (= 8.0.2.1) - activerecord (= 8.0.2.1) - activestorage (= 8.0.2.1) - activesupport (= 8.0.2.1) + actionmailbox (8.0.4.1) + actionpack (= 8.0.4.1) + activejob (= 8.0.4.1) + activerecord (= 8.0.4.1) + activestorage (= 8.0.4.1) + activesupport (= 8.0.4.1) mail (>= 2.8.0) - actionmailer (8.0.2.1) - actionpack (= 8.0.2.1) - actionview (= 8.0.2.1) - activejob (= 8.0.2.1) - activesupport (= 8.0.2.1) + actionmailer (8.0.4.1) + actionpack (= 8.0.4.1) + actionview (= 8.0.4.1) + activejob (= 8.0.4.1) + activesupport (= 8.0.4.1) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (8.0.2.1) - actionview (= 8.0.2.1) - activesupport (= 8.0.2.1) + actionpack (8.0.4.1) + actionview (= 8.0.4.1) + activesupport (= 8.0.4.1) nokogiri (>= 1.8.5) rack (>= 2.2.4) rack-session (>= 1.0.1) @@ -40,15 +40,15 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (8.0.2.1) - actionpack (= 8.0.2.1) - activerecord (= 8.0.2.1) - activestorage (= 8.0.2.1) - activesupport (= 8.0.2.1) + actiontext (8.0.4.1) + actionpack (= 8.0.4.1) + activerecord (= 8.0.4.1) + activestorage (= 8.0.4.1) + activesupport (= 8.0.4.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (8.0.2.1) - activesupport (= 8.0.2.1) + actionview (8.0.4.1) + activesupport (= 8.0.4.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -58,22 +58,22 @@ GEM activemodel (>= 4.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (8.0.2.1) - activesupport (= 8.0.2.1) + activejob (8.0.4.1) + activesupport (= 8.0.4.1) globalid (>= 0.3.6) - activemodel (8.0.2.1) - activesupport (= 8.0.2.1) - activerecord (8.0.2.1) - activemodel (= 8.0.2.1) - activesupport (= 8.0.2.1) + activemodel (8.0.4.1) + activesupport (= 8.0.4.1) + activerecord (8.0.4.1) + activemodel (= 8.0.4.1) + activesupport (= 8.0.4.1) timeout (>= 0.4.0) - activestorage (8.0.2.1) - actionpack (= 8.0.2.1) - activejob (= 8.0.2.1) - activerecord (= 8.0.2.1) - activesupport (= 8.0.2.1) + activestorage (8.0.4.1) + actionpack (= 8.0.4.1) + activejob (= 8.0.4.1) + activerecord (= 8.0.4.1) + activesupport (= 8.0.4.1) marcel (~> 1.0) - activesupport (8.0.2.1) + activesupport (8.0.4.1) base64 benchmark (>= 0.3) bigdecimal @@ -82,7 +82,7 @@ GEM drb i18n (>= 1.6, < 2) logger (>= 1.4.2) - minitest (>= 5.1) + minitest (>= 5.1, < 6) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) @@ -184,16 +184,16 @@ GEM irb (~> 1.10) reline (>= 0.3.8) debug_inspector (1.2.0) - devise (4.9.4) + devise (5.0.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0) + railties (>= 7.0) responders warden (~> 1.2.3) - devise-two-factor (6.1.0) - activesupport (>= 7.0, < 8.1) - devise (~> 4.0) - railties (>= 7.0, < 8.1) + devise-two-factor (6.4.0) + activesupport (>= 7.2, < 8.2) + devise (>= 4.0, < 6.0) + railties (>= 7.2, < 8.2) rotp (~> 6.0) devise_pam_authenticatable2 (9.2.0) devise (>= 4.0.0) @@ -233,7 +233,7 @@ GEM fabrication (3.0.0) faker (3.5.1) i18n (>= 1.8.11, < 2) - faraday (2.13.1) + faraday (2.14.1) faraday-net_http (>= 2.0, < 3.5) json logger @@ -458,7 +458,7 @@ GEM net-smtp (0.5.1) net-protocol nio4r (2.7.4) - nokogiri (1.18.9) + nokogiri (1.18.10) mini_portile2 (~> 2.8.2) racc (~> 1.4) oj (3.16.11) @@ -642,7 +642,7 @@ GEM activesupport (>= 3.0.0) raabro (1.4.0) racc (1.8.1) - rack (3.1.18) + rack (3.1.20) rack-attack (6.7.0) rack (>= 1.0, < 4) rack-cors (3.0.0) @@ -668,20 +668,20 @@ GEM rack (>= 1.3) rackup (2.2.1) rack (>= 3) - rails (8.0.2.1) - actioncable (= 8.0.2.1) - actionmailbox (= 8.0.2.1) - actionmailer (= 8.0.2.1) - actionpack (= 8.0.2.1) - actiontext (= 8.0.2.1) - actionview (= 8.0.2.1) - activejob (= 8.0.2.1) - activemodel (= 8.0.2.1) - activerecord (= 8.0.2.1) - activestorage (= 8.0.2.1) - activesupport (= 8.0.2.1) + rails (8.0.4.1) + actioncable (= 8.0.4.1) + actionmailbox (= 8.0.4.1) + actionmailer (= 8.0.4.1) + actionpack (= 8.0.4.1) + actiontext (= 8.0.4.1) + actionview (= 8.0.4.1) + activejob (= 8.0.4.1) + activemodel (= 8.0.4.1) + activerecord (= 8.0.4.1) + activestorage (= 8.0.4.1) + activesupport (= 8.0.4.1) bundler (>= 1.15.0) - railties (= 8.0.2.1) + railties (= 8.0.4.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -692,13 +692,14 @@ GEM rails-i18n (8.0.1) i18n (>= 0.7, < 2) railties (>= 8.0.0, < 9) - railties (8.0.2.1) - actionpack (= 8.0.2.1) - activesupport (= 8.0.2.1) + railties (8.0.4.1) + actionpack (= 8.0.4.1) + activesupport (= 8.0.4.1) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.3.0) @@ -876,6 +877,7 @@ GEM bindata (~> 2.4) openssl (> 2.0) openssl-signature_algorithm (~> 1.0) + tsort (0.2.0) tty-color (0.6.0) tty-cursor (0.7.1) tty-prompt (0.23.1) @@ -970,7 +972,7 @@ DEPENDENCIES csv (~> 3.2) database_cleaner-active_record debug (~> 1.8) - devise (~> 4.9) + devise devise-two-factor devise_pam_authenticatable2 (~> 9.2) discard (~> 1.2) diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 2808066aaf9..c7690c86969 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -186,14 +186,14 @@ class Auth::SessionsController < Devise::SessionsController "2fa_auth_attempts:#{user.id}:#{Time.now.utc.hour}" end - def respond_to_on_destroy + def respond_to_on_destroy(**) respond_to do |format| format.json do render json: { redirect_to: after_sign_out_path_for(resource_name), }, status: 200 end - format.all { super } + format.all { super(**) } end end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index f69f7519c8b..149c1b1af4a 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -105,11 +105,9 @@ Devise.setup do |config| # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render invalid all existing # confirmation, reset password and unlock tokens in the database. - # - # Set explicitly to Rails default to avoid deprecation warnings. - # https://github.com/heartcombo/devise/pull/5645#issuecomment-1871849856 - # Remove when Devise changes `SecretKeyFinder` to not emit deprecations. - config.secret_key = Rails.application.secret_key_base + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = '<%= SecureRandom.hex(64) %>' # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, diff --git a/spec/controllers/auth/sessions_controller_spec.rb b/spec/controllers/auth/sessions_controller_spec.rb index c852b16a69c..162141b011c 100644 --- a/spec/controllers/auth/sessions_controller_spec.rb +++ b/spec/controllers/auth/sessions_controller_spec.rb @@ -70,7 +70,7 @@ RSpec.describe Auth::SessionsController do end it 'shows a login error and does not log the user in' do - expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: I18n.t('activerecord.attributes.user.email')) + expect(flash[:alert]).to match(/#{failure_message_invalid_email}/i) expect(controller.current_user).to be_nil end @@ -160,7 +160,7 @@ RSpec.describe Auth::SessionsController do end it 'shows a login error and does not log the user in' do - expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: I18n.t('activerecord.attributes.user.email')) + expect(flash[:alert]).to match(/#{failure_message_invalid_email}/i) expect(controller.current_user).to be_nil end @@ -411,5 +411,9 @@ RSpec.describe Auth::SessionsController do end end end + + def failure_message_invalid_email + I18n.t('devise.failure.invalid', authentication_keys: I18n.t('activerecord.attributes.user.email')) + end end end diff --git a/spec/system/log_in_spec.rb b/spec/system/log_in_spec.rb index 10869fd240e..af3a99164f7 100644 --- a/spec/system/log_in_spec.rb +++ b/spec/system/log_in_spec.rb @@ -25,7 +25,7 @@ RSpec.describe 'Log in' do it 'A invalid email and password user is not able to log in' do fill_in_auth_details('invalid_email', 'invalid_password') - expect(subject).to have_css('.flash-message', text: failure_message('invalid')) + expect(subject).to have_css('.flash-message', text: /#{failure_message_invalid}/i) end context 'when confirmed at is nil' do @@ -38,8 +38,8 @@ RSpec.describe 'Log in' do end end - def failure_message(message) + def failure_message_invalid keys = User.authentication_keys.map { |key| User.human_attribute_name(key) } - I18n.t("devise.failure.#{message}", authentication_keys: keys.join('support.array.words_connector')) + I18n.t('devise.failure.invalid', authentication_keys: keys.join('support.array.words_connector')) end end