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
[32748] Remove whitespace from login and mail
Oliver Günther93577fb31df9
diff --git a/Gemfile b/Gemfileindex 1db90f7413c..eae3883563c 100644--- a/Gemfile+++ b/Gemfile@@ -60,6 +60,9 @@ gem 'typed_dag', '~> 2.0.2'gem 'addressable', '~> 2.7.0'+# Remove whitespace from model input+gem "auto_strip_attributes", "~> 2.5"+# Provide timezone info for TZInfo used by ARgem 'tzinfo-data', '~> 1.2019.3'diff --git a/Gemfile.lock b/Gemfile.lockindex a5ec7f381b5..697cecb7289 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -296,6 +296,8 @@ GEMrbtree3 (~> 0.5)ast (2.4.0)attr_required (1.0.1)+ auto_strip_attributes (2.5.0)+ activerecord (>= 4.0)autoprefixer-rails (9.7.4)execjsawesome_nested_set (3.2.0)@@ -967,6 +969,7 @@ DEPENDENCIESacts_as_tree (~> 2.9.0)addressable (~> 2.7.0)airbrake (~> 9.4.3)+ auto_strip_attributes (~> 2.5)autoprefixer-rails (~> 9.7.4)awesome_nested_set (~> 3.2.0)aws-sdk-core (~> 3.91.0)@@ -1125,4 +1128,4 @@ RUBY VERSIONruby 2.6.5p114BUNDLED WITH- 2.0.2+ 2.1.4diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rbindex 215d998eecc..d2e08cdf11c 100644--- a/app/controllers/account_controller.rb+++ b/app/controllers/account_controller.rb@@ -373,7 +373,7 @@ class AccountController < ApplicationControllerif OpenProject::Configuration.disable_password_login?render_404else- password_authentication(params[:username], params[:password])+ password_authentication(params[:username]&.strip, params[:password])endenddiff --git a/app/models/user.rb b/app/models/user.rbindex 6b10206db75..9eb47d5e5bc 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -131,6 +131,9 @@ class User < Principalvalidates_confirmation_of :password, allow_nil: truevalidates_inclusion_of :mail_notification, in: MAIL_NOTIFICATION_OPTIONS.map(&:first), allow_blank: true+ auto_strip_attributes :login, nullify: false+ auto_strip_attributes :mail, nullify: false+validate :login_is_not_special_valuevalidate :password_meets_requirementsdiff --git a/db/migrate/20200325101528_strip_whitespace_from_user_attributes.rb b/db/migrate/20200325101528_strip_whitespace_from_user_attributes.rbnew file mode 100644index 00000000000..f7d47fece44--- /dev/null+++ b/db/migrate/20200325101528_strip_whitespace_from_user_attributes.rb@@ -0,0 +1,12 @@+class StripWhitespaceFromUserAttributes < ActiveRecord::Migration[6.0]+ def up+ User.update_all('login = TRIM(login), mail = TRIM(mail)')+ end++ def down+ warn <<~WARNING+ We cannot restore leading and trailing white space in user login and mail attributes.+ Please ensure you do not have logins with only leading or trailing white space differences.+ WARNING+ end+enddiff --git a/spec/features/auth/login_spec.rb b/spec/features/auth/login_spec.rbindex c2d149efa65..18d1c87417a 100644--- a/spec/features/auth/login_spec.rb+++ b/spec/features/auth/login_spec.rb@@ -67,6 +67,17 @@ describe 'Login', type: :feature dopassword_confirmation: user_password)end+ context 'with leading and trailing space in login' do+ it 'can still login' do+ # first login+ login_with(" #{user.login} ", user.password)++ # on the my page+ expect(page)+ .to have_current_path my_page_path+ end+ end+context 'with force password change' dolet(:force_password_change) { true }let(:first_login) { true }