authlogic 3.8.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/authlogic/acts_as_authentic/base.rb +33 -36
- data/lib/authlogic/acts_as_authentic/email.rb +8 -141
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +17 -10
- data/lib/authlogic/acts_as_authentic/login.rb +14 -165
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +13 -10
- data/lib/authlogic/acts_as_authentic/password.rb +186 -254
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +30 -22
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +19 -18
- data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +83 -0
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +94 -62
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +28 -14
- data/lib/authlogic/config.rb +29 -10
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +43 -13
- data/lib/authlogic/controller_adapters/rack_adapter.rb +11 -5
- data/lib/authlogic/controller_adapters/rails_adapter.rb +11 -29
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +8 -2
- data/lib/authlogic/cookie_credentials.rb +63 -0
- data/lib/authlogic/crypto_providers/bcrypt.rb +24 -18
- data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
- data/lib/authlogic/crypto_providers/md5.rb +8 -6
- data/lib/authlogic/crypto_providers/scrypt.rb +24 -17
- data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
- data/lib/authlogic/crypto_providers/sha1.rb +12 -5
- data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
- data/lib/authlogic/crypto_providers/sha256.rb +18 -9
- data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
- data/lib/authlogic/crypto_providers/sha512.rb +9 -26
- data/lib/authlogic/crypto_providers.rb +77 -1
- data/lib/authlogic/errors.rb +35 -0
- data/lib/authlogic/i18n/translator.rb +4 -1
- data/lib/authlogic/i18n.rb +29 -20
- data/lib/authlogic/random.rb +12 -28
- data/lib/authlogic/session/base.rb +2087 -33
- data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
- data/lib/authlogic/test_case/mock_controller.rb +7 -4
- data/lib/authlogic/test_case/mock_cookie_jar.rb +19 -3
- data/lib/authlogic/test_case/mock_logger.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +8 -3
- data/lib/authlogic/test_case/rails_request_adapter.rb +5 -2
- data/lib/authlogic/test_case.rb +74 -2
- data/lib/authlogic/version.rb +22 -0
- data/lib/authlogic.rb +33 -54
- metadata +208 -234
- data/.github/ISSUE_TEMPLATE.md +0 -13
- data/.gitignore +0 -14
- data/.rubocop.yml +0 -33
- data/.rubocop_todo.yml +0 -391
- data/.travis.yml +0 -48
- data/CHANGELOG.md +0 -5
- data/CONTRIBUTING.md +0 -60
- data/Gemfile +0 -5
- data/LICENSE +0 -20
- data/README.md +0 -294
- data/Rakefile +0 -21
- data/authlogic.gemspec +0 -27
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -70
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -32
- data/lib/authlogic/authenticates_many/association.rb +0 -50
- data/lib/authlogic/authenticates_many/base.rb +0 -65
- data/lib/authlogic/crypto_providers/aes256.rb +0 -66
- data/lib/authlogic/crypto_providers/wordpress.rb +0 -43
- data/lib/authlogic/regex.rb +0 -48
- data/lib/authlogic/session/activation.rb +0 -70
- data/lib/authlogic/session/active_record_trickery.rb +0 -61
- data/lib/authlogic/session/brute_force_protection.rb +0 -120
- data/lib/authlogic/session/callbacks.rb +0 -105
- data/lib/authlogic/session/cookies.rb +0 -244
- data/lib/authlogic/session/existence.rb +0 -93
- data/lib/authlogic/session/foundation.rb +0 -55
- data/lib/authlogic/session/http_auth.rb +0 -100
- data/lib/authlogic/session/id.rb +0 -48
- data/lib/authlogic/session/klass.rb +0 -70
- data/lib/authlogic/session/magic_columns.rb +0 -116
- data/lib/authlogic/session/magic_states.rb +0 -76
- data/lib/authlogic/session/params.rb +0 -116
- data/lib/authlogic/session/password.rb +0 -308
- data/lib/authlogic/session/perishable_token.rb +0 -23
- data/lib/authlogic/session/persistence.rb +0 -71
- data/lib/authlogic/session/priority_record.rb +0 -35
- data/lib/authlogic/session/scopes.rb +0 -119
- data/lib/authlogic/session/session.rb +0 -67
- data/lib/authlogic/session/timeout.rb +0 -103
- data/lib/authlogic/session/unauthorized_record.rb +0 -51
- data/lib/authlogic/session/validation.rb +0 -93
- data/test/acts_as_authentic_test/base_test.rb +0 -25
- data/test/acts_as_authentic_test/email_test.rb +0 -240
- data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -62
- data/test/acts_as_authentic_test/login_test.rb +0 -156
- data/test/acts_as_authentic_test/magic_columns_test.rb +0 -27
- data/test/acts_as_authentic_test/password_test.rb +0 -249
- data/test/acts_as_authentic_test/perishable_token_test.rb +0 -90
- data/test/acts_as_authentic_test/persistence_token_test.rb +0 -56
- data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -37
- data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -96
- data/test/acts_as_authentic_test/single_access_test.rb +0 -44
- data/test/authenticates_many_test.rb +0 -31
- data/test/config_test.rb +0 -36
- data/test/crypto_provider_test/aes256_test.rb +0 -14
- data/test/crypto_provider_test/bcrypt_test.rb +0 -14
- data/test/crypto_provider_test/scrypt_test.rb +0 -14
- data/test/crypto_provider_test/sha1_test.rb +0 -23
- data/test/crypto_provider_test/sha256_test.rb +0 -14
- data/test/crypto_provider_test/sha512_test.rb +0 -14
- data/test/fixtures/companies.yml +0 -5
- data/test/fixtures/employees.yml +0 -17
- data/test/fixtures/projects.yml +0 -3
- data/test/fixtures/users.yml +0 -41
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-5.0.x +0 -6
- data/test/gemfiles/Gemfile.rails-5.1.x +0 -6
- data/test/gemfiles/Gemfile.rails-5.2.x +0 -6
- data/test/i18n/lol.yml +0 -4
- data/test/i18n_test.rb +0 -33
- data/test/libs/affiliate.rb +0 -7
- data/test/libs/company.rb +0 -6
- data/test/libs/employee.rb +0 -7
- data/test/libs/employee_session.rb +0 -2
- data/test/libs/ldaper.rb +0 -3
- data/test/libs/project.rb +0 -3
- data/test/libs/user.rb +0 -7
- data/test/libs/user_session.rb +0 -25
- data/test/random_test.rb +0 -43
- data/test/session_test/activation_test.rb +0 -43
- data/test/session_test/active_record_trickery_test.rb +0 -75
- data/test/session_test/brute_force_protection_test.rb +0 -108
- data/test/session_test/callbacks_test.rb +0 -34
- data/test/session_test/cookies_test.rb +0 -201
- data/test/session_test/credentials_test.rb +0 -0
- data/test/session_test/existence_test.rb +0 -75
- data/test/session_test/foundation_test.rb +0 -6
- data/test/session_test/http_auth_test.rb +0 -56
- data/test/session_test/id_test.rb +0 -17
- data/test/session_test/klass_test.rb +0 -40
- data/test/session_test/magic_columns_test.rb +0 -62
- data/test/session_test/magic_states_test.rb +0 -58
- data/test/session_test/params_test.rb +0 -53
- data/test/session_test/password_test.rb +0 -105
- data/test/session_test/perishability_test.rb +0 -15
- data/test/session_test/persistence_test.rb +0 -32
- data/test/session_test/scopes_test.rb +0 -60
- data/test/session_test/session_test.rb +0 -78
- data/test/session_test/timeout_test.rb +0 -82
- data/test/session_test/unauthorized_record_test.rb +0 -13
- data/test/session_test/validation_test.rb +0 -23
- data/test/test_helper.rb +0 -233
@@ -1,156 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActsAsAuthenticTest
|
4
|
-
class LoginTest < ActiveSupport::TestCase
|
5
|
-
def test_login_field_config
|
6
|
-
assert_equal :login, User.login_field
|
7
|
-
assert_nil Employee.login_field
|
8
|
-
|
9
|
-
User.login_field = :nope
|
10
|
-
assert_equal :nope, User.login_field
|
11
|
-
User.login_field :login
|
12
|
-
assert_equal :login, User.login_field
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_validate_login_field_config
|
16
|
-
assert User.validate_login_field
|
17
|
-
assert Employee.validate_login_field
|
18
|
-
|
19
|
-
User.validate_login_field = false
|
20
|
-
refute User.validate_login_field
|
21
|
-
User.validate_login_field true
|
22
|
-
assert User.validate_login_field
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_validates_length_of_login_field_options_config
|
26
|
-
assert_equal({ :within => 3..100 }, User.validates_length_of_login_field_options)
|
27
|
-
assert_equal({ :within => 3..100 }, Employee.validates_length_of_login_field_options)
|
28
|
-
|
29
|
-
User.validates_length_of_login_field_options = { :yes => "no" }
|
30
|
-
assert_equal({ :yes => "no" }, User.validates_length_of_login_field_options)
|
31
|
-
User.validates_length_of_login_field_options({ :within => 3..100 })
|
32
|
-
assert_equal({ :within => 3..100 }, User.validates_length_of_login_field_options)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_validates_format_of_login_field_options_config
|
36
|
-
default = {
|
37
|
-
:with => /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
|
38
|
-
:message => proc do
|
39
|
-
I18n.t(
|
40
|
-
'error_messages.login_invalid',
|
41
|
-
:default => "should use only letters, numbers, spaces, and .-_@+ please."
|
42
|
-
)
|
43
|
-
end
|
44
|
-
}
|
45
|
-
default_message = default.delete(:message).call
|
46
|
-
|
47
|
-
options = User.validates_format_of_login_field_options
|
48
|
-
message = options.delete(:message)
|
49
|
-
assert message.is_a?(Proc)
|
50
|
-
assert_equal default_message, message.call
|
51
|
-
assert_equal default, options
|
52
|
-
|
53
|
-
options = Employee.validates_format_of_login_field_options
|
54
|
-
message = options.delete(:message)
|
55
|
-
assert message.is_a?(Proc)
|
56
|
-
assert_equal default_message, message.call
|
57
|
-
assert_equal default, options
|
58
|
-
|
59
|
-
User.validates_format_of_login_field_options = { :yes => "no" }
|
60
|
-
assert_equal({ :yes => "no" }, User.validates_format_of_login_field_options)
|
61
|
-
User.validates_format_of_login_field_options default
|
62
|
-
assert_equal default, User.validates_format_of_login_field_options
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_validates_uniqueness_of_login_field_options_config
|
66
|
-
default = { :case_sensitive => false, :scope => User.validations_scope, :if => "#{User.login_field}_changed?".to_sym }
|
67
|
-
assert_equal default, User.validates_uniqueness_of_login_field_options
|
68
|
-
|
69
|
-
User.validates_uniqueness_of_login_field_options = { :yes => "no" }
|
70
|
-
assert_equal({ :yes => "no" }, User.validates_uniqueness_of_login_field_options)
|
71
|
-
User.validates_uniqueness_of_login_field_options default
|
72
|
-
assert_equal default, User.validates_uniqueness_of_login_field_options
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_validates_length_of_login_field
|
76
|
-
u = User.new
|
77
|
-
u.login = "a"
|
78
|
-
refute u.valid?
|
79
|
-
refute u.errors[:login].empty?
|
80
|
-
|
81
|
-
u.login = "aaaaaaaaaa"
|
82
|
-
refute u.valid?
|
83
|
-
assert u.errors[:login].empty?
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_validates_format_of_login_field
|
87
|
-
u = User.new
|
88
|
-
u.login = "fdsf@^&*"
|
89
|
-
refute u.valid?
|
90
|
-
refute u.errors[:login].empty?
|
91
|
-
|
92
|
-
u.login = "fdsfdsfdsfdsfs"
|
93
|
-
refute u.valid?
|
94
|
-
assert u.errors[:login].empty?
|
95
|
-
|
96
|
-
u.login = "dakota.dux+1@gmail.com"
|
97
|
-
refute u.valid?
|
98
|
-
assert u.errors[:login].empty?
|
99
|
-
|
100
|
-
u.login = "marks .-_@+"
|
101
|
-
refute u.valid?
|
102
|
-
assert u.errors[:login].empty?
|
103
|
-
|
104
|
-
u.login = " space"
|
105
|
-
refute u.valid?
|
106
|
-
refute u.errors[:login].empty?
|
107
|
-
|
108
|
-
u.login = ".dot"
|
109
|
-
refute u.valid?
|
110
|
-
refute u.errors[:login].empty?
|
111
|
-
|
112
|
-
u.login = "-hyphen"
|
113
|
-
refute u.valid?
|
114
|
-
refute u.errors[:login].empty?
|
115
|
-
|
116
|
-
u.login = "_underscore"
|
117
|
-
refute u.valid?
|
118
|
-
assert u.errors[:login].empty?
|
119
|
-
|
120
|
-
u.login = "@atmark"
|
121
|
-
refute u.valid?
|
122
|
-
refute u.errors[:login].empty?
|
123
|
-
|
124
|
-
u.login = "+plus"
|
125
|
-
refute u.valid?
|
126
|
-
refute u.errors[:login].empty?
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_validates_uniqueness_of_login_field
|
130
|
-
u = User.new
|
131
|
-
u.login = "bjohnson"
|
132
|
-
refute u.valid?
|
133
|
-
refute u.errors[:login].empty?
|
134
|
-
|
135
|
-
u.login = "BJOHNSON"
|
136
|
-
refute u.valid?
|
137
|
-
refute u.errors[:login].empty?
|
138
|
-
|
139
|
-
u.login = "fdsfdsf"
|
140
|
-
refute u.valid?
|
141
|
-
assert u.errors[:login].empty?
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_find_by_smart_case_login_field
|
145
|
-
ben = users(:ben)
|
146
|
-
assert_equal ben, User.find_by_smart_case_login_field("bjohnson")
|
147
|
-
assert_equal ben, User.find_by_smart_case_login_field("BJOHNSON")
|
148
|
-
assert_equal ben, User.find_by_smart_case_login_field("Bjohnson")
|
149
|
-
|
150
|
-
drew = employees(:drew)
|
151
|
-
assert_equal drew, Employee.find_by_smart_case_login_field("dgainor@binarylogic.com")
|
152
|
-
assert_equal drew, Employee.find_by_smart_case_login_field("Dgainor@binarylogic.com")
|
153
|
-
assert_equal drew, Employee.find_by_smart_case_login_field("DGAINOR@BINARYLOGIC.COM")
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActsAsAuthenticTest
|
4
|
-
class MagicColumnsTest < ActiveSupport::TestCase
|
5
|
-
def test_validates_numericality_of_login_count
|
6
|
-
u = User.new
|
7
|
-
u.login_count = -1
|
8
|
-
refute u.valid?
|
9
|
-
refute u.errors[:login_count].empty?
|
10
|
-
|
11
|
-
u.login_count = 0
|
12
|
-
refute u.valid?
|
13
|
-
assert u.errors[:login_count].empty?
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_validates_numericality_of_failed_login_count
|
17
|
-
u = User.new
|
18
|
-
u.failed_login_count = -1
|
19
|
-
refute u.valid?
|
20
|
-
refute u.errors[:failed_login_count].empty?
|
21
|
-
|
22
|
-
u.failed_login_count = 0
|
23
|
-
refute u.valid?
|
24
|
-
assert u.errors[:failed_login_count].empty?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,249 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActsAsAuthenticTest
|
4
|
-
class PasswordTest < ActiveSupport::TestCase
|
5
|
-
i_suck_and_my_tests_are_order_dependent! # If test_human_name is executed after test_i18n_of_human_name the test will fail.
|
6
|
-
def test_crypted_password_field_config
|
7
|
-
assert_equal :crypted_password, User.crypted_password_field
|
8
|
-
assert_equal :crypted_password, Employee.crypted_password_field
|
9
|
-
|
10
|
-
User.crypted_password_field = :nope
|
11
|
-
assert_equal :nope, User.crypted_password_field
|
12
|
-
User.crypted_password_field :crypted_password
|
13
|
-
assert_equal :crypted_password, User.crypted_password_field
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_password_salt_field_config
|
17
|
-
assert_equal :password_salt, User.password_salt_field
|
18
|
-
assert_equal :password_salt, Employee.password_salt_field
|
19
|
-
|
20
|
-
User.password_salt_field = :nope
|
21
|
-
assert_equal :nope, User.password_salt_field
|
22
|
-
User.password_salt_field :password_salt
|
23
|
-
assert_equal :password_salt, User.password_salt_field
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_ignore_blank_passwords_config
|
27
|
-
assert User.ignore_blank_passwords
|
28
|
-
assert Employee.ignore_blank_passwords
|
29
|
-
|
30
|
-
User.ignore_blank_passwords = false
|
31
|
-
refute User.ignore_blank_passwords
|
32
|
-
User.ignore_blank_passwords true
|
33
|
-
assert User.ignore_blank_passwords
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_check_passwords_against_database
|
37
|
-
assert User.check_passwords_against_database
|
38
|
-
User.check_passwords_against_database = false
|
39
|
-
refute User.check_passwords_against_database
|
40
|
-
User.check_passwords_against_database true
|
41
|
-
assert User.check_passwords_against_database
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_validate_password_field_config
|
45
|
-
assert User.validate_password_field
|
46
|
-
assert Employee.validate_password_field
|
47
|
-
|
48
|
-
User.validate_password_field = false
|
49
|
-
refute User.validate_password_field
|
50
|
-
User.validate_password_field true
|
51
|
-
assert User.validate_password_field
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_validates_length_of_password_field_options_config
|
55
|
-
default = { :minimum => 8, :if => :require_password? }
|
56
|
-
assert_equal default, User.validates_length_of_password_field_options
|
57
|
-
assert_equal default, Employee.validates_length_of_password_field_options
|
58
|
-
|
59
|
-
User.validates_length_of_password_field_options = { :yes => "no" }
|
60
|
-
assert_equal({ :yes => "no" }, User.validates_length_of_password_field_options)
|
61
|
-
User.validates_length_of_password_field_options default
|
62
|
-
assert_equal default, User.validates_length_of_password_field_options
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_validates_confirmation_of_password_field_options_config
|
66
|
-
default = { :if => :require_password? }
|
67
|
-
assert_equal default, User.validates_confirmation_of_password_field_options
|
68
|
-
assert_equal default, Employee.validates_confirmation_of_password_field_options
|
69
|
-
|
70
|
-
User.validates_confirmation_of_password_field_options = { :yes => "no" }
|
71
|
-
assert_equal({ :yes => "no" }, User.validates_confirmation_of_password_field_options)
|
72
|
-
User.validates_confirmation_of_password_field_options default
|
73
|
-
assert_equal default, User.validates_confirmation_of_password_field_options
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_validates_length_of_password_confirmation_field_options_config
|
77
|
-
default = { :minimum => 8, :if => :require_password? }
|
78
|
-
assert_equal default, User.validates_length_of_password_confirmation_field_options
|
79
|
-
assert_equal default, Employee.validates_length_of_password_confirmation_field_options
|
80
|
-
|
81
|
-
User.validates_length_of_password_confirmation_field_options = { :yes => "no" }
|
82
|
-
assert_equal({ :yes => "no" }, User.validates_length_of_password_confirmation_field_options)
|
83
|
-
User.validates_length_of_password_confirmation_field_options default
|
84
|
-
assert_equal default, User.validates_length_of_password_confirmation_field_options
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_crypto_provider_config
|
88
|
-
assert_equal Authlogic::CryptoProviders::SCrypt, User.crypto_provider
|
89
|
-
assert_equal Authlogic::CryptoProviders::AES256, Employee.crypto_provider
|
90
|
-
|
91
|
-
User.crypto_provider = Authlogic::CryptoProviders::BCrypt
|
92
|
-
assert_equal Authlogic::CryptoProviders::BCrypt, User.crypto_provider
|
93
|
-
User.crypto_provider Authlogic::CryptoProviders::Sha512
|
94
|
-
assert_equal Authlogic::CryptoProviders::Sha512, User.crypto_provider
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_transition_from_crypto_providers_config
|
98
|
-
assert_equal [Authlogic::CryptoProviders::Sha512], User.transition_from_crypto_providers
|
99
|
-
assert_equal [], Employee.transition_from_crypto_providers
|
100
|
-
|
101
|
-
User.transition_from_crypto_providers = [Authlogic::CryptoProviders::BCrypt]
|
102
|
-
assert_equal [Authlogic::CryptoProviders::BCrypt], User.transition_from_crypto_providers
|
103
|
-
User.transition_from_crypto_providers []
|
104
|
-
assert_equal [], User.transition_from_crypto_providers
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_validates_length_of_password
|
108
|
-
u = User.new(login: "abcde", email: "abcde@test.com", password: "abcdefgh", password_confirmation: "abcdefgh")
|
109
|
-
assert u.valid?
|
110
|
-
|
111
|
-
u.password = u.password_confirmation = "abcdef"
|
112
|
-
refute u.valid?
|
113
|
-
|
114
|
-
assert u.errors[:password].include?("is too short (minimum is 8 characters)")
|
115
|
-
assert u.errors[:password_confirmation].include?("is too short (minimum is 8 characters)")
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_validates_confirmation_of_password
|
119
|
-
u = User.new(login: "abcde", email: "abcde@test.com", password: "abcdefgh", password_confirmation: "abcdefgh")
|
120
|
-
assert u.valid?
|
121
|
-
|
122
|
-
u.password_confirmation = "abcdefghij"
|
123
|
-
refute u.valid?
|
124
|
-
|
125
|
-
if ActiveModel.respond_to?(:version) and ActiveModel.version.segments.first >= 4
|
126
|
-
assert u.errors[:password_confirmation].include?("doesn't match Password")
|
127
|
-
else
|
128
|
-
assert u.errors[:password].include?("doesn't match confirmation")
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_validates_length_of_password_confirmation
|
133
|
-
u = User.new
|
134
|
-
|
135
|
-
u.password = "testpass"
|
136
|
-
u.password_confirmation = ""
|
137
|
-
refute u.valid?
|
138
|
-
refute u.errors[:password_confirmation].empty?
|
139
|
-
|
140
|
-
u.password_confirmation = "testpass"
|
141
|
-
refute u.valid?
|
142
|
-
assert u.errors[:password_confirmation].empty?
|
143
|
-
|
144
|
-
ben = users(:ben)
|
145
|
-
assert ben.valid?
|
146
|
-
|
147
|
-
ben.password = "newpasswd"
|
148
|
-
refute ben.valid?
|
149
|
-
refute ben.errors[:password_confirmation].empty?
|
150
|
-
|
151
|
-
ben.password_confirmation = "newpasswd"
|
152
|
-
assert ben.valid?
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_password
|
156
|
-
u = User.new
|
157
|
-
old_password_salt = u.password_salt
|
158
|
-
old_crypted_password = u.crypted_password
|
159
|
-
u.password = "test"
|
160
|
-
assert_not_equal old_password_salt, u.password_salt
|
161
|
-
assert_not_equal old_crypted_password, u.crypted_password
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_transitioning_password
|
165
|
-
ben = users(:ben)
|
166
|
-
|
167
|
-
transition_password_to(Authlogic::CryptoProviders::BCrypt, ben)
|
168
|
-
transition_password_to(
|
169
|
-
Authlogic::CryptoProviders::Sha1,
|
170
|
-
ben,
|
171
|
-
[Authlogic::CryptoProviders::Sha512, Authlogic::CryptoProviders::BCrypt]
|
172
|
-
)
|
173
|
-
transition_password_to(
|
174
|
-
Authlogic::CryptoProviders::Sha512,
|
175
|
-
ben,
|
176
|
-
[Authlogic::CryptoProviders::Sha1, Authlogic::CryptoProviders::BCrypt]
|
177
|
-
)
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_checks_password_against_database
|
181
|
-
ben = users(:aaron)
|
182
|
-
ben.password = "new pass"
|
183
|
-
refute ben.valid_password?("new pass")
|
184
|
-
assert ben.valid_password?("aaronrocks")
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_checks_password_against_database_and_always_fails_on_new_records
|
188
|
-
user = User.new
|
189
|
-
user.password = "new pass"
|
190
|
-
refute user.valid_password?("new pass")
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_checks_password_against_object
|
194
|
-
ben = users(:ben)
|
195
|
-
ben.password = "new pass"
|
196
|
-
assert ben.valid_password?("new pass", false)
|
197
|
-
refute ben.valid_password?("benrocks", false)
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_reset_password
|
201
|
-
ben = users(:ben)
|
202
|
-
old_crypted_password = ben.crypted_password
|
203
|
-
old_password_salt = ben.password_salt
|
204
|
-
|
205
|
-
# soft reset
|
206
|
-
ben.reset_password
|
207
|
-
assert_not_equal old_crypted_password, ben.crypted_password
|
208
|
-
assert_not_equal old_password_salt, ben.password_salt
|
209
|
-
|
210
|
-
# make sure it didn't go into the db
|
211
|
-
ben.reload
|
212
|
-
assert_equal old_crypted_password, ben.crypted_password
|
213
|
-
assert_equal old_password_salt, ben.password_salt
|
214
|
-
|
215
|
-
# hard reset
|
216
|
-
assert ben.reset_password!
|
217
|
-
assert_not_equal old_crypted_password, ben.crypted_password
|
218
|
-
assert_not_equal old_password_salt, ben.password_salt
|
219
|
-
|
220
|
-
# make sure it did go into the db
|
221
|
-
ben.reload
|
222
|
-
assert_not_equal old_crypted_password, ben.crypted_password
|
223
|
-
assert_not_equal old_password_salt, ben.password_salt
|
224
|
-
end
|
225
|
-
|
226
|
-
private
|
227
|
-
|
228
|
-
def transition_password_to(crypto_provider, records, from_crypto_providers = Authlogic::CryptoProviders::Sha512)
|
229
|
-
records = [records] unless records.is_a?(Array)
|
230
|
-
User.acts_as_authentic do |c|
|
231
|
-
c.crypto_provider = crypto_provider
|
232
|
-
c.transition_from_crypto_providers = from_crypto_providers
|
233
|
-
end
|
234
|
-
records.each do |record|
|
235
|
-
old_hash = record.crypted_password
|
236
|
-
old_persistence_token = record.persistence_token
|
237
|
-
assert record.valid_password?(password_for(record))
|
238
|
-
assert_not_equal old_hash.to_s, record.crypted_password.to_s
|
239
|
-
assert_not_equal old_persistence_token.to_s, record.persistence_token.to_s
|
240
|
-
|
241
|
-
old_hash = record.crypted_password
|
242
|
-
old_persistence_token = record.persistence_token
|
243
|
-
assert record.valid_password?(password_for(record))
|
244
|
-
assert_equal old_hash.to_s, record.crypted_password.to_s
|
245
|
-
assert_equal old_persistence_token.to_s, record.persistence_token.to_s
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActsAsAuthenticTest
|
4
|
-
class PerishableTokenTest < ActiveSupport::TestCase
|
5
|
-
def test_perishable_token_valid_for_config
|
6
|
-
assert_equal 10.minutes.to_i, User.perishable_token_valid_for
|
7
|
-
assert_equal 10.minutes.to_i, Employee.perishable_token_valid_for
|
8
|
-
|
9
|
-
User.perishable_token_valid_for = 1.hour
|
10
|
-
assert_equal 1.hour.to_i, User.perishable_token_valid_for
|
11
|
-
User.perishable_token_valid_for 10.minutes
|
12
|
-
assert_equal 10.minutes.to_i, User.perishable_token_valid_for
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_disable_perishable_token_maintenance_config
|
16
|
-
refute User.disable_perishable_token_maintenance
|
17
|
-
refute Employee.disable_perishable_token_maintenance
|
18
|
-
|
19
|
-
User.disable_perishable_token_maintenance = true
|
20
|
-
assert User.disable_perishable_token_maintenance
|
21
|
-
User.disable_perishable_token_maintenance false
|
22
|
-
refute User.disable_perishable_token_maintenance
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_validates_uniqueness_of_perishable_token
|
26
|
-
u = User.new
|
27
|
-
u.perishable_token = users(:ben).perishable_token
|
28
|
-
refute u.valid?
|
29
|
-
refute u.errors[:perishable_token].empty?
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_before_save_reset_perishable_token
|
33
|
-
ben = users(:ben)
|
34
|
-
old_perishable_token = ben.perishable_token
|
35
|
-
assert ben.save
|
36
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_reset_perishable_token
|
40
|
-
ben = users(:ben)
|
41
|
-
old_perishable_token = ben.perishable_token
|
42
|
-
|
43
|
-
assert ben.reset_perishable_token
|
44
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
45
|
-
|
46
|
-
ben.reload
|
47
|
-
assert_equal old_perishable_token, ben.perishable_token
|
48
|
-
|
49
|
-
assert ben.reset_perishable_token!
|
50
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
51
|
-
|
52
|
-
ben.reload
|
53
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_find_using_perishable_token
|
57
|
-
ben = users(:ben)
|
58
|
-
assert_equal ben, User.find_using_perishable_token(ben.perishable_token)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_find_using_perishable_token_when_perished
|
62
|
-
ben = users(:ben)
|
63
|
-
ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{1.week.ago.to_s(:db)}' where id = #{ben.id}")
|
64
|
-
assert_nil User.find_using_perishable_token(ben.perishable_token)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_find_using_perishable_token_when_perished_2
|
68
|
-
User.perishable_token_valid_for = 1.minute
|
69
|
-
ben = users(:ben)
|
70
|
-
ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{2.minutes.ago.to_s(:db)}' where id = #{ben.id}")
|
71
|
-
assert_nil User.find_using_perishable_token(ben.perishable_token)
|
72
|
-
User.perishable_token_valid_for = 10.minutes
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_find_using_perishable_token_when_passing_threshold
|
76
|
-
User.perishable_token_valid_for = 1.minute
|
77
|
-
ben = users(:ben)
|
78
|
-
ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{10.minutes.ago.to_s(:db)}' where id = #{ben.id}")
|
79
|
-
assert_nil User.find_using_perishable_token(ben.perishable_token, 5.minutes)
|
80
|
-
assert_equal ben, User.find_using_perishable_token(ben.perishable_token, 20.minutes)
|
81
|
-
User.perishable_token_valid_for = 10.minutes
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_find_perishable_token_with_bang
|
85
|
-
assert_raises ActiveRecord::RecordNotFound do
|
86
|
-
User.find_using_perishable_token!('some_bad_value')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActsAsAuthenticTest
|
4
|
-
class PersistenceTokenTest < ActiveSupport::TestCase
|
5
|
-
def test_after_password_set_reset_persistence_token
|
6
|
-
ben = users(:ben)
|
7
|
-
old_persistence_token = ben.persistence_token
|
8
|
-
ben.password = "newpass"
|
9
|
-
assert_not_equal old_persistence_token, ben.persistence_token
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_after_password_verification_reset_persistence_token
|
13
|
-
aaron = users(:aaron)
|
14
|
-
old_persistence_token = aaron.persistence_token
|
15
|
-
|
16
|
-
assert aaron.valid_password?(password_for(aaron))
|
17
|
-
assert_equal old_persistence_token, aaron.reload.persistence_token
|
18
|
-
|
19
|
-
# only update it if it is nil
|
20
|
-
assert aaron.update_attribute(:persistence_token, nil)
|
21
|
-
assert aaron.valid_password?(password_for(aaron))
|
22
|
-
assert_not_equal old_persistence_token, aaron.persistence_token
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_before_validate_reset_persistence_token
|
26
|
-
u = User.new
|
27
|
-
refute u.valid?
|
28
|
-
assert_not_nil u.persistence_token
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_forget_all
|
32
|
-
http_basic_auth_for(users(:ben)) { UserSession.find }
|
33
|
-
http_basic_auth_for(users(:zack)) { UserSession.find(:ziggity_zack) }
|
34
|
-
assert UserSession.find
|
35
|
-
assert UserSession.find(:ziggity_zack)
|
36
|
-
User.forget_all
|
37
|
-
refute UserSession.find
|
38
|
-
refute UserSession.find(:ziggity_zack)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_forget
|
42
|
-
ben = users(:ben)
|
43
|
-
zack = users(:zack)
|
44
|
-
http_basic_auth_for(ben) { UserSession.find }
|
45
|
-
http_basic_auth_for(zack) { UserSession.find(:ziggity_zack) }
|
46
|
-
|
47
|
-
assert ben.reload.logged_in?
|
48
|
-
assert zack.reload.logged_in?
|
49
|
-
|
50
|
-
ben.forget!
|
51
|
-
|
52
|
-
refute UserSession.find
|
53
|
-
assert UserSession.find(:ziggity_zack)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActsAsAuthenticTest
|
4
|
-
class RestfulAuthenticationTest < ActiveSupport::TestCase
|
5
|
-
def test_act_like_restful_authentication_config
|
6
|
-
refute User.act_like_restful_authentication
|
7
|
-
refute Employee.act_like_restful_authentication
|
8
|
-
|
9
|
-
User.act_like_restful_authentication = true
|
10
|
-
assert User.act_like_restful_authentication
|
11
|
-
assert_equal Authlogic::CryptoProviders::Sha1, User.crypto_provider
|
12
|
-
assert defined?(::REST_AUTH_SITE_KEY)
|
13
|
-
assert_equal '', ::REST_AUTH_SITE_KEY
|
14
|
-
assert_equal 1, Authlogic::CryptoProviders::Sha1.stretches
|
15
|
-
|
16
|
-
User.act_like_restful_authentication false
|
17
|
-
refute User.act_like_restful_authentication
|
18
|
-
|
19
|
-
User.crypto_provider = Authlogic::CryptoProviders::Sha512
|
20
|
-
User.transition_from_crypto_providers = []
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_transition_from_restful_authentication_config
|
24
|
-
refute User.transition_from_restful_authentication
|
25
|
-
refute Employee.transition_from_restful_authentication
|
26
|
-
|
27
|
-
User.transition_from_restful_authentication = true
|
28
|
-
assert User.transition_from_restful_authentication
|
29
|
-
assert defined?(::REST_AUTH_SITE_KEY)
|
30
|
-
assert_equal '', ::REST_AUTH_SITE_KEY
|
31
|
-
assert_equal 1, Authlogic::CryptoProviders::Sha1.stretches
|
32
|
-
|
33
|
-
User.transition_from_restful_authentication false
|
34
|
-
refute User.transition_from_restful_authentication
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|