Use User#generate_password in MailHandler.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11457 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
fac4a79d4c
commit
e14caf8e33
|
@ -429,10 +429,8 @@ class MailHandler < ActionMailer::Base
|
|||
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?
|
||||
|
|
|
@ -726,14 +726,6 @@ class MailHandlerTest < ActiveSupport::TestCase
|
|||
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('jsmith@example.net')
|
||||
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('foo+bar@example.net')
|
||||
assert user.valid?
|
||||
|
|
|
@ -70,6 +70,20 @@ class UserTest < ActiveSupport::TestCase
|
|||
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 => "newuser@somenet.foo")
|
||||
user.login = "newuser"
|
||||
|
|
Loading…
Reference in New Issue