@@ -429,10 +429,8 class MailHandler < ActionMailer::Base | |||||
429 | assign_string_attribute_with_limit(user, 'firstname', names.shift, 30) |
|
429 | assign_string_attribute_with_limit(user, 'firstname', names.shift, 30) | |
430 | assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30) |
|
430 | assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30) | |
431 | user.lastname = '-' if user.lastname.blank? |
|
431 | user.lastname = '-' if user.lastname.blank? | |
432 |
|
||||
433 | password_length = [Setting.password_min_length.to_i, 10].max |
|
|||
434 | user.password = Redmine::Utils.random_hex(password_length / 2 + 1) |
|
|||
435 | user.language = Setting.default_language |
|
432 | user.language = Setting.default_language | |
|
433 | user.generate_password = true | |||
436 |
|
434 | |||
437 | unless user.valid? |
|
435 | unless user.valid? | |
438 | user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank? |
|
436 | user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank? |
@@ -726,14 +726,6 class MailHandlerTest < ActiveSupport::TestCase | |||||
726 | end |
|
726 | end | |
727 | end |
|
727 | end | |
728 |
|
728 | |||
729 | def test_new_user_from_attributes_should_respect_minimum_password_length |
|
|||
730 | with_settings :password_min_length => 15 do |
|
|||
731 | user = MailHandler.new_user_from_attributes('jsmith@example.net') |
|
|||
732 | assert user.valid? |
|
|||
733 | assert user.password.length >= 15 |
|
|||
734 | end |
|
|||
735 | end |
|
|||
736 |
|
||||
737 | def test_new_user_from_attributes_should_use_default_login_if_invalid |
|
729 | def test_new_user_from_attributes_should_use_default_login_if_invalid | |
738 | user = MailHandler.new_user_from_attributes('foo+bar@example.net') |
|
730 | user = MailHandler.new_user_from_attributes('foo+bar@example.net') | |
739 | assert user.valid? |
|
731 | assert user.valid? |
@@ -70,6 +70,20 class UserTest < ActiveSupport::TestCase | |||||
70 | assert user.save |
|
70 | assert user.save | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
|
73 | def test_generate_password_should_respect_minimum_password_length | |||
|
74 | with_settings :password_min_length => 15 do | |||
|
75 | user = User.generate!(:generate_password => true) | |||
|
76 | assert user.password.length >= 15 | |||
|
77 | end | |||
|
78 | end | |||
|
79 | ||||
|
80 | def test_generate_password_should_not_generate_password_with_less_than_10_characters | |||
|
81 | with_settings :password_min_length => 4 do | |||
|
82 | user = User.generate!(:generate_password => true) | |||
|
83 | assert user.password.length >= 10 | |||
|
84 | end | |||
|
85 | end | |||
|
86 | ||||
73 | def test_generate_password_on_create_should_set_password |
|
87 | def test_generate_password_on_create_should_set_password | |
74 | user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") |
|
88 | user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") | |
75 | user.login = "newuser" |
|
89 | user.login = "newuser" |
General Comments 0
You need to be logged in to leave comments.
Login now