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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
fixed password confirmation during token reset (#9314)
Markus Kahl2bf74725b209
diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rbindex 6b6e43ba139..76a30ccab7e 100644--- a/app/controllers/admin/backups_controller.rb+++ b/app/controllers/admin/backups_controller.rb@@ -29,6 +29,7 @@#++class Admin::BackupsController < ApplicationController+ include PasswordConfirmationinclude ActionView::Helpers::TagHelperinclude BackupHelper@@ -37,6 +38,8 @@ class Admin::BackupsController < ApplicationControllerbefore_action :check_enabledbefore_action :require_admin+ before_action :check_password_confirmation, only: %i[perform_token_reset]+menu_item :backupsdef show@@ -54,6 +57,7 @@ class Admin::BackupsController < ApplicationControllerdef reset_token@backup_token = Token::Backup.find_by user: current_user+ @user = current_userenddef perform_token_resetdiff --git a/app/views/admin/backups/reset_token.html.erb b/app/views/admin/backups/reset_token.html.erbindex 18e72610f29..6261e96707f 100644--- a/app/views/admin/backups/reset_token.html.erb+++ b/app/views/admin/backups/reset_token.html.erb@@ -32,14 +32,17 @@ See docs/COPYRIGHT.rdoc for more details.<% html_title(t(:label_administration), t("backup.reset_token.heading_#{action}")) -%>-<%= labelled_tabular_form_for(- :user,- url: { action: 'reset_token' },+<%= password_confirmation_form_for(+ @user,+ as: :user,+ url: { action: 'perform_token_reset' },+ builder: ::TabularFormBuilder,+ lang: current_language,html: {- method: :post, class: 'confirm_required request-for-confirmation form danger-zone',- data: { "request-for-confirmation": true }+ method: :post,+ class: '-wide-labels confirm_required request-for-confirmation form danger-zone'}-) do %>+) do |f| %><div class='wiki'><section class="form--section"><h3 class="form--section-title">diff --git a/spec/features/admin/backup_spec.rb b/spec/features/admin/backup_spec.rbindex c94a171cc5c..2b9a9c7a99b 100644--- a/spec/features/admin/backup_spec.rb+++ b/spec/features/admin/backup_spec.rb@@ -74,21 +74,35 @@ describe 'backup', type: :feature, js: true doendend- it "allows the backup token to be reset" do- visit "/admin/backups"- click_on I18n.t("backup.label_reset_token")+ describe "token reset" do+ let(:dialog) { ::Components::PasswordConfirmationDialog.new }- expect(page).to have_content /#{I18n.t('backup.reset_token.heading_reset')}/i+ before do+ visit "/admin/backups"+ click_on I18n.t("backup.label_reset_token")- fill_in "login_verification", with: "reset"- click_on "Reset"- fill_in "request_for_confirmation_password", with: user_password- click_on "Confirm"+ expect(page).to have_content /#{I18n.t('backup.reset_token.heading_reset')}/i- new_token = Token::Backup.find_by(user: current_user)+ fill_in "login_verification", with: "reset"+ click_on "Reset"+ end- expect(new_token.plain_value).not_to eq backup_token.plain_value- expect(page).to have_content new_token.plain_value+ it 'works given the correct password' do+ dialog.confirm_flow_with(user_password)++ new_token = Token::Backup.find_by(user: current_user)++ expect(new_token.plain_value).not_to eq backup_token.plain_value+ expect(page).to have_content new_token.plain_value+ end++ it 'declines the change when an invalid password is given' do+ dialog.confirm_flow_with(user_password + 'INVALID', should_fail: true)++ new_token = Token::Backup.find_by_plaintext_value backup_token.plain_value++ expect(new_token).to eq backup_token+ endendit "allows the backup token to be deleted" do