summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/mail_handler.rb4
-rw-r--r--test/unit/mail_handler_test.rb8
-rw-r--r--test/unit/user_test.rb14
3 files changed, 15 insertions, 11 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index febee3d1c..0e07f1069 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -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?
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index 7b4ffde13..adb250e56 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -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?
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 9ea57c722..9105dfda0 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -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"