authlogic 4.5.0 → 6.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authlogic/acts_as_authentic/base.rb +19 -19
  3. data/lib/authlogic/acts_as_authentic/email.rb +3 -170
  4. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +3 -1
  5. data/lib/authlogic/acts_as_authentic/login.rb +7 -174
  6. data/lib/authlogic/acts_as_authentic/magic_columns.rb +7 -4
  7. data/lib/authlogic/acts_as_authentic/password.rb +67 -256
  8. data/lib/authlogic/acts_as_authentic/perishable_token.rb +8 -5
  9. data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -4
  10. data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
  11. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +36 -20
  12. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +12 -8
  13. data/lib/authlogic/acts_as_authentic/single_access_token.rb +10 -8
  14. data/lib/authlogic/config.rb +9 -1
  15. data/lib/authlogic/controller_adapters/abstract_adapter.rb +28 -4
  16. data/lib/authlogic/controller_adapters/rack_adapter.rb +2 -0
  17. data/lib/authlogic/controller_adapters/rails_adapter.rb +7 -30
  18. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +6 -0
  19. data/lib/authlogic/cookie_credentials.rb +63 -0
  20. data/lib/authlogic/crypto_providers/bcrypt.rb +3 -3
  21. data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
  22. data/lib/authlogic/crypto_providers/md5.rb +6 -6
  23. data/lib/authlogic/crypto_providers/scrypt.rb +2 -0
  24. data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
  25. data/lib/authlogic/crypto_providers/sha1.rb +7 -6
  26. data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
  27. data/lib/authlogic/crypto_providers/sha256.rb +5 -0
  28. data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
  29. data/lib/authlogic/crypto_providers/sha512.rb +9 -5
  30. data/lib/authlogic/crypto_providers.rb +5 -20
  31. data/lib/authlogic/errors.rb +50 -0
  32. data/lib/authlogic/i18n/translator.rb +4 -1
  33. data/lib/authlogic/i18n.rb +3 -1
  34. data/lib/authlogic/random.rb +2 -0
  35. data/lib/authlogic/session/base.rb +2197 -39
  36. data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
  37. data/lib/authlogic/test_case/mock_api_controller.rb +52 -0
  38. data/lib/authlogic/test_case/mock_controller.rb +3 -1
  39. data/lib/authlogic/test_case/mock_cookie_jar.rb +32 -6
  40. data/lib/authlogic/test_case/mock_logger.rb +2 -0
  41. data/lib/authlogic/test_case/mock_request.rb +12 -0
  42. data/lib/authlogic/test_case/rails_request_adapter.rb +9 -1
  43. data/lib/authlogic/test_case.rb +5 -0
  44. data/lib/authlogic/version.rb +2 -1
  45. data/lib/authlogic.rb +5 -28
  46. metadata +175 -200
  47. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
  48. data/.github/ISSUE_TEMPLATE/feature_proposal.md +0 -32
  49. data/.github/triage.md +0 -86
  50. data/.gitignore +0 -15
  51. data/.rubocop.yml +0 -133
  52. data/.rubocop_todo.yml +0 -74
  53. data/.travis.yml +0 -24
  54. data/CHANGELOG.md +0 -348
  55. data/CONTRIBUTING.md +0 -91
  56. data/Gemfile +0 -6
  57. data/LICENSE +0 -20
  58. data/README.md +0 -448
  59. data/Rakefile +0 -21
  60. data/UPGRADING.md +0 -22
  61. data/authlogic.gemspec +0 -40
  62. data/doc/use_normal_rails_validation.md +0 -82
  63. data/gemfiles/Gemfile.rails-4.2.x +0 -6
  64. data/gemfiles/Gemfile.rails-5.1.x +0 -6
  65. data/gemfiles/Gemfile.rails-5.2.x +0 -6
  66. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -106
  67. data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -35
  68. data/lib/authlogic/authenticates_many/association.rb +0 -50
  69. data/lib/authlogic/authenticates_many/base.rb +0 -81
  70. data/lib/authlogic/crypto_providers/aes256.rb +0 -71
  71. data/lib/authlogic/crypto_providers/wordpress.rb +0 -72
  72. data/lib/authlogic/regex.rb +0 -79
  73. data/lib/authlogic/session/activation.rb +0 -73
  74. data/lib/authlogic/session/active_record_trickery.rb +0 -65
  75. data/lib/authlogic/session/brute_force_protection.rb +0 -127
  76. data/lib/authlogic/session/callbacks.rb +0 -153
  77. data/lib/authlogic/session/cookies.rb +0 -329
  78. data/lib/authlogic/session/existence.rb +0 -103
  79. data/lib/authlogic/session/foundation.rb +0 -105
  80. data/lib/authlogic/session/http_auth.rb +0 -107
  81. data/lib/authlogic/session/id.rb +0 -53
  82. data/lib/authlogic/session/klass.rb +0 -73
  83. data/lib/authlogic/session/magic_columns.rb +0 -119
  84. data/lib/authlogic/session/magic_states.rb +0 -82
  85. data/lib/authlogic/session/params.rb +0 -130
  86. data/lib/authlogic/session/password.rb +0 -318
  87. data/lib/authlogic/session/perishable_token.rb +0 -24
  88. data/lib/authlogic/session/persistence.rb +0 -77
  89. data/lib/authlogic/session/priority_record.rb +0 -38
  90. data/lib/authlogic/session/scopes.rb +0 -138
  91. data/lib/authlogic/session/session.rb +0 -77
  92. data/lib/authlogic/session/timeout.rb +0 -103
  93. data/lib/authlogic/session/unauthorized_record.rb +0 -56
  94. data/lib/authlogic/session/validation.rb +0 -93
  95. data/test/acts_as_authentic_test/base_test.rb +0 -27
  96. data/test/acts_as_authentic_test/email_test.rb +0 -241
  97. data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -64
  98. data/test/acts_as_authentic_test/login_test.rb +0 -153
  99. data/test/acts_as_authentic_test/magic_columns_test.rb +0 -29
  100. data/test/acts_as_authentic_test/password_test.rb +0 -263
  101. data/test/acts_as_authentic_test/perishable_token_test.rb +0 -98
  102. data/test/acts_as_authentic_test/persistence_token_test.rb +0 -62
  103. data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -48
  104. data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -150
  105. data/test/acts_as_authentic_test/single_access_test.rb +0 -46
  106. data/test/adapter_test.rb +0 -23
  107. data/test/authenticates_many_test.rb +0 -33
  108. data/test/config_test.rb +0 -38
  109. data/test/crypto_provider_test/aes256_test.rb +0 -16
  110. data/test/crypto_provider_test/bcrypt_test.rb +0 -16
  111. data/test/crypto_provider_test/scrypt_test.rb +0 -16
  112. data/test/crypto_provider_test/sha1_test.rb +0 -25
  113. data/test/crypto_provider_test/sha256_test.rb +0 -16
  114. data/test/crypto_provider_test/sha512_test.rb +0 -16
  115. data/test/crypto_provider_test/wordpress_test.rb +0 -26
  116. data/test/fixtures/companies.yml +0 -5
  117. data/test/fixtures/employees.yml +0 -17
  118. data/test/fixtures/projects.yml +0 -3
  119. data/test/fixtures/users.yml +0 -41
  120. data/test/i18n/lol.yml +0 -4
  121. data/test/i18n_test.rb +0 -35
  122. data/test/libs/affiliate.rb +0 -9
  123. data/test/libs/company.rb +0 -8
  124. data/test/libs/employee.rb +0 -9
  125. data/test/libs/employee_session.rb +0 -4
  126. data/test/libs/ldaper.rb +0 -5
  127. data/test/libs/project.rb +0 -5
  128. data/test/libs/user.rb +0 -9
  129. data/test/libs/user_session.rb +0 -27
  130. data/test/random_test.rb +0 -15
  131. data/test/session_test/activation_test.rb +0 -45
  132. data/test/session_test/active_record_trickery_test.rb +0 -78
  133. data/test/session_test/brute_force_protection_test.rb +0 -110
  134. data/test/session_test/callbacks_test.rb +0 -42
  135. data/test/session_test/cookies_test.rb +0 -244
  136. data/test/session_test/credentials_test.rb +0 -0
  137. data/test/session_test/existence_test.rb +0 -88
  138. data/test/session_test/foundation_test.rb +0 -24
  139. data/test/session_test/http_auth_test.rb +0 -60
  140. data/test/session_test/id_test.rb +0 -19
  141. data/test/session_test/klass_test.rb +0 -42
  142. data/test/session_test/magic_columns_test.rb +0 -62
  143. data/test/session_test/magic_states_test.rb +0 -60
  144. data/test/session_test/params_test.rb +0 -61
  145. data/test/session_test/password_test.rb +0 -107
  146. data/test/session_test/perishability_test.rb +0 -17
  147. data/test/session_test/persistence_test.rb +0 -35
  148. data/test/session_test/scopes_test.rb +0 -68
  149. data/test/session_test/session_test.rb +0 -80
  150. data/test/session_test/timeout_test.rb +0 -84
  151. data/test/session_test/unauthorized_record_test.rb +0 -15
  152. data/test/session_test/validation_test.rb +0 -25
  153. data/test/test_helper.rb +0 -272
@@ -1,241 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module ActsAsAuthenticTest
6
- class EmailTest < ActiveSupport::TestCase
7
- GOOD_ASCII_EMAILS = [
8
- "a@a.com",
9
- "damien+test1...etc..@mydomain.com",
10
- "dakota.dux+1@gmail.com",
11
- "dakota.d'ux@gmail.com",
12
- "a&b@c.com",
13
- "someuser@somedomain.travelersinsurance"
14
- ].freeze
15
-
16
- BAD_ASCII_EMAILS = [
17
- "",
18
- "aaaaaaaaaaaaa",
19
- "question?mark@gmail.com",
20
- "backslash@g\\mail.com",
21
- "<script>alert(123);</script>\nnobody@example.com",
22
- "someuser@somedomain.isreallytoolongandimeanreallytoolong"
23
- ].freeze
24
-
25
- # http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
26
- GOOD_ISO88591_EMAILS = [
27
- "töm.öm@dömain.fi", # https://github.com/binarylogic/authlogic/issues/176
28
- "Pelé@examplé.com", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
29
- ].freeze
30
-
31
- BAD_ISO88591_EMAILS = [
32
- "",
33
- "öm(@ava.fi", # L paren
34
- "é)@domain.com", # R paren
35
- "é[@example.com", # L bracket
36
- "question?mark@gmail.com", # question mark
37
- "back\\slash@gmail.com", # backslash
38
- ].freeze
39
-
40
- GOOD_UTF8_EMAILS = [
41
- "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
42
- "我本@屋企.香港", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
43
- "甲斐@黒川.日買", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
44
- "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
45
- "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
46
- ].freeze
47
-
48
- BAD_UTF8_EMAILS = [
49
- "",
50
- ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
51
- "δκιμή@παράδεγμα.δ", # short TLD
52
- "öm(@ava.fi", # L paren
53
- "é)@domain.com", # R paren
54
- "é[@example.com", # L bracket
55
- "δ]@πράιγμα.δοκμή", # R bracket
56
- "我\.香港", # slash
57
- "甲;.日本", # semicolon
58
- "ч:@ящик-с-пельнами.рф", # colon
59
- "斐,.みんな", # comma
60
- "香<.香港", # less than
61
- "我>.香港", # greater than
62
- "我?本@屋企.香港", # question mark
63
- "чебурша@ьн\\ами.рф", # backslash
64
- "user@domain.com%0A<script>alert('hello')</script>"
65
- ].freeze
66
-
67
- def test_email_field_config
68
- assert_equal :email, User.email_field
69
- assert_equal :email, Employee.email_field
70
-
71
- User.email_field = :nope
72
- assert_equal :nope, User.email_field
73
- User.email_field :email
74
- assert_equal :email, User.email_field
75
- end
76
-
77
- def test_validate_email_field_config
78
- assert User.validate_email_field
79
- assert Employee.validate_email_field
80
-
81
- User.validate_email_field = false
82
- refute User.validate_email_field
83
- User.validate_email_field true
84
- assert User.validate_email_field
85
- end
86
-
87
- def test_validates_length_of_email_field_options_config
88
- assert_equal({ maximum: 100 }, User.validates_length_of_email_field_options)
89
- assert_equal({ maximum: 100 }, Employee.validates_length_of_email_field_options)
90
-
91
- User.validates_length_of_email_field_options = { yes: "no" }
92
- assert_equal({ yes: "no" }, User.validates_length_of_email_field_options)
93
- User.validates_length_of_email_field_options(within: 6..100)
94
- assert_equal({ within: 6..100 }, User.validates_length_of_email_field_options)
95
- end
96
-
97
- def test_validates_format_of_email_field_options_config
98
- default = {
99
- with: Authlogic::Regex::EMAIL,
100
- message: proc do
101
- I18n.t(
102
- "error_messages.email_invalid",
103
- default: "should look like an email address."
104
- )
105
- end
106
- }
107
- default_message = default.delete(:message).call
108
-
109
- options = User.validates_format_of_email_field_options
110
- message = options.delete(:message)
111
- assert message.is_a?(Proc)
112
- assert_equal default_message, message.call
113
- assert_equal default, options
114
-
115
- options = Employee.validates_format_of_email_field_options
116
- message = options.delete(:message)
117
- assert message.is_a?(Proc)
118
- assert_equal default_message, message.call
119
- assert_equal default, options
120
-
121
- User.validates_format_of_email_field_options = { yes: "no" }
122
- assert_equal({ yes: "no" }, User.validates_format_of_email_field_options)
123
- User.validates_format_of_email_field_options default
124
- assert_equal default, User.validates_format_of_email_field_options
125
-
126
- with_email_nonascii = {
127
- with: Authlogic::Regex::EMAIL_NONASCII,
128
- message: proc do
129
- I18n.t(
130
- "error_messages.email_invalid_international",
131
- default: "should look like an international email address."
132
- )
133
- end
134
- }
135
- User.validates_format_of_email_field_options = with_email_nonascii
136
- assert_equal(with_email_nonascii, User.validates_format_of_email_field_options)
137
- User.validates_format_of_email_field_options with_email_nonascii
138
- assert_equal with_email_nonascii, User.validates_format_of_email_field_options
139
- end
140
-
141
- def test_deferred_error_message_translation
142
- # ensure we successfully loaded the test locale
143
- assert I18n.available_locales.include?(:lol), "Test locale failed to load"
144
-
145
- I18n.with_locale("lol") do
146
- message = I18n.t("authlogic.error_messages.email_invalid")
147
-
148
- cat = User.new
149
- cat.email = "meow"
150
- cat.valid?
151
-
152
- # filter duplicate error messages
153
- error = cat.errors[:email]
154
- error = error.first if error.is_a?(Array)
155
-
156
- assert_equal message, error
157
- end
158
- end
159
-
160
- def test_validates_uniqueness_of_email_field_options_config
161
- default = {
162
- case_sensitive: false,
163
- scope: Employee.validations_scope,
164
- if: "#{Employee.email_field}_changed?".to_sym
165
- }
166
- assert_equal default, Employee.validates_uniqueness_of_email_field_options
167
-
168
- Employee.validates_uniqueness_of_email_field_options = { yes: "no" }
169
- assert_equal({ yes: "no" }, Employee.validates_uniqueness_of_email_field_options)
170
- Employee.validates_uniqueness_of_email_field_options default
171
- assert_equal default, Employee.validates_uniqueness_of_email_field_options
172
- end
173
-
174
- def test_validates_length_of_email_field
175
- u = User.new
176
- u.email = "a@a.a"
177
- refute u.valid?
178
- refute u.errors[:email].empty?
179
-
180
- u.email = "a@a.com"
181
- refute u.valid?
182
- assert u.errors[:email].empty?
183
- end
184
-
185
- def test_validates_format_of_email_field
186
- u = User.new
187
- u.email = "aaaaaaaaaaaaa"
188
- u.valid?
189
- refute u.errors[:email].empty?
190
-
191
- u.email = "a@a.com"
192
- u.valid?
193
- assert u.errors[:email].empty?
194
-
195
- u.email = "damien+test1...etc..@mydomain.com"
196
- u.valid?
197
- assert u.errors[:email].empty?
198
-
199
- u.email = "dakota.dux+1@gmail.com"
200
- u.valid?
201
- assert u.errors[:email].empty?
202
-
203
- u.email = "dakota.d'ux@gmail.com"
204
- u.valid?
205
- assert u.errors[:email].empty?
206
-
207
- u.email = "<script>alert(123);</script>\nnobody@example.com"
208
- refute u.valid?
209
- refute u.errors[:email].empty?
210
-
211
- u.email = "a&b@c.com"
212
- u.valid?
213
- assert u.errors[:email].empty?
214
- end
215
-
216
- def test_validates_format_of_nonascii_email_field
217
- (GOOD_ASCII_EMAILS + GOOD_ISO88591_EMAILS + GOOD_UTF8_EMAILS).each do |e|
218
- assert e =~ Authlogic::Regex::EMAIL_NONASCII, "Good email should validate: #{e}"
219
- end
220
-
221
- (BAD_ASCII_EMAILS + BAD_ISO88591_EMAILS + BAD_UTF8_EMAILS).each do |e|
222
- assert e !~ Authlogic::Regex::EMAIL_NONASCII, "Bad email should not validate: #{e}"
223
- end
224
- end
225
-
226
- def test_validates_uniqueness_of_email_field
227
- u = User.new
228
- u.email = "bjohnson@binarylogic.com"
229
- refute u.valid?
230
- refute u.errors[:email].empty?
231
-
232
- u.email = "BJOHNSON@binarylogic.com"
233
- refute u.valid?
234
- refute u.errors[:email].empty?
235
-
236
- u.email = "a@a.com"
237
- refute u.valid?
238
- assert u.errors[:email].empty?
239
- end
240
- end
241
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module ActsAsAuthenticTest
6
- class LoggedInStatusTest < ActiveSupport::TestCase
7
- ERROR_MSG = "Multiple calls to %s should result in different relations"
8
-
9
- def test_logged_in_timeout_config
10
- assert_equal 10.minutes.to_i, User.logged_in_timeout
11
- assert_equal 10.minutes.to_i, Employee.logged_in_timeout
12
-
13
- User.logged_in_timeout = 1.hour
14
- assert_equal 1.hour.to_i, User.logged_in_timeout
15
- User.logged_in_timeout 10.minutes
16
- assert_equal 10.minutes.to_i, User.logged_in_timeout
17
- end
18
-
19
- def test_named_scope_logged_in
20
- # Testing that the scope returned differs, because the time it was called should be
21
- # slightly different. This is an attempt to make sure the scope is lambda wrapped
22
- # so that it is re-evaluated every time its called. My biggest concern is that the
23
- # test happens so fast that the test fails... I just don't know a better way to test it!
24
-
25
- # for rails 5 I've changed the where_values to to_sql to compare
26
-
27
- query1 = User.logged_in.to_sql
28
- sleep 0.1
29
- query2 = User.logged_in.to_sql
30
- assert query1 != query2, ERROR_MSG % "#logged_in"
31
-
32
- assert_equal 0, User.logged_in.count
33
- user = User.first
34
- user.last_request_at = Time.now
35
- user.current_login_at = Time.now
36
- user.save!
37
- assert_equal 1, User.logged_in.count
38
- end
39
-
40
- def test_named_scope_logged_out
41
- # Testing that the scope returned differs, because the time it was called should be
42
- # slightly different. This is an attempt to make sure the scope is lambda wrapped
43
- # so that it is re-evaluated every time its called. My biggest concern is that the
44
- # test happens so fast that the test fails... I just don't know a better way to test it!
45
-
46
- # for rails 5 I've changed the where_values to to_sql to compare
47
-
48
- assert User.logged_in.to_sql != User.logged_out.to_sql, ERROR_MSG % "#logged_out"
49
-
50
- assert_equal 3, User.logged_out.count
51
- User.first.update_attribute(:last_request_at, Time.now)
52
- assert_equal 2, User.logged_out.count
53
- end
54
-
55
- def test_logged_in_logged_out
56
- u = User.first
57
- refute u.logged_in?
58
- assert u.logged_out?
59
- u.last_request_at = Time.now
60
- assert u.logged_in?
61
- refute u.logged_out?
62
- end
63
- end
64
- end
@@ -1,153 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module ActsAsAuthenticTest
6
- # Tests for configuration option: `validates_format_of_login_field_options`
7
- class ValidatesFormatOfLoginTest < ActiveSupport::TestCase
8
- def test_invalid_format
9
- [
10
- "fdsf@^&*",
11
- " space",
12
- ".dot",
13
- "-hyphen",
14
- "@atmark",
15
- "+plus"
16
- ].each do |login|
17
- u = User.new(login: login)
18
- refute u.valid?
19
- refute u.errors[:login].empty?
20
- end
21
- end
22
-
23
- def test_valid_format
24
- [
25
- "fdsfdsfdsfdsfs",
26
- "dakota.dux+1@gmail.com",
27
- "marks .-_@+",
28
- "_underscore"
29
- ].each do |login|
30
- u = User.new(login: login)
31
- refute u.valid?
32
- assert u.errors[:login].empty?
33
- end
34
- end
35
-
36
- def test_validates_format_of_login_field_options_config
37
- default = {
38
- with: /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
39
- message: proc do
40
- I18n.t(
41
- "error_messages.login_invalid",
42
- default: "should use only letters, numbers, spaces, and .-_@+ please."
43
- )
44
- end
45
- }
46
- default_message = default.delete(:message).call
47
-
48
- options = User.validates_format_of_login_field_options
49
- message = options.delete(:message)
50
- assert message.is_a?(Proc)
51
- assert_equal default_message, message.call
52
- assert_equal default, options
53
-
54
- options = Employee.validates_format_of_login_field_options
55
- message = options.delete(:message)
56
- assert message.is_a?(Proc)
57
- assert_equal default_message, message.call
58
- assert_equal default, options
59
-
60
- User.validates_format_of_login_field_options = { yes: "no" }
61
- assert_equal({ yes: "no" }, User.validates_format_of_login_field_options)
62
- User.validates_format_of_login_field_options default
63
- assert_equal default, User.validates_format_of_login_field_options
64
- end
65
- end
66
-
67
- # Miscellaneous tests for configuration options related to the `login_field`.
68
- # Feel free to organize these into separate `TestCase`s as we have done above
69
- # with `ValidatesFormatOfLoginTest`.
70
- class MiscellaneousLoginTest < ActiveSupport::TestCase
71
- def test_login_field_config
72
- assert_equal :login, User.login_field
73
- assert_nil Employee.login_field
74
-
75
- User.login_field = :nope
76
- assert_equal :nope, User.login_field
77
- User.login_field :login
78
- assert_equal :login, User.login_field
79
- end
80
-
81
- def test_validate_login_field_config
82
- assert User.validate_login_field
83
- assert Employee.validate_login_field
84
-
85
- User.validate_login_field = false
86
- refute User.validate_login_field
87
- User.validate_login_field true
88
- assert User.validate_login_field
89
- end
90
-
91
- def test_validates_length_of_login_field_options_config
92
- assert_equal({ within: 3..100 }, User.validates_length_of_login_field_options)
93
- assert_equal({ within: 3..100 }, Employee.validates_length_of_login_field_options)
94
-
95
- User.validates_length_of_login_field_options = { yes: "no" }
96
- assert_equal({ yes: "no" }, User.validates_length_of_login_field_options)
97
- User.validates_length_of_login_field_options(within: 3..100)
98
- assert_equal({ within: 3..100 }, User.validates_length_of_login_field_options)
99
- end
100
-
101
- def test_validates_uniqueness_of_login_field_options_config
102
- default = {
103
- case_sensitive: false,
104
- scope: User.validations_scope,
105
- if: "#{User.login_field}_changed?".to_sym
106
- }
107
- assert_equal default, User.validates_uniqueness_of_login_field_options
108
-
109
- User.validates_uniqueness_of_login_field_options = { yes: "no" }
110
- assert_equal({ yes: "no" }, User.validates_uniqueness_of_login_field_options)
111
- User.validates_uniqueness_of_login_field_options default
112
- assert_equal default, User.validates_uniqueness_of_login_field_options
113
- end
114
-
115
- def test_validates_length_of_login_field
116
- u = User.new
117
- u.login = "a"
118
- refute u.valid?
119
- refute u.errors[:login].empty?
120
-
121
- u.login = "aaaaaaaaaa"
122
- refute u.valid?
123
- assert u.errors[:login].empty?
124
- end
125
-
126
- def test_validates_uniqueness_of_login_field
127
- u = User.new
128
- u.login = "bjohnson"
129
- refute u.valid?
130
- refute u.errors[:login].empty?
131
-
132
- u.login = "BJOHNSON"
133
- refute u.valid?
134
- refute u.errors[:login].empty?
135
-
136
- u.login = "fdsfdsf"
137
- refute u.valid?
138
- assert u.errors[:login].empty?
139
- end
140
-
141
- def test_find_by_smart_case_login_field
142
- ben = users(:ben)
143
- assert_equal ben, User.find_by_smart_case_login_field("bjohnson")
144
- assert_equal ben, User.find_by_smart_case_login_field("BJOHNSON")
145
- assert_equal ben, User.find_by_smart_case_login_field("Bjohnson")
146
-
147
- drew = employees(:drew)
148
- assert_equal drew, Employee.find_by_smart_case_login_field("dgainor@binarylogic.com")
149
- assert_equal drew, Employee.find_by_smart_case_login_field("Dgainor@binarylogic.com")
150
- assert_equal drew, Employee.find_by_smart_case_login_field("DGAINOR@BINARYLOGIC.COM")
151
- end
152
- end
153
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module ActsAsAuthenticTest
6
- class MagicColumnsTest < ActiveSupport::TestCase
7
- def test_validates_numericality_of_login_count
8
- u = User.new
9
- u.login_count = -1
10
- refute u.valid?
11
- refute u.errors[:login_count].empty?
12
-
13
- u.login_count = 0
14
- refute u.valid?
15
- assert u.errors[:login_count].empty?
16
- end
17
-
18
- def test_validates_numericality_of_failed_login_count
19
- u = User.new
20
- u.failed_login_count = -1
21
- refute u.valid?
22
- refute u.errors[:failed_login_count].empty?
23
-
24
- u.failed_login_count = 0
25
- refute u.valid?
26
- assert u.errors[:failed_login_count].empty?
27
- end
28
- end
29
- end