Skip to content

Commit 1697989

Browse files
committed
allow single character usernames fixes #5818
Change-Id: Ied53f5d44ec0a2ae38a4917af69bbc41eee90868 Reviewed-on: https://gerrit.instructure.com/5966 Reviewed-by: JT Olds <jt@instructure.com> Tested-by: Hudson <hudson@instructure.com>
1 parent 20535f8 commit 1697989

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

app/models/pseudonym.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ class Pseudonym < ActiveRecord::Base
4343
attr_accessor :path, :path_type
4444

4545
acts_as_authentic do |config|
46-
config.validates_format_of_login_field_options = {:with => /\A\w[\w\.\+\-_@ =]+\z/}
46+
config.validates_format_of_login_field_options = {:with => /\A\w[\w\.\+\-_@ =]*\z/}
4747
config.login_field :unique_id
4848
config.validations_scope = :account_id
4949
config.perishable_token_valid_for = 30.minutes
5050
config.validates_length_of_password_field_options = { :minimum => 6, :if => :require_password? }
51+
config.validates_length_of_login_field_options = {:within => 1..100}
5152
end
5253

5354
def require_password?

spec/lib/sis_csv_importer_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,18 +782,18 @@ def gen_ssha_password(password)
782782

783783
end
784784

785-
it "should catch active-record-level errors, like too short unique_id" do
785+
it "should catch active-record-level errors, like invalid unique_id" do
786786
before_user_count = User.count
787787
before_pseudo_count = Pseudonym.count
788788
importer = process_csv_data(
789789
"user_id,login_id,first_name,last_name,email,status",
790-
"U1,u1,User,Uno,user@example.com,active"
790+
"U1,@,User,Uno,user@example.com,active"
791791
)
792792
user = User.find_by_email('user@example.com')
793793
user.should be_nil
794794

795795
importer.errors.map(&:last).should == []
796-
importer.warnings.map(&:last).should == ["Failed saving user. Internal error: unique_id is too short (minimum is 3 characters)"]
796+
importer.warnings.map(&:last).should == ["Failed saving user. Internal error: unique_id is invalid"]
797797
[User.count, Pseudonym.count].should == [before_user_count, before_pseudo_count]
798798
end
799799

spec/models/pseudonym_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
user_model
2525
factory_with_protected_attributes(Pseudonym, valid_pseudonym_attributes)
2626
end
27+
28+
it "should allow single character usernames" do
29+
user_model
30+
pseudonym_model
31+
@pseudonym.unique_id = 'c'
32+
@pseudonym.save!
33+
end
2734

2835
it "should associate to another user" do
2936
user_model

0 commit comments

Comments
 (0)