blob: c46a092d2d91e16b350541b22e9a7db74f4452d5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
require 'cases/helper'
require 'models/user'
class SecurePasswordTest < ActiveModel::TestCase
setup do
@user = User.new
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?
assert_equal ["must be longer than 6 characters"], @user.errors[:password]
@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
end
|