diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-09 15:53:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-09 15:53:48 +0000 |
commit | 269e9057ddff73081eadffd533ab3ad1a18b0011 (patch) | |
tree | 477658f1fb53a322cc1ba4b0ad52f386b3ef93c4 | |
parent | ea307619beceb51d6b9229987480e051f53b67d6 (diff) | |
download | redmine-269e9057ddff73081eadffd533ab3ad1a18b0011.tar.gz redmine-269e9057ddff73081eadffd533ab3ad1a18b0011.zip |
Fixed that "Default administrator account changed" is always true (#10622).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9379 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/admin_controller.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 5 | ||||
-rw-r--r-- | test/unit/user_test.rb | 32 |
3 files changed, 38 insertions, 3 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 9684f5cbf..b8d4981f5 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -75,9 +75,7 @@ class AdminController < ApplicationController def info @db_adapter_name = ActiveRecord::Base.connection.adapter_name @checklist = [ - [:text_default_administrator_account_changed, - User.find(:first, - :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?], + [:text_default_administrator_account_changed, User.default_admin_account_changed?], [:text_file_repository_writable, File.writable?(Attachment.storage_path)], [:text_plugin_assets_writable, File.writable?(Redmine::Plugin.public_directory)], [:text_rmagick_available, Object.const_defined?(:Magick)] diff --git a/app/models/user.rb b/app/models/user.rb index a37c4dffa..d1fa2822a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -348,6 +348,11 @@ class User < Principal find(:first, :conditions => ["LOWER(mail) = ?", mail.to_s.downcase]) end + # Returns true if the default admin account can no longer be used + def self.default_admin_account_changed? + !User.active.find_by_login("admin").try(:check_password?, "admin") + end + def to_s name end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 1c85625e9..e698207da 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -630,6 +630,38 @@ class UserTest < ActiveSupport::TestCase end end + def test_default_admin_account_changed_should_return_false_if_account_was_not_changed + user = User.find_by_login("admin") + user.password = "admin" + user.save! + + assert_equal false, User.default_admin_account_changed? + end + + def test_default_admin_account_changed_should_return_true_if_password_was_changed + user = User.find_by_login("admin") + user.password = "newpassword" + user.save! + + assert_equal true, User.default_admin_account_changed? + end + + def test_default_admin_account_changed_should_return_true_if_account_is_disabled + user = User.find_by_login("admin") + user.password = "admin" + user.status = User::STATUS_LOCKED + user.save! + + assert_equal true, User.default_admin_account_changed? + end + + def test_default_admin_account_changed_should_return_true_if_account_does_not_exist + user = User.find_by_login("admin") + user.destroy + + assert_equal true, User.default_admin_account_changed? + end + def test_roles_for_project # user with a role roles = @jsmith.roles_for_project(Project.find(1)) |