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,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class CallbacksTest < ActiveSupport::TestCase
7
- def setup
8
- WackyUserSession.reset_callbacks(:persist)
9
- end
10
-
11
- def test_no_callbacks
12
- assert_equal [], WackyUserSession._persist_callbacks.map(&:filter)
13
- session = WackyUserSession.new
14
- session.send(:persist)
15
- assert_equal 0, session.counter
16
- end
17
-
18
- def test_true_callback_cancelling_later_callbacks
19
- WackyUserSession.persist :persist_by_true, :persist_by_false
20
- assert_equal(
21
- %i[persist_by_true persist_by_false],
22
- WackyUserSession._persist_callbacks.map(&:filter)
23
- )
24
-
25
- session = WackyUserSession.new
26
- session.send(:persist)
27
- assert_equal 1, session.counter
28
- end
29
-
30
- def test_false_callback_continuing_to_later_callbacks
31
- WackyUserSession.persist :persist_by_false, :persist_by_true
32
- assert_equal(
33
- %i[persist_by_false persist_by_true],
34
- WackyUserSession._persist_callbacks.map(&:filter)
35
- )
36
-
37
- session = WackyUserSession.new
38
- session.send(:persist)
39
- assert_equal 2, session.counter
40
- end
41
- end
42
- end
@@ -1,244 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module CookiesTest
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_cookie_key
9
- UserSession.cookie_key = "my_cookie_key"
10
- assert_equal "my_cookie_key", UserSession.cookie_key
11
-
12
- UserSession.cookie_key "user_credentials"
13
- assert_equal "user_credentials", UserSession.cookie_key
14
- end
15
-
16
- def test_default_cookie_key
17
- assert_equal "user_credentials", UserSession.cookie_key
18
- assert_equal "back_office_user_credentials", BackOfficeUserSession.cookie_key
19
- end
20
-
21
- def test_remember_me
22
- UserSession.remember_me = true
23
- assert_equal true, UserSession.remember_me
24
- session = UserSession.new
25
- assert_equal true, session.remember_me
26
-
27
- UserSession.remember_me false
28
- assert_equal false, UserSession.remember_me
29
- session = UserSession.new
30
- assert_equal false, session.remember_me
31
- end
32
-
33
- def test_remember_me_for
34
- UserSession.remember_me_for = 3.years
35
- assert_equal 3.years, UserSession.remember_me_for
36
- session = UserSession.new
37
- session.remember_me = true
38
- assert_equal 3.years, session.remember_me_for
39
-
40
- UserSession.remember_me_for 3.months
41
- assert_equal 3.months, UserSession.remember_me_for
42
- session = UserSession.new
43
- session.remember_me = true
44
- assert_equal 3.months, session.remember_me_for
45
- end
46
-
47
- def test_secure
48
- assert_equal true, UserSession.secure
49
- session = UserSession.new
50
- assert_equal true, session.secure
51
-
52
- UserSession.secure false
53
- assert_equal false, UserSession.secure
54
- session = UserSession.new
55
- assert_equal false, session.secure
56
- end
57
-
58
- def test_httponly
59
- assert_equal true, UserSession.httponly
60
- session = UserSession.new
61
- assert_equal true, session.httponly
62
-
63
- UserSession.httponly false
64
- assert_equal false, UserSession.httponly
65
- session = UserSession.new
66
- assert_equal false, session.httponly
67
- end
68
-
69
- def test_same_site
70
- assert_nil UserSession.same_site
71
- assert_nil UserSession.new.same_site
72
-
73
- UserSession.same_site "Strict"
74
- assert_equal "Strict", UserSession.same_site
75
- session = UserSession.new
76
- assert_equal "Strict", session.same_site
77
- session.same_site = "Lax"
78
- assert_equal "Lax", session.same_site
79
- session.same_site = "None"
80
- assert_equal "None", session.same_site
81
-
82
- assert_raise(ArgumentError) { UserSession.same_site "foo" }
83
- assert_raise(ArgumentError) { UserSession.new.same_site "foo" }
84
- end
85
-
86
- def test_sign_cookie
87
- UserSession.sign_cookie = true
88
- assert_equal true, UserSession.sign_cookie
89
- session = UserSession.new
90
- assert_equal true, session.sign_cookie
91
-
92
- UserSession.sign_cookie false
93
- assert_equal false, UserSession.sign_cookie
94
- session = UserSession.new
95
- assert_equal false, session.sign_cookie
96
- end
97
- end
98
-
99
- class InstanceMethodsTest < ActiveSupport::TestCase
100
- def test_credentials
101
- session = UserSession.new
102
- session.credentials = { remember_me: true }
103
- assert_equal true, session.remember_me
104
- end
105
-
106
- def test_remember_me
107
- session = UserSession.new
108
- assert_equal false, session.remember_me
109
- refute session.remember_me?
110
-
111
- session.remember_me = false
112
- assert_equal false, session.remember_me
113
- refute session.remember_me?
114
-
115
- session.remember_me = true
116
- assert_equal true, session.remember_me
117
- assert session.remember_me?
118
-
119
- session.remember_me = nil
120
- assert_nil session.remember_me
121
- refute session.remember_me?
122
-
123
- session.remember_me = "1"
124
- assert_equal "1", session.remember_me
125
- assert session.remember_me?
126
-
127
- session.remember_me = "true"
128
- assert_equal "true", session.remember_me
129
- assert session.remember_me?
130
- end
131
-
132
- def test_remember_me_until
133
- session = UserSession.new
134
- assert_nil session.remember_me_until
135
-
136
- session.remember_me = true
137
- assert 3.months.from_now <= session.remember_me_until
138
- end
139
-
140
- def test_persist_persist_by_cookie
141
- ben = users(:ben)
142
- refute UserSession.find
143
- set_cookie_for(ben)
144
- assert session = UserSession.find
145
- assert_equal ben, session.record
146
- end
147
-
148
- def test_persist_persist_by_cookie_with_blank_persistence_token
149
- ben = users(:ben)
150
- ben.update_column(:persistence_token, "")
151
- refute UserSession.find
152
- set_cookie_for(ben)
153
- refute UserSession.find
154
- end
155
-
156
- def test_remember_me_expired
157
- ben = users(:ben)
158
- session = UserSession.new(ben)
159
- session.remember_me = true
160
- assert session.save
161
- refute session.remember_me_expired?
162
-
163
- session = UserSession.new(ben)
164
- session.remember_me = false
165
- assert session.save
166
- refute session.remember_me_expired?
167
- end
168
-
169
- def test_after_save_save_cookie
170
- ben = users(:ben)
171
- session = UserSession.new(ben)
172
- assert session.save
173
- assert_equal(
174
- "#{ben.persistence_token}::#{ben.id}",
175
- controller.cookies["user_credentials"]
176
- )
177
- end
178
-
179
- def test_after_save_save_cookie_encrypted
180
- ben = users(:ben)
181
-
182
- assert_nil controller.cookies["user_credentials"]
183
- payload = "#{ben.persistence_token}::#{ben.id}"
184
-
185
- session = UserSession.new(ben)
186
- session.encrypt_cookie = true
187
- assert session.save
188
- assert_equal payload, controller.cookies.encrypted["user_credentials"]
189
- assert_equal(
190
- Authlogic::TestCase::MockEncryptedCookieJar.encrypt(payload),
191
- controller.cookies.encrypted.parent_jar["user_credentials"]
192
- )
193
- end
194
-
195
- def test_after_save_save_cookie_signed
196
- ben = users(:ben)
197
-
198
- assert_nil controller.cookies["user_credentials"]
199
- payload = "#{ben.persistence_token}::#{ben.id}"
200
-
201
- session = UserSession.new(ben)
202
- session.sign_cookie = true
203
- assert session.save
204
- assert_equal payload, controller.cookies.signed["user_credentials"]
205
- assert_equal(
206
- "#{payload}--#{Digest::SHA1.hexdigest payload}",
207
- controller.cookies.signed.parent_jar["user_credentials"]
208
- )
209
- end
210
-
211
- def test_after_save_save_cookie_with_remember_me
212
- Timecop.freeze do
213
- ben = users(:ben)
214
- session = UserSession.new(ben)
215
- session.remember_me = true
216
- assert session.save
217
- assert_equal(
218
- "#{ben.persistence_token}::#{ben.id}::#{session.remember_me_until.iso8601}",
219
- controller.cookies["user_credentials"]
220
- )
221
- end
222
- end
223
-
224
- def test_after_save_save_cookie_with_same_site
225
- session = UserSession.new(users(:ben))
226
- session.same_site = "Strict"
227
- assert session.save
228
- assert_equal(
229
- "Strict",
230
- controller.cookies.set_cookies["user_credentials"][:same_site]
231
- )
232
- end
233
-
234
- def test_after_destroy_destroy_cookie
235
- ben = users(:ben)
236
- set_cookie_for(ben)
237
- session = UserSession.find
238
- assert controller.cookies["user_credentials"]
239
- assert session.destroy
240
- refute controller.cookies["user_credentials"]
241
- end
242
- end
243
- end
244
- end
File without changes
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module ExistenceTest
7
- class ClassMethodsTest < ActiveSupport::TestCase
8
- def test_create_with_good_credentials
9
- ben = users(:ben)
10
- session = UserSession.create(login: ben.login, password: "benrocks")
11
- refute session.new_session?
12
- end
13
-
14
- def test_create_with_bad_credentials
15
- session = UserSession.create(login: "somelogin", password: "badpw2")
16
- assert session.new_session?
17
- end
18
-
19
- def test_create_bang
20
- ben = users(:ben)
21
- err = assert_raise(Authlogic::Session::Existence::SessionInvalidError) do
22
- UserSession.create!(login: ben.login, password: "badpw")
23
- end
24
- assert_includes err.message, "Password is not valid"
25
- refute UserSession.create!(login: ben.login, password: "benrocks").new_session?
26
- end
27
- end
28
-
29
- class InstanceMethodsTest < ActiveSupport::TestCase
30
- def test_new_session
31
- session = UserSession.new
32
- assert session.new_session?
33
-
34
- set_session_for(users(:ben))
35
- session = UserSession.find
36
- refute session.new_session?
37
- end
38
-
39
- def test_save_with_nothing
40
- session = UserSession.new
41
- refute session.save
42
- assert session.new_session?
43
- end
44
-
45
- def test_save_with_block
46
- session = UserSession.new
47
- block_result = session.save do |result|
48
- refute result
49
- end
50
- refute block_result
51
- assert session.new_session?
52
- end
53
-
54
- def test_save_with_bang
55
- session = UserSession.new
56
- assert_raise(Authlogic::Session::Existence::SessionInvalidError) { session.save! }
57
-
58
- session.unauthorized_record = users(:ben)
59
- assert_nothing_raised { session.save! }
60
- end
61
-
62
- def test_destroy
63
- ben = users(:ben)
64
- session = UserSession.new
65
- refute session.valid?
66
- refute session.errors.empty?
67
- assert session.destroy
68
- assert session.errors.empty?
69
- session.unauthorized_record = ben
70
- assert session.save
71
- assert session.record
72
- assert session.destroy
73
- refute session.record
74
- end
75
- end
76
-
77
- class SessionInvalidErrorTest < ActiveSupport::TestCase
78
- def test_message
79
- session = UserSession.new
80
- assert !session.valid?
81
- error = Authlogic::Session::Existence::SessionInvalidError.new(session)
82
- message = "Your session is invalid and has the following errors: " +
83
- session.errors.full_messages.to_sentence
84
- assert_equal message, error.message
85
- end
86
- end
87
- end
88
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- # We forbid the use of AC::Parameters, and we have a test to that effect, but we
6
- # do not want a development dependency on `actionpack`, so we define it here.
7
- module ActionController
8
- class Parameters; end
9
- end
10
-
11
- module SessionTest
12
- class FoundationTest < ActiveSupport::TestCase
13
- def test_credentials_raise_if_not_a_hash
14
- session = UserSession.new
15
- e = assert_raises(TypeError) {
16
- session.credentials = ActionController::Parameters.new
17
- }
18
- assert_equal(
19
- ::Authlogic::Session::Foundation::InstanceMethods::E_AC_PARAMETERS,
20
- e.message
21
- )
22
- end
23
- end
24
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class HttpAuthTest < ActiveSupport::TestCase
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_allow_http_basic_auth
9
- UserSession.allow_http_basic_auth = false
10
- assert_equal false, UserSession.allow_http_basic_auth
11
-
12
- UserSession.allow_http_basic_auth true
13
- assert_equal true, UserSession.allow_http_basic_auth
14
- end
15
-
16
- def test_request_http_basic_auth
17
- UserSession.request_http_basic_auth = true
18
- assert_equal true, UserSession.request_http_basic_auth
19
-
20
- UserSession.request_http_basic_auth = false
21
- assert_equal false, UserSession.request_http_basic_auth
22
- end
23
-
24
- def test_http_basic_auth_realm
25
- assert_equal "Application", UserSession.http_basic_auth_realm
26
- UserSession.http_basic_auth_realm = "TestRealm"
27
- assert_equal "TestRealm", UserSession.http_basic_auth_realm
28
- end
29
- end
30
-
31
- class InstanceMethodsTest < ActiveSupport::TestCase
32
- def test_persist_persist_by_http_auth
33
- UserSession.allow_http_basic_auth = true
34
-
35
- aaron = users(:aaron)
36
- http_basic_auth_for do
37
- refute UserSession.find
38
- end
39
- http_basic_auth_for(aaron) do
40
- assert session = UserSession.find
41
- assert_equal aaron, session.record
42
- assert_equal aaron.login, session.login
43
- assert_equal "aaronrocks", session.send(:protected_password)
44
- refute controller.http_auth_requested?
45
- end
46
- unset_session
47
- UserSession.request_http_basic_auth = true
48
- UserSession.http_basic_auth_realm = "PersistTestRealm"
49
- http_basic_auth_for(aaron) do
50
- assert session = UserSession.find
51
- assert_equal aaron, session.record
52
- assert_equal aaron.login, session.login
53
- assert_equal "aaronrocks", session.send(:protected_password)
54
- assert_equal "PersistTestRealm", controller.realm
55
- assert controller.http_auth_requested?
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class IdTest < ActiveSupport::TestCase
7
- def test_credentials
8
- session = UserSession.new
9
- session.credentials = [:my_id]
10
- assert_equal :my_id, session.id
11
- end
12
-
13
- def test_id
14
- session = UserSession.new
15
- session.id = :my_id
16
- assert_equal :my_id, session.id
17
- end
18
- end
19
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module KlassTest
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_authenticate_with
9
- UserSession.authenticate_with = Employee
10
- assert_equal "Employee", UserSession.klass_name
11
- assert_equal Employee, UserSession.klass
12
-
13
- UserSession.authenticate_with User
14
- assert_equal "User", UserSession.klass_name
15
- assert_equal User, UserSession.klass
16
- end
17
-
18
- def test_klass
19
- assert_equal User, UserSession.klass
20
- end
21
-
22
- def test_klass_name
23
- assert_equal "User", UserSession.klass_name
24
- end
25
-
26
- def test_klass_name_uses_custom_name
27
- assert_equal "User", UserSession.klass_name
28
- assert_equal "BackOfficeUser", BackOfficeUserSession.klass_name
29
- end
30
- end
31
-
32
- class InstanceMethodsTest < ActiveSupport::TestCase
33
- def test_record_method
34
- ben = users(:ben)
35
- set_session_for(ben)
36
- session = UserSession.find
37
- assert_equal ben, session.record
38
- assert_equal ben, session.user
39
- end
40
- end
41
- end
42
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module MagicColumnsTest
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_last_request_at_threshold_config
9
- UserSession.last_request_at_threshold = 2.minutes
10
- assert_equal 2.minutes, UserSession.last_request_at_threshold
11
-
12
- UserSession.last_request_at_threshold 0
13
- assert_equal 0, UserSession.last_request_at_threshold
14
- end
15
- end
16
-
17
- class InstanceMethodsTest < ActiveSupport::TestCase
18
- def test_after_persisting_set_last_request_at
19
- ben = users(:ben)
20
- refute UserSession.create(ben).new_session?
21
-
22
- set_cookie_for(ben)
23
- old_last_request_at = ben.last_request_at
24
- assert UserSession.find
25
- ben.reload
26
- assert ben.last_request_at != old_last_request_at
27
- end
28
-
29
- def test_valid_increase_failed_login_count
30
- ben = users(:ben)
31
- old_failed_login_count = ben.failed_login_count
32
- session = UserSession.create(login: ben.login, password: "wrong")
33
- assert session.new_session?
34
- ben.reload
35
- assert_equal old_failed_login_count + 1, ben.failed_login_count
36
- end
37
-
38
- def test_before_save_update_info
39
- aaron = users(:aaron)
40
-
41
- # increase failed login count
42
- session = UserSession.create(login: aaron.login, password: "wrong")
43
- assert session.new_session?
44
- aaron.reload
45
- assert_equal 0, aaron.login_count
46
- assert_nil aaron.current_login_at
47
- assert_nil aaron.current_login_ip
48
-
49
- session = UserSession.create(login: aaron.login, password: "aaronrocks")
50
- assert session.valid?
51
-
52
- aaron.reload
53
- assert_equal 1, aaron.login_count
54
- assert_equal 0, aaron.failed_login_count
55
- assert_nil aaron.last_login_at
56
- assert_not_nil aaron.current_login_at
57
- assert_nil aaron.last_login_ip
58
- assert_equal "1.1.1.1", aaron.current_login_ip
59
- end
60
- end
61
- end
62
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module SessionTest
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_disable_magic_states_config
9
- UserSession.disable_magic_states = true
10
- assert_equal true, UserSession.disable_magic_states
11
-
12
- UserSession.disable_magic_states false
13
- assert_equal false, UserSession.disable_magic_states
14
- end
15
- end
16
-
17
- class InstanceMethodsTest < ActiveSupport::TestCase
18
- def test_disabling_magic_states
19
- UserSession.disable_magic_states = true
20
- ben = users(:ben)
21
- ben.update_attribute(:active, false)
22
- refute UserSession.create(ben).new_session?
23
- UserSession.disable_magic_states = false
24
- end
25
-
26
- def test_validate_validate_magic_states_active
27
- session = UserSession.new
28
- ben = users(:ben)
29
- session.unauthorized_record = ben
30
- assert session.valid?
31
-
32
- ben.update_attribute(:active, false)
33
- refute session.valid?
34
- refute session.errors[:base].empty?
35
- end
36
-
37
- def test_validate_validate_magic_states_approved
38
- session = UserSession.new
39
- ben = users(:ben)
40
- session.unauthorized_record = ben
41
- assert session.valid?
42
-
43
- ben.update_attribute(:approved, false)
44
- refute session.valid?
45
- refute session.errors[:base].empty?
46
- end
47
-
48
- def test_validate_validate_magic_states_confirmed
49
- session = UserSession.new
50
- ben = users(:ben)
51
- session.unauthorized_record = ben
52
- assert session.valid?
53
-
54
- ben.update_attribute(:confirmed, false)
55
- refute session.valid?
56
- refute session.errors[:base].empty?
57
- end
58
- end
59
- end
60
- end