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,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module ParamsTest
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_params_key
9
- UserSession.params_key = "my_params_key"
10
- assert_equal "my_params_key", UserSession.params_key
11
-
12
- UserSession.params_key "user_credentials"
13
- assert_equal "user_credentials", UserSession.params_key
14
- end
15
-
16
- def test_single_access_allowed_request_types
17
- UserSession.single_access_allowed_request_types = ["my request type"]
18
- assert_equal ["my request type"], UserSession.single_access_allowed_request_types
19
- UserSession.single_access_allowed_request_types(
20
- ["application/rss+xml", "application/atom+xml"]
21
- )
22
- assert_equal(
23
- ["application/rss+xml", "application/atom+xml"],
24
- UserSession.single_access_allowed_request_types
25
- )
26
- end
27
- end
28
-
29
- class InstanceMethodsTest < ActiveSupport::TestCase
30
- def test_persist_persist_by_params
31
- ben = users(:ben)
32
- session = UserSession.new
33
-
34
- refute session.persisting?
35
- set_params_for(ben)
36
-
37
- refute session.persisting?
38
- refute session.unauthorized_record
39
- refute session.record
40
- assert_nil controller.session["user_credentials"]
41
-
42
- set_request_content_type("text/plain")
43
- refute session.persisting?
44
- refute session.unauthorized_record
45
- assert_nil controller.session["user_credentials"]
46
-
47
- set_request_content_type("application/atom+xml")
48
- assert session.persisting?
49
- assert_equal ben, session.record
50
-
51
- # should not persist since this is single access
52
- assert_nil controller.session["user_credentials"]
53
-
54
- set_request_content_type("application/rss+xml")
55
- assert session.persisting?
56
- assert_equal ben, session.unauthorized_record
57
- assert_nil controller.session["user_credentials"]
58
- end
59
- end
60
- end
61
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module PasswordTest
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_find_by_login_method
9
- UserSession.find_by_login_method = "my_login_method"
10
- assert_equal "my_login_method", UserSession.find_by_login_method
11
-
12
- UserSession.find_by_login_method "find_by_login"
13
- assert_equal "find_by_login", UserSession.find_by_login_method
14
- end
15
-
16
- def test_verify_password_method
17
- UserSession.verify_password_method = "my_login_method"
18
- assert_equal "my_login_method", UserSession.verify_password_method
19
-
20
- UserSession.verify_password_method "valid_password?"
21
- assert_equal "valid_password?", UserSession.verify_password_method
22
- end
23
-
24
- def test_generalize_credentials_error_mesages_set_to_false
25
- UserSession.generalize_credentials_error_messages false
26
- refute UserSession.generalize_credentials_error_messages
27
- session = UserSession.create(login: users(:ben).login, password: "invalud-password")
28
- assert_equal ["Password is not valid"], session.errors.full_messages
29
- end
30
-
31
- def test_generalize_credentials_error_messages_set_to_true
32
- UserSession.generalize_credentials_error_messages true
33
- assert UserSession.generalize_credentials_error_messages
34
- session = UserSession.create(login: users(:ben).login, password: "invalud-password")
35
- assert_equal ["Login/Password combination is not valid"], session.errors.full_messages
36
- end
37
-
38
- def test_generalize_credentials_error_messages_set_to_string
39
- UserSession.generalize_credentials_error_messages = "Custom Error Message"
40
- assert UserSession.generalize_credentials_error_messages
41
- session = UserSession.create(login: users(:ben).login, password: "invalud-password")
42
- assert_equal ["Custom Error Message"], session.errors.full_messages
43
- end
44
-
45
- def test_login_field
46
- UserSession.configured_password_methods = false
47
- UserSession.login_field = :saweet
48
- assert_equal :saweet, UserSession.login_field
49
- session = UserSession.new
50
- assert session.respond_to?(:saweet)
51
-
52
- UserSession.login_field :login
53
- assert_equal :login, UserSession.login_field
54
- session = UserSession.new
55
- assert session.respond_to?(:login)
56
- end
57
-
58
- def test_password_field
59
- UserSession.configured_password_methods = false
60
- UserSession.password_field = :saweet
61
- assert_equal :saweet, UserSession.password_field
62
- session = UserSession.new
63
- assert session.respond_to?(:saweet)
64
-
65
- UserSession.password_field :password
66
- assert_equal :password, UserSession.password_field
67
- session = UserSession.new
68
- assert session.respond_to?(:password)
69
- end
70
- end
71
-
72
- class InstanceMethodsTest < ActiveSupport::TestCase
73
- def test_init
74
- session = UserSession.new
75
- assert session.respond_to?(:login)
76
- assert session.respond_to?(:login=)
77
- assert session.respond_to?(:password)
78
- assert session.respond_to?(:password=)
79
- assert session.respond_to?(:protected_password, true)
80
- end
81
-
82
- def test_credentials
83
- session = UserSession.new
84
- session.credentials = { login: "login", password: "pass" }
85
- assert_equal "login", session.login
86
- assert_nil session.password
87
- assert_equal "pass", session.send(:protected_password)
88
- assert_equal({ password: "<protected>", login: "login" }, session.credentials)
89
- end
90
-
91
- def test_credentials_are_params_safe
92
- session = UserSession.new
93
- assert_nothing_raised { session.credentials = { hacker_method: "error!" } }
94
- end
95
-
96
- def test_save_with_credentials
97
- aaron = users(:aaron)
98
- session = UserSession.new(login: aaron.login, password: "aaronrocks")
99
- assert session.save
100
- refute session.new_session?
101
- assert_equal 1, session.record.login_count
102
- assert Time.now >= session.record.current_login_at
103
- assert_equal "1.1.1.1", session.record.current_login_ip
104
- end
105
- end
106
- end
107
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class PerishabilityTest < ActiveSupport::TestCase
7
- def test_after_save
8
- ben = users(:ben)
9
- old_perishable_token = ben.perishable_token
10
- UserSession.create(ben)
11
- assert_not_equal old_perishable_token, ben.perishable_token
12
-
13
- drew = employees(:drew)
14
- refute UserSession.create(drew).new_session?
15
- end
16
- end
17
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class PersistenceTest < ActiveSupport::TestCase
7
- def test_find
8
- aaron = users(:aaron)
9
- refute UserSession.find
10
- UserSession.allow_http_basic_auth = true
11
- http_basic_auth_for(aaron) { assert UserSession.find }
12
- set_cookie_for(aaron)
13
- assert UserSession.find
14
- unset_cookie
15
- set_session_for(aaron)
16
- session = UserSession.find
17
- assert session
18
- end
19
-
20
- def test_persisting
21
- # tested thoroughly in test_find
22
- end
23
-
24
- def test_should_set_remember_me_on_the_next_request
25
- aaron = users(:aaron)
26
- session = UserSession.new(aaron)
27
- session.remember_me = true
28
- refute UserSession.remember_me
29
- assert session.save
30
- assert session.remember_me?
31
- session = UserSession.find(aaron)
32
- assert session.remember_me?
33
- end
34
- end
35
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class ScopesTest < ActiveSupport::TestCase
7
- def test_scope_method
8
- assert_nil Authlogic::Session::Base.scope
9
-
10
- thread1 = Thread.new do
11
- scope = { id: :scope1 }
12
- Authlogic::Session::Base.send(:scope=, scope)
13
- assert_equal scope, Authlogic::Session::Base.scope
14
- end
15
- thread1.join
16
-
17
- assert_nil Authlogic::Session::Base.scope
18
-
19
- thread2 = Thread.new do
20
- scope = { id: :scope2 }
21
- Authlogic::Session::Base.send(:scope=, scope)
22
- assert_equal scope, Authlogic::Session::Base.scope
23
- end
24
- thread2.join
25
-
26
- assert_nil Authlogic::Session::Base.scope
27
- end
28
-
29
- def test_with_scope_method
30
- assert_raise(ArgumentError) { UserSession.with_scope }
31
-
32
- UserSession.with_scope(find_options: { conditions: "awesome = 1" }, id: "some_id") do
33
- assert_equal(
34
- { find_options: { conditions: "awesome = 1" }, id: "some_id" },
35
- UserSession.scope
36
- )
37
- end
38
-
39
- assert_nil UserSession.scope
40
- end
41
-
42
- def test_initialize
43
- UserSession.with_scope(find_options: { conditions: "awesome = 1" }, id: "some_id") do
44
- session = UserSession.new
45
- assert_equal(
46
- { find_options: { conditions: "awesome = 1" }, id: "some_id" },
47
- session.scope
48
- )
49
- session.id = :another_id
50
- assert_equal "another_id_some_id_test", session.send(:build_key, "test")
51
- end
52
- end
53
-
54
- def test_search_for_record_with_scopes
55
- binary_logic = companies(:binary_logic)
56
- ben = users(:ben)
57
- zack = users(:zack)
58
-
59
- session = UserSession.new
60
- assert_equal zack, session.send(:search_for_record, "find_by_login", zack.login)
61
-
62
- session.scope = { find_options: { conditions: ["company_id = ?", binary_logic.id] } }
63
- assert_nil session.send(:search_for_record, "find_by_login", zack.login)
64
-
65
- assert_equal ben, session.send(:search_for_record, "find_by_login", ben.login)
66
- end
67
- end
68
- end
@@ -1,80 +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_session_key
9
- UserSession.session_key = "my_session_key"
10
- assert_equal "my_session_key", UserSession.session_key
11
-
12
- UserSession.session_key "user_credentials"
13
- assert_equal "user_credentials", UserSession.session_key
14
- end
15
- end
16
-
17
- class InstanceMethodsTest < ActiveSupport::TestCase
18
- def test_persist_persist_by_session
19
- ben = users(:ben)
20
- set_session_for(ben)
21
- assert session = UserSession.find
22
- assert_equal ben, session.record
23
- assert_equal ben.persistence_token, controller.session["user_credentials"]
24
- end
25
-
26
- def test_persist_persist_by_session_with_session_fixation_attack
27
- ben = users(:ben)
28
- controller.session["user_credentials"] = "neo"
29
- controller.session["user_credentials_id"] = {
30
- select: " *,'neo' AS persistence_token FROM users WHERE id = #{ben.id} limit 1 -- "
31
- }
32
- @user_session = UserSession.find
33
- assert @user_session.blank?
34
- end
35
-
36
- def test_persist_persist_by_session_with_sql_injection_attack
37
- controller.session["user_credentials"] = { select: "ABRA CADABRA" }
38
- controller.session["user_credentials_id"] = nil
39
- assert_nothing_raised do
40
- @user_session = UserSession.find
41
- end
42
- assert @user_session.blank?
43
- end
44
-
45
- def test_persist_persist_by_session_with_token_only
46
- ben = users(:ben)
47
- set_session_for(ben)
48
- controller.session["user_credentials_id"] = nil
49
- session = UserSession.find
50
- assert_equal ben, session.record
51
- assert_equal ben.persistence_token, controller.session["user_credentials"]
52
- end
53
-
54
- def test_after_save_update_session
55
- ben = users(:ben)
56
- session = UserSession.new(ben)
57
- assert controller.session["user_credentials"].blank?
58
- assert session.save
59
- assert_equal ben.persistence_token, controller.session["user_credentials"]
60
- end
61
-
62
- def test_after_destroy_update_session
63
- ben = users(:ben)
64
- set_session_for(ben)
65
- assert_equal ben.persistence_token, controller.session["user_credentials"]
66
- assert session = UserSession.find
67
- assert session.destroy
68
- assert controller.session["user_credentials"].blank?
69
- end
70
-
71
- def test_after_persisting_update_session
72
- ben = users(:ben)
73
- set_cookie_for(ben)
74
- assert controller.session["user_credentials"].blank?
75
- assert UserSession.find
76
- assert_equal ben.persistence_token, controller.session["user_credentials"]
77
- end
78
- end
79
- end
80
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- module TimeoutTest
7
- class ConfigTest < ActiveSupport::TestCase
8
- def test_logout_on_timeout
9
- UserSession.logout_on_timeout = true
10
- assert UserSession.logout_on_timeout
11
-
12
- UserSession.logout_on_timeout false
13
- refute UserSession.logout_on_timeout
14
- end
15
- end
16
-
17
- class InstanceMethods < ActiveSupport::TestCase
18
- def test_stale_state
19
- UserSession.logout_on_timeout = true
20
- ben = users(:ben)
21
- ben.last_request_at = 3.years.ago
22
- ben.save
23
- set_session_for(ben)
24
-
25
- session = UserSession.new
26
- assert session.persisting?
27
- assert session.stale?
28
- assert_equal ben, session.stale_record
29
- assert_nil session.record
30
- assert_nil controller.session["user_credentials_id"]
31
-
32
- set_session_for(ben)
33
-
34
- ben.last_request_at = Time.now
35
- ben.save
36
-
37
- assert session.persisting?
38
- refute session.stale?
39
- assert_nil session.stale_record
40
-
41
- UserSession.logout_on_timeout = false
42
- end
43
-
44
- def test_should_be_stale_with_expired_remember_date
45
- UserSession.logout_on_timeout = true
46
- UserSession.remember_me = true
47
- UserSession.remember_me_for = 3.months
48
- ben = users(:ben)
49
- assert ben.save
50
- session = UserSession.new(ben)
51
- assert session.save
52
- Timecop.freeze(Time.now + 4.month)
53
- assert session.persisting?
54
- assert session.stale?
55
- UserSession.remember_me = false
56
- end
57
-
58
- def test_should_not_be_stale_with_valid_remember_date
59
- UserSession.logout_on_timeout = true # Default is 10.minutes
60
- UserSession.remember_me = true
61
- UserSession.remember_me_for = 3.months
62
- ben = users(:ben)
63
- assert ben.save
64
- session = UserSession.new(ben)
65
- assert session.save
66
- Timecop.freeze(Time.now + 2.months)
67
- assert session.persisting?
68
- refute session.stale?
69
- UserSession.remember_me = false
70
- end
71
-
72
- def test_successful_login
73
- UserSession.logout_on_timeout = true
74
- ben = users(:ben)
75
- session = UserSession.create(login: ben.login, password: "benrocks")
76
- refute session.new_session?
77
- session = UserSession.find
78
- assert session
79
- assert_equal ben, session.record
80
- UserSession.logout_on_timeout = false
81
- end
82
- end
83
- end
84
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class UnauthorizedRecordTest < ActiveSupport::TestCase
7
- def test_credentials
8
- ben = users(:ben)
9
- session = UserSession.new
10
- session.credentials = [ben]
11
- assert_equal ben, session.unauthorized_record
12
- assert_equal({ unauthorized_record: "<protected>" }, session.credentials)
13
- end
14
- end
15
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SessionTest
6
- class ValidationTest < ActiveSupport::TestCase
7
- def test_errors
8
- session = UserSession.new
9
- assert session.errors.is_a?(Authlogic::Session::Validation::Errors)
10
- end
11
-
12
- def test_valid
13
- session = UserSession.new
14
- refute session.valid?
15
- assert_nil session.record
16
- assert session.errors.count > 0
17
-
18
- ben = users(:ben)
19
- session.unauthorized_record = ben
20
- assert session.valid?
21
- assert_equal ben, session.attempted_record
22
- assert session.errors.empty?
23
- end
24
- end
25
- end