From 35e6a532f56d1a3e54476d2adb36375169e9bef9 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Thu, 29 Aug 2019 01:35:09 +0000 Subject: Force passwords to contain specified character classes (#4221). Patch by Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@18411 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/unit/user_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index e03528809..519de8b04 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -539,6 +539,18 @@ class UserTest < ActiveSupport::TestCase end end + def test_validate_password_format + Setting::PASSWORD_CHAR_CLASSES.each do |key, regexp| + with_settings :password_required_char_classes => key do + user = User.new(:firstname => "new", :lastname => "user", :login => "random", :mail => "random@somnet.foo") + p = 'PASSWDpasswd01234!@#$%'.gsub(regexp, '') + user.password, user.password_confirmation = p, p + assert !user.save + assert_equal 1, user.errors.count + end + end + end + def test_name_format assert_equal 'John S.', @jsmith.name(:firstname_lastinitial) assert_equal 'Smith, John', @jsmith.name(:lastname_comma_firstname) @@ -1058,6 +1070,14 @@ class UserTest < ActiveSupport::TestCase assert !u.password_confirmation.blank? end + def test_random_password_include_required_characters + with_settings :password_required_char_classes => Setting::PASSWORD_CHAR_CLASSES do + u = User.new(:firstname => "new", :lastname => "user", :login => "random", :mail => "random@somnet.foo") + u.random_password + assert u.valid? + end + end + test "#change_password_allowed? should be allowed if no auth source is set" do user = User.generate! assert user.change_password_allowed? -- cgit v1.2.3