Skip to content

Commit

Permalink
Allow logins to receive umlauts and other letter class chars
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Mar 21, 2024
1 parent 2f7601f commit 808c271
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def self.blocked_condition(blocked)
validates :login, uniqueness: { if: Proc.new { |user| user.login.present? }, case_sensitive: false }
validates :mail, uniqueness: { allow_blank: true, case_sensitive: false }
# Login must contain letters, numbers, underscores only
validates :login, format: { with: /\A[a-z0-9_\-@.+ ]*\z/i }
validates :login, format: { with: /\A[\p{L}0-9_\-@.+ ]*\z/i }
validates :login, length: { maximum: 256 }

validates :firstname, :lastname, length: { maximum: 256 }
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/ldap/users.ldif
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,5 @@ givenName: Bölle
mail: [email protected]
uid: bölle
samAccountName: bölle
# Password is "smada"
userpassword:: e1NIQX10Nk1mdHRLRG5HSm1xZnRqRUVEeEpLZ2ZjNEE9Cg==
# Password is "bólle"
userpassword:: e1NIQX1rNDBGWHRYQ3RFL3l2cENhblRpQmZ2cE1ON1k9Cg==
14 changes: 13 additions & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@
end
end

context 'with other letter char classes' do
let(:login) { "célîneüberölig" }

it 'is valid' do
expect(user).to be_valid
end

it 'may be stored in the database' do
expect(user.save).to be_truthy
end
end

context "with tabs" do
let(:login) { 'ab\tc' }

Expand Down Expand Up @@ -172,7 +184,7 @@
end

context "with combination thereof" do
let(:login) { "the+boss-is@the_house." }
let(:login) { "the+boss-is-über@the_house." }

it "is valid" do
expect(user).to be_valid
Expand Down
17 changes: 17 additions & 0 deletions spec/requests/auth/ldap_sso_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@
expect(subject).to redirect_to "/?first_time_user=true"
end

context 'with a user that has umlauts in their name' do
let(:username) { 'bölle' }
let(:password) { 'bólle' }

it 'creates a user with umlauts on the fly' do
expect(User.find_by(login: 'bölle')).to be_nil

expect { subject }.to change(User.not_builtin.active, :count).by(1)

user = User.find_by(login: 'bölle')
expect(user).to be_present
expect(user).to be_active
expect(session[:user_id]).to eq user.id
expect(subject).to redirect_to '/?first_time_user=true'
end
end

context "when not all attributes present" do
let(:attr_mail) { nil }

Expand Down

0 comments on commit 808c271

Please sign in to comment.