authlogic 3.8.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
  3. data/.github/ISSUE_TEMPLATE/feature_proposal.md +32 -0
  4. data/.github/triage.md +86 -0
  5. data/.gitignore +4 -3
  6. data/.rubocop.yml +109 -9
  7. data/.rubocop_todo.yml +38 -355
  8. data/.travis.yml +11 -35
  9. data/CHANGELOG.md +345 -2
  10. data/CONTRIBUTING.md +45 -14
  11. data/Gemfile +3 -2
  12. data/README.md +244 -90
  13. data/Rakefile +10 -10
  14. data/UPGRADING.md +22 -0
  15. data/authlogic.gemspec +34 -21
  16. data/doc/use_normal_rails_validation.md +82 -0
  17. data/gemfiles/Gemfile.rails-4.2.x +6 -0
  18. data/{test/gemfiles → gemfiles}/Gemfile.rails-5.1.x +2 -2
  19. data/{test/gemfiles → gemfiles}/Gemfile.rails-5.2.x +2 -2
  20. data/lib/authlogic/acts_as_authentic/base.rb +36 -24
  21. data/lib/authlogic/acts_as_authentic/email.rb +65 -31
  22. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +14 -9
  23. data/lib/authlogic/acts_as_authentic/login.rb +61 -45
  24. data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
  25. data/lib/authlogic/acts_as_authentic/password.rb +267 -146
  26. data/lib/authlogic/acts_as_authentic/perishable_token.rb +24 -19
  27. data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -15
  28. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +67 -0
  29. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +50 -14
  30. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +88 -60
  31. data/lib/authlogic/acts_as_authentic/single_access_token.rb +23 -11
  32. data/lib/authlogic/acts_as_authentic/validations_scope.rb +9 -6
  33. data/lib/authlogic/authenticates_many/association.rb +7 -7
  34. data/lib/authlogic/authenticates_many/base.rb +37 -21
  35. data/lib/authlogic/config.rb +21 -10
  36. data/lib/authlogic/controller_adapters/abstract_adapter.rb +38 -11
  37. data/lib/authlogic/controller_adapters/rack_adapter.rb +9 -5
  38. data/lib/authlogic/controller_adapters/rails_adapter.rb +12 -7
  39. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +2 -2
  40. data/lib/authlogic/crypto_providers/aes256.rb +37 -32
  41. data/lib/authlogic/crypto_providers/bcrypt.rb +21 -15
  42. data/lib/authlogic/crypto_providers/md5.rb +4 -2
  43. data/lib/authlogic/crypto_providers/scrypt.rb +22 -17
  44. data/lib/authlogic/crypto_providers/sha1.rb +11 -5
  45. data/lib/authlogic/crypto_providers/sha256.rb +13 -9
  46. data/lib/authlogic/crypto_providers/sha512.rb +0 -21
  47. data/lib/authlogic/crypto_providers/wordpress.rb +32 -3
  48. data/lib/authlogic/crypto_providers.rb +91 -0
  49. data/lib/authlogic/i18n.rb +26 -19
  50. data/lib/authlogic/random.rb +10 -28
  51. data/lib/authlogic/regex.rb +59 -28
  52. data/lib/authlogic/session/activation.rb +10 -7
  53. data/lib/authlogic/session/active_record_trickery.rb +13 -9
  54. data/lib/authlogic/session/base.rb +15 -4
  55. data/lib/authlogic/session/brute_force_protection.rb +40 -33
  56. data/lib/authlogic/session/callbacks.rb +94 -46
  57. data/lib/authlogic/session/cookies.rb +130 -45
  58. data/lib/authlogic/session/existence.rb +21 -11
  59. data/lib/authlogic/session/foundation.rb +64 -14
  60. data/lib/authlogic/session/http_auth.rb +35 -28
  61. data/lib/authlogic/session/id.rb +9 -4
  62. data/lib/authlogic/session/klass.rb +15 -12
  63. data/lib/authlogic/session/magic_columns.rb +58 -55
  64. data/lib/authlogic/session/magic_states.rb +25 -19
  65. data/lib/authlogic/session/params.rb +42 -28
  66. data/lib/authlogic/session/password.rb +130 -120
  67. data/lib/authlogic/session/perishable_token.rb +5 -4
  68. data/lib/authlogic/session/persistence.rb +18 -12
  69. data/lib/authlogic/session/priority_record.rb +15 -12
  70. data/lib/authlogic/session/scopes.rb +51 -32
  71. data/lib/authlogic/session/session.rb +38 -28
  72. data/lib/authlogic/session/timeout.rb +13 -13
  73. data/lib/authlogic/session/unauthorized_record.rb +18 -13
  74. data/lib/authlogic/session/validation.rb +9 -9
  75. data/lib/authlogic/test_case/mock_controller.rb +5 -4
  76. data/lib/authlogic/test_case/mock_cookie_jar.rb +47 -3
  77. data/lib/authlogic/test_case/mock_request.rb +6 -3
  78. data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
  79. data/lib/authlogic/test_case.rb +70 -2
  80. data/lib/authlogic/version.rb +21 -0
  81. data/lib/authlogic.rb +51 -49
  82. data/test/acts_as_authentic_test/base_test.rb +3 -1
  83. data/test/acts_as_authentic_test/email_test.rb +43 -42
  84. data/test/acts_as_authentic_test/logged_in_status_test.rb +6 -4
  85. data/test/acts_as_authentic_test/login_test.rb +77 -80
  86. data/test/acts_as_authentic_test/magic_columns_test.rb +3 -1
  87. data/test/acts_as_authentic_test/password_test.rb +51 -37
  88. data/test/acts_as_authentic_test/perishable_token_test.rb +13 -5
  89. data/test/acts_as_authentic_test/persistence_token_test.rb +7 -1
  90. data/test/acts_as_authentic_test/restful_authentication_test.rb +14 -3
  91. data/test/acts_as_authentic_test/session_maintenance_test.rb +69 -15
  92. data/test/acts_as_authentic_test/single_access_test.rb +3 -1
  93. data/test/adapter_test.rb +23 -0
  94. data/test/authenticates_many_test.rb +3 -1
  95. data/test/config_test.rb +11 -9
  96. data/test/crypto_provider_test/aes256_test.rb +3 -1
  97. data/test/crypto_provider_test/bcrypt_test.rb +3 -1
  98. data/test/crypto_provider_test/scrypt_test.rb +3 -1
  99. data/test/crypto_provider_test/sha1_test.rb +3 -1
  100. data/test/crypto_provider_test/sha256_test.rb +3 -1
  101. data/test/crypto_provider_test/sha512_test.rb +3 -1
  102. data/test/crypto_provider_test/wordpress_test.rb +26 -0
  103. data/test/fixtures/companies.yml +2 -2
  104. data/test/fixtures/employees.yml +1 -1
  105. data/test/i18n_test.rb +6 -4
  106. data/test/libs/affiliate.rb +2 -0
  107. data/test/libs/company.rb +4 -2
  108. data/test/libs/employee.rb +2 -0
  109. data/test/libs/employee_session.rb +2 -0
  110. data/test/libs/ldaper.rb +2 -0
  111. data/test/libs/project.rb +2 -0
  112. data/test/libs/user.rb +2 -0
  113. data/test/libs/user_session.rb +4 -2
  114. data/test/random_test.rb +10 -38
  115. data/test/session_test/activation_test.rb +3 -1
  116. data/test/session_test/active_record_trickery_test.rb +7 -4
  117. data/test/session_test/brute_force_protection_test.rb +11 -9
  118. data/test/session_test/callbacks_test.rb +12 -4
  119. data/test/session_test/cookies_test.rb +48 -5
  120. data/test/session_test/existence_test.rb +18 -5
  121. data/test/session_test/foundation_test.rb +19 -1
  122. data/test/session_test/http_auth_test.rb +11 -7
  123. data/test/session_test/id_test.rb +3 -1
  124. data/test/session_test/klass_test.rb +3 -1
  125. data/test/session_test/magic_columns_test.rb +13 -13
  126. data/test/session_test/magic_states_test.rb +3 -1
  127. data/test/session_test/params_test.rb +13 -5
  128. data/test/session_test/password_test.rb +10 -8
  129. data/test/session_test/perishability_test.rb +3 -1
  130. data/test/session_test/persistence_test.rb +4 -1
  131. data/test/session_test/scopes_test.rb +16 -8
  132. data/test/session_test/session_test.rb +6 -4
  133. data/test/session_test/timeout_test.rb +4 -2
  134. data/test/session_test/unauthorized_record_test.rb +4 -2
  135. data/test/session_test/validation_test.rb +3 -1
  136. data/test/test_helper.rb +84 -45
  137. metadata +87 -73
  138. data/.github/ISSUE_TEMPLATE.md +0 -13
  139. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  140. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  141. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
  142. data/test/gemfiles/Gemfile.rails-4.2.x +0 -7
  143. data/test/gemfiles/Gemfile.rails-5.0.x +0 -6
@@ -1,5 +1,6 @@
1
- # encoding: utf-8
2
- require 'test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
3
4
 
4
5
  module ActsAsAuthenticTest
5
6
  class EmailTest < ActiveSupport::TestCase
@@ -10,7 +11,7 @@ module ActsAsAuthenticTest
10
11
  "dakota.d'ux@gmail.com",
11
12
  "a&b@c.com",
12
13
  "someuser@somedomain.travelersinsurance"
13
- ]
14
+ ].freeze
14
15
 
15
16
  BAD_ASCII_EMAILS = [
16
17
  "",
@@ -19,13 +20,13 @@ module ActsAsAuthenticTest
19
20
  "backslash@g\\mail.com",
20
21
  "<script>alert(123);</script>\nnobody@example.com",
21
22
  "someuser@somedomain.isreallytoolongandimeanreallytoolong"
22
- ]
23
+ ].freeze
23
24
 
24
25
  # http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
25
26
  GOOD_ISO88591_EMAILS = [
26
27
  "töm.öm@dömain.fi", # https://github.com/binarylogic/authlogic/issues/176
27
28
  "Pelé@examplé.com", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
28
- ]
29
+ ].freeze
29
30
 
30
31
  BAD_ISO88591_EMAILS = [
31
32
  "",
@@ -34,34 +35,34 @@ module ActsAsAuthenticTest
34
35
  "é[@example.com", # L bracket
35
36
  "question?mark@gmail.com", # question mark
36
37
  "back\\slash@gmail.com", # backslash
37
- ]
38
+ ].freeze
38
39
 
39
40
  GOOD_UTF8_EMAILS = [
40
- "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
41
+ "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
41
42
  "我本@屋企.香港", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
42
43
  "甲斐@黒川.日買", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
43
- "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
44
- "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
45
- ]
44
+ "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
45
+ "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
46
+ ].freeze
46
47
 
47
48
  BAD_UTF8_EMAILS = [
48
49
  "",
49
- ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
50
- 'δκιμή@παράδεγμα.δ', # short TLD
50
+ ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
51
+ "δκιμή@παράδεγμα.δ", # short TLD
51
52
  "öm(@ava.fi", # L paren
52
53
  "é)@domain.com", # R paren
53
54
  "é[@example.com", # L bracket
54
55
  "δ]@πράιγμα.δοκμή", # R bracket
55
56
  "我\.香港", # slash
56
57
  "甲;.日本", # semicolon
57
- "ч:@ящик-с-пельнами.рф", # colon
58
- "斐,.みんな", # comma
58
+ "ч:@ящик-с-пельнами.рф", # colon
59
+ "斐,.みんな", # comma
59
60
  "香<.香港", # less than
60
61
  "我>.香港", # greater than
61
- "我?本@屋企.香港", # question mark
62
- "чебурша@ьн\\ами.рф", # backslash
62
+ "我?本@屋企.香港", # question mark
63
+ "чебурша@ьн\\ами.рф", # backslash
63
64
  "user@domain.com%0A<script>alert('hello')</script>"
64
- ]
65
+ ].freeze
65
66
 
66
67
  def test_email_field_config
67
68
  assert_equal :email, User.email_field
@@ -84,22 +85,22 @@ module ActsAsAuthenticTest
84
85
  end
85
86
 
86
87
  def test_validates_length_of_email_field_options_config
87
- assert_equal({ :maximum => 100 }, User.validates_length_of_email_field_options)
88
- assert_equal({ :maximum => 100 }, Employee.validates_length_of_email_field_options)
88
+ assert_equal({ maximum: 100 }, User.validates_length_of_email_field_options)
89
+ assert_equal({ maximum: 100 }, Employee.validates_length_of_email_field_options)
89
90
 
90
- User.validates_length_of_email_field_options = { :yes => "no" }
91
- assert_equal({ :yes => "no" }, User.validates_length_of_email_field_options)
92
- User.validates_length_of_email_field_options({ :within => 6..100 })
93
- assert_equal({ :within => 6..100 }, User.validates_length_of_email_field_options)
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)
94
95
  end
95
96
 
96
97
  def test_validates_format_of_email_field_options_config
97
98
  default = {
98
- :with => Authlogic::Regex.email,
99
- :message => proc do
99
+ with: Authlogic::Regex::EMAIL,
100
+ message: proc do
100
101
  I18n.t(
101
- 'error_messages.email_invalid',
102
- :default => "should look like an email address."
102
+ "error_messages.email_invalid",
103
+ default: "should look like an email address."
103
104
  )
104
105
  end
105
106
  }
@@ -117,17 +118,17 @@ module ActsAsAuthenticTest
117
118
  assert_equal default_message, message.call
118
119
  assert_equal default, options
119
120
 
120
- User.validates_format_of_email_field_options = { :yes => "no" }
121
- assert_equal({ :yes => "no" }, User.validates_format_of_email_field_options)
121
+ User.validates_format_of_email_field_options = { yes: "no" }
122
+ assert_equal({ yes: "no" }, User.validates_format_of_email_field_options)
122
123
  User.validates_format_of_email_field_options default
123
124
  assert_equal default, User.validates_format_of_email_field_options
124
125
 
125
126
  with_email_nonascii = {
126
- :with => Authlogic::Regex.email_nonascii,
127
- :message => Proc.new do
127
+ with: Authlogic::Regex::EMAIL_NONASCII,
128
+ message: proc do
128
129
  I18n.t(
129
- 'error_messages.email_invalid_international',
130
- :default => "should look like an international email address."
130
+ "error_messages.email_invalid_international",
131
+ default: "should look like an international email address."
131
132
  )
132
133
  end
133
134
  }
@@ -141,11 +142,11 @@ module ActsAsAuthenticTest
141
142
  # ensure we successfully loaded the test locale
142
143
  assert I18n.available_locales.include?(:lol), "Test locale failed to load"
143
144
 
144
- I18n.with_locale('lol') do
145
+ I18n.with_locale("lol") do
145
146
  message = I18n.t("authlogic.error_messages.email_invalid")
146
147
 
147
148
  cat = User.new
148
- cat.email = 'meow'
149
+ cat.email = "meow"
149
150
  cat.valid?
150
151
 
151
152
  # filter duplicate error messages
@@ -158,14 +159,14 @@ module ActsAsAuthenticTest
158
159
 
159
160
  def test_validates_uniqueness_of_email_field_options_config
160
161
  default = {
161
- :case_sensitive => false,
162
- :scope => Employee.validations_scope,
163
- :if => "#{Employee.email_field}_changed?".to_sym
162
+ case_sensitive: false,
163
+ scope: Employee.validations_scope,
164
+ if: "#{Employee.email_field}_changed?".to_sym
164
165
  }
165
166
  assert_equal default, Employee.validates_uniqueness_of_email_field_options
166
167
 
167
- Employee.validates_uniqueness_of_email_field_options = { :yes => "no" }
168
- assert_equal({ :yes => "no" }, Employee.validates_uniqueness_of_email_field_options)
168
+ Employee.validates_uniqueness_of_email_field_options = { yes: "no" }
169
+ assert_equal({ yes: "no" }, Employee.validates_uniqueness_of_email_field_options)
169
170
  Employee.validates_uniqueness_of_email_field_options default
170
171
  assert_equal default, Employee.validates_uniqueness_of_email_field_options
171
172
  end
@@ -214,11 +215,11 @@ module ActsAsAuthenticTest
214
215
 
215
216
  def test_validates_format_of_nonascii_email_field
216
217
  (GOOD_ASCII_EMAILS + GOOD_ISO88591_EMAILS + GOOD_UTF8_EMAILS).each do |e|
217
- assert e =~ Authlogic::Regex.email_nonascii, "Good email should validate: #{e}"
218
+ assert e =~ Authlogic::Regex::EMAIL_NONASCII, "Good email should validate: #{e}"
218
219
  end
219
220
 
220
221
  (BAD_ASCII_EMAILS + BAD_ISO88591_EMAILS + BAD_UTF8_EMAILS).each do |e|
221
- assert e !~ Authlogic::Regex.email_nonascii, "Bad email should not validate: #{e}"
222
+ assert e !~ Authlogic::Regex::EMAIL_NONASCII, "Bad email should not validate: #{e}"
222
223
  end
223
224
  end
224
225
 
@@ -1,8 +1,10 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
2
4
 
3
5
  module ActsAsAuthenticTest
4
6
  class LoggedInStatusTest < ActiveSupport::TestCase
5
- ERROR_MSG = 'Multiple calls to %s should result in different relations'
7
+ ERROR_MSG = "Multiple calls to %s should result in different relations"
6
8
 
7
9
  def test_logged_in_timeout_config
8
10
  assert_equal 10.minutes.to_i, User.logged_in_timeout
@@ -25,7 +27,7 @@ module ActsAsAuthenticTest
25
27
  query1 = User.logged_in.to_sql
26
28
  sleep 0.1
27
29
  query2 = User.logged_in.to_sql
28
- assert query1 != query2, ERROR_MSG % '#logged_in'
30
+ assert query1 != query2, ERROR_MSG % "#logged_in"
29
31
 
30
32
  assert_equal 0, User.logged_in.count
31
33
  user = User.first
@@ -43,7 +45,7 @@ module ActsAsAuthenticTest
43
45
 
44
46
  # for rails 5 I've changed the where_values to to_sql to compare
45
47
 
46
- assert User.logged_in.to_sql != User.logged_out.to_sql, ERROR_MSG % '#logged_out'
48
+ assert User.logged_in.to_sql != User.logged_out.to_sql, ERROR_MSG % "#logged_out"
47
49
 
48
50
  assert_equal 3, User.logged_out.count
49
51
  User.first.update_attribute(:last_request_at, Time.now)
@@ -1,44 +1,45 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
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
3
+ require "test_helper"
14
4
 
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
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
23
21
  end
24
22
 
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)
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
33
34
  end
34
35
 
35
36
  def test_validates_format_of_login_field_options_config
36
37
  default = {
37
- :with => /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
38
- :message => proc do
38
+ with: /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
39
+ message: proc do
39
40
  I18n.t(
40
- 'error_messages.login_invalid',
41
- :default => "should use only letters, numbers, spaces, and .-_@+ please."
41
+ "error_messages.login_invalid",
42
+ default: "should use only letters, numbers, spaces, and .-_@+ please."
42
43
  )
43
44
  end
44
45
  }
@@ -56,18 +57,57 @@ module ActsAsAuthenticTest
56
57
  assert_equal default_message, message.call
57
58
  assert_equal default, options
58
59
 
59
- User.validates_format_of_login_field_options = { :yes => "no" }
60
- assert_equal({ :yes => "no" }, User.validates_format_of_login_field_options)
60
+ User.validates_format_of_login_field_options = { yes: "no" }
61
+ assert_equal({ yes: "no" }, User.validates_format_of_login_field_options)
61
62
  User.validates_format_of_login_field_options default
62
63
  assert_equal default, User.validates_format_of_login_field_options
63
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
64
100
 
65
101
  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 }
102
+ default = {
103
+ case_sensitive: false,
104
+ scope: User.validations_scope,
105
+ if: "#{User.login_field}_changed?".to_sym
106
+ }
67
107
  assert_equal default, User.validates_uniqueness_of_login_field_options
68
108
 
69
- User.validates_uniqueness_of_login_field_options = { :yes => "no" }
70
- assert_equal({ :yes => "no" }, User.validates_uniqueness_of_login_field_options)
109
+ User.validates_uniqueness_of_login_field_options = { yes: "no" }
110
+ assert_equal({ yes: "no" }, User.validates_uniqueness_of_login_field_options)
71
111
  User.validates_uniqueness_of_login_field_options default
72
112
  assert_equal default, User.validates_uniqueness_of_login_field_options
73
113
  end
@@ -83,49 +123,6 @@ module ActsAsAuthenticTest
83
123
  assert u.errors[:login].empty?
84
124
  end
85
125
 
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
126
  def test_validates_uniqueness_of_login_field
130
127
  u = User.new
131
128
  u.login = "bjohnson"
@@ -1,4 +1,6 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
2
4
 
3
5
  module ActsAsAuthenticTest
4
6
  class MagicColumnsTest < ActiveSupport::TestCase
@@ -1,8 +1,12 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
2
4
 
3
5
  module ActsAsAuthenticTest
4
6
  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.
7
+ # If test_human_name is executed after test_i18n_of_human_name the test will fail.
8
+ i_suck_and_my_tests_are_order_dependent!
9
+
6
10
  def test_crypted_password_field_config
7
11
  assert_equal :crypted_password, User.crypted_password_field
8
12
  assert_equal :crypted_password, Employee.crypted_password_field
@@ -52,34 +56,34 @@ module ActsAsAuthenticTest
52
56
  end
53
57
 
54
58
  def test_validates_length_of_password_field_options_config
55
- default = { :minimum => 8, :if => :require_password? }
59
+ default = { minimum: 8, if: :require_password? }
56
60
  assert_equal default, User.validates_length_of_password_field_options
57
61
  assert_equal default, Employee.validates_length_of_password_field_options
58
62
 
59
- User.validates_length_of_password_field_options = { :yes => "no" }
60
- assert_equal({ :yes => "no" }, User.validates_length_of_password_field_options)
63
+ User.validates_length_of_password_field_options = { yes: "no" }
64
+ assert_equal({ yes: "no" }, User.validates_length_of_password_field_options)
61
65
  User.validates_length_of_password_field_options default
62
66
  assert_equal default, User.validates_length_of_password_field_options
63
67
  end
64
68
 
65
69
  def test_validates_confirmation_of_password_field_options_config
66
- default = { :if => :require_password? }
70
+ default = { if: :require_password? }
67
71
  assert_equal default, User.validates_confirmation_of_password_field_options
68
72
  assert_equal default, Employee.validates_confirmation_of_password_field_options
69
73
 
70
- User.validates_confirmation_of_password_field_options = { :yes => "no" }
71
- assert_equal({ :yes => "no" }, User.validates_confirmation_of_password_field_options)
74
+ User.validates_confirmation_of_password_field_options = { yes: "no" }
75
+ assert_equal({ yes: "no" }, User.validates_confirmation_of_password_field_options)
72
76
  User.validates_confirmation_of_password_field_options default
73
77
  assert_equal default, User.validates_confirmation_of_password_field_options
74
78
  end
75
79
 
76
80
  def test_validates_length_of_password_confirmation_field_options_config
77
- default = { :minimum => 8, :if => :require_password? }
81
+ default = { minimum: 8, if: :require_password? }
78
82
  assert_equal default, User.validates_length_of_password_confirmation_field_options
79
83
  assert_equal default, Employee.validates_length_of_password_confirmation_field_options
80
84
 
81
- User.validates_length_of_password_confirmation_field_options = { :yes => "no" }
82
- assert_equal({ :yes => "no" }, User.validates_length_of_password_confirmation_field_options)
85
+ User.validates_length_of_password_confirmation_field_options = { yes: "no" }
86
+ assert_equal({ yes: "no" }, User.validates_length_of_password_confirmation_field_options)
83
87
  User.validates_length_of_password_confirmation_field_options default
84
88
  assert_equal default, User.validates_length_of_password_confirmation_field_options
85
89
  end
@@ -105,7 +109,12 @@ module ActsAsAuthenticTest
105
109
  end
106
110
 
107
111
  def test_validates_length_of_password
108
- u = User.new(login: "abcde", email: "abcde@test.com", password: "abcdefgh", password_confirmation: "abcdefgh")
112
+ u = User.new(
113
+ login: "abcde",
114
+ email: "abcde@test.com",
115
+ password: "abcdefgh",
116
+ password_confirmation: "abcdefgh"
117
+ )
109
118
  assert u.valid?
110
119
 
111
120
  u.password = u.password_confirmation = "abcdef"
@@ -116,17 +125,18 @@ module ActsAsAuthenticTest
116
125
  end
117
126
 
118
127
  def test_validates_confirmation_of_password
119
- u = User.new(login: "abcde", email: "abcde@test.com", password: "abcdefgh", password_confirmation: "abcdefgh")
128
+ u = User.new(
129
+ login: "abcde",
130
+ email: "abcde@test.com",
131
+ password: "abcdefgh",
132
+ password_confirmation: "abcdefgh"
133
+ )
120
134
  assert u.valid?
121
135
 
122
136
  u.password_confirmation = "abcdefghij"
123
137
  refute u.valid?
124
138
 
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
139
+ assert u.errors[:password_confirmation].include?("doesn't match Password")
130
140
  end
131
141
 
132
142
  def test_validates_length_of_password_confirmation
@@ -225,25 +235,29 @@ module ActsAsAuthenticTest
225
235
 
226
236
  private
227
237
 
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
238
+ def transition_password_to(
239
+ crypto_provider,
240
+ records,
241
+ from_crypto_providers = Authlogic::CryptoProviders::Sha512
242
+ )
243
+ records = [records] unless records.is_a?(Array)
244
+ User.acts_as_authentic do |c|
245
+ c.crypto_provider = crypto_provider
246
+ c.transition_from_crypto_providers = from_crypto_providers
247
+ end
248
+ records.each do |record|
249
+ old_hash = record.crypted_password
250
+ old_persistence_token = record.persistence_token
251
+ assert record.valid_password?(password_for(record))
252
+ assert_not_equal old_hash.to_s, record.crypted_password.to_s
253
+ assert_not_equal old_persistence_token.to_s, record.persistence_token.to_s
254
+
255
+ old_hash = record.crypted_password
256
+ old_persistence_token = record.persistence_token
257
+ assert record.valid_password?(password_for(record))
258
+ assert_equal old_hash.to_s, record.crypted_password.to_s
259
+ assert_equal old_persistence_token.to_s, record.persistence_token.to_s
247
260
  end
261
+ end
248
262
  end
249
263
  end
@@ -1,4 +1,6 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
2
4
 
3
5
  module ActsAsAuthenticTest
4
6
  class PerishableTokenTest < ActiveSupport::TestCase
@@ -60,14 +62,18 @@ module ActsAsAuthenticTest
60
62
 
61
63
  def test_find_using_perishable_token_when_perished
62
64
  ben = users(:ben)
63
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{1.week.ago.to_s(:db)}' where id = #{ben.id}")
65
+ ActiveRecord::Base.connection.execute(
66
+ "UPDATE users set updated_at = '#{1.week.ago.to_s(:db)}' where id = #{ben.id}"
67
+ )
64
68
  assert_nil User.find_using_perishable_token(ben.perishable_token)
65
69
  end
66
70
 
67
71
  def test_find_using_perishable_token_when_perished_2
68
72
  User.perishable_token_valid_for = 1.minute
69
73
  ben = users(:ben)
70
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{2.minutes.ago.to_s(:db)}' where id = #{ben.id}")
74
+ ActiveRecord::Base.connection.execute(
75
+ "UPDATE users set updated_at = '#{2.minutes.ago.to_s(:db)}' where id = #{ben.id}"
76
+ )
71
77
  assert_nil User.find_using_perishable_token(ben.perishable_token)
72
78
  User.perishable_token_valid_for = 10.minutes
73
79
  end
@@ -75,7 +81,9 @@ module ActsAsAuthenticTest
75
81
  def test_find_using_perishable_token_when_passing_threshold
76
82
  User.perishable_token_valid_for = 1.minute
77
83
  ben = users(:ben)
78
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{10.minutes.ago.to_s(:db)}' where id = #{ben.id}")
84
+ ActiveRecord::Base.connection.execute(
85
+ "UPDATE users set updated_at = '#{10.minutes.ago.to_s(:db)}' where id = #{ben.id}"
86
+ )
79
87
  assert_nil User.find_using_perishable_token(ben.perishable_token, 5.minutes)
80
88
  assert_equal ben, User.find_using_perishable_token(ben.perishable_token, 20.minutes)
81
89
  User.perishable_token_valid_for = 10.minutes
@@ -83,7 +91,7 @@ module ActsAsAuthenticTest
83
91
 
84
92
  def test_find_perishable_token_with_bang
85
93
  assert_raises ActiveRecord::RecordNotFound do
86
- User.find_using_perishable_token!('some_bad_value')
94
+ User.find_using_perishable_token!("some_bad_value")
87
95
  end
88
96
  end
89
97
  end
@@ -1,4 +1,6 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
2
4
 
3
5
  module ActsAsAuthenticTest
4
6
  class PersistenceTokenTest < ActiveSupport::TestCase
@@ -29,6 +31,8 @@ module ActsAsAuthenticTest
29
31
  end
30
32
 
31
33
  def test_forget_all
34
+ UserSession.allow_http_basic_auth = true
35
+
32
36
  http_basic_auth_for(users(:ben)) { UserSession.find }
33
37
  http_basic_auth_for(users(:zack)) { UserSession.find(:ziggity_zack) }
34
38
  assert UserSession.find
@@ -39,6 +43,8 @@ module ActsAsAuthenticTest
39
43
  end
40
44
 
41
45
  def test_forget
46
+ UserSession.allow_http_basic_auth = true
47
+
42
48
  ben = users(:ben)
43
49
  zack = users(:zack)
44
50
  http_basic_auth_for(ben) { UserSession.find }