FIX: password validator was being too strict
This commit is contained in:
parent
dba16b57cb
commit
8feb94e13f
|
@ -18,7 +18,7 @@ class PasswordValidator < ActiveModel::EachValidator
|
||||||
record.errors.add(attribute, :same_as_current)
|
record.errors.add(attribute, :same_as_current)
|
||||||
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
|
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
|
||||||
record.errors.add(attribute, :common)
|
record.errors.add(attribute, :common)
|
||||||
elsif value.chars.inject(Hash.new(0)) { |h,char| h[char] += 1; h }.reject { |k,v| v > 1 }.size < SiteSetting.password_unique_characters
|
elsif value.split("").uniq.length < SiteSetting.password_unique_characters
|
||||||
record.errors.add(attribute, :unique_characters)
|
record.errors.add(attribute, :unique_characters)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -93,19 +93,20 @@ describe PasswordValidator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds an error when there are too few unique characters" do
|
it "adds an error when there are too few unique characters" do
|
||||||
|
SiteSetting.password_unique_characters = 6
|
||||||
@password = "aaaaaa5432"
|
@password = "aaaaaa5432"
|
||||||
validate
|
validate
|
||||||
expect(record.errors[:password]).to include(password_error_message(:unique_characters))
|
expect(record.errors[:password]).to include(password_error_message(:unique_characters))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't add an error when there are enough unique characters" do
|
it "doesn't add an error when there are enough unique characters" do
|
||||||
@password = "aaaaa54321"
|
@password = "aaaaa54322"
|
||||||
validate
|
validate
|
||||||
expect(record.errors[:password]).not_to be_present
|
expect(record.errors[:password]).not_to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it "counts capital letters as different" do
|
it "counts capital letters as different" do
|
||||||
@password = "aaaAaa5432"
|
@password = "aaaAaa543A"
|
||||||
validate
|
validate
|
||||||
expect(record.errors[:password]).not_to be_present
|
expect(record.errors[:password]).not_to be_present
|
||||||
end
|
end
|
||||||
|
|
|
@ -613,9 +613,9 @@ describe UsersController do
|
||||||
auth[:authenticator_name] = 'twitter'
|
auth[:authenticator_name] = 'twitter'
|
||||||
auth[:extra_data] = twitter_auth
|
auth[:extra_data] = twitter_auth
|
||||||
|
|
||||||
TwitterUserInfo.expects(:create)
|
|
||||||
|
|
||||||
post_user
|
post_user
|
||||||
|
|
||||||
|
expect(TwitterUserInfo.count).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue