aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/secure_password_test.rb
diff options
context:
space:
mode:
authorMikel Lindsaar <mikel@rubyx.com>2010-12-19 20:39:54 +1100
committerMikel Lindsaar <mikel@rubyx.com>2010-12-19 20:39:54 +1100
commita39a3337698ca42ab158dc3b4b08ea75039b8a89 (patch)
tree094ec71054ed86e0bc71df4958423e775153ef48 /activemodel/test/cases/secure_password_test.rb
parent863de37b05900f037132656812b7ef550d096ae1 (diff)
downloadrails-a39a3337698ca42ab158dc3b4b08ea75039b8a89.tar.gz
rails-a39a3337698ca42ab158dc3b4b08ea75039b8a89.tar.bz2
rails-a39a3337698ca42ab158dc3b4b08ea75039b8a89.zip
Added ability to specify which passwords you want as weak passwords
Diffstat (limited to 'activemodel/test/cases/secure_password_test.rb')
-rw-r--r--activemodel/test/cases/secure_password_test.rb42
1 files changed, 31 insertions, 11 deletions
diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb
index e75bfca02a..5d788d7a1e 100644
--- a/activemodel/test/cases/secure_password_test.rb
+++ b/activemodel/test/cases/secure_password_test.rb
@@ -2,37 +2,57 @@ require 'cases/helper'
require 'models/user'
class SecurePasswordTest < ActiveModel::TestCase
+
setup do
+ User.weak_passwords = %w( password qwerty 123456 )
@user = User.new
end
+ test "there should be a list of default weak passwords" do
+ assert_equal %w( password qwerty 123456 ), User.weak_passwords
+ end
+
+ test "specifying the list of passwords" do
+ User.weak_passwords = %w( pass )
+ assert_equal %w( pass ), User.weak_passwords
+ end
+
+ test "adding to the list of passwords" do
+ User.weak_passwords << 'pass'
+ @user.password = "password"
+ assert !@user.valid?
+
+ @user.password = "pass"
+ assert !@user.valid?
+ end
+
test "password must be present" do
assert !@user.valid?
assert_equal 1, @user.errors.size
end
-
+
test "password must match confirmation" do
@user.password = "thiswillberight"
@user.password_confirmation = "wrong"
-
+
assert !@user.valid?
-
+
@user.password_confirmation = "thiswillberight"
-
+
assert @user.valid?
end
-
+
test "password must pass validation rules" do
@user.password = "password"
assert !@user.valid?
-
+
@user.password = "short"
assert !@user.valid?
-
+
@user.password = "plentylongenough"
assert @user.valid?
end
-
+
test "too weak passwords" do
@user.password = "012345"
assert !@user.valid?
@@ -41,14 +61,14 @@ class SecurePasswordTest < ActiveModel::TestCase
@user.password = "password"
assert !@user.valid?
assert_equal ["is too weak and common"], @user.errors[:password]
-
+
@user.password = "d9034rfjlakj34RR$!!"
assert @user.valid?
end
-
+
test "authenticate" do
@user.password = "secret"
-
+
assert !@user.authenticate("wrong")
assert @user.authenticate("secret")
end