Skip to content

Commit

Permalink
Use User#generate_password in MailHandler.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11457 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed Feb 23, 2013
1 parent fac4a79 commit e14caf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 1 addition & 3 deletions app/models/mail_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,8 @@ def self.new_user_from_attributes(email_address, fullname=nil)
assign_string_attribute_with_limit(user, 'firstname', names.shift, 30)
assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30)
user.lastname = '-' if user.lastname.blank?

password_length = [Setting.password_min_length.to_i, 10].max
user.password = Redmine::Utils.random_hex(password_length / 2 + 1)
user.language = Setting.default_language
user.generate_password = true

unless user.valid?
user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank?
Expand Down
8 changes: 0 additions & 8 deletions test/unit/mail_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,14 +726,6 @@ def test_new_user_from_attributes_should_return_valid_user
end
end

def test_new_user_from_attributes_should_respect_minimum_password_length
with_settings :password_min_length => 15 do
user = MailHandler.new_user_from_attributes('[email protected]')
assert user.valid?
assert user.password.length >= 15
end
end

def test_new_user_from_attributes_should_use_default_login_if_invalid
user = MailHandler.new_user_from_attributes('[email protected]')
assert user.valid?
Expand Down
14 changes: 14 additions & 0 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ def test_login_length_validation
assert user.save
end

def test_generate_password_should_respect_minimum_password_length
with_settings :password_min_length => 15 do
user = User.generate!(:generate_password => true)
assert user.password.length >= 15
end
end

def test_generate_password_should_not_generate_password_with_less_than_10_characters
with_settings :password_min_length => 4 do
user = User.generate!(:generate_password => true)
assert user.password.length >= 10
end
end

def test_generate_password_on_create_should_set_password
user = User.new(:firstname => "new", :lastname => "user", :mail => "[email protected]")
user.login = "newuser"
Expand Down

0 comments on commit e14caf8

Please sign in to comment.