Option to generate a random password on user creation/update.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11456 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2013-02-23 16:50:07 +00:00
parent 78997eea16
commit fac4a79d4c
7 changed files with 117 additions and 11 deletions

View File

@@ -218,6 +218,30 @@ class UsersControllerTest < ActionController::TestCase
assert_equal '0', user.pref[:warn_on_leaving_unsaved]
end
def test_create_with_generate_password_should_email_the_password
assert_difference 'User.count' do
post :create, :user => {
:login => 'randompass',
:firstname => 'Random',
:lastname => 'Pass',
:mail => 'randompass@example.net',
:language => 'en',
:generate_password => '1',
:password => '',
:password_confirmation => ''
}, :send_information => 1
end
user = User.order('id DESC').first
assert_equal 'randompass', user.login
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
assert m
password = m[1]
assert user.check_password?(password)
end
def test_create_with_failure
assert_no_difference 'User.count' do
post :create, :user => {}
@@ -290,6 +314,37 @@ class UsersControllerTest < ActionController::TestCase
assert_mail_body_match 'newpass123', mail
end
def test_update_with_generate_password_should_email_the_password
ActionMailer::Base.deliveries.clear
Setting.bcc_recipients = '1'
put :update, :id => 2, :user => {
:generate_password => '1',
:password => '',
:password_confirmation => ''
}, :send_information => '1'
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
assert m
password = m[1]
assert User.find(2).check_password?(password)
end
def test_update_without_generate_password_should_not_change_password
put :update, :id => 2, :user => {
:firstname => 'changed',
:generate_password => '0',
:password => '',
:password_confirmation => ''
}, :send_information => '1'
user = User.find(2)
assert_equal 'changed', user.firstname
assert user.check_password?('jsmith')
end
def test_update_user_switchin_from_auth_source_to_password_authentication
# Configure as auth source
u = User.find(2)